mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 08:00:20 +00:00
WindowServer: Add WSClientConnection::post_message().
This way WSWindow doesn't have to grab at the Process.
This commit is contained in:
parent
427df5f312
commit
9ab9734da0
Notes:
sideshowbarker
2024-07-19 15:45:10 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/9ab9734da06
3 changed files with 43 additions and 39 deletions
|
@ -57,6 +57,14 @@ void WSClientConnection::post_error(const String& error_message)
|
|||
WSMessageLoop::the().post_message_to_client(m_client_id, message);
|
||||
}
|
||||
|
||||
void WSClientConnection::post_message(GUI_ServerMessage&& message)
|
||||
{
|
||||
if (!m_process)
|
||||
return;
|
||||
LOCKER(m_process->gui_events_lock());
|
||||
m_process->gui_events().append(move(message));
|
||||
}
|
||||
|
||||
void WSClientConnection::on_message(WSMessage& message)
|
||||
{
|
||||
if (message.is_client_request()) {
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
class WSWindow;
|
||||
class WSMenu;
|
||||
class WSMenuBar;
|
||||
struct GUI_ServerMessage;
|
||||
|
||||
// FIXME: Remove.
|
||||
class Process;
|
||||
|
@ -21,6 +22,8 @@ public:
|
|||
static WSClientConnection* from_client_id(int client_id);
|
||||
static WSClientConnection* ensure_for_client_id(int client_id);
|
||||
|
||||
void post_message(GUI_ServerMessage&&);
|
||||
|
||||
// FIXME: Remove.
|
||||
Process* process() { return m_process.ptr(); }
|
||||
|
||||
|
|
|
@ -85,69 +85,62 @@ void WSWindow::on_message(WSMessage& message)
|
|||
return;
|
||||
}
|
||||
|
||||
GUI_ServerMessage gui_event;
|
||||
gui_event.window_id = window_id();
|
||||
GUI_ServerMessage server_message;
|
||||
server_message.window_id = window_id();
|
||||
|
||||
switch (message.type()) {
|
||||
case WSMessage::MouseMove:
|
||||
gui_event.type = GUI_ServerMessage::Type::MouseMove;
|
||||
gui_event.mouse.position = static_cast<WSMouseEvent&>(message).position();
|
||||
gui_event.mouse.button = GUI_MouseButton::NoButton;
|
||||
gui_event.mouse.buttons = static_cast<WSMouseEvent&>(message).buttons();
|
||||
server_message.type = GUI_ServerMessage::Type::MouseMove;
|
||||
server_message.mouse.position = static_cast<WSMouseEvent&>(message).position();
|
||||
server_message.mouse.button = GUI_MouseButton::NoButton;
|
||||
server_message.mouse.buttons = static_cast<WSMouseEvent&>(message).buttons();
|
||||
break;
|
||||
case WSMessage::MouseDown:
|
||||
gui_event.type = GUI_ServerMessage::Type::MouseDown;
|
||||
gui_event.mouse.position = static_cast<WSMouseEvent&>(message).position();
|
||||
gui_event.mouse.button = to_api(static_cast<WSMouseEvent&>(message).button());
|
||||
gui_event.mouse.buttons = static_cast<WSMouseEvent&>(message).buttons();
|
||||
server_message.type = GUI_ServerMessage::Type::MouseDown;
|
||||
server_message.mouse.position = static_cast<WSMouseEvent&>(message).position();
|
||||
server_message.mouse.button = to_api(static_cast<WSMouseEvent&>(message).button());
|
||||
server_message.mouse.buttons = static_cast<WSMouseEvent&>(message).buttons();
|
||||
break;
|
||||
case WSMessage::MouseUp:
|
||||
gui_event.type = GUI_ServerMessage::Type::MouseUp;
|
||||
gui_event.mouse.position = static_cast<WSMouseEvent&>(message).position();
|
||||
gui_event.mouse.button = to_api(static_cast<WSMouseEvent&>(message).button());
|
||||
gui_event.mouse.buttons = static_cast<WSMouseEvent&>(message).buttons();
|
||||
server_message.type = GUI_ServerMessage::Type::MouseUp;
|
||||
server_message.mouse.position = static_cast<WSMouseEvent&>(message).position();
|
||||
server_message.mouse.button = to_api(static_cast<WSMouseEvent&>(message).button());
|
||||
server_message.mouse.buttons = static_cast<WSMouseEvent&>(message).buttons();
|
||||
break;
|
||||
case WSMessage::KeyDown:
|
||||
gui_event.type = GUI_ServerMessage::Type::KeyDown;
|
||||
gui_event.key.character = static_cast<WSKeyEvent&>(message).character();
|
||||
gui_event.key.key = static_cast<WSKeyEvent&>(message).key();
|
||||
gui_event.key.alt = static_cast<WSKeyEvent&>(message).alt();
|
||||
gui_event.key.ctrl = static_cast<WSKeyEvent&>(message).ctrl();
|
||||
gui_event.key.shift = static_cast<WSKeyEvent&>(message).shift();
|
||||
server_message.type = GUI_ServerMessage::Type::KeyDown;
|
||||
server_message.key.character = static_cast<WSKeyEvent&>(message).character();
|
||||
server_message.key.key = static_cast<WSKeyEvent&>(message).key();
|
||||
server_message.key.alt = static_cast<WSKeyEvent&>(message).alt();
|
||||
server_message.key.ctrl = static_cast<WSKeyEvent&>(message).ctrl();
|
||||
server_message.key.shift = static_cast<WSKeyEvent&>(message).shift();
|
||||
break;
|
||||
case WSMessage::KeyUp:
|
||||
gui_event.type = GUI_ServerMessage::Type::KeyUp;
|
||||
gui_event.key.character = static_cast<WSKeyEvent&>(message).character();
|
||||
gui_event.key.key = static_cast<WSKeyEvent&>(message).key();
|
||||
gui_event.key.alt = static_cast<WSKeyEvent&>(message).alt();
|
||||
gui_event.key.ctrl = static_cast<WSKeyEvent&>(message).ctrl();
|
||||
gui_event.key.shift = static_cast<WSKeyEvent&>(message).shift();
|
||||
server_message.type = GUI_ServerMessage::Type::KeyUp;
|
||||
server_message.key.character = static_cast<WSKeyEvent&>(message).character();
|
||||
server_message.key.key = static_cast<WSKeyEvent&>(message).key();
|
||||
server_message.key.alt = static_cast<WSKeyEvent&>(message).alt();
|
||||
server_message.key.ctrl = static_cast<WSKeyEvent&>(message).ctrl();
|
||||
server_message.key.shift = static_cast<WSKeyEvent&>(message).shift();
|
||||
break;
|
||||
case WSMessage::WindowActivated:
|
||||
gui_event.type = GUI_ServerMessage::Type::WindowActivated;
|
||||
server_message.type = GUI_ServerMessage::Type::WindowActivated;
|
||||
break;
|
||||
case WSMessage::WindowDeactivated:
|
||||
gui_event.type = GUI_ServerMessage::Type::WindowDeactivated;
|
||||
server_message.type = GUI_ServerMessage::Type::WindowDeactivated;
|
||||
break;
|
||||
case WSMessage::WindowCloseRequest:
|
||||
gui_event.type = GUI_ServerMessage::Type::WindowCloseRequest;
|
||||
server_message.type = GUI_ServerMessage::Type::WindowCloseRequest;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (gui_event.type == GUI_ServerMessage::Type::Invalid)
|
||||
if (server_message.type == GUI_ServerMessage::Type::Invalid)
|
||||
return;
|
||||
|
||||
{
|
||||
WSWindowLocker window_locker(*this);
|
||||
if (auto* client = WSClientConnection::from_client_id(m_client_id)) {
|
||||
if (auto* process = client->process()) {
|
||||
LOCKER(process->gui_events_lock());
|
||||
process->gui_events().append(move(gui_event));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (auto* client = WSClientConnection::from_client_id(m_client_id))
|
||||
client->post_message(move(server_message));
|
||||
}
|
||||
|
||||
void WSWindow::set_global_cursor_tracking_enabled(bool enabled)
|
||||
|
|
Loading…
Reference in a new issue