summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-07-28 00:58:01 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-28 01:01:02 +0200
commitb3d27c2340a030a737515942fd7b0b860e111fcc (patch)
treecf64f87899783835a8a589a4740390702fd8be2e
parent3d4f93cf8d35719588d98ef3d169b98a3e064c2a (diff)
downloadserenity-b3d27c2340a030a737515942fd7b0b860e111fcc.zip
LibGUI: Add GUI_HOVER_DEBUG runtime debugging flag (environment)
You can now see the outline of GUI widgets when hovering them. For example: $ export GUI_HOVER_DEBUG=1 $ FileManager Then move the mouse around in the file manager. :^)
-rw-r--r--Meta/CMake/all_the_debug_macros.cmake2
-rw-r--r--Userland/Libraries/LibGUI/Application.cpp3
-rw-r--r--Userland/Libraries/LibGUI/Application.h2
-rw-r--r--Userland/Libraries/LibGUI/Widget.cpp5
-rw-r--r--Userland/Libraries/LibGUI/Window.cpp4
5 files changed, 16 insertions, 0 deletions
diff --git a/Meta/CMake/all_the_debug_macros.cmake b/Meta/CMake/all_the_debug_macros.cmake
index 14bca912c3..baeb3591e8 100644
--- a/Meta/CMake/all_the_debug_macros.cmake
+++ b/Meta/CMake/all_the_debug_macros.cmake
@@ -200,6 +200,8 @@ set(WSSCREEN_DEBUG ON)
# set(DT_DEBUG ON)
# False positive: GUI_DND_DEBUG is a flag, but passed as an envvar.
# set(GUI_DND_DEBUG ON)
+# False positive: GUI_HOVER_DEBUG is a flag, but passed as an envvar.
+# set(GUI_HOVER_DEBUG ON)
# False positive: GUI_FOCUS_DEBUG is a flag, but passed as an envvar.
# set(GUI_FOCUS_DEBUG ON)
# False positive: LOG_DEBUG is a flag, but for a bitset, not a feature.
diff --git a/Userland/Libraries/LibGUI/Application.cpp b/Userland/Libraries/LibGUI/Application.cpp
index f9a1c9e3d6..fbf936153e 100644
--- a/Userland/Libraries/LibGUI/Application.cpp
+++ b/Userland/Libraries/LibGUI/Application.cpp
@@ -81,6 +81,9 @@ Application::Application(int argc, char** argv, Core::EventLoop::MakeInspectable
if (getenv("GUI_FOCUS_DEBUG"))
m_focus_debugging_enabled = true;
+ if (getenv("GUI_HOVER_DEBUG"))
+ m_hover_debugging_enabled = true;
+
if (getenv("GUI_DND_DEBUG"))
m_dnd_debugging_enabled = true;
diff --git a/Userland/Libraries/LibGUI/Application.h b/Userland/Libraries/LibGUI/Application.h
index 09a073a20c..7ce9379e78 100644
--- a/Userland/Libraries/LibGUI/Application.h
+++ b/Userland/Libraries/LibGUI/Application.h
@@ -54,6 +54,7 @@ public:
void set_system_palette(Core::AnonymousBuffer&);
bool focus_debugging_enabled() const { return m_focus_debugging_enabled; }
+ bool hover_debugging_enabled() const { return m_hover_debugging_enabled; }
bool dnd_debugging_enabled() const { return m_dnd_debugging_enabled; }
Core::EventLoop& event_loop() { return *m_event_loop; }
@@ -102,6 +103,7 @@ private:
WeakPtr<Window> m_active_window;
bool m_quit_when_last_window_deleted { true };
bool m_focus_debugging_enabled { false };
+ bool m_hover_debugging_enabled { false };
bool m_dnd_debugging_enabled { false };
String m_invoked_as;
Vector<String> m_args;
diff --git a/Userland/Libraries/LibGUI/Widget.cpp b/Userland/Libraries/LibGUI/Widget.cpp
index cd1a7753a9..eb22af1f4c 100644
--- a/Userland/Libraries/LibGUI/Widget.cpp
+++ b/Userland/Libraries/LibGUI/Widget.cpp
@@ -356,6 +356,11 @@ void Widget::handle_paint_event(PaintEvent& event)
painter.draw_rect(rect(), Color::Cyan);
}
+ if (app && app->hover_debugging_enabled() && this == window()->hovered_widget()) {
+ Painter painter(*this);
+ painter.draw_rect(rect(), Color::Red);
+ }
+
if (is_being_inspected()) {
Painter painter(*this);
painter.draw_rect(rect(), Color::Magenta);
diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp
index 910e04fc0a..aa00e8b684 100644
--- a/Userland/Libraries/LibGUI/Window.cpp
+++ b/Userland/Libraries/LibGUI/Window.cpp
@@ -809,6 +809,10 @@ void Window::set_hovered_widget(Widget* widget)
if (m_hovered_widget)
Core::EventLoop::current().post_event(*m_hovered_widget, make<Event>(Event::Enter));
+
+ auto* app = Application::the();
+ if (app && app->hover_debugging_enabled())
+ update();
}
void Window::set_current_backing_store(WindowBackingStore& backing_store, bool flush_immediately)