mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
WindowServer: Let menu objects reference the WSClientConnection by pointer.
Since these are owner/ownee relationships, there's no need for indirection.
This commit is contained in:
parent
459cc23441
commit
fa452fadca
Notes:
sideshowbarker
2024-07-19 15:41:13 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/fa452fadca1
6 changed files with 19 additions and 16 deletions
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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"));
|
||||
|
|
Loading…
Reference in a new issue