diff options
author | Lucas CHOLLET <lucas.chollet@free.fr> | 2023-03-08 18:31:53 -0500 |
---|---|---|
committer | Jelle Raaijmakers <jelle@gmta.nl> | 2023-03-25 21:42:53 +0100 |
commit | baac824ee3b49608549671aec91e5c78961c19af (patch) | |
tree | 2a884ff3ef819f64727da931d80b360258e9cbdb /Userland/Libraries | |
parent | 0b14ef134d411ccc01a8c70d62f8bdf331892b16 (diff) | |
download | serenity-baac824ee3b49608549671aec91e5c78961c19af.zip |
LibGUI: Make `propagate_shortcuts` handle different level of propagation
First, this patch renames the function
`propagate_shortcuts_up_to_application` to `propagate_shortcuts`.
Handling those levels, will allow us to differentiate shortcuts at
`Window` level and `Application` level. Which will be convenient to
handle dialog-specific shortcuts.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibGUI/Window.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Window.h | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibVT/TerminalWidget.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWebView/OutOfProcessWebView.cpp | 2 |
4 files changed, 12 insertions, 7 deletions
diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp index 519c6e54ee..bdbcd951b8 100644 --- a/Userland/Libraries/LibGUI/Window.cpp +++ b/Userland/Libraries/LibGUI/Window.cpp @@ -479,7 +479,7 @@ void Window::handle_multi_paint_event(MultiPaintEvent& event) ConnectionToWindowServer::the().async_did_finish_painting(m_window_id, rects); } -void Window::propagate_shortcuts_up_to_application(KeyEvent& event, Widget* widget) +void Window::propagate_shortcuts(KeyEvent& event, Widget* widget, ShortcutPropagationBoundary boundary) { VERIFY(event.type() == Event::KeyDown); auto shortcut = Shortcut(event.modifiers(), event.key()); @@ -497,9 +497,9 @@ void Window::propagate_shortcuts_up_to_application(KeyEvent& event, Widget* widg } while (widget); } - if (!action) + if (!action && boundary >= ShortcutPropagationBoundary::Window) action = action_for_shortcut(shortcut); - if (!action) + if (!action && boundary >= ShortcutPropagationBoundary::Application) action = Application::the()->action_for_shortcut(shortcut); if (action) { @@ -533,7 +533,7 @@ void Window::handle_key_event(KeyEvent& event) // Only process shortcuts if this is a keydown event. if (event.type() == Event::KeyDown) - propagate_shortcuts_up_to_application(event, nullptr); + propagate_shortcuts(event, nullptr, PropagationLimit::Application); } void Window::handle_resize_event(ResizeEvent& event) diff --git a/Userland/Libraries/LibGUI/Window.h b/Userland/Libraries/LibGUI/Window.h index 335f9dd0d1..41670a9753 100644 --- a/Userland/Libraries/LibGUI/Window.h +++ b/Userland/Libraries/LibGUI/Window.h @@ -229,7 +229,12 @@ public: void set_always_on_top(bool always_on_top = true); - void propagate_shortcuts_up_to_application(KeyEvent& event, Widget* widget); + enum class ShortcutPropagationBoundary { + Window, + Application, + }; + + void propagate_shortcuts(KeyEvent& event, Widget* widget, ShortcutPropagationBoundary = ShortcutPropagationBoundary::Application); protected: Window(Core::Object* parent = nullptr); diff --git a/Userland/Libraries/LibVT/TerminalWidget.cpp b/Userland/Libraries/LibVT/TerminalWidget.cpp index 46c46f2b85..1a0468ab67 100644 --- a/Userland/Libraries/LibVT/TerminalWidget.cpp +++ b/Userland/Libraries/LibVT/TerminalWidget.cpp @@ -208,7 +208,7 @@ void TerminalWidget::keydown_event(GUI::KeyEvent& event) { // We specifically need to process shortcuts before input to the Terminal is done // since otherwise escape sequences will eat all our shortcuts for dinner. - window()->propagate_shortcuts_up_to_application(event, this); + window()->propagate_shortcuts(event, this); if (event.is_accepted()) return; diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index fe767b09b7..cee2b51ba1 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -751,7 +751,7 @@ void OutOfProcessWebView::notify_server_did_finish_handling_input_event(bool eve // NOTE: If other events can ever trigger shortcuts, propagate those here. if (!event.is_accepted() && event.type() == GUI::Event::Type::KeyDown) - window()->propagate_shortcuts_up_to_application(event, this); + window()->propagate_shortcuts(event, this); } }, [this](GUI::MouseEvent& event) { |