summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-08-15 22:29:12 +0200
committerAndreas Kling <kling@serenityos.org>2022-08-16 00:58:26 +0200
commit6548ae8afda66264c3ba68463cbbe8d78e37b839 (patch)
tree09af4f78df31df4eeedaed6fe307f72b0fcde1ad /Userland
parent1885445a7912c96e0e7c4c79a5fa9c25f87c1c31 (diff)
downloadserenity-6548ae8afda66264c3ba68463cbbe8d78e37b839.zip
LibGUI: Retain the active input tracking widget's cursor
Until the tracking stops, we want to keep displaying the same cursor.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGUI/Widget.h2
-rw-r--r--Userland/Libraries/LibGUI/Window.cpp15
2 files changed, 12 insertions, 5 deletions
diff --git a/Userland/Libraries/LibGUI/Widget.h b/Userland/Libraries/LibGUI/Widget.h
index f856f137b6..ee868b7d54 100644
--- a/Userland/Libraries/LibGUI/Widget.h
+++ b/Userland/Libraries/LibGUI/Widget.h
@@ -345,7 +345,7 @@ public:
virtual Gfx::IntRect children_clip_rect() const;
- AK::Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> override_cursor() const { return m_override_cursor; }
+ AK::Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> const& override_cursor() const { return m_override_cursor; }
void set_override_cursor(AK::Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>>);
bool load_from_gml(StringView);
diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp
index a2e6ee831d..7857419ad4 100644
--- a/Userland/Libraries/LibGUI/Window.cpp
+++ b/Userland/Libraries/LibGUI/Window.cpp
@@ -1177,10 +1177,17 @@ void Window::update_cursor()
{
auto new_cursor = m_cursor;
- if (m_hovered_widget) {
- auto override_cursor = m_hovered_widget->override_cursor();
- if (override_cursor.has<NonnullRefPtr<Gfx::Bitmap>>() || override_cursor.get<Gfx::StandardCursor>() != Gfx::StandardCursor::None)
- new_cursor = move(override_cursor);
+ auto is_usable_cursor = [](auto& cursor) {
+ return cursor.template has<NonnullRefPtr<Gfx::Bitmap>>() || cursor.template get<Gfx::StandardCursor>() != Gfx::StandardCursor::None;
+ };
+
+ // NOTE: If there's an automatic cursor tracking widget, we retain its cursor until tracking stops.
+ if (auto widget = m_automatic_cursor_tracking_widget) {
+ if (is_usable_cursor(widget->override_cursor()))
+ new_cursor = widget->override_cursor();
+ } else if (auto widget = m_hovered_widget) {
+ if (is_usable_cursor(widget->override_cursor()))
+ new_cursor = widget->override_cursor();
}
if (are_cursors_the_same(m_effective_cursor, new_cursor))