diff options
author | Andreas Kling <kling@serenityos.org> | 2020-12-28 00:33:46 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-28 01:02:57 +0100 |
commit | 644d5c5404cfebac3a9b1e915a59ba04acc730bd (patch) | |
tree | 762c970496803cfde2fa25d369d6a43cf864f95c | |
parent | df6106854e0ee70b7bcb72a9e52253f07b346c96 (diff) | |
download | serenity-644d5c5404cfebac3a9b1e915a59ba04acc730bd.zip |
LibGUI: Switch focus if the currently focused widget is disabled
-rw-r--r-- | Libraries/LibGUI/Widget.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibGUI/Window.cpp | 5 | ||||
-rw-r--r-- | Libraries/LibGUI/Window.h | 2 |
3 files changed, 11 insertions, 0 deletions
diff --git a/Libraries/LibGUI/Widget.cpp b/Libraries/LibGUI/Widget.cpp index 1b57897f4a..47aaf29646 100644 --- a/Libraries/LibGUI/Widget.cpp +++ b/Libraries/LibGUI/Widget.cpp @@ -728,6 +728,10 @@ void Widget::set_enabled(bool enabled) return IterationDecision::Continue; }); + if (!m_enabled && window() && window()->focused_widget() == this) { + window()->did_disable_focused_widget({}); + } + Event e(Event::EnabledChange); event(e); update(); diff --git a/Libraries/LibGUI/Window.cpp b/Libraries/LibGUI/Window.cpp index 59e26f2c3c..9cf1e37ab9 100644 --- a/Libraries/LibGUI/Window.cpp +++ b/Libraries/LibGUI/Window.cpp @@ -927,4 +927,9 @@ void Window::focus_a_widget_if_possible(FocusSource source) set_focused_widget(focusable_widgets[0], source); } +void Window::did_disable_focused_widget(Badge<Widget>) +{ + focus_a_widget_if_possible(FocusSource::Mouse); +} + } diff --git a/Libraries/LibGUI/Window.h b/Libraries/LibGUI/Window.h index 93fec29e49..f4298c6986 100644 --- a/Libraries/LibGUI/Window.h +++ b/Libraries/LibGUI/Window.h @@ -196,6 +196,8 @@ public: void update_cursor(Badge<Widget>) { update_cursor(); } + void did_disable_focused_widget(Badge<Widget>); + protected: Window(Core::Object* parent = nullptr); virtual void wm_event(WMEvent&); |