mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:17:46 +00:00
LibGUI: Fixes Widget->set_visible(false) still maintains focus bug
When setting a Widget->set_visible(false), if that Widget->has_focus() it will continue to have focus, even though it's not visible to the user anymore. Now calling Widget->set_visible(false) will remove focus from the Widget if it had focus, and the Window will give focus back to the Widget that had it previously, if there was one.
This commit is contained in:
parent
9720261540
commit
123848f0c1
3 changed files with 8 additions and 0 deletions
|
@ -654,11 +654,15 @@ void Window::set_focused_widget(Widget* widget, FocusSource source)
|
|||
WeakPtr<Widget> previously_focused_widget = m_focused_widget;
|
||||
m_focused_widget = widget;
|
||||
|
||||
if (!m_focused_widget && m_previously_focused_widget)
|
||||
m_focused_widget = m_previously_focused_widget;
|
||||
|
||||
if (previously_focused_widget) {
|
||||
Core::EventLoop::current().post_event(*previously_focused_widget, make<FocusEvent>(Event::FocusOut, source));
|
||||
previously_focused_widget->update();
|
||||
if (previously_focused_widget && previously_focused_widget->on_focus_change)
|
||||
previously_focused_widget->on_focus_change(previously_focused_widget->is_focused(), source);
|
||||
m_previously_focused_widget = previously_focused_widget;
|
||||
}
|
||||
if (m_focused_widget) {
|
||||
Core::EventLoop::current().post_event(*m_focused_widget, make<FocusEvent>(Event::FocusIn, source));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue