From d17a91f1851e8f0b3a3353d677ad8d1f51e921b7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 20 Mar 2019 04:34:14 +0100 Subject: Move WindowServer into Servers. --- Servers/WindowServer/WSClientConnection.h | 101 ++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Servers/WindowServer/WSClientConnection.h (limited to 'Servers/WindowServer/WSClientConnection.h') diff --git a/Servers/WindowServer/WSClientConnection.h b/Servers/WindowServer/WSClientConnection.h new file mode 100644 index 0000000000..06e643ed37 --- /dev/null +++ b/Servers/WindowServer/WSClientConnection.h @@ -0,0 +1,101 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +class WSWindow; +class WSMenu; +class WSMenuBar; +struct WSAPI_ServerMessage; + +class WSClientConnection final : public WSMessageReceiver { +public: + explicit WSClientConnection(int fd); + virtual ~WSClientConnection() override; + + static WSClientConnection* from_client_id(int client_id); + static void for_each_client(Function); + + void post_message(const WSAPI_ServerMessage&); + RetainPtr create_shared_bitmap(GraphicsBitmap::Format, const Size&); + + int client_id() const { return m_client_id; } + WSMenuBar* app_menubar() { return m_app_menubar.ptr(); } + + int fd() const { return m_fd; } + pid_t pid() const { return m_pid; } + + bool is_showing_modal_window() const; + + template void for_each_window_matching(Matching, Callback); + template void for_each_window(Callback); + +private: + virtual void on_message(WSMessage&) override; + + void on_request(WSAPIClientRequest&); + void handle_request(WSAPICreateMenubarRequest&); + void handle_request(WSAPIDestroyMenubarRequest&); + void handle_request(WSAPICreateMenuRequest&); + void handle_request(WSAPIDestroyMenuRequest&); + void handle_request(WSAPISetApplicationMenubarRequest&); + void handle_request(WSAPIAddMenuToMenubarRequest&); + void handle_request(WSAPIAddMenuItemRequest&); + void handle_request(WSAPIAddMenuSeparatorRequest&); + void handle_request(WSAPISetWindowTitleRequest&); + void handle_request(WSAPIGetWindowTitleRequest&); + void handle_request(WSAPISetWindowRectRequest&); + void handle_request(WSAPIGetWindowRectRequest&); + void handle_request(WSAPISetClipboardContentsRequest&); + void handle_request(WSAPIGetClipboardContentsRequest&); + void handle_request(WSAPICreateWindowRequest&); + void handle_request(WSAPIDestroyWindowRequest&); + void handle_request(WSAPIInvalidateRectRequest&); + void handle_request(WSAPIDidFinishPaintingNotification&); + void handle_request(WSAPIGetWindowBackingStoreRequest&); + void handle_request(WSAPISetWindowBackingStoreRequest&); + void handle_request(WSAPISetGlobalCursorTrackingRequest&); + void handle_request(WSAPISetWindowOpacityRequest&); + + void post_error(const String&); + + int m_client_id { 0 }; + int m_fd { -1 }; + pid_t m_pid { 0 }; + + HashMap> m_windows; + HashMap> m_menubars; + HashMap> m_menus; + WeakPtr m_app_menubar; + + int m_next_menubar_id { 10000 }; + int m_next_menu_id { 20000 }; + int m_next_window_id { 1982 }; + + RetainPtr m_last_sent_clipboard_content; +}; + +template +void WSClientConnection::for_each_window_matching(Matching matching, Callback callback) +{ + for (auto& it : m_windows) { + if (matching(*it.value)) { + if (callback(*it.value) == IterationDecision::Abort) + return; + } + } +} + +template +void WSClientConnection::for_each_window(Callback callback) +{ + for (auto& it : m_windows) { + if (callback(*it.value) == IterationDecision::Abort) + return; + } +} -- cgit v1.2.3