diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-02-17 09:06:47 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-02-17 09:07:07 +0100 |
commit | fa452fadca1c372cff8486d726d25b27de54fbfd (patch) | |
tree | b86a7d709f2bafb6f0cc3cb719152522bd9c61cb /WindowServer | |
parent | 459cc234410bf2344144b2a5419c27f769dd3981 (diff) | |
download | serenity-fa452fadca1c372cff8486d726d25b27de54fbfd.zip |
WindowServer: Let menu objects reference the WSClientConnection by pointer.
Since these are owner/ownee relationships, there's no need for indirection.
Diffstat (limited to 'WindowServer')
-rw-r--r-- | WindowServer/WSClientConnection.cpp | 6 | ||||
-rw-r--r-- | WindowServer/WSMenu.cpp | 8 | ||||
-rw-r--r-- | WindowServer/WSMenu.h | 8 | ||||
-rw-r--r-- | WindowServer/WSMenuBar.cpp | 4 | ||||
-rw-r--r-- | WindowServer/WSMenuBar.h | 7 | ||||
-rw-r--r-- | WindowServer/WSWindowManager.cpp | 2 |
6 files changed, 19 insertions, 16 deletions
diff --git a/WindowServer/WSClientConnection.cpp b/WindowServer/WSClientConnection.cpp index 3df245d655..b178a58ed1 100644 --- a/WindowServer/WSClientConnection.cpp +++ b/WindowServer/WSClientConnection.cpp @@ -102,10 +102,10 @@ void WSClientConnection::on_message(WSMessage& message) } } -void WSClientConnection::handle_request(WSAPICreateMenubarRequest& request) +void WSClientConnection::handle_request(WSAPICreateMenubarRequest&) { int menubar_id = m_next_menubar_id++; - auto menubar = make<WSMenuBar>(request.client_id(), menubar_id); + auto menubar = make<WSMenuBar>(*this, menubar_id); m_menubars.set(menubar_id, move(menubar)); WSAPI_ServerMessage response; response.type = WSAPI_ServerMessage::Type::DidCreateMenubar; @@ -133,7 +133,7 @@ void WSClientConnection::handle_request(WSAPIDestroyMenubarRequest& request) void WSClientConnection::handle_request(WSAPICreateMenuRequest& request) { int menu_id = m_next_menu_id++; - auto menu = make<WSMenu>(request.client_id(), menu_id, request.text()); + auto menu = make<WSMenu>(this, menu_id, request.text()); m_menus.set(menu_id, move(menu)); WSAPI_ServerMessage response; response.type = WSAPI_ServerMessage::Type::DidCreateMenu; diff --git a/WindowServer/WSMenu.cpp b/WindowServer/WSMenu.cpp index 04201f7a15..6555157241 100644 --- a/WindowServer/WSMenu.cpp +++ b/WindowServer/WSMenu.cpp @@ -9,8 +9,8 @@ #include <SharedGraphics/Painter.h> #include <SharedGraphics/Font.h> -WSMenu::WSMenu(int client_id, int menu_id, String&& name) - : m_client_id(client_id) +WSMenu::WSMenu(WSClientConnection* client, int menu_id, String&& name) + : m_client(client) , m_menu_id(menu_id) , m_name(move(name)) { @@ -144,8 +144,8 @@ void WSMenu::did_activate(WSMenuItem& item) message.menu.menu_id = m_menu_id; message.menu.identifier = item.identifier(); - if (auto* client = WSClientConnection::from_client_id(m_client_id)) - client->post_message(message); + if (m_client) + m_client->post_message(message); } WSMenuItem* WSMenu::item_at(const Point& position) diff --git a/WindowServer/WSMenu.h b/WindowServer/WSMenu.h index 7f05830fb3..2ec7001657 100644 --- a/WindowServer/WSMenu.h +++ b/WindowServer/WSMenu.h @@ -6,6 +6,7 @@ #include <SharedGraphics/Rect.h> #include "WSMenuItem.h" +class WSClientConnection; class WSMenuBar; class WSMessage; class WSWindow; @@ -13,10 +14,11 @@ class Font; class WSMenu : public Weakable<WSMenu> { public: - WSMenu(int client_id, int menu_id, String&& name); + WSMenu(WSClientConnection*, int menu_id, String&& name); ~WSMenu(); - int client_id() const { return m_client_id; } + WSClientConnection* client() { return m_client; } + const WSClientConnection* client() const { return m_client; } int menu_id() const { return m_menu_id; } WSMenuBar* menu_bar() { return m_menubar; } @@ -74,7 +76,7 @@ public: private: void did_activate(WSMenuItem&); - int m_client_id { 0 }; + WSClientConnection* m_client { nullptr }; int m_menu_id { 0 }; String m_name; Rect m_rect_in_menubar; diff --git a/WindowServer/WSMenuBar.cpp b/WindowServer/WSMenuBar.cpp index 0f6b389936..6d642d160d 100644 --- a/WindowServer/WSMenuBar.cpp +++ b/WindowServer/WSMenuBar.cpp @@ -2,8 +2,8 @@ #include "WSMenu.h" #include "WSMenuItem.h" -WSMenuBar::WSMenuBar(int client_id, int menubar_id) - : m_client_id(client_id) +WSMenuBar::WSMenuBar(WSClientConnection& client, int menubar_id) + : m_client(client) , m_menubar_id(menubar_id) { } diff --git a/WindowServer/WSMenuBar.h b/WindowServer/WSMenuBar.h index da209e9b9d..7854795ed5 100644 --- a/WindowServer/WSMenuBar.h +++ b/WindowServer/WSMenuBar.h @@ -7,10 +7,11 @@ class WSMenuBar : public Weakable<WSMenuBar> { public: - WSMenuBar(int client_id, int menubar_id); + WSMenuBar(WSClientConnection& client, int menubar_id); ~WSMenuBar(); - int client_id() const { return m_client_id; } + WSClientConnection& client() { return m_client; } + const WSClientConnection& client() const { return m_client; } int menubar_id() const { return m_menubar_id; } void add_menu(WSMenu* menu) { m_menus.append(menu); } @@ -24,7 +25,7 @@ public: } private: - int m_client_id { 0 }; + WSClientConnection& m_client; int m_menubar_id { 0 }; Vector<WSMenu*> m_menus; }; diff --git a/WindowServer/WSWindowManager.cpp b/WindowServer/WSWindowManager.cpp index 08ffefa86d..6d239a0fc2 100644 --- a/WindowServer/WSWindowManager.cpp +++ b/WindowServer/WSWindowManager.cpp @@ -184,7 +184,7 @@ WSWindowManager::WSWindowManager() { byte system_menu_name[] = { 0xf8, 0 }; - m_system_menu = make<WSMenu>(-1, -1, String((const char*)system_menu_name)); + m_system_menu = make<WSMenu>(nullptr, -1, String((const char*)system_menu_name)); m_system_menu->add_item(make<WSMenuItem>(0, "Launch Terminal")); m_system_menu->add_item(make<WSMenuItem>(WSMenuItem::Separator)); m_system_menu->add_item(make<WSMenuItem>(1, "Hello again")); |