From 444ed565215f5b164978cab7a7cb1ee86959cc34 Mon Sep 17 00:00:00 2001 From: sin-ack Date: Sun, 25 Jul 2021 21:07:55 +0000 Subject: [PATCH] LibGUI: Add virtual handlers for WindowEntered and WindowLeft events These can be useful if an application wants to react to the cursor entering the window at any point, rather than just on a widget. --- Userland/Libraries/LibGUI/Window.cpp | 21 +++++++++++++++++++-- Userland/Libraries/LibGUI/Window.h | 6 +++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp index 6945cb230f..781dcd8636 100644 --- a/Userland/Libraries/LibGUI/Window.cpp +++ b/Userland/Libraries/LibGUI/Window.cpp @@ -572,10 +572,24 @@ void Window::handle_drag_move_event(DragEvent& event) } } -void Window::handle_left_event() +void Window::enter_event(Core::Event&) +{ +} + +void Window::leave_event(Core::Event&) +{ +} + +void Window::handle_entered_event(Core::Event& event) +{ + enter_event(event); +} + +void Window::handle_left_event(Core::Event& event) { set_hovered_widget(nullptr); Application::the()->set_drag_hovered_widget({}, nullptr); + leave_event(event); } void Window::event(Core::Event& event) @@ -605,8 +619,11 @@ void Window::event(Core::Event& event) if (event.type() == Event::WindowCloseRequest) return handle_close_request(); + if (event.type() == Event::WindowEntered) + return handle_entered_event(event); + if (event.type() == Event::WindowLeft) - return handle_left_event(); + return handle_left_event(event); if (event.type() == Event::Resize) return handle_resize_event(static_cast(event)); diff --git a/Userland/Libraries/LibGUI/Window.h b/Userland/Libraries/LibGUI/Window.h index 9f2b433b41..0b597f90ed 100644 --- a/Userland/Libraries/LibGUI/Window.h +++ b/Userland/Libraries/LibGUI/Window.h @@ -208,6 +208,9 @@ protected: virtual void wm_event(WMEvent&); virtual void screen_rects_change_event(ScreenRectsChangeEvent&); + virtual void enter_event(Core::Event&); + virtual void leave_event(Core::Event&); + private: void update_cursor(); void focus_a_widget_if_possible(FocusSource); @@ -224,7 +227,8 @@ private: void handle_fonts_change_event(FontsChangeEvent&); void handle_screen_rects_change_event(ScreenRectsChangeEvent&); void handle_drag_move_event(DragEvent&); - void handle_left_event(); + void handle_entered_event(Core::Event&); + void handle_left_event(Core::Event&); void server_did_destroy();