From 273e9bbc92efa3c9632c097e81e29373eb5a3d25 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 27 Jun 2025 14:09:58 +0300 Subject: [PATCH] LibGUI/WindowServer: Implement per-window cursor hiding --- .../libraries/LibGUI/include/LibGUI/Packet.h | 1 + .../libraries/LibGUI/include/LibGUI/Window.h | 3 +++ .../programs/WindowServer/WindowServer.cpp | 19 +++++++++++++------ .../programs/WindowServer/WindowServer.h | 3 ++- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/userspace/libraries/LibGUI/include/LibGUI/Packet.h b/userspace/libraries/LibGUI/include/LibGUI/Packet.h index 26a995ca..47a6e63d 100644 --- a/userspace/libraries/LibGUI/include/LibGUI/Packet.h +++ b/userspace/libraries/LibGUI/include/LibGUI/Packet.h @@ -234,6 +234,7 @@ namespace LibGUI bool alpha_channel; bool resizable; bool shown; + bool cursor_visible; }; DEFINE_PACKET( diff --git a/userspace/libraries/LibGUI/include/LibGUI/Window.h b/userspace/libraries/LibGUI/include/LibGUI/Window.h index bcdc02f3..7be5ccfa 100644 --- a/userspace/libraries/LibGUI/include/LibGUI/Window.h +++ b/userspace/libraries/LibGUI/include/LibGUI/Window.h @@ -26,6 +26,7 @@ namespace LibGUI .alpha_channel = false, .resizable = false, .shown = true, + .cursor_visible = true, }; public: @@ -48,6 +49,8 @@ namespace LibGUI void set_position(int32_t x, int32_t y); + void set_cursor_visible(bool visible); + Attributes get_attributes() const { return m_attributes; } void set_attributes(Attributes attributes); diff --git a/userspace/programs/WindowServer/WindowServer.cpp b/userspace/programs/WindowServer/WindowServer.cpp index 84db5b66..e8c20cc0 100644 --- a/userspace/programs/WindowServer/WindowServer.cpp +++ b/userspace/programs/WindowServer/WindowServer.cpp @@ -1201,6 +1201,8 @@ void WindowServer::sync() Rectangle WindowServer::cursor_area() const { + if (auto window = find_hovered_window(); window && !window->get_attributes().cursor_visible) + return { m_cursor.x, m_cursor.y, 0, 0 }; return { m_cursor.x, m_cursor.y, s_cursor_width, s_cursor_height }; } @@ -1241,14 +1243,19 @@ Rectangle WindowServer::resize_area(Position cursor) const }; } -BAN::RefPtr WindowServer::find_window_with_fd(int fd) +BAN::RefPtr WindowServer::find_window_with_fd(int fd) const { for (auto window : m_client_windows) - { - if (window->client_fd() != fd) - continue; - return window; - } + if (window->client_fd() == fd) + return window; + return {}; +} + +BAN::RefPtr WindowServer::find_hovered_window() const +{ + for (auto window : m_client_windows) + if (window->full_area().contains(m_cursor)) + return window; return {}; } diff --git a/userspace/programs/WindowServer/WindowServer.h b/userspace/programs/WindowServer/WindowServer.h index 745ab3fc..796a21a0 100644 --- a/userspace/programs/WindowServer/WindowServer.h +++ b/userspace/programs/WindowServer/WindowServer.h @@ -66,7 +66,8 @@ private: bool resize_window(BAN::RefPtr window, uint32_t width, uint32_t height) const; - BAN::RefPtr find_window_with_fd(int fd); + BAN::RefPtr find_window_with_fd(int fd) const; + BAN::RefPtr find_hovered_window() const; private: struct RangeList