2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2020-02-15 02:10:34 +03:00
|
|
|
#include <AK/Badge.h>
|
2020-02-06 14:07:05 +03:00
|
|
|
#include <LibGfx/Bitmap.h>
|
2020-12-26 00:45:47 +03:00
|
|
|
#include <LibGfx/StandardCursor.h>
|
2020-02-06 14:04:00 +03:00
|
|
|
#include <LibGfx/SystemTheme.h>
|
2020-02-09 20:37:42 +03:00
|
|
|
#include <WindowServer/AppletManager.h>
|
2020-02-06 22:03:37 +03:00
|
|
|
#include <WindowServer/ClientConnection.h>
|
|
|
|
#include <WindowServer/Compositor.h>
|
|
|
|
#include <WindowServer/Menu.h>
|
|
|
|
#include <WindowServer/MenuBar.h>
|
|
|
|
#include <WindowServer/MenuItem.h>
|
|
|
|
#include <WindowServer/Screen.h>
|
|
|
|
#include <WindowServer/Window.h>
|
2019-12-02 11:33:37 +03:00
|
|
|
#include <WindowServer/WindowClientEndpoint.h>
|
2020-02-06 22:03:37 +03:00
|
|
|
#include <WindowServer/WindowManager.h>
|
|
|
|
#include <WindowServer/WindowSwitcher.h>
|
2019-05-24 20:32:46 +03:00
|
|
|
#include <errno.h>
|
2019-12-30 21:27:58 +03:00
|
|
|
#include <serenity.h>
|
2019-05-24 20:32:46 +03:00
|
|
|
#include <stdio.h>
|
2019-02-17 02:13:47 +03:00
|
|
|
#include <unistd.h>
|
2019-02-14 10:22:47 +03:00
|
|
|
|
2020-02-06 22:03:37 +03:00
|
|
|
namespace WindowServer {
|
2019-02-14 10:22:47 +03:00
|
|
|
|
2020-02-06 22:03:37 +03:00
|
|
|
HashMap<int, NonnullRefPtr<ClientConnection>>* s_connections;
|
|
|
|
|
|
|
|
void ClientConnection::for_each_client(Function<void(ClientConnection&)> callback)
|
2019-02-14 19:18:35 +03:00
|
|
|
{
|
|
|
|
if (!s_connections)
|
|
|
|
return;
|
2019-02-17 02:13:47 +03:00
|
|
|
for (auto& it : *s_connections) {
|
2019-02-14 19:18:35 +03:00
|
|
|
callback(*it.value);
|
|
|
|
}
|
|
|
|
}
|
2019-02-14 10:22:47 +03:00
|
|
|
|
2020-02-06 22:03:37 +03:00
|
|
|
ClientConnection* ClientConnection::from_client_id(int client_id)
|
2019-02-14 10:22:47 +03:00
|
|
|
{
|
|
|
|
if (!s_connections)
|
|
|
|
return nullptr;
|
2019-02-17 02:13:47 +03:00
|
|
|
auto it = s_connections->find(client_id);
|
|
|
|
if (it == s_connections->end())
|
2019-02-14 10:22:47 +03:00
|
|
|
return nullptr;
|
2019-09-22 01:17:53 +03:00
|
|
|
return (*it).value.ptr();
|
2019-02-14 10:22:47 +03:00
|
|
|
}
|
|
|
|
|
2020-07-06 14:23:39 +03:00
|
|
|
ClientConnection::ClientConnection(NonnullRefPtr<Core::LocalSocket> client_socket, int client_id)
|
2020-09-12 12:44:00 +03:00
|
|
|
: IPC::ClientConnection<WindowClientEndpoint, WindowServerEndpoint>(*this, move(client_socket), client_id)
|
2019-02-14 10:22:47 +03:00
|
|
|
{
|
|
|
|
if (!s_connections)
|
2020-02-06 22:03:37 +03:00
|
|
|
s_connections = new HashMap<int, NonnullRefPtr<ClientConnection>>;
|
2019-09-22 01:17:53 +03:00
|
|
|
s_connections->set(client_id, *this);
|
2019-07-17 11:31:52 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:03:37 +03:00
|
|
|
ClientConnection::~ClientConnection()
|
2019-07-17 11:31:52 +03:00
|
|
|
{
|
2020-04-22 01:07:48 +03:00
|
|
|
if (m_has_display_link)
|
|
|
|
Compositor::the().decrement_display_link_count({});
|
|
|
|
|
2020-02-06 22:03:37 +03:00
|
|
|
MenuManager::the().close_all_menus_from_client({}, *this);
|
2019-07-31 11:00:16 +03:00
|
|
|
auto windows = move(m_windows);
|
2020-03-31 14:52:35 +03:00
|
|
|
for (auto& window : windows) {
|
2020-01-25 12:25:49 +03:00
|
|
|
window.value->detach_client({});
|
2020-03-31 14:52:35 +03:00
|
|
|
if (window.value->type() == WindowType::MenuApplet)
|
|
|
|
AppletManager::the().remove_applet(window.value);
|
|
|
|
}
|
2019-07-17 11:31:52 +03:00
|
|
|
}
|
2019-02-20 23:59:13 +03:00
|
|
|
|
2020-02-06 22:03:37 +03:00
|
|
|
void ClientConnection::die()
|
2019-09-22 01:17:53 +03:00
|
|
|
{
|
2020-01-25 12:21:44 +03:00
|
|
|
deferred_invoke([this](auto&) {
|
|
|
|
s_connections->remove(client_id());
|
|
|
|
});
|
2019-09-22 01:17:53 +03:00
|
|
|
}
|
|
|
|
|
2020-06-10 11:57:59 +03:00
|
|
|
void ClientConnection::notify_about_new_screen_rect(const Gfx::IntRect& rect)
|
2019-04-03 18:22:14 +03:00
|
|
|
{
|
2020-02-06 22:20:44 +03:00
|
|
|
post_message(Messages::WindowClient::ScreenRectChanged(rect));
|
2019-04-03 18:22:14 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::CreateMenubarResponse> ClientConnection::handle(const Messages::WindowServer::CreateMenubar&)
|
2019-02-14 10:22:47 +03:00
|
|
|
{
|
2019-02-14 10:43:29 +03:00
|
|
|
int menubar_id = m_next_menubar_id++;
|
2020-02-06 22:03:37 +03:00
|
|
|
auto menubar = make<MenuBar>(*this, menubar_id);
|
2019-02-14 10:43:29 +03:00
|
|
|
m_menubars.set(menubar_id, move(menubar));
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::CreateMenubarResponse>(menubar_id);
|
2019-02-14 10:43:29 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::DestroyMenubarResponse> ClientConnection::handle(const Messages::WindowServer::DestroyMenubar& message)
|
2019-02-14 10:43:29 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
int menubar_id = message.menubar_id();
|
2019-02-14 10:43:29 +03:00
|
|
|
auto it = m_menubars.find(menubar_id);
|
|
|
|
if (it == m_menubars.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("DestroyMenubar: Bad menubar ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-02-14 10:22:47 +03:00
|
|
|
}
|
2019-02-14 10:43:29 +03:00
|
|
|
auto& menubar = *(*it).value;
|
2020-02-06 22:03:37 +03:00
|
|
|
MenuManager::the().close_menubar(menubar);
|
2019-02-14 10:43:29 +03:00
|
|
|
m_menubars.remove(it);
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::DestroyMenubarResponse>();
|
2019-02-14 10:43:29 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::CreateMenuResponse> ClientConnection::handle(const Messages::WindowServer::CreateMenu& message)
|
2019-02-14 10:43:29 +03:00
|
|
|
{
|
|
|
|
int menu_id = m_next_menu_id++;
|
2020-02-06 22:03:37 +03:00
|
|
|
auto menu = Menu::construct(this, menu_id, message.menu_title());
|
2019-02-14 10:43:29 +03:00
|
|
|
m_menus.set(menu_id, move(menu));
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::CreateMenuResponse>(menu_id);
|
2019-02-14 10:43:29 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::DestroyMenuResponse> ClientConnection::handle(const Messages::WindowServer::DestroyMenu& message)
|
2019-02-14 10:43:29 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
int menu_id = message.menu_id();
|
2019-02-14 10:43:29 +03:00
|
|
|
auto it = m_menus.find(menu_id);
|
|
|
|
if (it == m_menus.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("DestroyMenu: Bad menu ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-02-14 10:22:47 +03:00
|
|
|
}
|
2019-02-14 10:43:29 +03:00
|
|
|
auto& menu = *(*it).value;
|
2019-11-11 14:21:57 +03:00
|
|
|
menu.close();
|
2019-02-14 10:43:29 +03:00
|
|
|
m_menus.remove(it);
|
2019-09-22 01:17:53 +03:00
|
|
|
remove_child(menu);
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::DestroyMenuResponse>();
|
2019-02-14 10:43:29 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetApplicationMenubarResponse> ClientConnection::handle(const Messages::WindowServer::SetApplicationMenubar& message)
|
2019-02-14 10:43:29 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
int menubar_id = message.menubar_id();
|
2019-02-14 10:43:29 +03:00
|
|
|
auto it = m_menubars.find(menubar_id);
|
|
|
|
if (it == m_menubars.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("SetApplicationMenubar: Bad menubar ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-02-14 10:22:47 +03:00
|
|
|
}
|
2019-02-14 10:43:29 +03:00
|
|
|
auto& menubar = *(*it).value;
|
|
|
|
m_app_menubar = menubar.make_weak_ptr();
|
2020-02-06 22:03:37 +03:00
|
|
|
WindowManager::the().notify_client_changed_app_menubar(*this);
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::SetApplicationMenubarResponse>();
|
2019-02-14 10:43:29 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::AddMenuToMenubarResponse> ClientConnection::handle(const Messages::WindowServer::AddMenuToMenubar& message)
|
2019-02-14 10:43:29 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
int menubar_id = message.menubar_id();
|
|
|
|
int menu_id = message.menu_id();
|
2019-02-14 10:43:29 +03:00
|
|
|
auto it = m_menubars.find(menubar_id);
|
|
|
|
auto jt = m_menus.find(menu_id);
|
2019-02-14 11:32:34 +03:00
|
|
|
if (it == m_menubars.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("AddMenuToMenubar: Bad menubar ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-02-14 11:32:34 +03:00
|
|
|
}
|
|
|
|
if (jt == m_menus.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("AddMenuToMenubar: Bad menu ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-02-14 10:22:47 +03:00
|
|
|
}
|
2019-02-14 10:43:29 +03:00
|
|
|
auto& menubar = *(*it).value;
|
|
|
|
auto& menu = *(*jt).value;
|
2019-04-14 03:16:49 +03:00
|
|
|
menubar.add_menu(menu);
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::AddMenuToMenubarResponse>();
|
2019-02-14 10:43:29 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::AddMenuItemResponse> ClientConnection::handle(const Messages::WindowServer::AddMenuItem& message)
|
2019-02-14 10:43:29 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
int menu_id = message.menu_id();
|
|
|
|
unsigned identifier = message.identifier();
|
2019-02-14 10:43:29 +03:00
|
|
|
auto it = m_menus.find(menu_id);
|
|
|
|
if (it == m_menus.end()) {
|
2021-01-17 20:39:00 +03:00
|
|
|
dbgln("AddMenuItem: Bad menu ID: {}", menu_id);
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-02-14 10:22:47 +03:00
|
|
|
}
|
2019-02-14 10:43:29 +03:00
|
|
|
auto& menu = *(*it).value;
|
2020-02-06 22:03:37 +03:00
|
|
|
auto menu_item = make<MenuItem>(menu, identifier, message.text(), message.shortcut(), message.enabled(), message.checkable(), message.checked());
|
2020-07-10 22:29:21 +03:00
|
|
|
if (message.is_default())
|
|
|
|
menu_item->set_default(true);
|
2021-01-16 12:59:25 +03:00
|
|
|
menu_item->set_icon(message.icon().bitmap());
|
2019-12-02 11:33:37 +03:00
|
|
|
menu_item->set_submenu_id(message.submenu_id());
|
2020-01-08 22:44:41 +03:00
|
|
|
menu_item->set_exclusive(message.exclusive());
|
2019-08-26 19:54:44 +03:00
|
|
|
menu.add_item(move(menu_item));
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::AddMenuItemResponse>();
|
2019-02-14 10:43:29 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::PopupMenuResponse> ClientConnection::handle(const Messages::WindowServer::PopupMenu& message)
|
2019-04-12 18:10:30 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
int menu_id = message.menu_id();
|
|
|
|
auto position = message.screen_position();
|
2019-04-12 18:10:30 +03:00
|
|
|
auto it = m_menus.find(menu_id);
|
|
|
|
if (it == m_menus.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("PopupMenu: Bad menu ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-04-12 18:10:30 +03:00
|
|
|
}
|
|
|
|
auto& menu = *(*it).value;
|
2019-05-16 02:06:21 +03:00
|
|
|
menu.popup(position);
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::PopupMenuResponse>();
|
2019-04-12 18:10:30 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::DismissMenuResponse> ClientConnection::handle(const Messages::WindowServer::DismissMenu& message)
|
2019-04-14 02:53:19 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
int menu_id = message.menu_id();
|
2019-04-14 02:53:19 +03:00
|
|
|
auto it = m_menus.find(menu_id);
|
|
|
|
if (it == m_menus.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("DismissMenu: Bad menu ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-04-14 02:53:19 +03:00
|
|
|
}
|
|
|
|
auto& menu = *(*it).value;
|
|
|
|
menu.close();
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::DismissMenuResponse>();
|
2019-04-14 02:53:19 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::UpdateMenuItemResponse> ClientConnection::handle(const Messages::WindowServer::UpdateMenuItem& message)
|
2019-04-12 03:53:27 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
int menu_id = message.menu_id();
|
2019-04-12 03:53:27 +03:00
|
|
|
auto it = m_menus.find(menu_id);
|
|
|
|
if (it == m_menus.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("UpdateMenuItem: Bad menu ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-04-12 03:53:27 +03:00
|
|
|
}
|
|
|
|
auto& menu = *(*it).value;
|
2019-12-02 11:33:37 +03:00
|
|
|
auto* menu_item = menu.item_with_identifier(message.identifier());
|
2019-04-12 03:53:27 +03:00
|
|
|
if (!menu_item) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("UpdateMenuItem: Bad menu item identifier");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-04-12 03:53:27 +03:00
|
|
|
}
|
2019-12-02 11:33:37 +03:00
|
|
|
menu_item->set_text(message.text());
|
|
|
|
menu_item->set_shortcut_text(message.shortcut());
|
|
|
|
menu_item->set_enabled(message.enabled());
|
|
|
|
menu_item->set_checkable(message.checkable());
|
2020-07-10 22:29:21 +03:00
|
|
|
menu_item->set_default(message.is_default());
|
2019-12-02 11:33:37 +03:00
|
|
|
if (message.checkable())
|
|
|
|
menu_item->set_checked(message.checked());
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::UpdateMenuItemResponse>();
|
2019-04-12 03:53:27 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::AddMenuSeparatorResponse> ClientConnection::handle(const Messages::WindowServer::AddMenuSeparator& message)
|
2019-02-14 10:43:29 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
int menu_id = message.menu_id();
|
2019-02-14 10:43:29 +03:00
|
|
|
auto it = m_menus.find(menu_id);
|
|
|
|
if (it == m_menus.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("AddMenuSeparator: Bad menu ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-02-14 10:22:47 +03:00
|
|
|
}
|
2019-02-14 10:43:29 +03:00
|
|
|
auto& menu = *(*it).value;
|
2020-02-06 22:03:37 +03:00
|
|
|
menu.add_item(make<MenuItem>(menu, MenuItem::Separator));
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::AddMenuSeparatorResponse>();
|
2019-02-14 10:43:29 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::MoveWindowToFrontResponse> ClientConnection::handle(const Messages::WindowServer::MoveWindowToFront& message)
|
2019-06-01 21:10:37 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
auto it = m_windows.find(message.window_id());
|
2019-06-01 21:10:37 +03:00
|
|
|
if (it == m_windows.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("MoveWindowToFront: Bad window ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-06-01 21:10:37 +03:00
|
|
|
}
|
2020-02-06 22:03:37 +03:00
|
|
|
WindowManager::the().move_to_front_and_make_active(*(*it).value);
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::MoveWindowToFrontResponse>();
|
2019-06-01 21:10:37 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetFullscreenResponse> ClientConnection::handle(const Messages::WindowServer::SetFullscreen& message)
|
2019-09-16 19:38:42 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
auto it = m_windows.find(message.window_id());
|
2019-09-16 19:38:42 +03:00
|
|
|
if (it == m_windows.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("SetFullscreen: Bad window ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-09-16 19:38:42 +03:00
|
|
|
}
|
2019-12-02 11:33:37 +03:00
|
|
|
it->value->set_fullscreen(message.fullscreen());
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::SetFullscreenResponse>();
|
2019-09-16 19:38:42 +03:00
|
|
|
}
|
|
|
|
|
2021-02-21 09:10:21 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetFramelessResponse> ClientConnection::handle(const Messages::WindowServer::SetFrameless& message)
|
|
|
|
{
|
|
|
|
auto it = m_windows.find(message.window_id());
|
|
|
|
if (it == m_windows.end()) {
|
|
|
|
did_misbehave("SetFrameless: Bad window ID");
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
it->value->set_frameless(message.frameless());
|
|
|
|
WindowManager::the().tell_wm_listeners_window_state_changed(*it->value);
|
|
|
|
return make<Messages::WindowServer::SetFramelessResponse>();
|
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetWindowOpacityResponse> ClientConnection::handle(const Messages::WindowServer::SetWindowOpacity& message)
|
2019-02-19 03:42:53 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
auto it = m_windows.find(message.window_id());
|
2019-02-19 03:42:53 +03:00
|
|
|
if (it == m_windows.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("SetWindowOpacity: Bad window ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-02-19 03:42:53 +03:00
|
|
|
}
|
2019-12-02 11:33:37 +03:00
|
|
|
it->value->set_opacity(message.opacity());
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::SetWindowOpacityResponse>();
|
2019-02-19 03:42:53 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
void ClientConnection::handle(const Messages::WindowServer::AsyncSetWallpaper& message)
|
2019-03-21 17:54:19 +03:00
|
|
|
{
|
2020-02-06 22:03:37 +03:00
|
|
|
Compositor::the().set_wallpaper(message.path(), [&](bool success) {
|
2020-02-06 22:20:44 +03:00
|
|
|
post_message(Messages::WindowClient::AsyncSetWallpaperFinished(success));
|
2019-05-01 17:07:47 +03:00
|
|
|
});
|
2019-03-21 17:54:19 +03:00
|
|
|
}
|
|
|
|
|
2020-03-29 13:32:06 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetBackgroundColorResponse> ClientConnection::handle(const Messages::WindowServer::SetBackgroundColor& message)
|
|
|
|
{
|
2020-04-29 21:58:39 +03:00
|
|
|
Compositor::the().set_background_color(message.background_color());
|
2020-03-29 13:32:06 +03:00
|
|
|
return make<Messages::WindowServer::SetBackgroundColorResponse>();
|
|
|
|
}
|
|
|
|
|
|
|
|
OwnPtr<Messages::WindowServer::SetWallpaperModeResponse> ClientConnection::handle(const Messages::WindowServer::SetWallpaperMode& message)
|
|
|
|
{
|
|
|
|
Compositor::the().set_wallpaper_mode(message.mode());
|
|
|
|
return make<Messages::WindowServer::SetWallpaperModeResponse>();
|
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::GetWallpaperResponse> ClientConnection::handle(const Messages::WindowServer::GetWallpaper&)
|
2019-03-21 17:54:19 +03:00
|
|
|
{
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::GetWallpaperResponse>(Compositor::the().wallpaper_path());
|
2019-03-21 17:54:19 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetResolutionResponse> ClientConnection::handle(const Messages::WindowServer::SetResolution& message)
|
2019-09-03 14:45:02 +03:00
|
|
|
{
|
2021-01-15 22:53:53 +03:00
|
|
|
return make<Messages::WindowServer::SetResolutionResponse>(WindowManager::the().set_resolution(message.resolution().width(), message.resolution().height(), message.scale_factor()), WindowManager::the().resolution(), WindowManager::the().scale_factor());
|
2019-09-03 14:45:02 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetWindowTitleResponse> ClientConnection::handle(const Messages::WindowServer::SetWindowTitle& message)
|
2019-02-14 10:43:29 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
auto it = m_windows.find(message.window_id());
|
2019-02-14 10:43:29 +03:00
|
|
|
if (it == m_windows.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("SetWindowTitle: Bad window ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-02-14 10:22:47 +03:00
|
|
|
}
|
2019-12-02 11:33:37 +03:00
|
|
|
it->value->set_title(message.title());
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::SetWindowTitleResponse>();
|
2019-02-14 10:43:29 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::GetWindowTitleResponse> ClientConnection::handle(const Messages::WindowServer::GetWindowTitle& message)
|
2019-02-14 10:43:29 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
auto it = m_windows.find(message.window_id());
|
2019-02-14 10:43:29 +03:00
|
|
|
if (it == m_windows.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("GetWindowTitle: Bad window ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-02-14 10:22:47 +03:00
|
|
|
}
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::GetWindowTitleResponse>(it->value->title());
|
2019-02-14 10:43:29 +03:00
|
|
|
}
|
|
|
|
|
2020-06-18 13:14:00 +03:00
|
|
|
OwnPtr<Messages::WindowServer::IsMaximizedResponse> ClientConnection::handle(const Messages::WindowServer::IsMaximized& message)
|
|
|
|
{
|
|
|
|
auto it = m_windows.find(message.window_id());
|
|
|
|
if (it == m_windows.end()) {
|
|
|
|
did_misbehave("IsMaximized: Bad window ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2020-06-18 13:14:00 +03:00
|
|
|
}
|
2020-08-30 21:49:56 +03:00
|
|
|
return make<Messages::WindowServer::IsMaximizedResponse>(it->value->is_maximized());
|
2020-06-18 13:14:00 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetWindowIconBitmapResponse> ClientConnection::handle(const Messages::WindowServer::SetWindowIconBitmap& message)
|
2019-07-28 11:18:49 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
auto it = m_windows.find(message.window_id());
|
2019-07-28 11:18:49 +03:00
|
|
|
if (it == m_windows.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("SetWindowIconBitmap: Bad window ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-07-28 11:18:49 +03:00
|
|
|
}
|
|
|
|
auto& window = *(*it).value;
|
|
|
|
|
2020-03-29 20:10:19 +03:00
|
|
|
if (message.icon().is_valid()) {
|
|
|
|
window.set_icon(*message.icon().bitmap());
|
2019-07-28 11:18:49 +03:00
|
|
|
} else {
|
2020-03-29 20:10:19 +03:00
|
|
|
window.set_default_icon();
|
2019-07-28 11:18:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
window.frame().invalidate_title_bar();
|
2020-02-06 22:03:37 +03:00
|
|
|
WindowManager::the().tell_wm_listeners_window_icon_changed(window);
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::SetWindowIconBitmapResponse>();
|
2019-07-28 11:18:49 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetWindowRectResponse> ClientConnection::handle(const Messages::WindowServer::SetWindowRect& message)
|
2019-02-14 10:43:29 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
int window_id = message.window_id();
|
2019-02-14 10:43:29 +03:00
|
|
|
auto it = m_windows.find(window_id);
|
|
|
|
if (it == m_windows.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("SetWindowRect: Bad window ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-02-14 10:22:47 +03:00
|
|
|
}
|
2019-02-14 10:43:29 +03:00
|
|
|
auto& window = *(*it).value;
|
2019-05-17 22:33:44 +03:00
|
|
|
if (window.is_fullscreen()) {
|
2021-01-09 20:51:44 +03:00
|
|
|
dbgln("ClientConnection: Ignoring SetWindowRect request for fullscreen window");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-05-17 22:33:44 +03:00
|
|
|
}
|
2020-07-31 04:52:45 +03:00
|
|
|
|
|
|
|
if (message.rect().location() != window.rect().location()) {
|
|
|
|
window.set_default_positioned(false);
|
|
|
|
}
|
2021-01-29 00:47:32 +03:00
|
|
|
auto rect = message.rect();
|
|
|
|
window.apply_minimum_size(rect);
|
|
|
|
window.set_rect(rect);
|
|
|
|
window.nudge_into_desktop();
|
2021-01-22 23:46:59 +03:00
|
|
|
window.request_update(window.rect());
|
|
|
|
return make<Messages::WindowServer::SetWindowRectResponse>(window.rect());
|
2019-02-14 10:43:29 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::GetWindowRectResponse> ClientConnection::handle(const Messages::WindowServer::GetWindowRect& message)
|
2019-02-14 10:43:29 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
int window_id = message.window_id();
|
2019-02-14 10:43:29 +03:00
|
|
|
auto it = m_windows.find(window_id);
|
|
|
|
if (it == m_windows.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("GetWindowRect: Bad window ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-02-14 10:22:47 +03:00
|
|
|
}
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::GetWindowRectResponse>(it->value->rect());
|
2019-02-14 10:43:29 +03:00
|
|
|
}
|
|
|
|
|
2021-02-15 16:59:43 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetWindowMinimumSizeResponse> ClientConnection::handle(const Messages::WindowServer::SetWindowMinimumSize& message)
|
|
|
|
{
|
|
|
|
int window_id = message.window_id();
|
|
|
|
auto it = m_windows.find(window_id);
|
|
|
|
if (it == m_windows.end()) {
|
|
|
|
did_misbehave("SetWindowMinimumSize: Bad window ID");
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
auto& window = *(*it).value;
|
|
|
|
if (window.is_fullscreen()) {
|
|
|
|
dbgln("ClientConnection: Ignoring SetWindowMinimumSize request for fullscreen window");
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
window.set_minimum_size(message.size());
|
|
|
|
|
|
|
|
if (window.width() < window.minimum_size().width() || window.height() < window.minimum_size().height()) {
|
|
|
|
// New minimum size is larger than the current window size, resize accordingly.
|
|
|
|
auto new_rect = window.rect();
|
|
|
|
bool did_size_clamp = window.apply_minimum_size(new_rect);
|
|
|
|
window.set_rect(new_rect);
|
|
|
|
window.nudge_into_desktop();
|
|
|
|
window.request_update(window.rect());
|
|
|
|
|
|
|
|
if (did_size_clamp)
|
|
|
|
window.refresh_client_size();
|
|
|
|
}
|
|
|
|
|
|
|
|
return make<Messages::WindowServer::SetWindowMinimumSizeResponse>();
|
|
|
|
}
|
|
|
|
|
|
|
|
OwnPtr<Messages::WindowServer::GetWindowMinimumSizeResponse> ClientConnection::handle(const Messages::WindowServer::GetWindowMinimumSize& message)
|
|
|
|
{
|
|
|
|
int window_id = message.window_id();
|
|
|
|
auto it = m_windows.find(window_id);
|
|
|
|
if (it == m_windows.end()) {
|
|
|
|
did_misbehave("GetWindowMinimumSize: Bad window ID");
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
return make<Messages::WindowServer::GetWindowMinimumSizeResponse>(it->value->minimum_size());
|
|
|
|
}
|
|
|
|
|
2020-07-24 23:16:30 +03:00
|
|
|
OwnPtr<Messages::WindowServer::GetWindowRectInMenubarResponse> ClientConnection::handle(const Messages::WindowServer::GetWindowRectInMenubar& message)
|
|
|
|
{
|
|
|
|
int window_id = message.window_id();
|
|
|
|
auto it = m_windows.find(window_id);
|
|
|
|
if (it == m_windows.end()) {
|
|
|
|
did_misbehave("GetWindowRectInMenubar: Bad window ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2020-07-24 23:16:30 +03:00
|
|
|
}
|
|
|
|
return make<Messages::WindowServer::GetWindowRectInMenubarResponse>(it->value->rect_in_menubar());
|
|
|
|
}
|
|
|
|
|
2020-05-01 23:59:38 +03:00
|
|
|
Window* ClientConnection::window_from_id(i32 window_id)
|
|
|
|
{
|
|
|
|
auto it = m_windows.find(window_id);
|
|
|
|
if (it == m_windows.end())
|
|
|
|
return nullptr;
|
|
|
|
return it->value.ptr();
|
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::CreateWindowResponse> ClientConnection::handle(const Messages::WindowServer::CreateWindow& message)
|
2019-02-14 10:43:29 +03:00
|
|
|
{
|
2020-07-15 04:17:00 +03:00
|
|
|
Window* parent_window = nullptr;
|
2020-05-01 23:59:38 +03:00
|
|
|
if (message.parent_window_id()) {
|
2020-07-15 04:17:00 +03:00
|
|
|
parent_window = window_from_id(message.parent_window_id());
|
2020-05-01 23:59:38 +03:00
|
|
|
if (!parent_window) {
|
|
|
|
did_misbehave("CreateWindow with bad parent_window_id");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2020-05-01 23:59:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-15 04:17:00 +03:00
|
|
|
int window_id = m_next_window_id++;
|
|
|
|
auto window = Window::construct(*this, (WindowType)message.type(), window_id, message.modal(), message.minimizable(), message.frameless(), message.resizable(), message.fullscreen(), message.accessory(), parent_window);
|
|
|
|
|
2019-12-02 11:33:37 +03:00
|
|
|
window->set_has_alpha_channel(message.has_alpha_channel());
|
|
|
|
window->set_title(message.title());
|
2020-04-18 21:56:56 +03:00
|
|
|
if (!message.fullscreen()) {
|
2020-07-31 04:52:45 +03:00
|
|
|
auto rect = message.rect();
|
2021-02-16 18:10:39 +03:00
|
|
|
if (message.auto_position() && window->is_movable()) {
|
2020-07-31 04:52:45 +03:00
|
|
|
rect = { WindowManager::the().get_recommended_window_position({ 100, 100 }), message.rect().size() };
|
|
|
|
window->set_default_positioned(true);
|
|
|
|
}
|
2021-02-15 16:59:43 +03:00
|
|
|
window->set_minimum_size(message.minimum_size());
|
|
|
|
bool did_size_clamp = window->apply_minimum_size(rect);
|
2021-01-22 23:46:59 +03:00
|
|
|
window->set_rect(rect);
|
2021-01-29 00:47:32 +03:00
|
|
|
window->nudge_into_desktop();
|
2021-02-15 16:59:43 +03:00
|
|
|
|
|
|
|
if (did_size_clamp)
|
|
|
|
window->refresh_client_size();
|
2020-04-18 21:56:56 +03:00
|
|
|
}
|
2020-04-18 22:10:16 +03:00
|
|
|
if (window->type() == WindowType::Desktop) {
|
2020-04-18 22:18:11 +03:00
|
|
|
window->set_rect(WindowManager::the().desktop_rect());
|
2020-04-18 22:10:16 +03:00
|
|
|
window->recalculate_rect();
|
|
|
|
}
|
2019-12-02 11:33:37 +03:00
|
|
|
window->set_opacity(message.opacity());
|
2021-02-15 02:42:37 +03:00
|
|
|
window->set_alpha_hit_threshold(message.alpha_hit_threshold());
|
2019-12-02 11:33:37 +03:00
|
|
|
window->set_size_increment(message.size_increment());
|
|
|
|
window->set_base_size(message.base_size());
|
2020-08-21 23:19:10 +03:00
|
|
|
window->set_resize_aspect_ratio(message.resize_aspect_ratio());
|
2021-02-10 21:54:58 +03:00
|
|
|
window->invalidate(true, true);
|
2020-02-06 22:03:37 +03:00
|
|
|
if (window->type() == WindowType::MenuApplet)
|
2020-02-09 20:37:42 +03:00
|
|
|
AppletManager::the().add_applet(*window);
|
2019-02-14 10:43:29 +03:00
|
|
|
m_windows.set(window_id, move(window));
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::CreateWindowResponse>(window_id);
|
2019-02-14 10:43:29 +03:00
|
|
|
}
|
|
|
|
|
2020-05-02 00:53:05 +03:00
|
|
|
void ClientConnection::destroy_window(Window& window, Vector<i32>& destroyed_window_ids)
|
2019-02-14 10:43:29 +03:00
|
|
|
{
|
2020-05-02 00:53:05 +03:00
|
|
|
for (auto& child_window : window.child_windows()) {
|
|
|
|
if (!child_window)
|
|
|
|
continue;
|
2021-02-23 22:42:32 +03:00
|
|
|
VERIFY(child_window->window_id() != window.window_id());
|
2020-05-02 00:53:05 +03:00
|
|
|
destroy_window(*child_window, destroyed_window_ids);
|
2019-02-14 10:22:47 +03:00
|
|
|
}
|
2020-05-02 00:53:05 +03:00
|
|
|
|
2020-07-16 20:08:39 +03:00
|
|
|
for (auto& accessory_window : window.accessory_windows()) {
|
|
|
|
if (!accessory_window)
|
|
|
|
continue;
|
2021-02-23 22:42:32 +03:00
|
|
|
VERIFY(accessory_window->window_id() != window.window_id());
|
2020-07-16 20:08:39 +03:00
|
|
|
destroy_window(*accessory_window, destroyed_window_ids);
|
|
|
|
}
|
|
|
|
|
2020-05-02 00:53:05 +03:00
|
|
|
destroyed_window_ids.append(window.window_id());
|
2019-12-16 17:05:45 +03:00
|
|
|
|
2020-02-06 22:03:37 +03:00
|
|
|
if (window.type() == WindowType::MenuApplet)
|
2020-02-09 20:37:42 +03:00
|
|
|
AppletManager::the().remove_applet(window);
|
2019-12-16 17:05:45 +03:00
|
|
|
|
2020-07-16 20:08:39 +03:00
|
|
|
window.destroy();
|
2019-09-22 01:17:53 +03:00
|
|
|
remove_child(window);
|
2020-05-02 00:53:05 +03:00
|
|
|
m_windows.remove(window.window_id());
|
|
|
|
}
|
2019-12-02 11:33:37 +03:00
|
|
|
|
2020-05-02 00:53:05 +03:00
|
|
|
OwnPtr<Messages::WindowServer::DestroyWindowResponse> ClientConnection::handle(const Messages::WindowServer::DestroyWindow& message)
|
|
|
|
{
|
|
|
|
auto it = m_windows.find(message.window_id());
|
|
|
|
if (it == m_windows.end()) {
|
|
|
|
did_misbehave("DestroyWindow: Bad window ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2020-05-02 00:53:05 +03:00
|
|
|
}
|
|
|
|
auto& window = *(*it).value;
|
|
|
|
Vector<i32> destroyed_window_ids;
|
|
|
|
destroy_window(window, destroyed_window_ids);
|
|
|
|
return make<Messages::WindowServer::DestroyWindowResponse>(destroyed_window_ids);
|
2019-02-14 10:43:29 +03:00
|
|
|
}
|
|
|
|
|
2020-02-19 18:45:06 +03:00
|
|
|
void ClientConnection::post_paint_message(Window& window, bool ignore_occlusion)
|
2019-04-03 20:38:44 +03:00
|
|
|
{
|
2019-05-05 00:57:23 +03:00
|
|
|
auto rect_set = window.take_pending_paint_rects();
|
2020-02-19 18:45:06 +03:00
|
|
|
if (window.is_minimized() || (!ignore_occlusion && window.is_occluded()))
|
2019-05-05 00:57:23 +03:00
|
|
|
return;
|
2019-12-02 11:33:37 +03:00
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
post_message(Messages::WindowClient::Paint(window.window_id(), window.size(), rect_set.rects()));
|
2019-04-03 20:38:44 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
void ClientConnection::handle(const Messages::WindowServer::InvalidateRect& message)
|
2019-02-14 10:43:29 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
auto it = m_windows.find(message.window_id());
|
2019-02-14 10:43:29 +03:00
|
|
|
if (it == m_windows.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("InvalidateRect: Bad window ID");
|
2019-02-14 11:32:34 +03:00
|
|
|
return;
|
2019-02-14 10:22:47 +03:00
|
|
|
}
|
2019-02-26 12:50:25 +03:00
|
|
|
auto& window = *(*it).value;
|
2020-02-25 16:49:47 +03:00
|
|
|
for (size_t i = 0; i < message.rects().size(); ++i)
|
2020-02-19 18:45:06 +03:00
|
|
|
window.request_update(message.rects()[i].intersected({ {}, window.size() }), message.ignore_occlusion());
|
2019-02-14 10:43:29 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
void ClientConnection::handle(const Messages::WindowServer::DidFinishPainting& message)
|
2019-02-14 10:43:29 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
int window_id = message.window_id();
|
2019-02-14 10:43:29 +03:00
|
|
|
auto it = m_windows.find(window_id);
|
|
|
|
if (it == m_windows.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("DidFinishPainting: Bad window ID");
|
2019-02-14 11:32:34 +03:00
|
|
|
return;
|
2019-02-14 10:22:47 +03:00
|
|
|
}
|
2019-02-14 10:43:29 +03:00
|
|
|
auto& window = *(*it).value;
|
2019-12-02 11:33:37 +03:00
|
|
|
for (auto& rect : message.rects())
|
2020-05-19 20:14:20 +03:00
|
|
|
window.invalidate(rect);
|
2021-02-21 21:56:59 +03:00
|
|
|
if (window.has_alpha_channel() && window.alpha_hit_threshold() > 0.0)
|
|
|
|
WindowManager::the().reevaluate_hovered_window(&window);
|
2019-05-12 05:15:25 +03:00
|
|
|
|
2020-02-06 22:03:37 +03:00
|
|
|
WindowSwitcher::the().refresh_if_needed();
|
2019-02-14 10:43:29 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetWindowBackingStoreResponse> ClientConnection::handle(const Messages::WindowServer::SetWindowBackingStore& message)
|
2019-02-20 23:59:13 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
int window_id = message.window_id();
|
2019-02-20 23:59:13 +03:00
|
|
|
auto it = m_windows.find(window_id);
|
|
|
|
if (it == m_windows.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("SetWindowBackingStore: Bad window ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-02-20 23:59:13 +03:00
|
|
|
}
|
|
|
|
auto& window = *(*it).value;
|
2021-01-15 14:11:22 +03:00
|
|
|
if (window.last_backing_store() && window.last_backing_store_serial() == message.serial()) {
|
2019-03-18 22:52:23 +03:00
|
|
|
window.swap_backing_stores();
|
|
|
|
} else {
|
2021-01-19 20:10:47 +03:00
|
|
|
// FIXME: Plumb scale factor here eventually.
|
2021-01-15 14:11:22 +03:00
|
|
|
auto backing_store = Gfx::Bitmap::create_with_anon_fd(
|
2020-02-15 01:02:47 +03:00
|
|
|
message.has_alpha_channel() ? Gfx::BitmapFormat::RGBA32 : Gfx::BitmapFormat::RGB32,
|
2021-01-15 14:11:22 +03:00
|
|
|
message.anon_file().take_fd(),
|
|
|
|
message.size(),
|
2021-01-19 20:10:47 +03:00
|
|
|
1,
|
2021-01-17 01:57:57 +03:00
|
|
|
{},
|
2021-01-15 14:11:22 +03:00
|
|
|
Gfx::Bitmap::ShouldCloseAnonymousFile::Yes);
|
|
|
|
window.set_backing_store(move(backing_store), message.serial());
|
2019-03-18 22:52:23 +03:00
|
|
|
}
|
2019-03-17 06:23:54 +03:00
|
|
|
|
2019-12-02 11:33:37 +03:00
|
|
|
if (message.flush_immediately())
|
2020-08-18 07:45:10 +03:00
|
|
|
window.invalidate(false);
|
2019-03-17 06:23:54 +03:00
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::SetWindowBackingStoreResponse>();
|
2019-02-20 23:59:13 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetGlobalCursorTrackingResponse> ClientConnection::handle(const Messages::WindowServer::SetGlobalCursorTracking& message)
|
2019-02-14 10:43:29 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
int window_id = message.window_id();
|
2019-02-14 10:43:29 +03:00
|
|
|
auto it = m_windows.find(window_id);
|
|
|
|
if (it == m_windows.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("SetGlobalCursorTracking: Bad window ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-02-14 10:22:47 +03:00
|
|
|
}
|
2019-12-02 11:33:37 +03:00
|
|
|
it->value->set_global_cursor_tracking_enabled(message.enabled());
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::SetGlobalCursorTrackingResponse>();
|
2019-02-14 10:43:29 +03:00
|
|
|
}
|
|
|
|
|
2020-09-10 21:55:39 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetWindowCursorResponse> ClientConnection::handle(const Messages::WindowServer::SetWindowCursor& message)
|
2019-04-01 00:52:02 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
auto it = m_windows.find(message.window_id());
|
2019-04-01 00:52:02 +03:00
|
|
|
if (it == m_windows.end()) {
|
2020-09-10 21:55:39 +03:00
|
|
|
did_misbehave("SetWindowCursor: Bad window ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-04-01 00:52:02 +03:00
|
|
|
}
|
|
|
|
auto& window = *(*it).value;
|
2020-12-26 00:45:47 +03:00
|
|
|
if (message.cursor_type() < 0 || message.cursor_type() >= (i32)Gfx::StandardCursor::__Count) {
|
|
|
|
did_misbehave("SetWindowCursor: Bad cursor type");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2020-12-26 00:45:47 +03:00
|
|
|
}
|
2020-09-10 21:55:39 +03:00
|
|
|
window.set_cursor(Cursor::create((Gfx::StandardCursor)message.cursor_type()));
|
2021-02-21 21:56:59 +03:00
|
|
|
if (&window == WindowManager::the().hovered_window())
|
|
|
|
Compositor::the().invalidate_cursor();
|
2020-09-10 21:55:39 +03:00
|
|
|
return make<Messages::WindowServer::SetWindowCursorResponse>();
|
2019-04-01 00:52:02 +03:00
|
|
|
}
|
|
|
|
|
2020-09-10 21:55:39 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetWindowCustomCursorResponse> ClientConnection::handle(const Messages::WindowServer::SetWindowCustomCursor& message)
|
2020-05-16 04:04:09 +03:00
|
|
|
{
|
|
|
|
auto it = m_windows.find(message.window_id());
|
|
|
|
if (it == m_windows.end()) {
|
2020-09-10 21:55:39 +03:00
|
|
|
did_misbehave("SetWindowCustomCursor: Bad window ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2020-05-16 04:04:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
auto& window = *(*it).value;
|
|
|
|
if (!message.cursor().is_valid()) {
|
2020-09-10 21:55:39 +03:00
|
|
|
did_misbehave("SetWindowCustomCursor: Bad cursor");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2020-05-16 04:04:09 +03:00
|
|
|
}
|
|
|
|
|
2020-09-10 21:55:39 +03:00
|
|
|
window.set_cursor(Cursor::create(*message.cursor().bitmap()));
|
2020-05-16 04:04:09 +03:00
|
|
|
Compositor::the().invalidate_cursor();
|
2020-09-10 21:55:39 +03:00
|
|
|
return make<Messages::WindowServer::SetWindowCustomCursorResponse>();
|
2020-05-16 04:04:09 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetWindowHasAlphaChannelResponse> ClientConnection::handle(const Messages::WindowServer::SetWindowHasAlphaChannel& message)
|
2019-05-03 22:07:16 +03:00
|
|
|
{
|
2019-12-02 11:33:37 +03:00
|
|
|
auto it = m_windows.find(message.window_id());
|
2019-05-03 22:07:16 +03:00
|
|
|
if (it == m_windows.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("SetWindowHasAlphaChannel: Bad window ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2019-05-03 22:07:16 +03:00
|
|
|
}
|
2019-12-02 11:33:37 +03:00
|
|
|
it->value->set_has_alpha_channel(message.has_alpha_channel());
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::SetWindowHasAlphaChannelResponse>();
|
2019-05-03 22:07:16 +03:00
|
|
|
}
|
|
|
|
|
2021-02-15 02:42:37 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetWindowAlphaHitThresholdResponse> ClientConnection::handle(const Messages::WindowServer::SetWindowAlphaHitThreshold& message)
|
|
|
|
{
|
|
|
|
auto it = m_windows.find(message.window_id());
|
|
|
|
if (it == m_windows.end()) {
|
|
|
|
did_misbehave("SetWindowAlphaHitThreshold: Bad window ID");
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
it->value->set_alpha_hit_threshold(message.threshold());
|
|
|
|
return make<Messages::WindowServer::SetWindowAlphaHitThresholdResponse>();
|
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
void ClientConnection::handle(const Messages::WindowServer::WM_SetActiveWindow& message)
|
2019-04-04 15:38:53 +03:00
|
|
|
{
|
2020-02-06 22:03:37 +03:00
|
|
|
auto* client = ClientConnection::from_client_id(message.client_id());
|
2019-04-04 15:38:53 +03:00
|
|
|
if (!client) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("WM_SetActiveWindow: Bad client ID");
|
2019-04-04 15:38:53 +03:00
|
|
|
return;
|
|
|
|
}
|
2019-12-02 11:33:37 +03:00
|
|
|
auto it = client->m_windows.find(message.window_id());
|
2019-04-04 15:38:53 +03:00
|
|
|
if (it == client->m_windows.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("WM_SetActiveWindow: Bad window ID");
|
2019-04-04 15:38:53 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto& window = *(*it).value;
|
2020-07-16 02:40:52 +03:00
|
|
|
WindowManager::the().minimize_windows(window, false);
|
2020-02-06 22:03:37 +03:00
|
|
|
WindowManager::the().move_to_front_and_make_active(window);
|
2019-04-04 15:38:53 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
void ClientConnection::handle(const Messages::WindowServer::WM_PopupWindowMenu& message)
|
2019-06-21 12:03:43 +03:00
|
|
|
{
|
2020-02-06 22:03:37 +03:00
|
|
|
auto* client = ClientConnection::from_client_id(message.client_id());
|
2019-06-21 12:03:43 +03:00
|
|
|
if (!client) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("WM_PopupWindowMenu: Bad client ID");
|
2019-06-21 12:03:43 +03:00
|
|
|
return;
|
|
|
|
}
|
2019-12-02 11:33:37 +03:00
|
|
|
auto it = client->m_windows.find(message.window_id());
|
2019-06-21 12:03:43 +03:00
|
|
|
if (it == client->m_windows.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("WM_PopupWindowMenu: Bad window ID");
|
2019-06-21 12:03:43 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto& window = *(*it).value;
|
2021-01-07 22:12:17 +03:00
|
|
|
if (auto* modal_window = window.blocking_modal_window()) {
|
|
|
|
modal_window->popup_window_menu(message.screen_position(), WindowMenuDefaultAction::BasedOnWindowState);
|
2020-07-16 02:40:52 +03:00
|
|
|
} else {
|
|
|
|
window.popup_window_menu(message.screen_position(), WindowMenuDefaultAction::BasedOnWindowState);
|
|
|
|
}
|
2019-06-21 12:03:43 +03:00
|
|
|
}
|
|
|
|
|
2021-02-01 13:23:54 +03:00
|
|
|
void ClientConnection::handle(const Messages::WindowServer::StartWindowResize& request)
|
|
|
|
{
|
|
|
|
auto it = m_windows.find(request.window_id());
|
|
|
|
if (it == 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?
|
|
|
|
WindowManager::the().start_window_resize(window, Screen::the().cursor_location(), MouseButton::Left);
|
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
void ClientConnection::handle(const Messages::WindowServer::WM_StartWindowResize& request)
|
2019-05-03 02:38:24 +03:00
|
|
|
{
|
2020-02-06 22:03:37 +03:00
|
|
|
auto* client = ClientConnection::from_client_id(request.client_id());
|
2019-05-03 02:38:24 +03:00
|
|
|
if (!client) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("WM_StartWindowResize: Bad client ID");
|
2019-05-03 02:38:24 +03:00
|
|
|
return;
|
|
|
|
}
|
2019-12-02 11:33:37 +03:00
|
|
|
auto it = client->m_windows.find(request.window_id());
|
2019-05-03 02:38:24 +03:00
|
|
|
if (it == client->m_windows.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("WM_StartWindowResize: Bad window ID");
|
2019-05-03 02:38:24 +03:00
|
|
|
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?
|
2020-02-06 22:03:37 +03:00
|
|
|
WindowManager::the().start_window_resize(window, Screen::the().cursor_location(), MouseButton::Left);
|
2019-05-03 02:38:24 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
void ClientConnection::handle(const Messages::WindowServer::WM_SetWindowMinimized& message)
|
2019-04-24 00:14:14 +03:00
|
|
|
{
|
2020-02-06 22:03:37 +03:00
|
|
|
auto* client = ClientConnection::from_client_id(message.client_id());
|
2019-04-24 00:14:14 +03:00
|
|
|
if (!client) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("WM_SetWindowMinimized: Bad client ID");
|
2019-04-24 00:14:14 +03:00
|
|
|
return;
|
|
|
|
}
|
2019-12-02 11:33:37 +03:00
|
|
|
auto it = client->m_windows.find(message.window_id());
|
2019-04-24 00:14:14 +03:00
|
|
|
if (it == client->m_windows.end()) {
|
2019-12-02 17:55:14 +03:00
|
|
|
did_misbehave("WM_SetWindowMinimized: Bad window ID");
|
2019-04-24 00:14:14 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto& window = *(*it).value;
|
2020-07-16 02:40:52 +03:00
|
|
|
WindowManager::the().minimize_windows(window, message.minimized());
|
2019-04-24 00:14:14 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::GreetResponse> ClientConnection::handle(const Messages::WindowServer::Greet&)
|
2019-02-14 10:43:29 +03:00
|
|
|
{
|
2021-02-01 13:26:41 +03:00
|
|
|
return make<Messages::WindowServer::GreetResponse>(Screen::the().rect(), Gfx::current_system_theme_buffer());
|
2019-02-14 10:22:47 +03:00
|
|
|
}
|
2019-03-19 02:52:39 +03:00
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
void ClientConnection::handle(const Messages::WindowServer::WM_SetWindowTaskbarRect& message)
|
2019-12-03 23:34:34 +03:00
|
|
|
{
|
2020-09-16 01:09:10 +03: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.
|
2020-02-06 22:03:37 +03:00
|
|
|
auto* client = ClientConnection::from_client_id(message.client_id());
|
2020-09-16 01:09:10 +03:00
|
|
|
if (!client)
|
2019-12-03 23:34:34 +03:00
|
|
|
return;
|
2020-09-16 01:09:10 +03:00
|
|
|
|
2019-12-03 23:34:34 +03:00
|
|
|
auto it = client->m_windows.find(message.window_id());
|
2020-09-16 01:09:10 +03:00
|
|
|
if (it == client->m_windows.end())
|
2019-12-03 23:34:34 +03:00
|
|
|
return;
|
2020-09-16 01:09:10 +03:00
|
|
|
|
2019-12-03 23:34:34 +03:00
|
|
|
auto& window = *(*it).value;
|
|
|
|
window.set_taskbar_rect(message.rect());
|
|
|
|
}
|
2019-12-05 21:36:01 +03:00
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
OwnPtr<Messages::WindowServer::StartDragResponse> ClientConnection::handle(const Messages::WindowServer::StartDrag& message)
|
2019-12-08 18:50:23 +03:00
|
|
|
{
|
2020-02-06 22:03:37 +03:00
|
|
|
auto& wm = WindowManager::the();
|
2019-12-08 18:50:23 +03:00
|
|
|
if (wm.dnd_client())
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::StartDragResponse>(false);
|
2019-12-08 18:50:23 +03:00
|
|
|
|
2021-01-16 12:06:27 +03:00
|
|
|
wm.start_dnd_drag(*this, message.text(), message.drag_bitmap().bitmap(), Core::MimeData::construct(message.mime_data()));
|
2020-02-06 22:20:44 +03:00
|
|
|
return make<Messages::WindowServer::StartDragResponse>(true);
|
2019-12-08 18:50:23 +03:00
|
|
|
}
|
2019-12-30 21:27:58 +03:00
|
|
|
|
2020-02-17 22:05:14 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetSystemMenuResponse> ClientConnection::handle(const Messages::WindowServer::SetSystemMenu& message)
|
|
|
|
{
|
|
|
|
auto it = m_menus.find(message.menu_id());
|
|
|
|
if (it == m_menus.end()) {
|
|
|
|
did_misbehave("SetSystemMenu called with invalid menu ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2020-02-17 22:05:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
auto& menu = it->value;
|
|
|
|
MenuManager::the().set_system_menu(menu);
|
|
|
|
return make<Messages::WindowServer::SetSystemMenuResponse>();
|
|
|
|
}
|
|
|
|
|
|
|
|
OwnPtr<Messages::WindowServer::SetSystemThemeResponse> ClientConnection::handle(const Messages::WindowServer::SetSystemTheme& message)
|
|
|
|
{
|
|
|
|
bool success = WindowManager::the().update_theme(message.theme_path(), message.theme_name());
|
|
|
|
return make<Messages::WindowServer::SetSystemThemeResponse>(success);
|
|
|
|
}
|
|
|
|
|
2020-04-21 19:40:27 +03:00
|
|
|
OwnPtr<Messages::WindowServer::GetSystemThemeResponse> ClientConnection::handle(const Messages::WindowServer::GetSystemTheme&)
|
|
|
|
{
|
|
|
|
auto wm_config = Core::ConfigFile::open("/etc/WindowServer/WindowServer.ini");
|
|
|
|
auto name = wm_config->read_entry("Theme", "Name");
|
|
|
|
return make<Messages::WindowServer::GetSystemThemeResponse>(name);
|
|
|
|
}
|
|
|
|
|
2020-02-24 21:23:57 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrementResponse> ClientConnection::handle(const Messages::WindowServer::SetWindowBaseSizeAndSizeIncrement& message)
|
|
|
|
{
|
|
|
|
auto it = m_windows.find(message.window_id());
|
|
|
|
if (it == m_windows.end()) {
|
|
|
|
did_misbehave("SetWindowBaseSizeAndSizeIncrementResponse: Bad window ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2020-02-24 21:23:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
auto& window = *it->value;
|
|
|
|
window.set_base_size(message.base_size());
|
|
|
|
window.set_size_increment(message.size_increment());
|
|
|
|
|
|
|
|
return make<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrementResponse>();
|
|
|
|
}
|
|
|
|
|
2020-08-21 23:19:10 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetWindowResizeAspectRatioResponse> ClientConnection::handle(const Messages::WindowServer::SetWindowResizeAspectRatio& message)
|
|
|
|
{
|
|
|
|
auto it = m_windows.find(message.window_id());
|
|
|
|
if (it == m_windows.end()) {
|
|
|
|
did_misbehave("SetWindowResizeAspectRatioResponse: Bad window ID");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2020-08-21 23:19:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
auto& window = *it->value;
|
|
|
|
window.set_resize_aspect_ratio(message.resize_aspect_ratio());
|
|
|
|
|
|
|
|
return make<Messages::WindowServer::SetWindowResizeAspectRatioResponse>();
|
|
|
|
}
|
|
|
|
|
2020-03-22 23:13:23 +03:00
|
|
|
void ClientConnection::handle(const Messages::WindowServer::EnableDisplayLink&)
|
|
|
|
{
|
2020-04-22 01:07:48 +03:00
|
|
|
if (m_has_display_link)
|
|
|
|
return;
|
2020-03-22 23:13:23 +03:00
|
|
|
m_has_display_link = true;
|
2020-04-22 01:07:48 +03:00
|
|
|
Compositor::the().increment_display_link_count({});
|
2020-03-22 23:13:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientConnection::handle(const Messages::WindowServer::DisableDisplayLink&)
|
|
|
|
{
|
2020-04-22 01:07:48 +03:00
|
|
|
if (!m_has_display_link)
|
|
|
|
return;
|
2020-03-22 23:13:23 +03:00
|
|
|
m_has_display_link = false;
|
2020-04-22 01:07:48 +03:00
|
|
|
Compositor::the().decrement_display_link_count({});
|
2020-03-22 23:13:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientConnection::notify_display_link(Badge<Compositor>)
|
|
|
|
{
|
|
|
|
if (!m_has_display_link)
|
|
|
|
return;
|
|
|
|
|
|
|
|
post_message(Messages::WindowClient::DisplayLinkNotification());
|
|
|
|
}
|
|
|
|
|
2020-05-30 23:08:26 +03:00
|
|
|
void ClientConnection::handle(const Messages::WindowServer::SetWindowProgress& message)
|
|
|
|
{
|
|
|
|
auto it = m_windows.find(message.window_id());
|
|
|
|
if (it == m_windows.end()) {
|
|
|
|
did_misbehave("SetWindowProgress with bad window ID");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
it->value->set_progress(message.progress());
|
|
|
|
}
|
|
|
|
|
2021-01-16 07:56:41 +03:00
|
|
|
void ClientConnection::handle(const Messages::WindowServer::RefreshSystemTheme&)
|
|
|
|
{
|
|
|
|
// Post the client an UpdateSystemTheme message to refresh its theme.
|
2021-01-16 19:20:53 +03:00
|
|
|
post_message(Messages::WindowClient::UpdateSystemTheme(Gfx::current_system_theme_buffer()));
|
2021-01-16 07:56:41 +03:00
|
|
|
}
|
|
|
|
|
2020-06-11 23:46:49 +03:00
|
|
|
void ClientConnection::handle(const Messages::WindowServer::Pong&)
|
|
|
|
{
|
|
|
|
m_ping_timer = nullptr;
|
|
|
|
set_unresponsive(false);
|
|
|
|
}
|
|
|
|
|
2020-12-28 22:48:52 +03:00
|
|
|
OwnPtr<Messages::WindowServer::GetGlobalCursorPositionResponse> ClientConnection::handle(const Messages::WindowServer::GetGlobalCursorPosition&)
|
|
|
|
{
|
|
|
|
return make<Messages::WindowServer::GetGlobalCursorPositionResponse>(Screen::the().cursor_location());
|
|
|
|
}
|
|
|
|
|
2020-12-30 00:33:57 +03:00
|
|
|
OwnPtr<Messages::WindowServer::SetMouseAccelerationResponse> ClientConnection::handle(const Messages::WindowServer::SetMouseAcceleration& message)
|
|
|
|
{
|
|
|
|
if (message.factor() < mouse_accel_min || message.factor() > mouse_accel_max) {
|
|
|
|
did_misbehave("SetMouseAcceleration with bad acceleration factor");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2020-12-30 00:33:57 +03:00
|
|
|
}
|
|
|
|
WindowManager::the().set_acceleration_factor(message.factor());
|
|
|
|
return make<Messages::WindowServer::SetMouseAccelerationResponse>();
|
|
|
|
}
|
|
|
|
|
|
|
|
OwnPtr<Messages::WindowServer::GetMouseAccelerationResponse> ClientConnection::handle(const Messages::WindowServer::GetMouseAcceleration&)
|
|
|
|
{
|
|
|
|
return make<Messages::WindowServer::GetMouseAccelerationResponse>(Screen::the().acceleration_factor());
|
|
|
|
}
|
|
|
|
|
|
|
|
OwnPtr<Messages::WindowServer::SetScrollStepSizeResponse> ClientConnection::handle(const Messages::WindowServer::SetScrollStepSize& message)
|
|
|
|
{
|
|
|
|
if (message.step_size() < scroll_step_size_min) {
|
|
|
|
did_misbehave("SetScrollStepSize with bad scroll step size");
|
2021-01-11 02:29:28 +03:00
|
|
|
return {};
|
2020-12-30 00:33:57 +03:00
|
|
|
}
|
|
|
|
WindowManager::the().set_scroll_step_size(message.step_size());
|
|
|
|
return make<Messages::WindowServer::SetScrollStepSizeResponse>();
|
|
|
|
}
|
|
|
|
OwnPtr<Messages::WindowServer::GetScrollStepSizeResponse> ClientConnection::handle(const Messages::WindowServer::GetScrollStepSize&)
|
|
|
|
{
|
|
|
|
return make<Messages::WindowServer::GetScrollStepSizeResponse>(Screen::the().scroll_step_size());
|
|
|
|
}
|
|
|
|
|
2020-06-11 23:46:49 +03:00
|
|
|
void ClientConnection::set_unresponsive(bool unresponsive)
|
|
|
|
{
|
|
|
|
if (m_unresponsive == unresponsive)
|
|
|
|
return;
|
|
|
|
m_unresponsive = unresponsive;
|
|
|
|
for (auto& it : m_windows) {
|
2020-07-07 22:46:05 +03:00
|
|
|
auto& window = *it.value;
|
|
|
|
window.invalidate();
|
2021-02-19 19:27:14 +03:00
|
|
|
if (unresponsive) {
|
|
|
|
window.set_cursor_override(WindowManager::the().wait_cursor());
|
|
|
|
} else {
|
|
|
|
window.remove_cursor_override();
|
|
|
|
}
|
2020-06-11 23:46:49 +03:00
|
|
|
}
|
2020-07-07 22:46:05 +03:00
|
|
|
Compositor::the().invalidate_cursor();
|
2020-06-11 23:46:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientConnection::may_have_become_unresponsive()
|
|
|
|
{
|
|
|
|
post_message(Messages::WindowClient::Ping());
|
|
|
|
m_ping_timer = Core::Timer::create_single_shot(1000, [this] {
|
|
|
|
set_unresponsive(true);
|
|
|
|
});
|
2021-01-25 23:37:50 +03:00
|
|
|
m_ping_timer->start();
|
2020-06-11 23:46:49 +03:00
|
|
|
}
|
|
|
|
|
2020-06-13 14:47:01 +03:00
|
|
|
void ClientConnection::did_become_responsive()
|
|
|
|
{
|
|
|
|
set_unresponsive(false);
|
|
|
|
}
|
|
|
|
|
2020-02-06 22:03:37 +03:00
|
|
|
}
|