From 98b8bab441c94eef6e896b20c1e7ce846192a116 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 30 Apr 2023 10:42:54 +0200 Subject: [PATCH] LibGUI: Use Variant's built-in equality operator in Window and Widget Now that Variant has operator==(), we don't need to go through all this trouble to compare two Variant values. --- Userland/Libraries/LibGUI/Widget.cpp | 10 +--------- Userland/Libraries/LibGUI/Window.cpp | 15 +++------------ Userland/Libraries/LibGUI/Window.h | 2 -- 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/Userland/Libraries/LibGUI/Widget.cpp b/Userland/Libraries/LibGUI/Widget.cpp index 2edf9364946..5e93b3dfdb1 100644 --- a/Userland/Libraries/LibGUI/Widget.cpp +++ b/Userland/Libraries/LibGUI/Widget.cpp @@ -1128,15 +1128,7 @@ Gfx::IntRect Widget::children_clip_rect() const void Widget::set_override_cursor(AK::Variant> cursor) { - auto const& are_cursors_the_same = [](auto const& a, auto const& b) { - if (a.template has() != b.template has()) - return false; - if (a.template has()) - return a.template get() == b.template get(); - return a.template get>().ptr() == b.template get>().ptr(); - }; - - if (are_cursors_the_same(m_override_cursor, cursor)) + if (m_override_cursor == cursor) return; m_override_cursor = move(cursor); diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp index 0edf8c43218..d28d92db95c 100644 --- a/Userland/Libraries/LibGUI/Window.cpp +++ b/Userland/Libraries/LibGUI/Window.cpp @@ -336,18 +336,9 @@ void Window::make_window_manager(unsigned event_mask) GUI::ConnectionToWindowManagerServer::the().async_set_manager_window(m_window_id); } -bool Window::are_cursors_the_same(AK::Variant> const& left, AK::Variant> const& right) const -{ - if (left.has() != right.has()) - return false; - if (left.has()) - return left.get() == right.get(); - return left.get>().ptr() == right.get>().ptr(); -} - void Window::set_cursor(Gfx::StandardCursor cursor) { - if (are_cursors_the_same(m_cursor, cursor)) + if (m_cursor == cursor) return; m_cursor = cursor; update_cursor(); @@ -355,7 +346,7 @@ void Window::set_cursor(Gfx::StandardCursor cursor) void Window::set_cursor(NonnullRefPtr cursor) { - if (are_cursors_the_same(m_cursor, cursor)) + if (m_cursor == cursor) return; m_cursor = cursor; update_cursor(); @@ -1281,7 +1272,7 @@ void Window::update_cursor() new_cursor = widget->override_cursor(); } - if (are_cursors_the_same(m_effective_cursor, new_cursor)) + if (m_effective_cursor == new_cursor) return; m_effective_cursor = new_cursor; diff --git a/Userland/Libraries/LibGUI/Window.h b/Userland/Libraries/LibGUI/Window.h index c98197b4b89..57f75b2e107 100644 --- a/Userland/Libraries/LibGUI/Window.h +++ b/Userland/Libraries/LibGUI/Window.h @@ -279,8 +279,6 @@ private: void flip(Vector const& dirty_rects); void force_update(); - bool are_cursors_the_same(AK::Variant> const&, AK::Variant> const&) const; - WeakPtr m_previously_focused_widget; OwnPtr m_front_store;