diff --git a/WindowServer/WSClientConnection.cpp b/WindowServer/WSClientConnection.cpp index 166ae62554..9af3a148b6 100644 --- a/WindowServer/WSClientConnection.cpp +++ b/WindowServer/WSClientConnection.cpp @@ -118,7 +118,7 @@ void WSClientConnection::handle_request(WSAPIDestroyMenubarRequest& request) void WSClientConnection::handle_request(WSAPICreateMenuRequest& request) { int menu_id = m_next_menu_id++; - auto menu = make(*WSMessageLoop::process_from_client_id(request.client_id()), menu_id, request.text()); + auto menu = make(request.client_id(), menu_id, request.text()); m_menus.set(menu_id, move(menu)); GUI_ServerMessage response; response.type = GUI_ServerMessage::Type::DidCreateMenu; diff --git a/WindowServer/WSMenu.cpp b/WindowServer/WSMenu.cpp index e0f9e35e9b..dfe841e5a3 100644 --- a/WindowServer/WSMenu.cpp +++ b/WindowServer/WSMenu.cpp @@ -4,13 +4,14 @@ #include "WSMessage.h" #include "WSMessageLoop.h" #include "WSWindowManager.h" +#include #include #include -WSMenu::WSMenu(Process& process, int menu_id, String&& name) - : m_menu_id(menu_id) +WSMenu::WSMenu(int client_id, int menu_id, String&& name) + : m_client_id(client_id) + , m_menu_id(menu_id) , m_name(move(name)) - , m_process(process.make_weak_ptr()) { } @@ -137,15 +138,13 @@ void WSMenu::did_activate(WSMenuItem& item) close(); - 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(); + GUI_ServerMessage message; + message.type = GUI_ServerMessage::Type::MenuItemActivated; + message.menu.menu_id = m_menu_id; + message.menu.identifier = item.identifier(); - if (!m_process) - return; - LOCKER(m_process->gui_events_lock()); - m_process->gui_events().append(move(gui_event)); + if (auto* client = WSClientConnection::from_client_id(m_client_id)) + client->post_message(move(message)); } WSMenuItem* WSMenu::item_at(const Point& position) diff --git a/WindowServer/WSMenu.h b/WindowServer/WSMenu.h index 363f92b52c..7f05830fb3 100644 --- a/WindowServer/WSMenu.h +++ b/WindowServer/WSMenu.h @@ -10,15 +10,14 @@ class WSMenuBar; class WSMessage; class WSWindow; class Font; -class Process; class WSMenu : public Weakable { public: - WSMenu(Process&, int menu_id, String&& name); + WSMenu(int client_id, int menu_id, String&& name); ~WSMenu(); + int client_id() const { return m_client_id; } int menu_id() const { return m_menu_id; } - const Process* process() const { return m_process.ptr(); } WSMenuBar* menu_bar() { return m_menubar; } const WSMenuBar* menu_bar() const { return m_menubar; } @@ -75,7 +74,7 @@ public: private: void did_activate(WSMenuItem&); - + int m_client_id { 0 }; int m_menu_id { 0 }; String m_name; Rect m_rect_in_menubar; @@ -84,6 +83,5 @@ private: WSMenuItem* m_hovered_item { nullptr }; Vector> m_items; OwnPtr m_menu_window; - WeakPtr m_process; }; diff --git a/WindowServer/WSWindowManager.cpp b/WindowServer/WSWindowManager.cpp index ff34df15d9..021f3fb99b 100644 --- a/WindowServer/WSWindowManager.cpp +++ b/WindowServer/WSWindowManager.cpp @@ -186,7 +186,7 @@ WSWindowManager::WSWindowManager() { byte system_menu_name[] = { 0xf8, 0 }; - m_system_menu = make(*current, -1, String((const char*)system_menu_name)); + m_system_menu = make(-1, -1, String((const char*)system_menu_name)); m_system_menu->add_item(make(0, "Launch Terminal")); m_system_menu->add_item(make(WSMenuItem::Separator)); m_system_menu->add_item(make(1, "Hello again"));