diff options
author | Andreas Kling <kling@serenityos.org> | 2021-03-26 14:45:15 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-26 14:45:15 +0100 |
commit | ecb0ae9c3370f3214c8a97b792bc732612c271ff (patch) | |
tree | 5481fa1d0b29c1a914d3725af752c3e0447e7975 /Userland/Services | |
parent | b31b904ad01f771d385c3b4b3575203a20a46578 (diff) | |
download | serenity-ecb0ae9c3370f3214c8a97b792bc732612c271ff.zip |
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. :^)
Diffstat (limited to 'Userland/Services')
-rw-r--r-- | Userland/Services/WindowServer/Menu.cpp | 16 | ||||
-rw-r--r-- | Userland/Services/WindowServer/Menu.h | 4 | ||||
-rw-r--r-- | 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<MouseEvent&>(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); |