LibGUI/WindowServer: Implement per-window cursor hiding

This commit is contained in:
Bananymous 2025-06-27 14:09:58 +03:00
parent 7dcf1797e9
commit 273e9bbc92
4 changed files with 19 additions and 7 deletions

View File

@ -234,6 +234,7 @@ namespace LibGUI
bool alpha_channel; bool alpha_channel;
bool resizable; bool resizable;
bool shown; bool shown;
bool cursor_visible;
}; };
DEFINE_PACKET( DEFINE_PACKET(

View File

@ -26,6 +26,7 @@ namespace LibGUI
.alpha_channel = false, .alpha_channel = false,
.resizable = false, .resizable = false,
.shown = true, .shown = true,
.cursor_visible = true,
}; };
public: public:
@ -48,6 +49,8 @@ namespace LibGUI
void set_position(int32_t x, int32_t y); void set_position(int32_t x, int32_t y);
void set_cursor_visible(bool visible);
Attributes get_attributes() const { return m_attributes; } Attributes get_attributes() const { return m_attributes; }
void set_attributes(Attributes attributes); void set_attributes(Attributes attributes);

View File

@ -1201,6 +1201,8 @@ void WindowServer::sync()
Rectangle WindowServer::cursor_area() const 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 }; 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<Window> WindowServer::find_window_with_fd(int fd) BAN::RefPtr<Window> WindowServer::find_window_with_fd(int fd) const
{ {
for (auto window : m_client_windows) for (auto window : m_client_windows)
{ if (window->client_fd() == fd)
if (window->client_fd() != fd) return window;
continue; return {};
}
BAN::RefPtr<Window> WindowServer::find_hovered_window() const
{
for (auto window : m_client_windows)
if (window->full_area().contains(m_cursor))
return window; return window;
}
return {}; return {};
} }

View File

@ -66,7 +66,8 @@ private:
bool resize_window(BAN::RefPtr<Window> window, uint32_t width, uint32_t height) const; bool resize_window(BAN::RefPtr<Window> window, uint32_t width, uint32_t height) const;
BAN::RefPtr<Window> find_window_with_fd(int fd); BAN::RefPtr<Window> find_window_with_fd(int fd) const;
BAN::RefPtr<Window> find_hovered_window() const;
private: private:
struct RangeList struct RangeList