2019-01-20 04:49:48 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-04-10 17:30:34 +02:00
|
|
|
#include <LibCore/CEventLoop.h>
|
2019-02-15 09:14:21 +01:00
|
|
|
#include <WindowServer/WSAPITypes.h>
|
2019-03-02 10:04:49 +01:00
|
|
|
#include <LibGUI/GEvent.h>
|
2019-01-20 04:49:48 +01:00
|
|
|
|
2019-03-02 10:04:49 +01:00
|
|
|
class GAction;
|
2019-04-10 17:01:54 +02:00
|
|
|
class CObject;
|
2019-04-10 17:35:43 +02:00
|
|
|
class CNotifier;
|
2019-01-20 05:48:43 +01:00
|
|
|
class GWindow;
|
2019-01-20 04:49:48 +01:00
|
|
|
|
2019-04-10 17:30:34 +02:00
|
|
|
class GEventLoop final : public CEventLoop {
|
2019-01-20 04:49:48 +01:00
|
|
|
public:
|
|
|
|
|
GEventLoop();
|
2019-04-10 17:30:34 +02:00
|
|
|
virtual ~GEventLoop() override;
|
2019-01-20 04:49:48 +01:00
|
|
|
|
2019-04-10 17:30:34 +02:00
|
|
|
static GEventLoop& current() { return static_cast<GEventLoop&>(CEventLoop::current()); }
|
2019-02-05 10:31:37 +01:00
|
|
|
|
2019-04-22 01:15:47 +02:00
|
|
|
static bool post_message_to_server(const WSAPI_ClientMessage&, const ByteBuffer& extra_data = { });
|
2019-02-15 09:17:18 +01:00
|
|
|
bool wait_for_specific_event(WSAPI_ServerMessage::Type, WSAPI_ServerMessage&);
|
|
|
|
|
WSAPI_ServerMessage sync_request(const WSAPI_ClientMessage& request, WSAPI_ServerMessage::Type response_type);
|
2019-02-13 17:54:30 +01:00
|
|
|
|
2019-03-17 04:23:54 +01:00
|
|
|
static pid_t server_pid() { return s_server_pid; }
|
2019-05-03 01:38:24 +02:00
|
|
|
static int my_client_id() { return s_my_client_id; }
|
2019-02-20 21:59:13 +01:00
|
|
|
|
2019-04-10 17:30:34 +02:00
|
|
|
virtual void take_pending_events_from(CEventLoop& other) override
|
2019-03-19 00:01:02 +01:00
|
|
|
{
|
2019-04-10 17:30:34 +02:00
|
|
|
CEventLoop::take_pending_events_from(other);
|
2019-04-22 01:15:47 +02:00
|
|
|
m_unprocessed_bundles.append(move(static_cast<GEventLoop&>(other).m_unprocessed_bundles));
|
2019-03-19 00:01:02 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-20 04:49:48 +01:00
|
|
|
private:
|
2019-04-10 17:30:34 +02:00
|
|
|
virtual void add_file_descriptors_for_select(fd_set& fds, int& max_fd_added) override
|
|
|
|
|
{
|
2019-05-14 17:12:09 +02:00
|
|
|
FD_SET(s_windowserver_fd, &fds);
|
|
|
|
|
max_fd_added = s_windowserver_fd;
|
2019-04-10 17:30:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void process_file_descriptors_after_select(const fd_set& fds) override
|
|
|
|
|
{
|
2019-05-14 17:12:09 +02:00
|
|
|
if (FD_ISSET(s_windowserver_fd, &fds))
|
2019-04-10 17:30:34 +02:00
|
|
|
drain_messages_from_server();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void do_processing() override
|
|
|
|
|
{
|
2019-04-28 22:03:18 +02:00
|
|
|
while (!m_unprocessed_bundles.is_empty())
|
|
|
|
|
process_unprocessed_bundles();
|
2019-04-10 17:30:34 +02:00
|
|
|
}
|
|
|
|
|
|
2019-01-20 05:48:43 +01:00
|
|
|
void wait_for_event();
|
2019-02-13 17:59:38 +01:00
|
|
|
bool drain_messages_from_server();
|
2019-04-22 01:15:47 +02:00
|
|
|
void process_unprocessed_bundles();
|
|
|
|
|
void handle_paint_event(const WSAPI_ServerMessage&, GWindow&, const ByteBuffer& extra_data);
|
2019-02-20 15:34:55 +01:00
|
|
|
void handle_resize_event(const WSAPI_ServerMessage&, GWindow&);
|
2019-02-15 09:17:18 +01:00
|
|
|
void handle_mouse_event(const WSAPI_ServerMessage&, GWindow&);
|
|
|
|
|
void handle_key_event(const WSAPI_ServerMessage&, GWindow&);
|
|
|
|
|
void handle_window_activation_event(const WSAPI_ServerMessage&, GWindow&);
|
|
|
|
|
void handle_window_close_request_event(const WSAPI_ServerMessage&, GWindow&);
|
|
|
|
|
void handle_menu_event(const WSAPI_ServerMessage&);
|
2019-02-20 10:12:19 +01:00
|
|
|
void handle_window_entered_or_left_event(const WSAPI_ServerMessage&, GWindow&);
|
2019-04-04 01:44:35 +02:00
|
|
|
void handle_wm_event(const WSAPI_ServerMessage&, GWindow&);
|
2019-05-03 01:38:24 +02:00
|
|
|
void handle_greeting(WSAPI_ServerMessage&);
|
2019-03-09 17:34:09 +01:00
|
|
|
void connect_to_server();
|
2019-02-01 03:50:06 +01:00
|
|
|
|
2019-04-22 01:15:47 +02:00
|
|
|
struct IncomingWSMessageBundle {
|
|
|
|
|
WSAPI_ServerMessage message;
|
|
|
|
|
ByteBuffer extra_data;
|
|
|
|
|
};
|
|
|
|
|
|
2019-05-08 03:35:05 +02:00
|
|
|
Vector<IncomingWSMessageBundle> m_unprocessed_bundles;
|
2019-03-09 17:34:09 +01:00
|
|
|
static pid_t s_server_pid;
|
2019-05-03 01:38:24 +02:00
|
|
|
static int s_my_client_id;
|
2019-05-14 17:12:09 +02:00
|
|
|
static int s_windowserver_fd;
|
2019-01-20 04:49:48 +01:00
|
|
|
};
|