Serenity Operating System
at hosted 143 lines 8.9 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/Badge.h> 30#include <AK/Function.h> 31#include <AK/HashMap.h> 32#include <AK/OwnPtr.h> 33#include <AK/WeakPtr.h> 34#include <LibCore/Object.h> 35#include <LibGfx/Bitmap.h> 36#include <LibIPC/ClientConnection.h> 37#include <WindowServer/Event.h> 38#include <WindowServer/WindowServerEndpoint.h> 39 40namespace WindowServer { 41 42class Compositor; 43class Window; 44class Menu; 45class MenuBar; 46 47class ClientConnection final 48 : public IPC::ClientConnection<WindowServerEndpoint> 49 , public WindowServerEndpoint { 50 C_OBJECT(ClientConnection) 51public: 52 ~ClientConnection() override; 53 virtual void die() override; 54 55 void boost(); 56 void deboost(); 57 58 static ClientConnection* from_client_id(int client_id); 59 static void for_each_client(Function<void(ClientConnection&)>); 60 61 MenuBar* app_menubar() { return m_app_menubar.ptr(); } 62 63 bool is_showing_modal_window() const; 64 65 void notify_about_new_screen_rect(const Gfx::Rect&); 66 void notify_about_clipboard_contents_changed(); 67 void post_paint_message(Window&, bool ignore_occlusion = false); 68 69 Menu* find_menu_by_id(int menu_id) 70 { 71 auto menu = m_menus.get(menu_id); 72 if (!menu.has_value()) 73 return nullptr; 74 return const_cast<Menu*>(menu.value().ptr()); 75 } 76 77 void notify_display_link(Badge<Compositor>); 78 79private: 80 explicit ClientConnection(Core::LocalSocket&, int client_id); 81 82 virtual OwnPtr<Messages::WindowServer::GreetResponse> handle(const Messages::WindowServer::Greet&) override; 83 virtual OwnPtr<Messages::WindowServer::CreateMenubarResponse> handle(const Messages::WindowServer::CreateMenubar&) override; 84 virtual OwnPtr<Messages::WindowServer::DestroyMenubarResponse> handle(const Messages::WindowServer::DestroyMenubar&) override; 85 virtual OwnPtr<Messages::WindowServer::CreateMenuResponse> handle(const Messages::WindowServer::CreateMenu&) override; 86 virtual OwnPtr<Messages::WindowServer::DestroyMenuResponse> handle(const Messages::WindowServer::DestroyMenu&) override; 87 virtual OwnPtr<Messages::WindowServer::AddMenuToMenubarResponse> handle(const Messages::WindowServer::AddMenuToMenubar&) override; 88 virtual OwnPtr<Messages::WindowServer::SetApplicationMenubarResponse> handle(const Messages::WindowServer::SetApplicationMenubar&) override; 89 virtual OwnPtr<Messages::WindowServer::AddMenuItemResponse> handle(const Messages::WindowServer::AddMenuItem&) override; 90 virtual OwnPtr<Messages::WindowServer::AddMenuSeparatorResponse> handle(const Messages::WindowServer::AddMenuSeparator&) override; 91 virtual OwnPtr<Messages::WindowServer::UpdateMenuItemResponse> handle(const Messages::WindowServer::UpdateMenuItem&) override; 92 virtual OwnPtr<Messages::WindowServer::CreateWindowResponse> handle(const Messages::WindowServer::CreateWindow&) override; 93 virtual OwnPtr<Messages::WindowServer::DestroyWindowResponse> handle(const Messages::WindowServer::DestroyWindow&) override; 94 virtual OwnPtr<Messages::WindowServer::SetWindowTitleResponse> handle(const Messages::WindowServer::SetWindowTitle&) override; 95 virtual OwnPtr<Messages::WindowServer::GetWindowTitleResponse> handle(const Messages::WindowServer::GetWindowTitle&) override; 96 virtual OwnPtr<Messages::WindowServer::SetWindowRectResponse> handle(const Messages::WindowServer::SetWindowRect&) override; 97 virtual OwnPtr<Messages::WindowServer::GetWindowRectResponse> handle(const Messages::WindowServer::GetWindowRect&) override; 98 virtual void handle(const Messages::WindowServer::InvalidateRect&) override; 99 virtual void handle(const Messages::WindowServer::DidFinishPainting&) override; 100 virtual OwnPtr<Messages::WindowServer::SetGlobalCursorTrackingResponse> handle(const Messages::WindowServer::SetGlobalCursorTracking&) override; 101 virtual OwnPtr<Messages::WindowServer::SetWindowOpacityResponse> handle(const Messages::WindowServer::SetWindowOpacity&) override; 102 virtual OwnPtr<Messages::WindowServer::SetWindowBackingStoreResponse> handle(const Messages::WindowServer::SetWindowBackingStore&) override; 103 virtual OwnPtr<Messages::WindowServer::GetClipboardContentsResponse> handle(const Messages::WindowServer::GetClipboardContents&) override; 104 virtual OwnPtr<Messages::WindowServer::SetClipboardContentsResponse> handle(const Messages::WindowServer::SetClipboardContents&) override; 105 virtual void handle(const Messages::WindowServer::WM_SetActiveWindow&) override; 106 virtual void handle(const Messages::WindowServer::WM_SetWindowMinimized&) override; 107 virtual void handle(const Messages::WindowServer::WM_StartWindowResize&) override; 108 virtual void handle(const Messages::WindowServer::WM_PopupWindowMenu&) override; 109 virtual OwnPtr<Messages::WindowServer::SetWindowHasAlphaChannelResponse> handle(const Messages::WindowServer::SetWindowHasAlphaChannel&) override; 110 virtual OwnPtr<Messages::WindowServer::MoveWindowToFrontResponse> handle(const Messages::WindowServer::MoveWindowToFront&) override; 111 virtual OwnPtr<Messages::WindowServer::SetFullscreenResponse> handle(const Messages::WindowServer::SetFullscreen&) override; 112 virtual void handle(const Messages::WindowServer::AsyncSetWallpaper&) override; 113 virtual OwnPtr<Messages::WindowServer::SetBackgroundColorResponse> handle(const Messages::WindowServer::SetBackgroundColor&) override; 114 virtual OwnPtr<Messages::WindowServer::SetWallpaperModeResponse> handle(const Messages::WindowServer::SetWallpaperMode&) override; 115 virtual OwnPtr<Messages::WindowServer::GetWallpaperResponse> handle(const Messages::WindowServer::GetWallpaper&) override; 116 virtual OwnPtr<Messages::WindowServer::SetResolutionResponse> handle(const Messages::WindowServer::SetResolution&) override; 117 virtual OwnPtr<Messages::WindowServer::SetWindowOverrideCursorResponse> handle(const Messages::WindowServer::SetWindowOverrideCursor&) override; 118 virtual OwnPtr<Messages::WindowServer::PopupMenuResponse> handle(const Messages::WindowServer::PopupMenu&) override; 119 virtual OwnPtr<Messages::WindowServer::DismissMenuResponse> handle(const Messages::WindowServer::DismissMenu&) override; 120 virtual OwnPtr<Messages::WindowServer::SetWindowIconBitmapResponse> handle(const Messages::WindowServer::SetWindowIconBitmap&) override; 121 virtual void handle(const Messages::WindowServer::WM_SetWindowTaskbarRect&) override; 122 virtual OwnPtr<Messages::WindowServer::StartDragResponse> handle(const Messages::WindowServer::StartDrag&) override; 123 virtual OwnPtr<Messages::WindowServer::SetSystemMenuResponse> handle(const Messages::WindowServer::SetSystemMenu&) override; 124 virtual OwnPtr<Messages::WindowServer::SetSystemThemeResponse> handle(const Messages::WindowServer::SetSystemTheme&) override; 125 virtual OwnPtr<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrementResponse> handle(const Messages::WindowServer::SetWindowBaseSizeAndSizeIncrement&) override; 126 virtual void handle(const Messages::WindowServer::EnableDisplayLink&) override; 127 virtual void handle(const Messages::WindowServer::DisableDisplayLink&) override; 128 129 HashMap<int, NonnullRefPtr<Window>> m_windows; 130 HashMap<int, NonnullOwnPtr<MenuBar>> m_menubars; 131 HashMap<int, NonnullRefPtr<Menu>> m_menus; 132 WeakPtr<MenuBar> m_app_menubar; 133 134 int m_next_menubar_id { 10000 }; 135 int m_next_menu_id { 20000 }; 136 int m_next_window_id { 1982 }; 137 138 bool m_has_display_link { false }; 139 140 RefPtr<SharedBuffer> m_last_sent_clipboard_content; 141}; 142 143}