mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
WindowServer: WSWindow can have a pointer to the client rather than an ID.
Since WSWindows are owned by WSConnectionClients, it's fine for them to just reference the client directly.
This commit is contained in:
parent
1056a39bd6
commit
9a39c01551
5 changed files with 19 additions and 22 deletions
|
@ -295,7 +295,7 @@ void WSClientConnection::handle_request(WSAPIGetWindowRectRequest& request)
|
||||||
void WSClientConnection::handle_request(WSAPICreateWindowRequest& request)
|
void WSClientConnection::handle_request(WSAPICreateWindowRequest& request)
|
||||||
{
|
{
|
||||||
int window_id = m_next_window_id++;
|
int window_id = m_next_window_id++;
|
||||||
auto window = make<WSWindow>(request.client_id(), window_id);
|
auto window = make<WSWindow>(*this, window_id);
|
||||||
window->set_title(request.title());
|
window->set_title(request.title());
|
||||||
window->set_rect(request.rect());
|
window->set_rect(request.rect());
|
||||||
m_windows.set(window_id, move(window));
|
m_windows.set(window_id, move(window));
|
||||||
|
|
|
@ -12,8 +12,8 @@ WSWindow::WSWindow(WSMenu& menu)
|
||||||
WSWindowManager::the().add_window(*this);
|
WSWindowManager::the().add_window(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
WSWindow::WSWindow(int client_id, int window_id)
|
WSWindow::WSWindow(WSClientConnection& client, int window_id)
|
||||||
: m_client_id(client_id)
|
: m_client(&client)
|
||||||
, m_type(WSWindowType::Normal)
|
, m_type(WSWindowType::Normal)
|
||||||
, m_window_id(window_id)
|
, m_window_id(window_id)
|
||||||
{
|
{
|
||||||
|
@ -36,8 +36,7 @@ void WSWindow::set_title(String&& title)
|
||||||
void WSWindow::set_rect(const Rect& rect)
|
void WSWindow::set_rect(const Rect& rect)
|
||||||
{
|
{
|
||||||
Rect old_rect;
|
Rect old_rect;
|
||||||
auto* client = WSClientConnection::from_client_id(m_client_id);
|
if (!m_client && !m_menu)
|
||||||
if (!client && !m_menu)
|
|
||||||
return;
|
return;
|
||||||
if (m_rect == rect)
|
if (m_rect == rect)
|
||||||
return;
|
return;
|
||||||
|
@ -46,8 +45,8 @@ void WSWindow::set_rect(const Rect& rect)
|
||||||
if (!m_backing || old_rect.size() != rect.size()) {
|
if (!m_backing || old_rect.size() != rect.size()) {
|
||||||
if (m_menu)
|
if (m_menu)
|
||||||
m_backing = GraphicsBitmap::create(m_rect.size());
|
m_backing = GraphicsBitmap::create(m_rect.size());
|
||||||
else if (client)
|
else if (m_client)
|
||||||
m_backing = client->create_shared_bitmap(m_rect.size());
|
m_backing = m_client->create_shared_bitmap(m_rect.size());
|
||||||
|
|
||||||
}
|
}
|
||||||
WSWindowManager::the().notify_rect_changed(*this, old_rect, rect);
|
WSWindowManager::the().notify_rect_changed(*this, old_rect, rect);
|
||||||
|
@ -126,8 +125,8 @@ void WSWindow::on_message(WSMessage& message)
|
||||||
if (server_message.type == WSAPI_ServerMessage::Type::Invalid)
|
if (server_message.type == WSAPI_ServerMessage::Type::Invalid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (auto* client = WSClientConnection::from_client_id(m_client_id))
|
ASSERT(m_client);
|
||||||
client->post_message(server_message);
|
m_client->post_message(server_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WSWindow::set_global_cursor_tracking_enabled(bool enabled)
|
void WSWindow::set_global_cursor_tracking_enabled(bool enabled)
|
||||||
|
|
|
@ -7,15 +7,17 @@
|
||||||
#include "WSMessageReceiver.h"
|
#include "WSMessageReceiver.h"
|
||||||
#include <WindowServer/WSWindowType.h>
|
#include <WindowServer/WSWindowType.h>
|
||||||
|
|
||||||
|
class WSClientConnection;
|
||||||
class WSMenu;
|
class WSMenu;
|
||||||
|
|
||||||
class WSWindow final : public WSMessageReceiver, public InlineLinkedListNode<WSWindow> {
|
class WSWindow final : public WSMessageReceiver, public InlineLinkedListNode<WSWindow> {
|
||||||
public:
|
public:
|
||||||
WSWindow(int client_id, int window_id);
|
WSWindow(WSClientConnection&, int window_id);
|
||||||
explicit WSWindow(WSMenu&);
|
explicit WSWindow(WSMenu&);
|
||||||
virtual ~WSWindow() override;
|
virtual ~WSWindow() override;
|
||||||
|
|
||||||
int client_id() const { return m_client_id; }
|
WSClientConnection* client() { return m_client; }
|
||||||
|
const WSClientConnection* client() const { return m_client; }
|
||||||
|
|
||||||
WSWindowType type() const { return m_type; }
|
WSWindowType type() const { return m_type; }
|
||||||
int window_id() const { return m_window_id; }
|
int window_id() const { return m_window_id; }
|
||||||
|
@ -63,7 +65,7 @@ public:
|
||||||
WSWindow* m_prev { nullptr };
|
WSWindow* m_prev { nullptr };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_client_id { 0 };
|
WSClientConnection* m_client { nullptr };
|
||||||
String m_title;
|
String m_title;
|
||||||
Rect m_rect;
|
Rect m_rect;
|
||||||
WSWindowType m_type { WSWindowType::Normal };
|
WSWindowType m_type { WSWindowType::Normal };
|
||||||
|
|
|
@ -755,12 +755,8 @@ void WSWindowManager::set_active_window(WSWindow* window)
|
||||||
WSMessageLoop::the().post_message(m_active_window.ptr(), make<WSMessage>(WSMessage::WindowActivated));
|
WSMessageLoop::the().post_message(m_active_window.ptr(), make<WSMessage>(WSMessage::WindowActivated));
|
||||||
invalidate(*m_active_window);
|
invalidate(*m_active_window);
|
||||||
|
|
||||||
int client_id = window->client_id();
|
auto* client = window->client();
|
||||||
auto* client = WSClientConnection::from_client_id(client_id);
|
ASSERT(client);
|
||||||
if (!client) {
|
|
||||||
dbgprintf("WSWindow{%p} (type=%u) has no client! (id=%d)\n", window, window->type(), client_id);
|
|
||||||
ASSERT_NOT_REACHED();
|
|
||||||
}
|
|
||||||
set_current_menubar(client->app_menubar());
|
set_current_menubar(client->app_menubar());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -846,16 +842,16 @@ void WSWindowManager::close_menubar(WSMenuBar& menubar)
|
||||||
set_current_menubar(nullptr);
|
set_current_menubar(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int WSWindowManager::active_client_id() const
|
const WSClientConnection* WSWindowManager::active_client() const
|
||||||
{
|
{
|
||||||
if (m_active_window)
|
if (m_active_window)
|
||||||
return m_active_window->client_id();
|
return m_active_window->client();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WSWindowManager::notify_client_changed_app_menubar(WSClientConnection& client)
|
void WSWindowManager::notify_client_changed_app_menubar(WSClientConnection& client)
|
||||||
{
|
{
|
||||||
if (active_client_id() == client.client_id())
|
if (active_client() == &client)
|
||||||
set_current_menubar(client.app_menubar());
|
set_current_menubar(client.app_menubar());
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ public:
|
||||||
void notify_client_changed_app_menubar(WSClientConnection&);
|
void notify_client_changed_app_menubar(WSClientConnection&);
|
||||||
|
|
||||||
WSWindow* active_window() { return m_active_window.ptr(); }
|
WSWindow* active_window() { return m_active_window.ptr(); }
|
||||||
int active_client_id() const;
|
const WSClientConnection* active_client() const;
|
||||||
|
|
||||||
void move_to_front(WSWindow&);
|
void move_to_front(WSWindow&);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue