2021-04-14 21:38:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-04-14 21:38:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <WindowServer/AppletManager.h>
|
2022-02-25 10:18:30 +00:00
|
|
|
#include <WindowServer/ConnectionFromClient.h>
|
2021-04-14 21:38:53 +00:00
|
|
|
#include <WindowServer/Screen.h>
|
2022-02-25 10:18:30 +00:00
|
|
|
#include <WindowServer/WMConnectionFromClient.h>
|
2021-04-14 21:38:53 +00:00
|
|
|
|
|
|
|
namespace WindowServer {
|
|
|
|
|
2022-02-25 10:18:30 +00:00
|
|
|
HashMap<int, NonnullRefPtr<WMConnectionFromClient>> WMConnectionFromClient::s_connections {};
|
2021-04-14 21:38:53 +00:00
|
|
|
|
2022-02-25 10:18:30 +00:00
|
|
|
WMConnectionFromClient::WMConnectionFromClient(NonnullOwnPtr<Core::Stream::LocalSocket> client_socket, int client_id)
|
|
|
|
: IPC::ConnectionFromClient<WindowManagerClientEndpoint, WindowManagerServerEndpoint>(*this, move(client_socket), client_id)
|
2021-04-14 21:38:53 +00:00
|
|
|
{
|
|
|
|
s_connections.set(client_id, *this);
|
|
|
|
}
|
|
|
|
|
2022-02-25 10:18:30 +00:00
|
|
|
WMConnectionFromClient::~WMConnectionFromClient()
|
2021-04-14 21:38:53 +00:00
|
|
|
{
|
|
|
|
// The WM has gone away, so take away the applet manager (cause there's nowhere
|
|
|
|
// to draw it in).
|
|
|
|
AppletManager::the().set_position({});
|
|
|
|
}
|
|
|
|
|
2022-02-25 10:18:30 +00:00
|
|
|
void WMConnectionFromClient::die()
|
2021-04-14 21:38:53 +00:00
|
|
|
{
|
2021-08-30 18:12:48 +00:00
|
|
|
deferred_invoke([this] {
|
2021-04-14 21:38:53 +00:00
|
|
|
s_connections.remove(client_id());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-02-25 10:18:30 +00:00
|
|
|
void WMConnectionFromClient::set_applet_area_position(Gfx::IntPoint const& position)
|
2021-04-14 21:38:53 +00:00
|
|
|
{
|
|
|
|
if (m_window_id < 0) {
|
|
|
|
did_misbehave("SetAppletAreaPosition: WM didn't assign window as manager yet");
|
|
|
|
// FIXME: return ok boolean?
|
2021-05-02 03:20:28 +00:00
|
|
|
return;
|
2021-04-14 21:38:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 17:54:34 +00:00
|
|
|
AppletManager::the().set_position(position);
|
2021-08-24 12:01:01 +00:00
|
|
|
|
2022-02-25 10:18:30 +00:00
|
|
|
WindowServer::ConnectionFromClient::for_each_client([](auto& connection) {
|
2021-11-28 08:59:36 +00:00
|
|
|
if (auto result = connection.post_message(Messages::WindowClient::AppletAreaRectChanged(AppletManager::the().window()->rect())); result.is_error()) {
|
2022-02-25 10:18:30 +00:00
|
|
|
dbgln("WMConnectionFromClient::set_applet_area_position: {}", result.error());
|
2021-11-28 08:59:36 +00:00
|
|
|
}
|
2021-08-24 12:01:01 +00:00
|
|
|
});
|
2021-04-14 21:38:53 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 10:18:30 +00:00
|
|
|
void WMConnectionFromClient::set_active_window(i32 client_id, i32 window_id)
|
2021-04-14 21:38:53 +00:00
|
|
|
{
|
2022-02-25 10:18:30 +00:00
|
|
|
auto* client = WindowServer::ConnectionFromClient::from_client_id(client_id);
|
2021-04-14 21:38:53 +00:00
|
|
|
if (!client) {
|
|
|
|
did_misbehave("SetActiveWindow: Bad client ID");
|
|
|
|
return;
|
|
|
|
}
|
2021-05-02 17:54:34 +00:00
|
|
|
auto it = client->m_windows.find(window_id);
|
2021-04-14 21:38:53 +00:00
|
|
|
if (it == client->m_windows.end()) {
|
|
|
|
did_misbehave("SetActiveWindow: Bad window ID");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto& window = *(*it).value;
|
|
|
|
WindowManager::the().minimize_windows(window, false);
|
|
|
|
WindowManager::the().move_to_front_and_make_active(window);
|
|
|
|
}
|
|
|
|
|
2022-02-25 10:18:30 +00:00
|
|
|
void WMConnectionFromClient::popup_window_menu(i32 client_id, i32 window_id, Gfx::IntPoint const& screen_position)
|
2021-04-14 21:38:53 +00:00
|
|
|
{
|
2022-02-25 10:18:30 +00:00
|
|
|
auto* client = WindowServer::ConnectionFromClient::from_client_id(client_id);
|
2021-04-14 21:38:53 +00:00
|
|
|
if (!client) {
|
|
|
|
did_misbehave("PopupWindowMenu: Bad client ID");
|
|
|
|
return;
|
|
|
|
}
|
2021-05-02 17:54:34 +00:00
|
|
|
auto it = client->m_windows.find(window_id);
|
2021-04-14 21:38:53 +00:00
|
|
|
if (it == client->m_windows.end()) {
|
|
|
|
did_misbehave("PopupWindowMenu: Bad window ID");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto& window = *(*it).value;
|
|
|
|
if (auto* modal_window = window.blocking_modal_window()) {
|
2021-05-02 17:54:34 +00:00
|
|
|
modal_window->popup_window_menu(screen_position, WindowMenuDefaultAction::BasedOnWindowState);
|
2021-04-14 21:38:53 +00:00
|
|
|
} else {
|
2021-05-02 17:54:34 +00:00
|
|
|
window.popup_window_menu(screen_position, WindowMenuDefaultAction::BasedOnWindowState);
|
2021-04-14 21:38:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-25 10:18:30 +00:00
|
|
|
void WMConnectionFromClient::start_window_resize(i32 client_id, i32 window_id)
|
2021-04-14 21:38:53 +00:00
|
|
|
{
|
2022-02-25 10:18:30 +00:00
|
|
|
auto* client = WindowServer::ConnectionFromClient::from_client_id(client_id);
|
2021-04-14 21:38:53 +00:00
|
|
|
if (!client) {
|
|
|
|
did_misbehave("WM_StartWindowResize: Bad client ID");
|
|
|
|
return;
|
|
|
|
}
|
2021-05-02 17:54:34 +00:00
|
|
|
auto it = client->m_windows.find(window_id);
|
2021-04-14 21:38:53 +00:00
|
|
|
if (it == client->m_windows.end()) {
|
|
|
|
did_misbehave("WM_StartWindowResize: Bad window ID");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto& window = *(*it).value;
|
|
|
|
// FIXME: We are cheating a bit here by using the current cursor location and hard-coding the left button.
|
|
|
|
// Maybe the client should be allowed to specify what initiated this request?
|
2021-10-27 11:20:27 +00:00
|
|
|
WindowManager::the().start_window_resize(window, ScreenInput::the().cursor_location(), MouseButton::Primary);
|
2021-04-14 21:38:53 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 10:18:30 +00:00
|
|
|
void WMConnectionFromClient::set_window_minimized(i32 client_id, i32 window_id, bool minimized)
|
2021-04-14 21:38:53 +00:00
|
|
|
{
|
2022-02-25 10:18:30 +00:00
|
|
|
auto* client = WindowServer::ConnectionFromClient::from_client_id(client_id);
|
2021-04-14 21:38:53 +00:00
|
|
|
if (!client) {
|
|
|
|
did_misbehave("WM_SetWindowMinimized: Bad client ID");
|
|
|
|
return;
|
|
|
|
}
|
2021-05-02 17:54:34 +00:00
|
|
|
auto it = client->m_windows.find(window_id);
|
2021-04-14 21:38:53 +00:00
|
|
|
if (it == client->m_windows.end()) {
|
|
|
|
did_misbehave("WM_SetWindowMinimized: Bad window ID");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto& window = *(*it).value;
|
2021-05-02 17:54:34 +00:00
|
|
|
WindowManager::the().minimize_windows(window, minimized);
|
2021-04-14 21:38:53 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 10:18:30 +00:00
|
|
|
void WMConnectionFromClient::toggle_show_desktop()
|
2021-06-28 23:21:35 +00:00
|
|
|
{
|
|
|
|
bool should_hide = false;
|
2021-07-04 17:06:39 +00:00
|
|
|
auto& current_window_stack = WindowManager::the().current_window_stack();
|
|
|
|
current_window_stack.for_each_window([&](auto& window) {
|
|
|
|
if (window.type() == WindowType::Normal && window.is_minimizable()) {
|
|
|
|
if (!window.is_hidden() && !window.is_minimized()) {
|
|
|
|
should_hide = true;
|
|
|
|
return IterationDecision::Break;
|
2021-06-28 23:21:35 +00:00
|
|
|
}
|
2021-07-04 17:06:39 +00:00
|
|
|
}
|
|
|
|
return IterationDecision::Continue;
|
2021-06-28 23:21:35 +00:00
|
|
|
});
|
|
|
|
|
2021-07-04 17:06:39 +00:00
|
|
|
current_window_stack.for_each_window([&](auto& window) {
|
|
|
|
if (window.type() == WindowType::Normal && window.is_minimizable()) {
|
|
|
|
auto state = window.minimized_state();
|
|
|
|
if (state == WindowMinimizedState::None || state == WindowMinimizedState::Hidden) {
|
|
|
|
WindowManager::the().hide_windows(window, should_hide);
|
2021-06-28 23:21:35 +00:00
|
|
|
}
|
2021-07-04 17:06:39 +00:00
|
|
|
}
|
|
|
|
return IterationDecision::Continue;
|
2021-06-28 23:21:35 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-02-25 10:18:30 +00:00
|
|
|
void WMConnectionFromClient::set_event_mask(u32 event_mask)
|
2021-04-14 21:38:53 +00:00
|
|
|
{
|
2021-05-02 17:54:34 +00:00
|
|
|
m_event_mask = event_mask;
|
2021-04-14 21:38:53 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 10:18:30 +00:00
|
|
|
void WMConnectionFromClient::set_manager_window(i32 window_id)
|
2021-04-14 21:38:53 +00:00
|
|
|
{
|
2021-05-02 17:54:34 +00:00
|
|
|
m_window_id = window_id;
|
2021-04-14 21:38:53 +00:00
|
|
|
|
|
|
|
// Let the window manager know that we obtained a manager window, and should
|
|
|
|
// receive information about other windows.
|
|
|
|
WindowManager::the().greet_window_manager(*this);
|
|
|
|
}
|
|
|
|
|
2022-02-25 10:18:30 +00:00
|
|
|
void WMConnectionFromClient::set_workspace(u32 row, u32 col)
|
2021-07-18 18:42:53 +00:00
|
|
|
{
|
|
|
|
WindowManager::the().switch_to_window_stack(row, col);
|
|
|
|
}
|
|
|
|
|
2022-02-25 10:18:30 +00:00
|
|
|
void WMConnectionFromClient::set_window_taskbar_rect(i32 client_id, i32 window_id, Gfx::IntRect const& rect)
|
2021-04-14 21:38:53 +00:00
|
|
|
{
|
|
|
|
// Because the Taskbar (which should be the only user of this API) does not own the
|
|
|
|
// window or the client id, there is a possibility that it may send this message for
|
|
|
|
// a window or client that may have been destroyed already. This is not an error,
|
|
|
|
// and we should not call did_misbehave() for either.
|
2022-02-25 10:18:30 +00:00
|
|
|
auto* client = WindowServer::ConnectionFromClient::from_client_id(client_id);
|
2021-04-14 21:38:53 +00:00
|
|
|
if (!client)
|
|
|
|
return;
|
|
|
|
|
2021-05-02 17:54:34 +00:00
|
|
|
auto it = client->m_windows.find(window_id);
|
2021-04-14 21:38:53 +00:00
|
|
|
if (it == client->m_windows.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto& window = *(*it).value;
|
2021-05-02 17:54:34 +00:00
|
|
|
window.set_taskbar_rect(rect);
|
2021-04-14 21:38:53 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 23:06:35 +00:00
|
|
|
void WMConnectionFromClient::set_keymap(String const& keymap)
|
|
|
|
{
|
|
|
|
WindowManager::the().keymap_switcher()->set_keymap(keymap);
|
|
|
|
}
|
|
|
|
|
2021-04-14 21:38:53 +00:00
|
|
|
}
|