From 0b798a50dc84941c9e5e55f924aea3960ad8d867 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 30 Oct 2020 16:25:52 +0100 Subject: [PATCH] LibGUI: Make StackWidget/TabWidget preserve focus in inactive windows This one is a bit sketchy. While a window is inactive, none of its widgets are considered focused (Widget::is_focused() will return false) but this caused programmatic changes of the active widget in a tab or stack widget to fail focus propagation from old child to new child. Work around this by checking against Window::focused_widget() directly instead of asking Widget::is_focused(). --- Libraries/LibGUI/StackWidget.cpp | 3 ++- Libraries/LibGUI/TabWidget.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Libraries/LibGUI/StackWidget.cpp b/Libraries/LibGUI/StackWidget.cpp index bde65d5151..1f06eed24e 100644 --- a/Libraries/LibGUI/StackWidget.cpp +++ b/Libraries/LibGUI/StackWidget.cpp @@ -26,6 +26,7 @@ #include #include +#include namespace GUI { @@ -42,7 +43,7 @@ void StackWidget::set_active_widget(Widget* widget) if (widget == m_active_widget) return; - bool active_widget_had_focus = m_active_widget && m_active_widget->is_focused(); + bool active_widget_had_focus = m_active_widget && window() && window()->focused_widget() == m_active_widget; if (m_active_widget) m_active_widget->set_visible(false); diff --git a/Libraries/LibGUI/TabWidget.cpp b/Libraries/LibGUI/TabWidget.cpp index 39583e593e..e3a6dcdb44 100644 --- a/Libraries/LibGUI/TabWidget.cpp +++ b/Libraries/LibGUI/TabWidget.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -81,7 +82,7 @@ void TabWidget::set_active_widget(Widget* widget) if (widget == m_active_widget) return; - bool active_widget_had_focus = m_active_widget && m_active_widget->is_focused(); + bool active_widget_had_focus = m_active_widget && window() && window()->focused_widget() == m_active_widget; if (m_active_widget) m_active_widget->set_visible(false);