diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-14 01:53:19 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-14 01:53:19 +0200 |
commit | 91e1f3ffb1f6d967a0b1ca3af09d75d5c1ac0212 (patch) | |
tree | 98c2b357b14dae6a2749f15d97524cb09c764859 /Servers | |
parent | 29d0412a06adb134658c065ff5c801e20afdf7e5 (diff) | |
download | serenity-91e1f3ffb1f6d967a0b1ca3af09d75d5c1ac0212.zip |
LibGUI+WindowServer: Add a way to dismiss opened menus from the client.
Diffstat (limited to 'Servers')
-rw-r--r-- | Servers/WindowServer/WSAPITypes.h | 1 | ||||
-rw-r--r-- | Servers/WindowServer/WSClientConnection.cpp | 14 | ||||
-rw-r--r-- | Servers/WindowServer/WSClientConnection.h | 1 | ||||
-rw-r--r-- | Servers/WindowServer/WSMessage.h | 14 | ||||
-rw-r--r-- | Servers/WindowServer/WSMessageLoop.cpp | 3 |
5 files changed, 33 insertions, 0 deletions
diff --git a/Servers/WindowServer/WSAPITypes.h b/Servers/WindowServer/WSAPITypes.h index 5ba2e28895..c7c7dc6345 100644 --- a/Servers/WindowServer/WSAPITypes.h +++ b/Servers/WindowServer/WSAPITypes.h @@ -195,6 +195,7 @@ struct WSAPI_ClientMessage { SetWindowOverrideCursor, WM_SetActiveWindow, PopupMenu, + DismissMenu, SetWindowIcon, }; Type type { Invalid }; diff --git a/Servers/WindowServer/WSClientConnection.cpp b/Servers/WindowServer/WSClientConnection.cpp index 7df858b25e..bda8da4431 100644 --- a/Servers/WindowServer/WSClientConnection.cpp +++ b/Servers/WindowServer/WSClientConnection.cpp @@ -236,6 +236,18 @@ void WSClientConnection::handle_request(const WSAPIPopupMenuRequest& request) menu.popup(position); } +void WSClientConnection::handle_request(const WSAPIDismissMenuRequest& request) +{ + int menu_id = request.menu_id(); + auto it = m_menus.find(menu_id); + if (it == m_menus.end()) { + post_error("WSAPIDismissMenuRequest: Bad menu ID"); + return; + } + auto& menu = *(*it).value; + menu.close(); +} + void WSClientConnection::handle_request(const WSAPIUpdateMenuItemRequest& request) { int menu_id = request.menu_id(); @@ -655,6 +667,8 @@ void WSClientConnection::on_request(const WSAPIClientRequest& request) return handle_request(static_cast<const WSWMAPISetActiveWindowRequest&>(request)); case WSMessage::APIPopupMenuRequest: return handle_request(static_cast<const WSAPIPopupMenuRequest&>(request)); + case WSMessage::APIDismissMenuRequest: + return handle_request(static_cast<const WSAPIDismissMenuRequest&>(request)); default: break; } diff --git a/Servers/WindowServer/WSClientConnection.h b/Servers/WindowServer/WSClientConnection.h index ff1fda9c99..3cf9a0b861 100644 --- a/Servers/WindowServer/WSClientConnection.h +++ b/Servers/WindowServer/WSClientConnection.h @@ -72,6 +72,7 @@ private: void handle_request(const WSAPISetWindowOverrideCursorRequest&); void handle_request(const WSWMAPISetActiveWindowRequest&); void handle_request(const WSAPIPopupMenuRequest&); + void handle_request(const WSAPIDismissMenuRequest&); void post_error(const String&); diff --git a/Servers/WindowServer/WSMessage.h b/Servers/WindowServer/WSMessage.h index 628f113ffa..385b3afd44 100644 --- a/Servers/WindowServer/WSMessage.h +++ b/Servers/WindowServer/WSMessage.h @@ -59,6 +59,7 @@ public: APISetWindowOverrideCursorRequest, WMAPISetActiveWindowRequest, APIPopupMenuRequest, + APIDismissMenuRequest, __End_API_Client_Requests, }; @@ -208,6 +209,19 @@ private: Point m_position; }; +class WSAPIDismissMenuRequest : public WSAPIClientRequest { +public: + WSAPIDismissMenuRequest(int client_id, int menu_id) + : WSAPIClientRequest(WSMessage::APIDismissMenuRequest, client_id) + , m_menu_id(menu_id) + { + } + + int menu_id() const { return m_menu_id; } + +private: + int m_menu_id; +}; class WSAPICreateMenuRequest : public WSAPIClientRequest { public: diff --git a/Servers/WindowServer/WSMessageLoop.cpp b/Servers/WindowServer/WSMessageLoop.cpp index 938a65b1b0..b98937ae99 100644 --- a/Servers/WindowServer/WSMessageLoop.cpp +++ b/Servers/WindowServer/WSMessageLoop.cpp @@ -293,6 +293,9 @@ void WSMessageLoop::on_receive_from_client(int client_id, const WSAPI_ClientMess case WSAPI_ClientMessage::Type::PopupMenu: post_message(client, make<WSAPIPopupMenuRequest>(client_id, message.menu.menu_id, message.menu.position)); break; + case WSAPI_ClientMessage::Type::DismissMenu: + post_message(client, make<WSAPIDismissMenuRequest>(client_id, message.menu.menu_id)); + break; case WSAPI_ClientMessage::Type::SetWindowIcon: ASSERT(message.text_length < (ssize_t)sizeof(message.text)); post_message(client, make<WSAPISetWindowIconRequest>(client_id, message.window_id, String(message.text, message.text_length))); |