1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:17:35 +00:00

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.
This commit is contained in:
sin-ack 2021-07-25 21:07:55 +00:00 committed by Ali Mohammad Pur
parent 6162e78c7f
commit 444ed56521
2 changed files with 24 additions and 3 deletions

View file

@ -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); set_hovered_widget(nullptr);
Application::the()->set_drag_hovered_widget({}, nullptr); Application::the()->set_drag_hovered_widget({}, nullptr);
leave_event(event);
} }
void Window::event(Core::Event& event) void Window::event(Core::Event& event)
@ -605,8 +619,11 @@ void Window::event(Core::Event& event)
if (event.type() == Event::WindowCloseRequest) if (event.type() == Event::WindowCloseRequest)
return handle_close_request(); return handle_close_request();
if (event.type() == Event::WindowEntered)
return handle_entered_event(event);
if (event.type() == Event::WindowLeft) if (event.type() == Event::WindowLeft)
return handle_left_event(); return handle_left_event(event);
if (event.type() == Event::Resize) if (event.type() == Event::Resize)
return handle_resize_event(static_cast<ResizeEvent&>(event)); return handle_resize_event(static_cast<ResizeEvent&>(event));

View file

@ -208,6 +208,9 @@ protected:
virtual void wm_event(WMEvent&); virtual void wm_event(WMEvent&);
virtual void screen_rects_change_event(ScreenRectsChangeEvent&); virtual void screen_rects_change_event(ScreenRectsChangeEvent&);
virtual void enter_event(Core::Event&);
virtual void leave_event(Core::Event&);
private: private:
void update_cursor(); void update_cursor();
void focus_a_widget_if_possible(FocusSource); void focus_a_widget_if_possible(FocusSource);
@ -224,7 +227,8 @@ private:
void handle_fonts_change_event(FontsChangeEvent&); void handle_fonts_change_event(FontsChangeEvent&);
void handle_screen_rects_change_event(ScreenRectsChangeEvent&); void handle_screen_rects_change_event(ScreenRectsChangeEvent&);
void handle_drag_move_event(DragEvent&); 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(); void server_did_destroy();