mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:08:13 +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
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++;
|
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));
|
m_menubars.set(menubar_id, move(menubar));
|
||||||
WSAPI_ServerMessage response;
|
WSAPI_ServerMessage response;
|
||||||
response.type = WSAPI_ServerMessage::Type::DidCreateMenubar;
|
response.type = WSAPI_ServerMessage::Type::DidCreateMenubar;
|
||||||
|
@ -133,7 +133,7 @@ void WSClientConnection::handle_request(WSAPIDestroyMenubarRequest& request)
|
||||||
void WSClientConnection::handle_request(WSAPICreateMenuRequest& request)
|
void WSClientConnection::handle_request(WSAPICreateMenuRequest& request)
|
||||||
{
|
{
|
||||||
int menu_id = m_next_menu_id++;
|
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));
|
m_menus.set(menu_id, move(menu));
|
||||||
WSAPI_ServerMessage response;
|
WSAPI_ServerMessage response;
|
||||||
response.type = WSAPI_ServerMessage::Type::DidCreateMenu;
|
response.type = WSAPI_ServerMessage::Type::DidCreateMenu;
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
#include <SharedGraphics/Painter.h>
|
#include <SharedGraphics/Painter.h>
|
||||||
#include <SharedGraphics/Font.h>
|
#include <SharedGraphics/Font.h>
|
||||||
|
|
||||||
WSMenu::WSMenu(int client_id, int menu_id, String&& name)
|
WSMenu::WSMenu(WSClientConnection* client, int menu_id, String&& name)
|
||||||
: m_client_id(client_id)
|
: m_client(client)
|
||||||
, m_menu_id(menu_id)
|
, m_menu_id(menu_id)
|
||||||
, m_name(move(name))
|
, m_name(move(name))
|
||||||
{
|
{
|
||||||
|
@ -144,8 +144,8 @@ void WSMenu::did_activate(WSMenuItem& item)
|
||||||
message.menu.menu_id = m_menu_id;
|
message.menu.menu_id = m_menu_id;
|
||||||
message.menu.identifier = item.identifier();
|
message.menu.identifier = item.identifier();
|
||||||
|
|
||||||
if (auto* client = WSClientConnection::from_client_id(m_client_id))
|
if (m_client)
|
||||||
client->post_message(message);
|
m_client->post_message(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
WSMenuItem* WSMenu::item_at(const Point& position)
|
WSMenuItem* WSMenu::item_at(const Point& position)
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <SharedGraphics/Rect.h>
|
#include <SharedGraphics/Rect.h>
|
||||||
#include "WSMenuItem.h"
|
#include "WSMenuItem.h"
|
||||||
|
|
||||||
|
class WSClientConnection;
|
||||||
class WSMenuBar;
|
class WSMenuBar;
|
||||||
class WSMessage;
|
class WSMessage;
|
||||||
class WSWindow;
|
class WSWindow;
|
||||||
|
@ -13,10 +14,11 @@ class Font;
|
||||||
|
|
||||||
class WSMenu : public Weakable<WSMenu> {
|
class WSMenu : public Weakable<WSMenu> {
|
||||||
public:
|
public:
|
||||||
WSMenu(int client_id, int menu_id, String&& name);
|
WSMenu(WSClientConnection*, int menu_id, String&& name);
|
||||||
~WSMenu();
|
~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; }
|
int menu_id() const { return m_menu_id; }
|
||||||
|
|
||||||
WSMenuBar* menu_bar() { return m_menubar; }
|
WSMenuBar* menu_bar() { return m_menubar; }
|
||||||
|
@ -74,7 +76,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void did_activate(WSMenuItem&);
|
void did_activate(WSMenuItem&);
|
||||||
int m_client_id { 0 };
|
WSClientConnection* m_client { nullptr };
|
||||||
int m_menu_id { 0 };
|
int m_menu_id { 0 };
|
||||||
String m_name;
|
String m_name;
|
||||||
Rect m_rect_in_menubar;
|
Rect m_rect_in_menubar;
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
#include "WSMenu.h"
|
#include "WSMenu.h"
|
||||||
#include "WSMenuItem.h"
|
#include "WSMenuItem.h"
|
||||||
|
|
||||||
WSMenuBar::WSMenuBar(int client_id, int menubar_id)
|
WSMenuBar::WSMenuBar(WSClientConnection& client, int menubar_id)
|
||||||
: m_client_id(client_id)
|
: m_client(client)
|
||||||
, m_menubar_id(menubar_id)
|
, m_menubar_id(menubar_id)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,11 @@
|
||||||
|
|
||||||
class WSMenuBar : public Weakable<WSMenuBar> {
|
class WSMenuBar : public Weakable<WSMenuBar> {
|
||||||
public:
|
public:
|
||||||
WSMenuBar(int client_id, int menubar_id);
|
WSMenuBar(WSClientConnection& client, int menubar_id);
|
||||||
~WSMenuBar();
|
~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; }
|
int menubar_id() const { return m_menubar_id; }
|
||||||
void add_menu(WSMenu* menu) { m_menus.append(menu); }
|
void add_menu(WSMenu* menu) { m_menus.append(menu); }
|
||||||
|
|
||||||
|
@ -24,7 +25,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_client_id { 0 };
|
WSClientConnection& m_client;
|
||||||
int m_menubar_id { 0 };
|
int m_menubar_id { 0 };
|
||||||
Vector<WSMenu*> m_menus;
|
Vector<WSMenu*> m_menus;
|
||||||
};
|
};
|
||||||
|
|
|
@ -184,7 +184,7 @@ WSWindowManager::WSWindowManager()
|
||||||
|
|
||||||
{
|
{
|
||||||
byte system_menu_name[] = { 0xf8, 0 };
|
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>(0, "Launch Terminal"));
|
||||||
m_system_menu->add_item(make<WSMenuItem>(WSMenuItem::Separator));
|
m_system_menu->add_item(make<WSMenuItem>(WSMenuItem::Separator));
|
||||||
m_system_menu->add_item(make<WSMenuItem>(1, "Hello again"));
|
m_system_menu->add_item(make<WSMenuItem>(1, "Hello again"));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue