summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI/GEventLoop.h
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries/LibGUI/GEventLoop.h')
-rw-r--r--Libraries/LibGUI/GEventLoop.h66
1 files changed, 19 insertions, 47 deletions
diff --git a/Libraries/LibGUI/GEventLoop.h b/Libraries/LibGUI/GEventLoop.h
index aa54682545..303a77e835 100644
--- a/Libraries/LibGUI/GEventLoop.h
+++ b/Libraries/LibGUI/GEventLoop.h
@@ -1,6 +1,7 @@
#pragma once
#include <LibCore/CEventLoop.h>
+#include <LibCore/CIPCClientSideConnection.h>
#include <LibGUI/GEvent.h>
#include <WindowServer/WSAPITypes.h>
@@ -9,48 +10,16 @@ class CObject;
class CNotifier;
class GWindow;
-class GEventLoop final : public CEventLoop {
+class GWindowServerConnection : public CIPCClientSideConnection<WSAPI_ServerMessage, WSAPI_ClientMessage> {
public:
- GEventLoop();
- virtual ~GEventLoop() override;
-
- static GEventLoop& current() { return static_cast<GEventLoop&>(CEventLoop::current()); }
-
- static bool post_message_to_server(const WSAPI_ClientMessage&, const ByteBuffer& extra_data = {});
- bool wait_for_specific_event(WSAPI_ServerMessage::Type, WSAPI_ServerMessage&);
- WSAPI_ServerMessage sync_request(const WSAPI_ClientMessage& request, WSAPI_ServerMessage::Type response_type);
+ GWindowServerConnection()
+ : CIPCClientSideConnection("/tmp/wsportal")
+ {}
- static pid_t server_pid() { return s_server_pid; }
- static int my_client_id() { return s_my_client_id; }
-
- virtual void take_pending_events_from(CEventLoop& other) override
- {
- CEventLoop::take_pending_events_from(other);
- m_unprocessed_bundles.append(move(static_cast<GEventLoop&>(other).m_unprocessed_bundles));
- }
+ void handshake() override;
private:
- virtual void add_file_descriptors_for_select(fd_set& fds, int& max_fd_added) override
- {
- FD_SET(s_windowserver_fd, &fds);
- max_fd_added = s_windowserver_fd;
- }
-
- virtual void process_file_descriptors_after_select(const fd_set& fds) override
- {
- if (FD_ISSET(s_windowserver_fd, &fds))
- drain_messages_from_server();
- }
-
- virtual void do_processing() override
- {
- while (!m_unprocessed_bundles.is_empty())
- process_unprocessed_bundles();
- }
-
- void wait_for_event();
- bool drain_messages_from_server();
- void process_unprocessed_bundles();
+ void postprocess_bundles(Vector<IncomingASMessageBundle>& m_unprocessed_bundles) override;
void handle_paint_event(const WSAPI_ServerMessage&, GWindow&, const ByteBuffer& extra_data);
void handle_resize_event(const WSAPI_ServerMessage&, GWindow&);
void handle_mouse_event(const WSAPI_ServerMessage&, GWindow&);
@@ -61,15 +30,18 @@ private:
void handle_window_entered_or_left_event(const WSAPI_ServerMessage&, GWindow&);
void handle_wm_event(const WSAPI_ServerMessage&, GWindow&);
void handle_greeting(WSAPI_ServerMessage&);
- void connect_to_server();
+};
+
+class GEventLoop final : public CEventLoop {
+public:
+ GEventLoop();
+ virtual ~GEventLoop() override;
+
+ static GEventLoop& current() { return static_cast<GEventLoop&>(CEventLoop::current()); }
- struct IncomingWSMessageBundle {
- WSAPI_ServerMessage message;
- ByteBuffer extra_data;
- };
+ GWindowServerConnection& connection() { return m_connection; }
- Vector<IncomingWSMessageBundle> m_unprocessed_bundles;
- static pid_t s_server_pid;
- static int s_my_client_id;
- static int s_windowserver_fd;
+private:
+ void process_unprocessed_bundles();
+ GWindowServerConnection m_connection;
};