LibGUI+WindowServer: Add a way to dismiss opened menus from the client.

This commit is contained in:
Andreas Kling 2019-04-14 01:53:19 +02:00
parent 29d0412a06
commit 91e1f3ffb1
Notes: sideshowbarker 2024-07-19 14:43:43 +09:00
7 changed files with 44 additions and 0 deletions

View file

@ -50,6 +50,16 @@ void GMenu::popup(const Point& screen_position)
GEventLoop::post_message_to_server(request);
}
void GMenu::dismiss()
{
if (!m_menu_id)
return;
WSAPI_ClientMessage request;
request.type = WSAPI_ClientMessage::Type::DismissMenu;
request.menu.menu_id = m_menu_id;
GEventLoop::post_message_to_server(request);
}
int GMenu::realize_menu()
{
WSAPI_ClientMessage request;

View file

@ -20,6 +20,7 @@ public:
void add_separator();
void popup(const Point& screen_position);
void dismiss();
Function<void(unsigned)> on_item_activation;

View file

@ -195,6 +195,7 @@ struct WSAPI_ClientMessage {
SetWindowOverrideCursor,
WM_SetActiveWindow,
PopupMenu,
DismissMenu,
SetWindowIcon,
};
Type type { Invalid };

View file

@ -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;
}

View file

@ -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&);

View file

@ -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:

View file

@ -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)));