mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:07:34 +00:00
WindowServer: Make WSMenu use WSClientConnection::post_message().
This commit is contained in:
parent
8d5ba56cf9
commit
7723c06f27
4 changed files with 15 additions and 18 deletions
|
@ -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<WSMenu>(*WSMessageLoop::process_from_client_id(request.client_id()), menu_id, request.text());
|
||||
auto menu = make<WSMenu>(request.client_id(), menu_id, request.text());
|
||||
m_menus.set(menu_id, move(menu));
|
||||
GUI_ServerMessage response;
|
||||
response.type = GUI_ServerMessage::Type::DidCreateMenu;
|
||||
|
|
|
@ -4,13 +4,14 @@
|
|||
#include "WSMessage.h"
|
||||
#include "WSMessageLoop.h"
|
||||
#include "WSWindowManager.h"
|
||||
#include <WindowServer/WSClientConnection.h>
|
||||
#include <SharedGraphics/Painter.h>
|
||||
#include <SharedGraphics/Font.h>
|
||||
|
||||
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)
|
||||
|
|
|
@ -10,15 +10,14 @@ class WSMenuBar;
|
|||
class WSMessage;
|
||||
class WSWindow;
|
||||
class Font;
|
||||
class Process;
|
||||
|
||||
class WSMenu : public Weakable<WSMenu> {
|
||||
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<OwnPtr<WSMenuItem>> m_items;
|
||||
OwnPtr<WSWindow> m_menu_window;
|
||||
WeakPtr<Process> m_process;
|
||||
};
|
||||
|
||||
|
|
|
@ -186,7 +186,7 @@ WSWindowManager::WSWindowManager()
|
|||
|
||||
{
|
||||
byte system_menu_name[] = { 0xf8, 0 };
|
||||
m_system_menu = make<WSMenu>(*current, -1, String((const char*)system_menu_name));
|
||||
m_system_menu = make<WSMenu>(-1, -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"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue