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().
This commit is contained in:
Andreas Kling 2020-10-30 16:25:52 +01:00
parent cf93c66e6e
commit 0b798a50dc
Notes: sideshowbarker 2024-07-19 01:38:27 +09:00
2 changed files with 4 additions and 2 deletions

View File

@ -26,6 +26,7 @@
#include <LibGUI/BoxLayout.h>
#include <LibGUI/StackWidget.h>
#include <LibGUI/Window.h>
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);

View File

@ -29,6 +29,7 @@
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Painter.h>
#include <LibGUI/TabWidget.h>
#include <LibGUI/Window.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Font.h>
#include <LibGfx/Palette.h>
@ -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);