From 8c51063a88d3d3ae6e57798dbcd8d1af011f8f63 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 12 May 2020 17:05:00 +0200 Subject: [PATCH] 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. :^) --- Libraries/LibGUI/WindowServerConnection.cpp | 26 +++++++++++++++++---- 1 file 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 #include +//#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();