From 69d708fb215d5eb32a59bc3c3d50dae3e67ed7ab Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Fri, 3 Sep 2021 23:14:37 -0400 Subject: [PATCH] WindowServer: Add IPC endpoint to get the color under cursor This allows any client to ask the WindowServer to give it the color of the screen bitmap under the cursor. There's currently no way to get the screen bitmap *without* the cursor already drawn on it, so for now we just take a pixel beside the actual cursor position to avoid just getting the cursors color. --- Userland/Services/WindowServer/ClientConnection.cpp | 10 ++++++++++ Userland/Services/WindowServer/ClientConnection.h | 1 + Userland/Services/WindowServer/WindowServer.ipc | 1 + 3 files changed, 12 insertions(+) diff --git a/Userland/Services/WindowServer/ClientConnection.cpp b/Userland/Services/WindowServer/ClientConnection.cpp index 907cbe6c9a..9e58f831d4 100644 --- a/Userland/Services/WindowServer/ClientConnection.cpp +++ b/Userland/Services/WindowServer/ClientConnection.cpp @@ -1048,6 +1048,16 @@ Messages::WindowServer::GetScreenBitmapAroundCursorResponse ClientConnection::ge return { {} }; } +Messages::WindowServer::GetColorUnderCursorResponse ClientConnection::get_color_under_cursor() +{ + // FIXME: Add a mechanism to get screen bitmap without cursor, so we don't have to do this + // manual translation to avoid sampling the color on the actual cursor itself. + auto cursor_location = ScreenInput::the().cursor_location().translated(-1, -1); + auto& screen_with_cursor = ScreenInput::the().cursor_location_screen(); + auto color = Compositor::the().color_at_position({}, screen_with_cursor, cursor_location); + return color; +} + Messages::WindowServer::IsWindowModifiedResponse ClientConnection::is_window_modified(i32 window_id) { auto it = m_windows.find(window_id); diff --git a/Userland/Services/WindowServer/ClientConnection.h b/Userland/Services/WindowServer/ClientConnection.h index 5e3f4190b3..4a0cdab5c0 100644 --- a/Userland/Services/WindowServer/ClientConnection.h +++ b/Userland/Services/WindowServer/ClientConnection.h @@ -169,6 +169,7 @@ private: virtual void add_window_stealing_for_client(i32, i32) override; virtual void remove_window_stealing_for_client(i32, i32) override; virtual void remove_window_stealing(i32) override; + virtual Messages::WindowServer::GetColorUnderCursorResponse get_color_under_cursor() override; Window* window_from_id(i32 window_id); diff --git a/Userland/Services/WindowServer/WindowServer.ipc b/Userland/Services/WindowServer/WindowServer.ipc index 6d9a702b56..4689daac13 100644 --- a/Userland/Services/WindowServer/WindowServer.ipc +++ b/Userland/Services/WindowServer/WindowServer.ipc @@ -136,6 +136,7 @@ endpoint WindowServer get_screen_bitmap(Optional rect, Optional screen_index) => (Gfx::ShareableBitmap bitmap) get_screen_bitmap_around_cursor(Gfx::IntSize size) => (Gfx::ShareableBitmap bitmap) + get_color_under_cursor() => (Gfx::Color color) pong() =|