mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-27 03:37:53 +00:00
LibGUI: Make focus events more aware of why focus is changing
This patch adds GUI::FocusEvent which has a GUI::FocusSource. The focus source is one of three things: - Programmatic - Mouse - Keyboard This allows receivers of focus events to implement different behaviors depending on how they receive/lose focus.
This commit is contained in:
@@ -525,17 +525,17 @@ void Window::set_main_widget(Widget* widget)
|
||||
update();
|
||||
}
|
||||
|
||||
void Window::set_focused_widget(Widget* widget)
|
||||
void Window::set_focused_widget(Widget* widget, FocusSource source)
|
||||
{
|
||||
if (m_focused_widget == widget)
|
||||
return;
|
||||
if (m_focused_widget) {
|
||||
Core::EventLoop::current().post_event(*m_focused_widget, make<Event>(Event::FocusOut));
|
||||
Core::EventLoop::current().post_event(*m_focused_widget, make<FocusEvent>(Event::FocusOut, source));
|
||||
m_focused_widget->update();
|
||||
}
|
||||
m_focused_widget = widget ? widget->make_weak_ptr() : nullptr;
|
||||
if (m_focused_widget) {
|
||||
Core::EventLoop::current().post_event(*m_focused_widget, make<Event>(Event::FocusIn));
|
||||
Core::EventLoop::current().post_event(*m_focused_widget, make<FocusEvent>(Event::FocusIn, source));
|
||||
m_focused_widget->update();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user