Serenity Operating System
at portability 133 lines 8.3 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#pragma once 28 29#include <AK/Function.h> 30#include <AK/HashMap.h> 31#include <AK/OwnPtr.h> 32#include <AK/WeakPtr.h> 33#include <LibCore/Object.h> 34#include <LibGfx/Bitmap.h> 35#include <LibIPC/ClientConnection.h> 36#include <WindowServer/Event.h> 37#include <WindowServer/WindowServerEndpoint.h> 38 39namespace WindowServer { 40 41class Window; 42class Menu; 43class MenuBar; 44 45class ClientConnection final 46 : public IPC::ClientConnection<WindowServerEndpoint> 47 , public WindowServerEndpoint { 48 C_OBJECT(ClientConnection) 49public: 50 ~ClientConnection() override; 51 virtual void die() override; 52 53 void boost(); 54 void deboost(); 55 56 static ClientConnection* from_client_id(int client_id); 57 static void for_each_client(Function<void(ClientConnection&)>); 58 59 MenuBar* app_menubar() { return m_app_menubar.ptr(); } 60 61 bool is_showing_modal_window() const; 62 63 void notify_about_new_screen_rect(const Gfx::Rect&); 64 void notify_about_clipboard_contents_changed(); 65 void post_paint_message(Window&, bool ignore_occlusion = false); 66 67 Menu* find_menu_by_id(int menu_id) 68 { 69 auto menu = m_menus.get(menu_id); 70 if (!menu.has_value()) 71 return nullptr; 72 return const_cast<Menu*>(menu.value().ptr()); 73 } 74 75private: 76 explicit ClientConnection(Core::LocalSocket&, int client_id); 77 78 virtual OwnPtr<Messages::WindowServer::GreetResponse> handle(const Messages::WindowServer::Greet&) override; 79 virtual OwnPtr<Messages::WindowServer::CreateMenubarResponse> handle(const Messages::WindowServer::CreateMenubar&) override; 80 virtual OwnPtr<Messages::WindowServer::DestroyMenubarResponse> handle(const Messages::WindowServer::DestroyMenubar&) override; 81 virtual OwnPtr<Messages::WindowServer::CreateMenuResponse> handle(const Messages::WindowServer::CreateMenu&) override; 82 virtual OwnPtr<Messages::WindowServer::DestroyMenuResponse> handle(const Messages::WindowServer::DestroyMenu&) override; 83 virtual OwnPtr<Messages::WindowServer::AddMenuToMenubarResponse> handle(const Messages::WindowServer::AddMenuToMenubar&) override; 84 virtual OwnPtr<Messages::WindowServer::SetApplicationMenubarResponse> handle(const Messages::WindowServer::SetApplicationMenubar&) override; 85 virtual OwnPtr<Messages::WindowServer::AddMenuItemResponse> handle(const Messages::WindowServer::AddMenuItem&) override; 86 virtual OwnPtr<Messages::WindowServer::AddMenuSeparatorResponse> handle(const Messages::WindowServer::AddMenuSeparator&) override; 87 virtual OwnPtr<Messages::WindowServer::UpdateMenuItemResponse> handle(const Messages::WindowServer::UpdateMenuItem&) override; 88 virtual OwnPtr<Messages::WindowServer::CreateWindowResponse> handle(const Messages::WindowServer::CreateWindow&) override; 89 virtual OwnPtr<Messages::WindowServer::DestroyWindowResponse> handle(const Messages::WindowServer::DestroyWindow&) override; 90 virtual OwnPtr<Messages::WindowServer::SetWindowTitleResponse> handle(const Messages::WindowServer::SetWindowTitle&) override; 91 virtual OwnPtr<Messages::WindowServer::GetWindowTitleResponse> handle(const Messages::WindowServer::GetWindowTitle&) override; 92 virtual OwnPtr<Messages::WindowServer::SetWindowRectResponse> handle(const Messages::WindowServer::SetWindowRect&) override; 93 virtual OwnPtr<Messages::WindowServer::GetWindowRectResponse> handle(const Messages::WindowServer::GetWindowRect&) override; 94 virtual void handle(const Messages::WindowServer::InvalidateRect&) override; 95 virtual void handle(const Messages::WindowServer::DidFinishPainting&) override; 96 virtual OwnPtr<Messages::WindowServer::SetGlobalCursorTrackingResponse> handle(const Messages::WindowServer::SetGlobalCursorTracking&) override; 97 virtual OwnPtr<Messages::WindowServer::SetWindowOpacityResponse> handle(const Messages::WindowServer::SetWindowOpacity&) override; 98 virtual OwnPtr<Messages::WindowServer::SetWindowBackingStoreResponse> handle(const Messages::WindowServer::SetWindowBackingStore&) override; 99 virtual OwnPtr<Messages::WindowServer::GetClipboardContentsResponse> handle(const Messages::WindowServer::GetClipboardContents&) override; 100 virtual OwnPtr<Messages::WindowServer::SetClipboardContentsResponse> handle(const Messages::WindowServer::SetClipboardContents&) override; 101 virtual void handle(const Messages::WindowServer::WM_SetActiveWindow&) override; 102 virtual void handle(const Messages::WindowServer::WM_SetWindowMinimized&) override; 103 virtual void handle(const Messages::WindowServer::WM_StartWindowResize&) override; 104 virtual void handle(const Messages::WindowServer::WM_PopupWindowMenu&) override; 105 virtual OwnPtr<Messages::WindowServer::SetWindowHasAlphaChannelResponse> handle(const Messages::WindowServer::SetWindowHasAlphaChannel&) override; 106 virtual OwnPtr<Messages::WindowServer::MoveWindowToFrontResponse> handle(const Messages::WindowServer::MoveWindowToFront&) override; 107 virtual OwnPtr<Messages::WindowServer::SetFullscreenResponse> handle(const Messages::WindowServer::SetFullscreen&) override; 108 virtual void handle(const Messages::WindowServer::AsyncSetWallpaper&) override; 109 virtual OwnPtr<Messages::WindowServer::GetWallpaperResponse> handle(const Messages::WindowServer::GetWallpaper&) override; 110 virtual OwnPtr<Messages::WindowServer::SetResolutionResponse> handle(const Messages::WindowServer::SetResolution&) override; 111 virtual OwnPtr<Messages::WindowServer::SetWindowOverrideCursorResponse> handle(const Messages::WindowServer::SetWindowOverrideCursor&) override; 112 virtual OwnPtr<Messages::WindowServer::PopupMenuResponse> handle(const Messages::WindowServer::PopupMenu&) override; 113 virtual OwnPtr<Messages::WindowServer::DismissMenuResponse> handle(const Messages::WindowServer::DismissMenu&) override; 114 virtual OwnPtr<Messages::WindowServer::SetWindowIconBitmapResponse> handle(const Messages::WindowServer::SetWindowIconBitmap&) override; 115 virtual void handle(const Messages::WindowServer::WM_SetWindowTaskbarRect&) override; 116 virtual OwnPtr<Messages::WindowServer::StartDragResponse> handle(const Messages::WindowServer::StartDrag&) override; 117 virtual OwnPtr<Messages::WindowServer::SetSystemMenuResponse> handle(const Messages::WindowServer::SetSystemMenu&) override; 118 virtual OwnPtr<Messages::WindowServer::SetSystemThemeResponse> handle(const Messages::WindowServer::SetSystemTheme&) override; 119 virtual OwnPtr<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrementResponse> handle(const Messages::WindowServer::SetWindowBaseSizeAndSizeIncrement&) override; 120 121 HashMap<int, NonnullRefPtr<Window>> m_windows; 122 HashMap<int, NonnullOwnPtr<MenuBar>> m_menubars; 123 HashMap<int, NonnullRefPtr<Menu>> m_menus; 124 WeakPtr<MenuBar> m_app_menubar; 125 126 int m_next_menubar_id { 10000 }; 127 int m_next_menu_id { 20000 }; 128 int m_next_window_id { 1982 }; 129 130 RefPtr<SharedBuffer> m_last_sent_clipboard_content; 131}; 132 133}