summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-02-14 10:15:49 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-02-14 10:15:49 +0100
commit9ab9734da06fc93ddb125ac8906107512242032f (patch)
tree1a3652e5a8c5d0b0e6a31332817da737bd04f276
parent427df5f312bda5f8655e2a1124c16dbb0dcd01d9 (diff)
downloadserenity-9ab9734da06fc93ddb125ac8906107512242032f.zip
WindowServer: Add WSClientConnection::post_message().
This way WSWindow doesn't have to grab at the Process.
-rw-r--r--WindowServer/WSClientConnection.cpp8
-rw-r--r--WindowServer/WSClientConnection.h3
-rw-r--r--WindowServer/WSWindow.cpp71
3 files changed, 43 insertions, 39 deletions
diff --git a/WindowServer/WSClientConnection.cpp b/WindowServer/WSClientConnection.cpp
index 61598c92e4..847e565f27 100644
--- a/WindowServer/WSClientConnection.cpp
+++ b/WindowServer/WSClientConnection.cpp
@@ -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()) {
diff --git a/WindowServer/WSClientConnection.h b/WindowServer/WSClientConnection.h
index ee4512ec71..8eda8159d6 100644
--- a/WindowServer/WSClientConnection.h
+++ b/WindowServer/WSClientConnection.h
@@ -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(); }
diff --git a/WindowServer/WSWindow.cpp b/WindowServer/WSWindow.cpp
index bea91954dd..0992bd08eb 100644
--- a/WindowServer/WSWindow.cpp
+++ b/WindowServer/WSWindow.cpp
@@ -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)