From ecb0ae9c3370f3214c8a97b792bc732612c271ff Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 26 Mar 2021 14:45:15 +0100 Subject: [PATCH] WindowServer: Keep menu open when activating a menu item with Ctrl held This makes it easy to "try out" different options (like system themes!) in a menu without having to re-open the menu over and over. :^) --- Userland/Services/WindowServer/Menu.cpp | 16 +++++++++------- Userland/Services/WindowServer/Menu.h | 4 ++-- Userland/Services/WindowServer/MenuManager.cpp | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Userland/Services/WindowServer/Menu.cpp b/Userland/Services/WindowServer/Menu.cpp index 6b295a29d6..f476741f3d 100644 --- a/Userland/Services/WindowServer/Menu.cpp +++ b/Userland/Services/WindowServer/Menu.cpp @@ -296,15 +296,16 @@ void Menu::update_for_new_hovered_item(bool make_input) redraw(); } -void Menu::open_hovered_item() +void Menu::open_hovered_item(bool leave_menu_open) { VERIFY(menu_window()); VERIFY(menu_window()->is_visible()); if (!hovered_item()) return; if (hovered_item()->is_enabled()) - did_activate(*hovered_item()); - clear_hovered_item(); + did_activate(*hovered_item(), leave_menu_open); + if (!leave_menu_open) + clear_hovered_item(); } void Menu::descend_into_submenu_at_hovered_item() @@ -352,7 +353,7 @@ void Menu::event(Core::Event& event) } if (event.type() == Event::MouseUp) { - open_hovered_item(); + open_hovered_item(static_cast(event).modifiers() & KeyModifier::Mod_Ctrl); return; } @@ -455,7 +456,7 @@ void Menu::clear_hovered_item() redraw(); } -void Menu::did_activate(MenuItem& item) +void Menu::did_activate(MenuItem& item, bool leave_menu_open) { if (item.type() == MenuItem::Type::Separator) return; @@ -463,7 +464,8 @@ void Menu::did_activate(MenuItem& item) if (on_item_activation) on_item_activation(item); - MenuManager::the().close_everyone(); + if (!leave_menu_open) + MenuManager::the().close_everyone(); if (m_client) m_client->post_message(Messages::WindowClient::MenuItemActivated(m_menu_id, item.identifier())); @@ -475,7 +477,7 @@ bool Menu::activate_default() if (item.type() == MenuItem::Type::Separator) continue; if (item.is_enabled() && item.is_default()) { - did_activate(item); + did_activate(item, false); return true; } } diff --git a/Userland/Services/WindowServer/Menu.h b/Userland/Services/WindowServer/Menu.h index 4496361bf8..eacee3d7de 100644 --- a/Userland/Services/WindowServer/Menu.h +++ b/Userland/Services/WindowServer/Menu.h @@ -122,7 +122,7 @@ public: int scroll_offset() const { return m_scroll_offset; } void descend_into_submenu_at_hovered_item(); - void open_hovered_item(); + void open_hovered_item(bool leave_menu_open); private: virtual void event(Core::Event&) override; @@ -132,7 +132,7 @@ private: int item_index_at(const Gfx::IntPoint&); int padding_between_text_and_shortcut() const { return 50; } - void did_activate(MenuItem&); + void did_activate(MenuItem&, bool leave_menu_open); void update_for_new_hovered_item(bool make_input = false); ClientConnection* m_client { nullptr }; diff --git a/Userland/Services/WindowServer/MenuManager.cpp b/Userland/Services/WindowServer/MenuManager.cpp index 2bf48cf81f..f48e839211 100644 --- a/Userland/Services/WindowServer/MenuManager.cpp +++ b/Userland/Services/WindowServer/MenuManager.cpp @@ -197,7 +197,7 @@ void MenuManager::event(Core::Event& event) if (hovered_item->is_submenu()) m_current_menu->descend_into_submenu_at_hovered_item(); else - m_current_menu->open_hovered_item(); + m_current_menu->open_hovered_item(false); return; } m_current_menu->dispatch_event(event);