| 
									
										
										
										
											2020-01-18 09:38:21 +01: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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-24 20:57:54 +01:00
										 |  |  | #include <LibDraw/Palette.h>
 | 
					
						
							| 
									
										
										
										
											2019-12-23 20:24:26 +01:00
										 |  |  | #include <LibDraw/SystemTheme.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-07 11:46:02 +02:00
										 |  |  | #include <LibGUI/GAction.h>
 | 
					
						
							|  |  |  | #include <LibGUI/GApplication.h>
 | 
					
						
							| 
									
										
										
										
											2019-09-14 09:19:05 +02:00
										 |  |  | #include <LibGUI/GClipboard.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-07 11:46:02 +02:00
										 |  |  | #include <LibGUI/GDesktop.h>
 | 
					
						
							| 
									
										
										
										
											2019-12-08 16:50:23 +01:00
										 |  |  | #include <LibGUI/GDragOperation.h>
 | 
					
						
							| 
									
										
										
										
											2019-11-08 11:39:45 +01:00
										 |  |  | #include <LibGUI/GEvent.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-07 11:46:02 +02:00
										 |  |  | #include <LibGUI/GMenu.h>
 | 
					
						
							|  |  |  | #include <LibGUI/GWidget.h>
 | 
					
						
							| 
									
										
										
										
											2019-11-08 11:39:45 +01:00
										 |  |  | #include <LibGUI/GWindow.h>
 | 
					
						
							|  |  |  | #include <LibGUI/GWindowServerConnection.h>
 | 
					
						
							| 
									
										
										
										
											2018-10-10 15:12:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-20 07:03:38 +01:00
										 |  |  | //#define GEVENTLOOP_DEBUG
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | namespace GUI { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | WindowServerConnection& WindowServerConnection::the() | 
					
						
							| 
									
										
										
										
											2019-07-17 20:57:27 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     static WindowServerConnection* s_connection = nullptr; | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  |     if (!s_connection) | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |         s_connection = new WindowServerConnection; | 
					
						
							| 
									
										
										
										
											2019-07-17 20:57:27 +02:00
										 |  |  |     return *s_connection; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-23 20:24:26 +01:00
										 |  |  | static void set_system_theme_from_shared_buffer_id(int id) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto system_theme = SharedBuffer::create_from_shared_buffer_id(id); | 
					
						
							|  |  |  |     ASSERT(system_theme); | 
					
						
							|  |  |  |     set_system_theme(*system_theme); | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     Application::the().set_system_palette(*system_theme); | 
					
						
							| 
									
										
										
										
											2019-12-23 20:24:26 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handshake() | 
					
						
							| 
									
										
										
										
											2018-10-10 15:12:38 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-12-06 18:39:59 +01:00
										 |  |  |     auto response = send_sync<WindowServer::Greet>(); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  |     set_my_client_id(response->client_id()); | 
					
						
							| 
									
										
										
										
											2019-12-23 20:24:26 +01:00
										 |  |  |     set_system_theme_from_shared_buffer_id(response->system_theme_buffer_id()); | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     Desktop::the().did_receive_screen_rect({}, response->screen_rect()); | 
					
						
							| 
									
										
										
										
											2019-03-09 17:34:09 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::UpdateSystemTheme& message) | 
					
						
							| 
									
										
										
										
											2019-12-23 20:24:26 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     set_system_theme_from_shared_buffer_id(message.system_theme_buffer_id()); | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     Window::update_all_windows({}); | 
					
						
							| 
									
										
										
										
											2019-12-23 20:24:26 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::Paint& message) | 
					
						
							| 
									
										
										
										
											2019-01-20 05:48:43 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-01-26 21:44:13 +01:00
										 |  |  | #ifdef GEVENTLOOP_DEBUG
 | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  |     dbgprintf("WID=%d Paint\n", message.window_id()); | 
					
						
							| 
									
										
										
										
											2019-01-26 21:44:13 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     if (auto* window = Window::from_window_id(message.window_id())) | 
					
						
							|  |  |  |         Core::EventLoop::current().post_event(*window, make<MultiPaintEvent>(message.rects(), message.window_size())); | 
					
						
							| 
									
										
										
										
											2019-01-20 05:48:43 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::WindowResized& message) | 
					
						
							| 
									
										
										
										
											2019-02-20 15:34:55 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     if (auto* window = Window::from_window_id(message.window_id())) { | 
					
						
							|  |  |  |         Core::EventLoop::current().post_event(*window, make<ResizeEvent>(message.old_rect().size(), message.new_rect().size())); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::WindowActivated& message) | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | { | 
					
						
							|  |  |  | #ifdef GEVENTLOOP_DEBUG
 | 
					
						
							|  |  |  |     dbgprintf("(%d) WID=%d WindowActivated\n", getpid(), message.window_id()); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     if (auto* window = Window::from_window_id(message.window_id())) | 
					
						
							|  |  |  |         Core::EventLoop::current().post_event(*window, make<Event>(Event::WindowBecameActive)); | 
					
						
							| 
									
										
										
										
											2019-02-20 15:34:55 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::WindowDeactivated& message) | 
					
						
							| 
									
										
										
										
											2019-01-26 21:58:43 +01:00
										 |  |  | { | 
					
						
							|  |  |  | #ifdef GEVENTLOOP_DEBUG
 | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  |     dbgprintf("(%d) WID=%d WindowDeactivated\n", getpid(), message.window_id()); | 
					
						
							| 
									
										
										
										
											2019-01-26 21:58:43 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     if (auto* window = Window::from_window_id(message.window_id())) | 
					
						
							|  |  |  |         Core::EventLoop::current().post_event(*window, make<Event>(Event::WindowBecameInactive)); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::WindowCloseRequest& message) | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     if (auto* window = Window::from_window_id(message.window_id())) | 
					
						
							|  |  |  |         Core::EventLoop::current().post_event(*window, make<Event>(Event::WindowCloseRequest)); | 
					
						
							| 
									
										
										
										
											2019-01-26 21:58:43 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::WindowEntered& message) | 
					
						
							| 
									
										
										
										
											2019-02-05 10:31:37 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     if (auto* window = Window::from_window_id(message.window_id())) | 
					
						
							|  |  |  |         Core::EventLoop::current().post_event(*window, make<Event>(Event::WindowEntered)); | 
					
						
							| 
									
										
										
										
											2019-02-05 10:31:37 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::WindowLeft& message) | 
					
						
							| 
									
										
										
										
											2019-02-20 10:12:19 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     if (auto* window = Window::from_window_id(message.window_id())) | 
					
						
							|  |  |  |         Core::EventLoop::current().post_event(*window, make<Event>(Event::WindowLeft)); | 
					
						
							| 
									
										
										
										
											2019-02-20 10:12:19 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::KeyDown& message) | 
					
						
							| 
									
										
										
										
											2019-01-26 06:39:13 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-01-26 21:44:13 +01:00
										 |  |  | #ifdef GEVENTLOOP_DEBUG
 | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  |     dbgprintf("WID=%d KeyDown character=0x%02x\n", message.window_id(), message.character()); | 
					
						
							| 
									
										
										
										
											2019-01-26 21:44:13 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     auto* window = Window::from_window_id(message.window_id()); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  |     if (!window) | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2019-04-20 21:56:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     auto key_event = make<KeyEvent>(Event::KeyDown, message.key(), message.modifiers()); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  |     if (message.character() != '\0') { | 
					
						
							|  |  |  |         char ch = message.character(); | 
					
						
							|  |  |  |         key_event->m_text = String(&ch, 1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     Action* action = nullptr; | 
					
						
							| 
									
										
										
										
											2020-02-02 01:57:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (auto* focused_widget = window->focused_widget()) | 
					
						
							|  |  |  |         action = focused_widget->action_for_key_event(*key_event); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!action) | 
					
						
							|  |  |  |         action = window->action_for_key_event(*key_event); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 01:57:57 +01:00
										 |  |  |     if (!action) | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |         action = Application::the().action_for_key_event(*key_event); | 
					
						
							| 
									
										
										
										
											2020-02-02 01:57:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (action && action->is_enabled()) { | 
					
						
							|  |  |  |         action->activate(); | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-02-02 12:34:39 +01:00
										 |  |  |     Core::EventLoop::current().post_event(*window, move(key_event)); | 
					
						
							| 
									
										
										
										
											2019-01-26 06:39:13 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::KeyUp& message) | 
					
						
							| 
									
										
										
										
											2019-01-20 05:48:43 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-01-26 21:44:13 +01:00
										 |  |  | #ifdef GEVENTLOOP_DEBUG
 | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  |     dbgprintf("WID=%d KeyUp character=0x%02x\n", message.window_id(), message.character()); | 
					
						
							| 
									
										
										
										
											2019-01-26 21:44:13 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     auto* window = Window::from_window_id(message.window_id()); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  |     if (!window) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     auto key_event = make<KeyEvent>(Event::KeyUp, message.key(), message.modifiers()); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  |     if (message.character() != '\0') { | 
					
						
							|  |  |  |         char ch = message.character(); | 
					
						
							|  |  |  |         key_event->m_text = String(&ch, 1); | 
					
						
							| 
									
										
										
										
											2019-01-20 05:48:43 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 12:34:39 +01:00
										 |  |  |     Core::EventLoop::current().post_event(*window, move(key_event)); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | MouseButton to_gmousebutton(u32 button) | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     switch (button) { | 
					
						
							|  |  |  |     case 0: | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |         return MouseButton::None; | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  |     case 1: | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |         return MouseButton::Left; | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  |     case 2: | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |         return MouseButton::Right; | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  |     case 4: | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |         return MouseButton::Middle; | 
					
						
							| 
									
										
										
										
											2019-06-07 11:46:02 +02:00
										 |  |  |     default: | 
					
						
							|  |  |  |         ASSERT_NOT_REACHED(); | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2019-01-20 05:48:43 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-01-10 23:19:29 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::MouseDown& message) | 
					
						
							| 
									
										
										
										
											2019-02-12 10:08:35 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | #ifdef GEVENTLOOP_DEBUG
 | 
					
						
							|  |  |  |     dbgprintf("WID=%d MouseDown %d,%d,%d\n", message.window_id(), message.mouse_position().x(), message.mouse_position().y(), message.wheel_delta(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     if (auto* window = Window::from_window_id(message.window_id())) | 
					
						
							|  |  |  |         Core::EventLoop::current().post_event(*window, make<MouseEvent>(Event::MouseDown, message.mouse_position(), message.buttons(), to_gmousebutton(message.button()), message.modifiers(), message.wheel_delta())); | 
					
						
							| 
									
										
										
										
											2019-02-12 10:08:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::MouseUp& message) | 
					
						
							| 
									
										
										
										
											2019-04-04 01:44:35 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-04 16:23:23 +02:00
										 |  |  | #ifdef GEVENTLOOP_DEBUG
 | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  |     dbgprintf("WID=%d MouseUp %d,%d,%d\n", message.window_id(), message.mouse_position().x(), message.mouse_position().y(), message.wheel_delta(); | 
					
						
							| 
									
										
										
										
											2019-04-04 16:23:23 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     if (auto* window = Window::from_window_id(message.window_id())) | 
					
						
							|  |  |  |         Core::EventLoop::current().post_event(*window, make<MouseEvent>(Event::MouseUp, message.mouse_position(), message.buttons(), to_gmousebutton(message.button()), message.modifiers(), message.wheel_delta())); | 
					
						
							| 
									
										
										
										
											2019-04-04 01:44:35 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::MouseMove& message) | 
					
						
							| 
									
										
										
										
											2019-02-20 21:59:13 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | #ifdef GEVENTLOOP_DEBUG
 | 
					
						
							|  |  |  |     dbgprintf("WID=%d MouseMove %d,%d,%d\n", message.window_id(), message.mouse_position().x(), message.mouse_position().y(), message.wheel_delta(); | 
					
						
							| 
									
										
										
										
											2019-04-10 15:39:28 +02:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     if (auto* window = Window::from_window_id(message.window_id())) | 
					
						
							|  |  |  |         Core::EventLoop::current().post_event(*window, make<MouseEvent>(Event::MouseMove, message.mouse_position(), message.buttons(), to_gmousebutton(message.button()), message.modifiers(), message.wheel_delta())); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-03 17:22:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::MouseDoubleClick& message) | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | { | 
					
						
							|  |  |  | #ifdef GEVENTLOOP_DEBUG
 | 
					
						
							|  |  |  |     dbgprintf("WID=%d MouseDoubleClick %d,%d,%d\n", message.window_id(), message.mouse_position().x(), message.mouse_position().y(), message.wheel_delta(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-02-14 09:32:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     if (auto* window = Window::from_window_id(message.window_id())) | 
					
						
							|  |  |  |         Core::EventLoop::current().post_event(*window, make<MouseEvent>(Event::MouseDoubleClick, message.mouse_position(), message.buttons(), to_gmousebutton(message.button()), message.modifiers(), message.wheel_delta())); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-09-14 09:19:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::MouseWheel& message) | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | { | 
					
						
							|  |  |  | #ifdef GEVENTLOOP_DEBUG
 | 
					
						
							|  |  |  |     dbgprintf("WID=%d MouseWheel %d,%d,%d\n", message.window_id(), message.mouse_position().x(), message.mouse_position().y(), message.wheel_delta(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-02-14 09:32:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     if (auto* window = Window::from_window_id(message.window_id())) | 
					
						
							|  |  |  |         Core::EventLoop::current().post_event(*window, make<MouseEvent>(Event::MouseWheel, message.mouse_position(), message.buttons(), to_gmousebutton(message.button()), message.modifiers(), message.wheel_delta())); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-02-12 10:08:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::MenuItemActivated& message) | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     auto* menu = Menu::from_menu_id(message.menu_id()); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  |     if (!menu) { | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |         dbgprintf("EventLoop received event for invalid menu ID %d\n", message.menu_id()); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2019-01-20 05:48:43 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  |     if (auto* action = menu->action_at(message.identifier())) | 
					
						
							| 
									
										
										
										
											2019-12-09 21:25:48 +01:00
										 |  |  |         action->activate(menu); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-02-20 21:59:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::WM_WindowStateChanged& message) | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | { | 
					
						
							|  |  |  | #ifdef GEVENTLOOP_DEBUG
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     dbgprintf("EventLoop: handle_wm_event: %d\n", (int)event.type); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     if (auto* window = Window::from_window_id(message.wm_id())) | 
					
						
							|  |  |  |         Core::EventLoop::current().post_event(*window, make<WMWindowStateChangedEvent>(message.client_id(), message.window_id(), message.title(), message.rect(), message.is_active(), static_cast<WindowType>(message.window_type()), message.is_minimized())); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::WM_WindowRectChanged& message) | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | { | 
					
						
							|  |  |  | #ifdef GEVENTLOOP_DEBUG
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     dbgprintf("EventLoop: handle_wm_event: %d\n", (int)event.type); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     if (auto* window = Window::from_window_id(message.wm_id())) | 
					
						
							|  |  |  |         Core::EventLoop::current().post_event(*window, make<WMWindowRectChangedEvent>(message.client_id(), message.window_id(), message.rect())); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::WM_WindowIconBitmapChanged& message) | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | { | 
					
						
							|  |  |  | #ifdef GEVENTLOOP_DEBUG
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     dbgprintf("EventLoop: handle_wm_event: %d\n", (int)event.type); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     if (auto* window = Window::from_window_id(message.wm_id())) | 
					
						
							|  |  |  |         Core::EventLoop::current().post_event(*window, make<WMWindowIconBitmapChangedEvent>(message.client_id(), message.window_id(), message.icon_buffer_id(), message.icon_size())); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::WM_WindowRemoved& message) | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | { | 
					
						
							|  |  |  | #ifdef GEVENTLOOP_DEBUG
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     dbgprintf("EventLoop: handle_wm_event: %d\n", (int)event.type); | 
					
						
							| 
									
										
										
										
											2019-04-10 15:39:28 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     if (auto* window = Window::from_window_id(message.wm_id())) | 
					
						
							|  |  |  |         Core::EventLoop::current().post_event(*window, make<WMWindowRemovedEvent>(message.client_id(), message.window_id())); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::ScreenRectChanged& message) | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     Desktop::the().did_receive_screen_rect({}, message.rect()); | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::ClipboardContentsChanged& message) | 
					
						
							| 
									
										
										
										
											2019-12-02 09:33:37 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     Clipboard::the().did_receive_clipboard_contents_changed({}, message.content_type()); | 
					
						
							| 
									
										
										
										
											2018-10-10 15:12:38 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-02-01 03:50:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::AsyncSetWallpaperFinished&) | 
					
						
							| 
									
										
										
										
											2019-05-03 01:38:24 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     // This is handled manually by Desktop::set_wallpaper().
 | 
					
						
							| 
									
										
										
										
											2019-05-03 01:38:24 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-12-08 16:50:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::DragDropped& message) | 
					
						
							| 
									
										
										
										
											2019-12-08 16:50:23 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     if (auto* window = Window::from_window_id(message.window_id())) | 
					
						
							|  |  |  |         Core::EventLoop::current().post_event(*window, make<DropEvent>(message.mouse_position(), message.text(), message.data_type(), message.data())); | 
					
						
							| 
									
										
										
										
											2019-12-08 16:50:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::DragAccepted&) | 
					
						
							| 
									
										
										
										
											2019-12-08 16:50:23 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     DragOperation::notify_accepted({}); | 
					
						
							| 
									
										
										
										
											2019-12-08 16:50:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::DragCancelled&) | 
					
						
							| 
									
										
										
										
											2019-12-08 16:50:23 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     DragOperation::notify_cancelled({}); | 
					
						
							| 
									
										
										
										
											2019-12-08 16:50:23 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-12-26 12:06:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | void WindowServerConnection::handle(const WindowClient::WindowStateChanged& message) | 
					
						
							| 
									
										
										
										
											2019-12-26 12:06:07 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     if (auto* window = Window::from_window_id(message.window_id())) | 
					
						
							| 
									
										
										
										
											2019-12-27 11:34:40 +01:00
										 |  |  |         window->notify_state_changed({}, message.minimized(), message.occluded()); | 
					
						
							| 
									
										
										
										
											2019-12-26 12:06:07 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |