diff options
author | Andreas Kling <kling@serenityos.org> | 2020-05-12 17:05:00 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-12 17:05:00 +0200 |
commit | 8c51063a88d3d3ae6e57798dbcd8d1af011f8f63 (patch) | |
tree | 3556df1be0932f4d9a9a8711445dadd032f3febd /Libraries | |
parent | 479f16bb6c0362a85a3fa108c05faffd5faf3aea (diff) | |
download | serenity-8c51063a88d3d3ae6e57798dbcd8d1af011f8f63.zip |
LibGUI: Actually check widgets in focus chain for keyboard shortcuts
We were iterating the ancestor chain of the focused widget when looking
for a matching keyboard shortcut, but we didn't actually look at the
ancestors at each step.
With this fix, we now correctly activate actions found in the ancestor
chain of the focused widgets. :^)
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/WindowServerConnection.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/Libraries/LibGUI/WindowServerConnection.cpp b/Libraries/LibGUI/WindowServerConnection.cpp index 441294598d..e960c14ca3 100644 --- a/Libraries/LibGUI/WindowServerConnection.cpp +++ b/Libraries/LibGUI/WindowServerConnection.cpp @@ -42,6 +42,8 @@ #include <LibGfx/Palette.h> #include <LibGfx/SystemTheme.h> +//#define KEYBOARD_SHORTCUTS_DEBUG + namespace GUI { WindowServerConnection& WindowServerConnection::the() @@ -134,16 +136,32 @@ void WindowServerConnection::handle(const Messages::WindowClient::KeyDown& messa Action* action = nullptr; +#ifdef KEYBOARD_SHORTCUTS_DEBUG + dbg() << "Looking up action for " << key_event->to_string(); +#endif + if (auto* focused_widget = window->focused_widget()) { - for (auto* widget = focused_widget; widget && !action; widget = widget->parent_widget()) - action = focused_widget->action_for_key_event(*key_event); + for (auto* widget = focused_widget; widget && !action; widget = widget->parent_widget()) { + action = widget->action_for_key_event(*key_event); +#ifdef KEYBOARD_SHORTCUTS_DEBUG + dbg() << " > Focused widget " << *widget << " gave action: " << action; +#endif + } } - if (!action) + if (!action) { action = window->action_for_key_event(*key_event); +#ifdef KEYBOARD_SHORTCUTS_DEBUG + dbg() << " > Asked window " << *window << ", got action: " << action; +#endif + } - if (!action) + if (!action) { action = Application::the().action_for_key_event(*key_event); +#ifdef KEYBOARD_SHORTCUTS_DEBUG + dbg() << " > Asked application, got action: " << action; +#endif + } if (action && action->is_enabled()) { action->activate(); |