diff --git a/Kernel/GUIEventDevice.cpp b/Kernel/GUIEventDevice.cpp index a3914ee6358..36c91e37160 100644 --- a/Kernel/GUIEventDevice.cpp +++ b/Kernel/GUIEventDevice.cpp @@ -23,13 +23,13 @@ bool GUIEventDevice::can_read(Process& process) const ssize_t GUIEventDevice::read(Process& process, byte* buffer, size_t size) { #ifdef GUIEVENTDEVICE_DEBUG - dbgprintf("GUIEventDevice::read(): %s<%u>, size=%u, sizeof(GUI_Event)=%u\n", process.name().characters(), process.pid(), size, sizeof(GUI_Event)); + dbgprintf("GUIEventDevice::read(): %s<%u>, size=%u, sizeof(GUI_ServerMessage)=%u\n", process.name().characters(), process.pid(), size, sizeof(GUI_ServerMessage)); #endif if (process.gui_events().is_empty()) return 0; LOCKER(process.gui_events_lock()); - ASSERT(size == sizeof(GUI_Event)); - *reinterpret_cast(buffer) = process.gui_events().take_first(); + ASSERT(size == sizeof(GUI_ServerMessage)); + *reinterpret_cast(buffer) = process.gui_events().take_first(); return size; } diff --git a/Kernel/GUITypes.h b/Kernel/GUITypes.h index 426277649dd..e6aed51337b 100644 --- a/Kernel/GUITypes.h +++ b/Kernel/GUITypes.h @@ -55,7 +55,7 @@ struct GUI_KeyModifiers { enum { }; }; -struct GUI_Event { +struct GUI_ServerMessage { enum Type : unsigned { Invalid, Paint, diff --git a/Kernel/Process.h b/Kernel/Process.h index 259f1770e3a..4601dec6915 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -301,7 +301,7 @@ public: bool is_root() const { return m_euid == 0; } - Vector& gui_events() { return m_gui_events; } + Vector& gui_events() { return m_gui_events; } Lock& gui_events_lock() { return m_gui_events_lock; } bool wakeup_requested() { return m_wakeup_requested; } @@ -417,7 +417,7 @@ private: HashMap> m_windows; Vector> m_retained_backing_stores; - Vector m_gui_events; + Vector m_gui_events; Lock m_gui_events_lock; int m_next_window_id { 1 }; diff --git a/LibGUI/GEventLoop.cpp b/LibGUI/GEventLoop.cpp index 9e65597d847..553cc602c13 100644 --- a/LibGUI/GEventLoop.cpp +++ b/LibGUI/GEventLoop.cpp @@ -93,7 +93,7 @@ void GEventLoop::post_event(GObject* receiver, OwnPtr&& event) m_queued_events.append({ receiver, move(event) }); } -void GEventLoop::handle_paint_event(const GUI_Event& event, GWindow& window) +void GEventLoop::handle_paint_event(const GUI_ServerMessage& event, GWindow& window) { #ifdef GEVENTLOOP_DEBUG dbgprintf("WID=%x Paint [%d,%d %dx%d]\n", event.window_id, event.paint.rect.location.x, event.paint.rect.location.y, event.paint.rect.size.width, event.paint.rect.size.height); @@ -101,25 +101,25 @@ void GEventLoop::handle_paint_event(const GUI_Event& event, GWindow& window) post_event(&window, make(event.paint.rect)); } -void GEventLoop::handle_window_activation_event(const GUI_Event& event, GWindow& window) +void GEventLoop::handle_window_activation_event(const GUI_ServerMessage& event, GWindow& window) { #ifdef GEVENTLOOP_DEBUG dbgprintf("WID=%x WindowActivation\n", event.window_id); #endif - post_event(&window, make(event.type == GUI_Event::Type::WindowActivated ? GEvent::WindowBecameActive : GEvent::WindowBecameInactive)); + post_event(&window, make(event.type == GUI_ServerMessage::Type::WindowActivated ? GEvent::WindowBecameActive : GEvent::WindowBecameInactive)); } -void GEventLoop::handle_window_close_request_event(const GUI_Event&, GWindow& window) +void GEventLoop::handle_window_close_request_event(const GUI_ServerMessage&, GWindow& window) { post_event(&window, make(GEvent::WindowCloseRequest)); } -void GEventLoop::handle_key_event(const GUI_Event& event, GWindow& window) +void GEventLoop::handle_key_event(const GUI_ServerMessage& event, GWindow& window) { #ifdef GEVENTLOOP_DEBUG dbgprintf("WID=%x KeyEvent character=0x%b\n", event.window_id, event.key.character); #endif - auto key_event = make(event.type == GUI_Event::Type::KeyDown ? GEvent::KeyDown : GEvent::KeyUp, event.key.key); + auto key_event = make(event.type == GUI_ServerMessage::Type::KeyDown ? GEvent::KeyDown : GEvent::KeyUp, event.key.key); key_event->m_alt = event.key.alt; key_event->m_ctrl = event.key.ctrl; key_event->m_shift = event.key.shift; @@ -128,16 +128,16 @@ void GEventLoop::handle_key_event(const GUI_Event& event, GWindow& window) post_event(&window, move(key_event)); } -void GEventLoop::handle_mouse_event(const GUI_Event& event, GWindow& window) +void GEventLoop::handle_mouse_event(const GUI_ServerMessage& event, GWindow& window) { #ifdef GEVENTLOOP_DEBUG dbgprintf("WID=%x MouseEvent %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); #endif GMouseEvent::Type type; switch (event.type) { - case GUI_Event::Type::MouseMove: type = GEvent::MouseMove; break; - case GUI_Event::Type::MouseUp: type = GEvent::MouseUp; break; - case GUI_Event::Type::MouseDown: type = GEvent::MouseDown; break; + case GUI_ServerMessage::Type::MouseMove: type = GEvent::MouseMove; break; + case GUI_ServerMessage::Type::MouseUp: type = GEvent::MouseUp; break; + case GUI_ServerMessage::Type::MouseDown: type = GEvent::MouseDown; break; default: ASSERT_NOT_REACHED(); break; } GMouseButton button { GMouseButton::None }; @@ -151,9 +151,9 @@ void GEventLoop::handle_mouse_event(const GUI_Event& event, GWindow& window) post_event(&window, make(type, event.mouse.position, event.mouse.buttons, button)); } -void GEventLoop::handle_menu_event(const GUI_Event& event) +void GEventLoop::handle_menu_event(const GUI_ServerMessage& event) { - if (event.type == GUI_Event::Type::MenuItemActivated) { + if (event.type == GUI_ServerMessage::Type::MenuItemActivated) { auto* menu = GMenu::from_menu_id(event.menu.menu_id); if (!menu) { dbgprintf("GEventLoop received event for invalid window ID %d\n", event.window_id); @@ -228,13 +228,13 @@ void GEventLoop::wait_for_event() if (!FD_ISSET(m_event_fd, &rfds)) return; - bool success = drain_events_from_server(); + bool success = drain_messages_from_server(); ASSERT(success); - auto unprocessed_events = move(m_unprocessed_events); + auto unprocessed_events = move(m_unprocessed_messages); for (auto& event : unprocessed_events) { switch (event.type) { - case GUI_Event::MenuItemActivated: + case GUI_ServerMessage::MenuItemActivated: handle_menu_event(event); continue; default: @@ -247,23 +247,23 @@ void GEventLoop::wait_for_event() continue; } switch (event.type) { - case GUI_Event::Type::Paint: + case GUI_ServerMessage::Type::Paint: handle_paint_event(event, *window); break; - case GUI_Event::Type::MouseDown: - case GUI_Event::Type::MouseUp: - case GUI_Event::Type::MouseMove: + case GUI_ServerMessage::Type::MouseDown: + case GUI_ServerMessage::Type::MouseUp: + case GUI_ServerMessage::Type::MouseMove: handle_mouse_event(event, *window); break; - case GUI_Event::Type::WindowActivated: - case GUI_Event::Type::WindowDeactivated: + case GUI_ServerMessage::Type::WindowActivated: + case GUI_ServerMessage::Type::WindowDeactivated: handle_window_activation_event(event, *window); break; - case GUI_Event::Type::WindowCloseRequest: + case GUI_ServerMessage::Type::WindowCloseRequest: handle_window_close_request_event(event, *window); break; - case GUI_Event::Type::KeyDown: - case GUI_Event::Type::KeyUp: + case GUI_ServerMessage::Type::KeyDown: + case GUI_ServerMessage::Type::KeyUp: handle_key_event(event, *window); break; default: @@ -272,11 +272,11 @@ void GEventLoop::wait_for_event() } } -bool GEventLoop::drain_events_from_server() +bool GEventLoop::drain_messages_from_server() { for (;;) { - GUI_Event event; - ssize_t nread = read(m_event_fd, &event, sizeof(GUI_Event)); + GUI_ServerMessage message; + ssize_t nread = read(m_event_fd, &message, sizeof(GUI_ServerMessage)); if (nread < 0) { perror("read"); exit(1); @@ -284,8 +284,8 @@ bool GEventLoop::drain_events_from_server() } if (nread == 0) return true; - assert(nread == sizeof(event)); - m_unprocessed_events.append(move(event)); + assert(nread == sizeof(message)); + m_unprocessed_messages.append(move(message)); } } @@ -355,28 +355,28 @@ bool GEventLoop::post_message_to_server(const GUI_ClientMessage& message) return nwritten == sizeof(GUI_ClientMessage); } -bool GEventLoop::wait_for_specific_event(GUI_Event::Type type, GUI_Event& event) +bool GEventLoop::wait_for_specific_event(GUI_ServerMessage::Type type, GUI_ServerMessage& event) { for (;;) { - bool success = drain_events_from_server(); + bool success = drain_messages_from_server(); if (!success) return false; - for (size_t i = 0; i < m_unprocessed_events.size(); ++i) { - if (m_unprocessed_events[i].type == type) { - event = move(m_unprocessed_events[i]); - m_unprocessed_events.remove(i); + for (size_t i = 0; i < m_unprocessed_messages.size(); ++i) { + if (m_unprocessed_messages[i].type == type) { + event = move(m_unprocessed_messages[i]); + m_unprocessed_messages.remove(i); return true; } } } } -GUI_Event GEventLoop::sync_request(const GUI_ClientMessage& request, GUI_Event::Type response_type) +GUI_ServerMessage GEventLoop::sync_request(const GUI_ClientMessage& request, GUI_ServerMessage::Type response_type) { bool success = post_message_to_server(request); ASSERT(success); - GUI_Event response; + GUI_ServerMessage response; success = GEventLoop::main().wait_for_specific_event(response_type, response); ASSERT(success); return response; diff --git a/LibGUI/GEventLoop.h b/LibGUI/GEventLoop.h index db28c3cea40..8ab1f75b45e 100644 --- a/LibGUI/GEventLoop.h +++ b/LibGUI/GEventLoop.h @@ -35,19 +35,19 @@ public: void exit(int); bool post_message_to_server(const GUI_ClientMessage&); - bool wait_for_specific_event(GUI_Event::Type, GUI_Event&); + bool wait_for_specific_event(GUI_ServerMessage::Type, GUI_ServerMessage&); - GUI_Event sync_request(const GUI_ClientMessage& request, GUI_Event::Type response_type); + GUI_ServerMessage sync_request(const GUI_ClientMessage& request, GUI_ServerMessage::Type response_type); private: void wait_for_event(); - bool drain_events_from_server(); - void handle_paint_event(const GUI_Event&, GWindow&); - void handle_mouse_event(const GUI_Event&, GWindow&); - void handle_key_event(const GUI_Event&, GWindow&); - void handle_window_activation_event(const GUI_Event&, GWindow&); - void handle_window_close_request_event(const GUI_Event&, GWindow&); - void handle_menu_event(const GUI_Event&); + bool drain_messages_from_server(); + void handle_paint_event(const GUI_ServerMessage&, GWindow&); + void handle_mouse_event(const GUI_ServerMessage&, GWindow&); + void handle_key_event(const GUI_ServerMessage&, GWindow&); + void handle_window_activation_event(const GUI_ServerMessage&, GWindow&); + void handle_window_close_request_event(const GUI_ServerMessage&, GWindow&); + void handle_menu_event(const GUI_ServerMessage&); void get_next_timer_expiration(timeval&); struct QueuedEvent { @@ -56,7 +56,7 @@ private: }; Vector m_queued_events; - Vector m_unprocessed_events; + Vector m_unprocessed_messages; int m_event_fd { -1 }; bool m_running { false }; diff --git a/LibGUI/GMenuBar.cpp b/LibGUI/GMenuBar.cpp index 9a2467a8d29..3ad0261891d 100644 --- a/LibGUI/GMenuBar.cpp +++ b/LibGUI/GMenuBar.cpp @@ -20,7 +20,7 @@ int GMenuBar::realize_menubar() { GUI_ClientMessage request; request.type = GUI_ClientMessage::Type::CreateMenubar; - GUI_Event response = GEventLoop::main().sync_request(request, GUI_Event::Type::DidCreateMenubar); + GUI_ServerMessage response = GEventLoop::main().sync_request(request, GUI_ServerMessage::Type::DidCreateMenubar); return response.menu.menubar_id; } @@ -31,7 +31,7 @@ void GMenuBar::unrealize_menubar() GUI_ClientMessage request; request.type = GUI_ClientMessage::Type::DestroyMenubar; request.menu.menubar_id = m_menubar_id; - GEventLoop::main().sync_request(request, GUI_Event::Type::DidDestroyMenubar); + GEventLoop::main().sync_request(request, GUI_ServerMessage::Type::DidDestroyMenubar); m_menubar_id = 0; } diff --git a/Userland/guitest.cpp b/Userland/guitest.cpp index b9fc6f82d01..9541289dddf 100644 --- a/Userland/guitest.cpp +++ b/Userland/guitest.cpp @@ -51,30 +51,30 @@ int main(int argc, char** argv) } for (;;) { - GUI_Event event; - ssize_t nread = read(fd, &event, sizeof(event)); + GUI_ServerMessage message; + ssize_t nread = read(fd, &message, sizeof(message)); if (nread < 0) { perror("read"); return 1; } dbgprintf("(%d) ", getpid()); - assert(nread == sizeof(event)); - switch (event.type) { - case GUI_Event::Type::Paint: dbgprintf("WID=%x Paint [%d,%d %dx%d]\n", event.window_id, event.paint.rect.location.x, event.paint.rect.location.y, event.paint.rect.size.width, event.paint.rect.size.height); break; - case GUI_Event::Type::MouseDown: dbgprintf("WID=%x MouseDown %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break; - case GUI_Event::Type::MouseUp: dbgprintf("WID=%x MouseUp %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break; - case GUI_Event::Type::MouseMove: dbgprintf("WID=%x MouseMove %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break; - case GUI_Event::Type::WindowActivated: dbgprintf("WID=%x WindowActivated\n", event.window_id); break; - case GUI_Event::Type::WindowDeactivated: dbgprintf("WID=%x WindowDeactivated\n", event.window_id); break; - case GUI_Event::Type::WindowCloseRequest: return 0; + assert(nread == sizeof(message)); + switch (message.type) { + case GUI_ServerMessage::Type::Paint: dbgprintf("WID=%x Paint [%d,%d %dx%d]\n", message.window_id, message.paint.rect.location.x, message.paint.rect.location.y, message.paint.rect.size.width, message.paint.rect.size.height); break; + case GUI_ServerMessage::Type::MouseDown: dbgprintf("WID=%x MouseDown %d,%d\n", message.window_id, message.mouse.position.x, message.mouse.position.y); break; + case GUI_ServerMessage::Type::MouseUp: dbgprintf("WID=%x MouseUp %d,%d\n", message.window_id, message.mouse.position.x, message.mouse.position.y); break; + case GUI_ServerMessage::Type::MouseMove: dbgprintf("WID=%x MouseMove %d,%d\n", message.window_id, message.mouse.position.x, message.mouse.position.y); break; + case GUI_ServerMessage::Type::WindowActivated: dbgprintf("WID=%x WindowActivated\n", message.window_id); break; + case GUI_ServerMessage::Type::WindowDeactivated: dbgprintf("WID=%x WindowDeactivated\n", message.window_id); break; + case GUI_ServerMessage::Type::WindowCloseRequest: return 0; } - if (event.type == GUI_Event::Type::Paint) { + if (message.type == GUI_ServerMessage::Type::Paint) { paint(*bitmap, backing.size.width, backing.size.height); gui_notify_paint_finished(window_id, nullptr); } - if (event.type == GUI_Event::Type::MouseDown) { + if (message.type == GUI_ServerMessage::Type::MouseDown) { gui_invalidate_window(window_id, nullptr); } diff --git a/WindowServer/WSMenu.cpp b/WindowServer/WSMenu.cpp index 0e93ab893de..3b775819501 100644 --- a/WindowServer/WSMenu.cpp +++ b/WindowServer/WSMenu.cpp @@ -140,8 +140,8 @@ void WSMenu::did_activate(WSMenuItem& item) close(); - GUI_Event gui_event; - gui_event.type = GUI_Event::Type::MenuItemActivated; + GUI_ServerMessage gui_event; + gui_event.type = GUI_ServerMessage::Type::MenuItemActivated; gui_event.menu.menu_id = m_menu_id; gui_event.menu.identifier = item.identifier(); diff --git a/WindowServer/WSMessageLoop.cpp b/WindowServer/WSMessageLoop.cpp index 73f1ab9cc7f..2c1659eb6c6 100644 --- a/WindowServer/WSMessageLoop.cpp +++ b/WindowServer/WSMessageLoop.cpp @@ -73,7 +73,7 @@ Process* WSMessageLoop::process_from_client_id(int client_id) return (Process*)client_id; } -void WSMessageLoop::post_message_to_client(int client_id, const GUI_Event& message) +void WSMessageLoop::post_message_to_client(int client_id, const GUI_ServerMessage& message) { auto* process = process_from_client_id(client_id); if (!process) diff --git a/WindowServer/WSMessageLoop.h b/WindowServer/WSMessageLoop.h index 10667af932a..98b7b34838b 100644 --- a/WindowServer/WSMessageLoop.h +++ b/WindowServer/WSMessageLoop.h @@ -9,7 +9,7 @@ class WSMessageReceiver; class Process; -struct GUI_Event; +struct GUI_ServerMessage; class WSMessageLoop { public: @@ -30,7 +30,7 @@ public: int start_timer(int ms, Function&&); int stop_timer(int timer_id); - void post_message_to_client(int client_id, const GUI_Event&); + void post_message_to_client(int client_id, const GUI_ServerMessage&); ssize_t on_receive_from_client(int client_id, const byte*, size_t); static Process* process_from_client_id(int client_id); diff --git a/WindowServer/WSWindow.cpp b/WindowServer/WSWindow.cpp index 33a44bb1353..50714afe1df 100644 --- a/WindowServer/WSWindow.cpp +++ b/WindowServer/WSWindow.cpp @@ -79,34 +79,34 @@ void WSWindow::on_message(WSMessage& message) return; } - GUI_Event gui_event; + GUI_ServerMessage gui_event; gui_event.window_id = window_id(); switch (message.type()) { case WSMessage::WM_ClientWantsToPaint: - gui_event.type = GUI_Event::Type::Paint; + gui_event.type = GUI_ServerMessage::Type::Paint; gui_event.paint.rect = static_cast(message).rect(); break; case WSMessage::MouseMove: - gui_event.type = GUI_Event::Type::MouseMove; + gui_event.type = GUI_ServerMessage::Type::MouseMove; gui_event.mouse.position = static_cast(message).position(); gui_event.mouse.button = GUI_MouseButton::NoButton; gui_event.mouse.buttons = static_cast(message).buttons(); break; case WSMessage::MouseDown: - gui_event.type = GUI_Event::Type::MouseDown; + gui_event.type = GUI_ServerMessage::Type::MouseDown; gui_event.mouse.position = static_cast(message).position(); gui_event.mouse.button = to_api(static_cast(message).button()); gui_event.mouse.buttons = static_cast(message).buttons(); break; case WSMessage::MouseUp: - gui_event.type = GUI_Event::Type::MouseUp; + gui_event.type = GUI_ServerMessage::Type::MouseUp; gui_event.mouse.position = static_cast(message).position(); gui_event.mouse.button = to_api(static_cast(message).button()); gui_event.mouse.buttons = static_cast(message).buttons(); break; case WSMessage::KeyDown: - gui_event.type = GUI_Event::Type::KeyDown; + gui_event.type = GUI_ServerMessage::Type::KeyDown; gui_event.key.character = static_cast(message).character(); gui_event.key.key = static_cast(message).key(); gui_event.key.alt = static_cast(message).alt(); @@ -114,7 +114,7 @@ void WSWindow::on_message(WSMessage& message) gui_event.key.shift = static_cast(message).shift(); break; case WSMessage::KeyUp: - gui_event.type = GUI_Event::Type::KeyUp; + gui_event.type = GUI_ServerMessage::Type::KeyUp; gui_event.key.character = static_cast(message).character(); gui_event.key.key = static_cast(message).key(); gui_event.key.alt = static_cast(message).alt(); @@ -134,19 +134,19 @@ void WSWindow::on_message(WSMessage& message) delete this; return; case WSMessage::WindowActivated: - gui_event.type = GUI_Event::Type::WindowActivated; + gui_event.type = GUI_ServerMessage::Type::WindowActivated; break; case WSMessage::WindowDeactivated: - gui_event.type = GUI_Event::Type::WindowDeactivated; + gui_event.type = GUI_ServerMessage::Type::WindowDeactivated; break; case WSMessage::WindowCloseRequest: - gui_event.type = GUI_Event::Type::WindowCloseRequest; + gui_event.type = GUI_ServerMessage::Type::WindowCloseRequest; break; default: break; } - if (gui_event.type == GUI_Event::Type::Invalid) + if (gui_event.type == GUI_ServerMessage::Type::Invalid) return; { diff --git a/WindowServer/WSWindowManager.cpp b/WindowServer/WSWindowManager.cpp index bed78479647..5ac001bc451 100644 --- a/WindowServer/WSWindowManager.cpp +++ b/WindowServer/WSWindowManager.cpp @@ -741,10 +741,10 @@ void WSWindowManager::on_message(WSMessage& message) int menubar_id = m_next_menubar_id++; auto menubar = make(menubar_id, *WSMessageLoop::process_from_client_id(request.client_id())); m_menubars.set(menubar_id, move(menubar)); - GUI_Event event; - event.type = GUI_Event::Type::DidCreateMenubar; - event.menu.menubar_id = menubar_id; - WSMessageLoop::the().post_message_to_client(request.client_id(), event); + GUI_ServerMessage response; + response.type = GUI_ServerMessage::Type::DidCreateMenubar; + response.menu.menubar_id = menubar_id; + WSMessageLoop::the().post_message_to_client(request.client_id(), response); break; } case WSMessage::APIDestroyMenubarRequest: { @@ -759,10 +759,10 @@ void WSWindowManager::on_message(WSMessage& message) if (&menubar == m_current_menubar) set_current_menubar(nullptr); m_menubars.remove(it); - GUI_Event event; - event.type = GUI_Event::Type::DidDestroyMenubar; - event.menu.menubar_id = menubar_id; - WSMessageLoop::the().post_message_to_client(request.client_id(), event); + GUI_ServerMessage response; + response.type = GUI_ServerMessage::Type::DidDestroyMenubar; + response.menu.menubar_id = menubar_id; + WSMessageLoop::the().post_message_to_client(request.client_id(), response); } default: break;