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
|
|
|
|
|
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>
|
2019-04-14 06:15:22 +03:00
|
|
|
#include <LibCore/CObject.h>
|
2020-02-06 14:07:05 +03:00
|
|
|
#include <LibGfx/Bitmap.h>
|
2019-12-02 11:52:07 +03:00
|
|
|
#include <LibIPC/IClientConnection.h>
|
2019-04-14 06:23:37 +03:00
|
|
|
#include <WindowServer/WSEvent.h>
|
2019-12-02 11:33:37 +03:00
|
|
|
#include <WindowServer/WindowServerEndpoint.h>
|
2019-02-14 10:22:47 +03:00
|
|
|
|
|
|
|
class WSWindow;
|
|
|
|
class WSMenu;
|
|
|
|
class WSMenuBar;
|
|
|
|
|
2019-12-02 11:33:37 +03:00
|
|
|
class WSClientConnection final
|
2020-02-05 21:57:18 +03:00
|
|
|
: public IPC::ClientConnection<WindowServerEndpoint>
|
2019-12-02 11:33:37 +03:00
|
|
|
, public WindowServerEndpoint {
|
2019-07-27 19:43:59 +03:00
|
|
|
C_OBJECT(WSClientConnection)
|
2019-02-14 10:22:47 +03:00
|
|
|
public:
|
2019-07-17 11:31:52 +03:00
|
|
|
~WSClientConnection() override;
|
2019-09-22 01:17:53 +03:00
|
|
|
virtual void die() override;
|
2019-02-14 10:22:47 +03:00
|
|
|
|
2019-12-30 21:27:58 +03:00
|
|
|
void boost();
|
|
|
|
void deboost();
|
|
|
|
|
2019-02-14 10:22:47 +03:00
|
|
|
static WSClientConnection* from_client_id(int client_id);
|
2019-02-14 19:18:35 +03:00
|
|
|
static void for_each_client(Function<void(WSClientConnection&)>);
|
2019-02-14 10:22:47 +03:00
|
|
|
|
|
|
|
WSMenuBar* app_menubar() { return m_app_menubar.ptr(); }
|
|
|
|
|
2019-03-19 02:52:39 +03:00
|
|
|
bool is_showing_modal_window() const;
|
|
|
|
|
2020-02-06 13:56:38 +03:00
|
|
|
void notify_about_new_screen_rect(const Gfx::Rect&);
|
2019-09-14 10:19:05 +03:00
|
|
|
void notify_about_clipboard_contents_changed();
|
2019-04-20 18:19:56 +03:00
|
|
|
void post_paint_message(WSWindow&);
|
2019-04-03 18:22:14 +03:00
|
|
|
|
2019-08-28 22:11:53 +03:00
|
|
|
WSMenu* find_menu_by_id(int menu_id)
|
|
|
|
{
|
2019-09-22 01:17:53 +03:00
|
|
|
auto menu = m_menus.get(menu_id);
|
|
|
|
if (!menu.has_value())
|
|
|
|
return nullptr;
|
|
|
|
return const_cast<WSMenu*>(menu.value().ptr());
|
2019-08-28 22:11:53 +03:00
|
|
|
}
|
|
|
|
|
2019-02-14 10:22:47 +03:00
|
|
|
private:
|
2020-02-02 14:34:39 +03:00
|
|
|
explicit WSClientConnection(Core::LocalSocket&, int client_id);
|
2019-12-02 11:33:37 +03:00
|
|
|
|
|
|
|
virtual OwnPtr<WindowServer::GreetResponse> handle(const WindowServer::Greet&) override;
|
|
|
|
virtual OwnPtr<WindowServer::CreateMenubarResponse> handle(const WindowServer::CreateMenubar&) override;
|
|
|
|
virtual OwnPtr<WindowServer::DestroyMenubarResponse> handle(const WindowServer::DestroyMenubar&) override;
|
|
|
|
virtual OwnPtr<WindowServer::CreateMenuResponse> handle(const WindowServer::CreateMenu&) override;
|
|
|
|
virtual OwnPtr<WindowServer::DestroyMenuResponse> handle(const WindowServer::DestroyMenu&) override;
|
|
|
|
virtual OwnPtr<WindowServer::AddMenuToMenubarResponse> handle(const WindowServer::AddMenuToMenubar&) override;
|
|
|
|
virtual OwnPtr<WindowServer::SetApplicationMenubarResponse> handle(const WindowServer::SetApplicationMenubar&) override;
|
|
|
|
virtual OwnPtr<WindowServer::AddMenuItemResponse> handle(const WindowServer::AddMenuItem&) override;
|
|
|
|
virtual OwnPtr<WindowServer::AddMenuSeparatorResponse> handle(const WindowServer::AddMenuSeparator&) override;
|
|
|
|
virtual OwnPtr<WindowServer::UpdateMenuItemResponse> handle(const WindowServer::UpdateMenuItem&) override;
|
|
|
|
virtual OwnPtr<WindowServer::CreateWindowResponse> handle(const WindowServer::CreateWindow&) override;
|
|
|
|
virtual OwnPtr<WindowServer::DestroyWindowResponse> handle(const WindowServer::DestroyWindow&) override;
|
|
|
|
virtual OwnPtr<WindowServer::SetWindowTitleResponse> handle(const WindowServer::SetWindowTitle&) override;
|
|
|
|
virtual OwnPtr<WindowServer::GetWindowTitleResponse> handle(const WindowServer::GetWindowTitle&) override;
|
|
|
|
virtual OwnPtr<WindowServer::SetWindowRectResponse> handle(const WindowServer::SetWindowRect&) override;
|
|
|
|
virtual OwnPtr<WindowServer::GetWindowRectResponse> handle(const WindowServer::GetWindowRect&) override;
|
|
|
|
virtual void handle(const WindowServer::InvalidateRect&) override;
|
|
|
|
virtual void handle(const WindowServer::DidFinishPainting&) override;
|
|
|
|
virtual OwnPtr<WindowServer::SetGlobalCursorTrackingResponse> handle(const WindowServer::SetGlobalCursorTracking&) override;
|
|
|
|
virtual OwnPtr<WindowServer::SetWindowOpacityResponse> handle(const WindowServer::SetWindowOpacity&) override;
|
|
|
|
virtual OwnPtr<WindowServer::SetWindowBackingStoreResponse> handle(const WindowServer::SetWindowBackingStore&) override;
|
|
|
|
virtual OwnPtr<WindowServer::GetClipboardContentsResponse> handle(const WindowServer::GetClipboardContents&) override;
|
|
|
|
virtual OwnPtr<WindowServer::SetClipboardContentsResponse> handle(const WindowServer::SetClipboardContents&) override;
|
|
|
|
virtual void handle(const WindowServer::WM_SetActiveWindow&) override;
|
|
|
|
virtual void handle(const WindowServer::WM_SetWindowMinimized&) override;
|
|
|
|
virtual void handle(const WindowServer::WM_StartWindowResize&) override;
|
|
|
|
virtual void handle(const WindowServer::WM_PopupWindowMenu&) override;
|
|
|
|
virtual OwnPtr<WindowServer::SetWindowHasAlphaChannelResponse> handle(const WindowServer::SetWindowHasAlphaChannel&) override;
|
|
|
|
virtual OwnPtr<WindowServer::MoveWindowToFrontResponse> handle(const WindowServer::MoveWindowToFront&) override;
|
|
|
|
virtual OwnPtr<WindowServer::SetFullscreenResponse> handle(const WindowServer::SetFullscreen&) override;
|
|
|
|
virtual void handle(const WindowServer::AsyncSetWallpaper&) override;
|
|
|
|
virtual OwnPtr<WindowServer::GetWallpaperResponse> handle(const WindowServer::GetWallpaper&) override;
|
|
|
|
virtual OwnPtr<WindowServer::SetResolutionResponse> handle(const WindowServer::SetResolution&) override;
|
|
|
|
virtual OwnPtr<WindowServer::SetWindowOverrideCursorResponse> handle(const WindowServer::SetWindowOverrideCursor&) override;
|
|
|
|
virtual OwnPtr<WindowServer::PopupMenuResponse> handle(const WindowServer::PopupMenu&) override;
|
|
|
|
virtual OwnPtr<WindowServer::DismissMenuResponse> handle(const WindowServer::DismissMenu&) override;
|
|
|
|
virtual OwnPtr<WindowServer::SetWindowIconBitmapResponse> handle(const WindowServer::SetWindowIconBitmap&) override;
|
2019-12-03 23:34:34 +03:00
|
|
|
virtual void handle(const WindowServer::WM_SetWindowTaskbarRect&) override;
|
2019-12-08 18:50:23 +03:00
|
|
|
virtual OwnPtr<WindowServer::StartDragResponse> handle(const WindowServer::StartDrag&) override;
|
2019-02-14 10:22:47 +03:00
|
|
|
|
2019-09-22 01:17:53 +03:00
|
|
|
HashMap<int, NonnullRefPtr<WSWindow>> m_windows;
|
2019-07-24 09:42:55 +03:00
|
|
|
HashMap<int, NonnullOwnPtr<WSMenuBar>> m_menubars;
|
2019-09-22 01:17:53 +03:00
|
|
|
HashMap<int, NonnullRefPtr<WSMenu>> m_menus;
|
2019-02-14 10:22:47 +03:00
|
|
|
WeakPtr<WSMenuBar> m_app_menubar;
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-06-21 19:37:47 +03:00
|
|
|
RefPtr<SharedBuffer> m_last_sent_clipboard_content;
|
2019-02-14 10:22:47 +03:00
|
|
|
};
|