2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2019-02-14 10:22:47 +03:00
|
|
|
#pragma once
|
|
|
|
|
2020-03-22 23:13:23 +03:00
|
|
|
#include <AK/Badge.h>
|
2019-05-28 12:53:16 +03:00
|
|
|
#include <AK/Function.h>
|
2019-02-14 10:22:47 +03:00
|
|
|
#include <AK/HashMap.h>
|
|
|
|
#include <AK/OwnPtr.h>
|
|
|
|
#include <AK/WeakPtr.h>
|
2020-02-06 17:04:03 +03:00
|
|
|
#include <LibCore/Object.h>
|
2020-02-06 14:07:05 +03:00
|
|
|
#include <LibGfx/Bitmap.h>
|
2020-02-06 16:54:09 +03:00
|
|
|
#include <LibIPC/ClientConnection.h>
|
2020-02-06 22:03:37 +03:00
|
|
|
#include <WindowServer/Event.h>
|
2020-09-12 12:44:00 +03:00
|
|
|
#include <WindowServer/WindowClientEndpoint.h>
|
2019-12-02 11:33:37 +03:00
|
|
|
#include <WindowServer/WindowServerEndpoint.h>
|
2019-02-14 10:22:47 +03:00
|
|
|
|
2020-02-06 22:03:37 +03:00
|
|
|
namespace WindowServer {
|
2019-02-14 10:22:47 +03:00
|
|
|
|
2020-03-22 23:13:23 +03:00
|
|
|
class Compositor;
|
2020-02-06 22:03:37 +03:00
|
|
|
class Window;
|
|
|
|
class Menu;
|
|
|
|
class MenuBar;
|
|
|
|
|
|
|
|
class ClientConnection final
|
2020-09-12 12:44:00 +03:00
|
|
|
: public IPC::ClientConnection<WindowClientEndpoint, WindowServerEndpoint>
|
2019-12-02 11:33:37 +03:00
|
|
|
, public WindowServerEndpoint {
|
2020-02-06 22:03:37 +03:00
|
|
|
C_OBJECT(ClientConnection)
|
2019-02-14 10:22:47 +03:00
|
|
|
public:
|
2020-02-06 22:03:37 +03:00
|
|
|
~ClientConnection() override;
|
2020-06-11 23:46:49 +03:00
|
|
|
|
|
|
|
bool is_unresponsive() const { return m_unresponsive; }
|
2019-02-14 10:22:47 +03:00
|
|
|
|
2020-02-06 22:03:37 +03:00
|
|
|
static ClientConnection* from_client_id(int client_id);
|
|
|
|
static void for_each_client(Function<void(ClientConnection&)>);
|
2019-02-14 10:22:47 +03:00
|
|
|
|
2020-02-06 22:03:37 +03:00
|
|
|
MenuBar* app_menubar() { return m_app_menubar.ptr(); }
|
2019-02-14 10:22:47 +03:00
|
|
|
|
2020-06-10 11:57:59 +03:00
|
|
|
void notify_about_new_screen_rect(const Gfx::IntRect&);
|
2020-02-19 18:45:06 +03:00
|
|
|
void post_paint_message(Window&, bool ignore_occlusion = false);
|
2019-04-03 18:22:14 +03:00
|
|
|
|
2020-02-06 22:03:37 +03:00
|
|
|
Menu* find_menu_by_id(int menu_id)
|
2019-08-28 22:11:53 +03:00
|
|
|
{
|
2019-09-22 01:17:53 +03:00
|
|
|
auto menu = m_menus.get(menu_id);
|
|
|
|
if (!menu.has_value())
|
|
|
|
return nullptr;
|
2020-02-06 22:03:37 +03:00
|
|
|
return const_cast<Menu*>(menu.value().ptr());
|
2019-08-28 22:11:53 +03:00
|
|
|
}
|
2020-05-18 13:07:46 +03:00
|
|
|
const Menu* find_menu_by_id(int menu_id) const
|
|
|
|
{
|
|
|
|
auto menu = m_menus.get(menu_id);
|
|
|
|
if (!menu.has_value())
|
|
|
|
return nullptr;
|
|
|
|
return menu.value().ptr();
|
|
|
|
}
|
2019-08-28 22:11:53 +03:00
|
|
|
|
2020-03-22 23:13:23 +03:00
|
|
|
void notify_display_link(Badge<Compositor>);
|
|
|
|
|
2019-02-14 10:22:47 +03:00
|
|
|
private:
|
2020-07-06 14:23:39 +03:00
|
|
|
explicit ClientConnection(NonnullRefPtr<Core::LocalSocket>, int client_id);
|
2019-12-02 11:33:37 +03:00
|
|
|
|
2020-06-11 23:46:49 +03:00
|
|
|
// ^ClientConnection
|
|
|
|
virtual void die() override;
|
|
|
|
virtual void may_have_become_unresponsive() override;
|
2020-06-13 14:47:01 +03:00
|
|
|
virtual void did_become_responsive() override;
|
2020-06-11 23:46:49 +03:00
|
|
|
|
|
|
|
void set_unresponsive(bool);
|
2020-05-02 00:53:05 +03:00
|
|
|
void destroy_window(Window&, Vector<i32>& destroyed_window_ids);
|
|
|
|
|
2020-02-06 22:20:44 +03:00
|
|
|
virtual OwnPtr<Messages::WindowServer::GreetResponse> handle(const Messages::WindowServer::Greet&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::CreateMenubarResponse> handle(const Messages::WindowServer::CreateMenubar&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::DestroyMenubarResponse> handle(const Messages::WindowServer::DestroyMenubar&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::CreateMenuResponse> handle(const Messages::WindowServer::CreateMenu&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::DestroyMenuResponse> handle(const Messages::WindowServer::DestroyMenu&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::AddMenuToMenubarResponse> handle(const Messages::WindowServer::AddMenuToMenubar&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::SetApplicationMenubarResponse> handle(const Messages::WindowServer::SetApplicationMenubar&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::AddMenuItemResponse> handle(const Messages::WindowServer::AddMenuItem&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::AddMenuSeparatorResponse> handle(const Messages::WindowServer::AddMenuSeparator&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::UpdateMenuItemResponse> handle(const Messages::WindowServer::UpdateMenuItem&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::CreateWindowResponse> handle(const Messages::WindowServer::CreateWindow&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::DestroyWindowResponse> handle(const Messages::WindowServer::DestroyWindow&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::SetWindowTitleResponse> handle(const Messages::WindowServer::SetWindowTitle&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::GetWindowTitleResponse> handle(const Messages::WindowServer::GetWindowTitle&) override;
|
2020-06-18 13:14:00 +03:00
|
|
|
virtual OwnPtr<Messages::WindowServer::IsMaximizedResponse> handle(const Messages::WindowServer::IsMaximized&) override;
|
2020-02-06 22:20:44 +03:00
|
|
|
virtual OwnPtr<Messages::WindowServer::SetWindowRectResponse> handle(const Messages::WindowServer::SetWindowRect&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::GetWindowRectResponse> handle(const Messages::WindowServer::GetWindowRect&) override;
|
2020-07-24 23:16:30 +03:00
|
|
|
virtual OwnPtr<Messages::WindowServer::GetWindowRectInMenubarResponse> handle(const Messages::WindowServer::GetWindowRectInMenubar&) override;
|
2020-02-06 22:20:44 +03:00
|
|
|
virtual void handle(const Messages::WindowServer::InvalidateRect&) override;
|
|
|
|
virtual void handle(const Messages::WindowServer::DidFinishPainting&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::SetGlobalCursorTrackingResponse> handle(const Messages::WindowServer::SetGlobalCursorTracking&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::SetWindowOpacityResponse> handle(const Messages::WindowServer::SetWindowOpacity&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::SetWindowBackingStoreResponse> handle(const Messages::WindowServer::SetWindowBackingStore&) override;
|
|
|
|
virtual void handle(const Messages::WindowServer::WM_SetActiveWindow&) override;
|
|
|
|
virtual void handle(const Messages::WindowServer::WM_SetWindowMinimized&) override;
|
|
|
|
virtual void handle(const Messages::WindowServer::WM_StartWindowResize&) override;
|
|
|
|
virtual void handle(const Messages::WindowServer::WM_PopupWindowMenu&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::SetWindowHasAlphaChannelResponse> handle(const Messages::WindowServer::SetWindowHasAlphaChannel&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::MoveWindowToFrontResponse> handle(const Messages::WindowServer::MoveWindowToFront&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::SetFullscreenResponse> handle(const Messages::WindowServer::SetFullscreen&) override;
|
|
|
|
virtual void handle(const Messages::WindowServer::AsyncSetWallpaper&) override;
|
2020-03-29 13:32:06 +03:00
|
|
|
virtual OwnPtr<Messages::WindowServer::SetBackgroundColorResponse> handle(const Messages::WindowServer::SetBackgroundColor&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::SetWallpaperModeResponse> handle(const Messages::WindowServer::SetWallpaperMode&) override;
|
2020-02-06 22:20:44 +03:00
|
|
|
virtual OwnPtr<Messages::WindowServer::GetWallpaperResponse> handle(const Messages::WindowServer::GetWallpaper&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::SetResolutionResponse> handle(const Messages::WindowServer::SetResolution&) override;
|
2020-09-10 21:55:39 +03:00
|
|
|
virtual OwnPtr<Messages::WindowServer::SetWindowCursorResponse> handle(const Messages::WindowServer::SetWindowCursor&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::SetWindowCustomCursorResponse> handle(const Messages::WindowServer::SetWindowCustomCursor&) override;
|
2020-02-06 22:20:44 +03:00
|
|
|
virtual OwnPtr<Messages::WindowServer::PopupMenuResponse> handle(const Messages::WindowServer::PopupMenu&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::DismissMenuResponse> handle(const Messages::WindowServer::DismissMenu&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::SetWindowIconBitmapResponse> handle(const Messages::WindowServer::SetWindowIconBitmap&) override;
|
|
|
|
virtual void handle(const Messages::WindowServer::WM_SetWindowTaskbarRect&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::StartDragResponse> handle(const Messages::WindowServer::StartDrag&) override;
|
2020-02-17 22:05:14 +03:00
|
|
|
virtual OwnPtr<Messages::WindowServer::SetSystemMenuResponse> handle(const Messages::WindowServer::SetSystemMenu&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::SetSystemThemeResponse> handle(const Messages::WindowServer::SetSystemTheme&) override;
|
2020-04-21 19:40:27 +03:00
|
|
|
virtual OwnPtr<Messages::WindowServer::GetSystemThemeResponse> handle(const Messages::WindowServer::GetSystemTheme&) override;
|
2020-02-24 21:23:57 +03:00
|
|
|
virtual OwnPtr<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrementResponse> handle(const Messages::WindowServer::SetWindowBaseSizeAndSizeIncrement&) override;
|
2020-08-21 23:19:10 +03:00
|
|
|
virtual OwnPtr<Messages::WindowServer::SetWindowResizeAspectRatioResponse> handle(const Messages::WindowServer::SetWindowResizeAspectRatio&) override;
|
2020-03-22 23:13:23 +03:00
|
|
|
virtual void handle(const Messages::WindowServer::EnableDisplayLink&) override;
|
|
|
|
virtual void handle(const Messages::WindowServer::DisableDisplayLink&) override;
|
2020-05-30 23:08:26 +03:00
|
|
|
virtual void handle(const Messages::WindowServer::SetWindowProgress&) override;
|
2021-01-16 07:56:41 +03:00
|
|
|
virtual void handle(const Messages::WindowServer::RefreshSystemTheme&) override;
|
2020-06-11 23:46:49 +03:00
|
|
|
virtual void handle(const Messages::WindowServer::Pong&) override;
|
2020-12-28 22:48:52 +03:00
|
|
|
virtual OwnPtr<Messages::WindowServer::GetGlobalCursorPositionResponse> handle(const Messages::WindowServer::GetGlobalCursorPosition&) override;
|
2020-12-30 00:33:57 +03:00
|
|
|
virtual OwnPtr<Messages::WindowServer::SetMouseAccelerationResponse> handle(const Messages::WindowServer::SetMouseAcceleration&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::GetMouseAccelerationResponse> handle(const Messages::WindowServer::GetMouseAcceleration&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::SetScrollStepSizeResponse> handle(const Messages::WindowServer::SetScrollStepSize&) override;
|
|
|
|
virtual OwnPtr<Messages::WindowServer::GetScrollStepSizeResponse> handle(const Messages::WindowServer::GetScrollStepSize&) override;
|
2019-02-14 10:22:47 +03:00
|
|
|
|
2020-05-01 23:59:38 +03:00
|
|
|
Window* window_from_id(i32 window_id);
|
|
|
|
|
2020-02-06 22:03:37 +03:00
|
|
|
HashMap<int, NonnullRefPtr<Window>> m_windows;
|
|
|
|
HashMap<int, NonnullOwnPtr<MenuBar>> m_menubars;
|
|
|
|
HashMap<int, NonnullRefPtr<Menu>> m_menus;
|
|
|
|
WeakPtr<MenuBar> m_app_menubar;
|
2019-02-14 10:22:47 +03:00
|
|
|
|
2020-06-11 23:46:49 +03:00
|
|
|
RefPtr<Core::Timer> m_ping_timer;
|
|
|
|
|
2019-02-14 10:22:47 +03:00
|
|
|
int m_next_menubar_id { 10000 };
|
|
|
|
int m_next_menu_id { 20000 };
|
|
|
|
int m_next_window_id { 1982 };
|
2019-03-08 15:27:19 +03:00
|
|
|
|
2020-03-22 23:13:23 +03:00
|
|
|
bool m_has_display_link { false };
|
2020-06-11 23:46:49 +03:00
|
|
|
bool m_unresponsive { false };
|
2019-02-14 10:22:47 +03:00
|
|
|
};
|
2020-02-06 22:03:37 +03:00
|
|
|
|
|
|
|
}
|