1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:37:35 +00:00

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. :^)
This commit is contained in:
Andreas Kling 2021-03-26 14:45:15 +01:00
parent b31b904ad0
commit ecb0ae9c33
3 changed files with 12 additions and 10 deletions

View file

@ -296,15 +296,16 @@ void Menu::update_for_new_hovered_item(bool make_input)
redraw(); redraw();
} }
void Menu::open_hovered_item() void Menu::open_hovered_item(bool leave_menu_open)
{ {
VERIFY(menu_window()); VERIFY(menu_window());
VERIFY(menu_window()->is_visible()); VERIFY(menu_window()->is_visible());
if (!hovered_item()) if (!hovered_item())
return; return;
if (hovered_item()->is_enabled()) if (hovered_item()->is_enabled())
did_activate(*hovered_item()); did_activate(*hovered_item(), leave_menu_open);
clear_hovered_item(); if (!leave_menu_open)
clear_hovered_item();
} }
void Menu::descend_into_submenu_at_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) { if (event.type() == Event::MouseUp) {
open_hovered_item(); open_hovered_item(static_cast<MouseEvent&>(event).modifiers() & KeyModifier::Mod_Ctrl);
return; return;
} }
@ -455,7 +456,7 @@ void Menu::clear_hovered_item()
redraw(); redraw();
} }
void Menu::did_activate(MenuItem& item) void Menu::did_activate(MenuItem& item, bool leave_menu_open)
{ {
if (item.type() == MenuItem::Type::Separator) if (item.type() == MenuItem::Type::Separator)
return; return;
@ -463,7 +464,8 @@ void Menu::did_activate(MenuItem& item)
if (on_item_activation) if (on_item_activation)
on_item_activation(item); on_item_activation(item);
MenuManager::the().close_everyone(); if (!leave_menu_open)
MenuManager::the().close_everyone();
if (m_client) if (m_client)
m_client->post_message(Messages::WindowClient::MenuItemActivated(m_menu_id, item.identifier())); 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) if (item.type() == MenuItem::Type::Separator)
continue; continue;
if (item.is_enabled() && item.is_default()) { if (item.is_enabled() && item.is_default()) {
did_activate(item); did_activate(item, false);
return true; return true;
} }
} }

View file

@ -122,7 +122,7 @@ public:
int scroll_offset() const { return m_scroll_offset; } int scroll_offset() const { return m_scroll_offset; }
void descend_into_submenu_at_hovered_item(); void descend_into_submenu_at_hovered_item();
void open_hovered_item(); void open_hovered_item(bool leave_menu_open);
private: private:
virtual void event(Core::Event&) override; virtual void event(Core::Event&) override;
@ -132,7 +132,7 @@ private:
int item_index_at(const Gfx::IntPoint&); int item_index_at(const Gfx::IntPoint&);
int padding_between_text_and_shortcut() const { return 50; } 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); void update_for_new_hovered_item(bool make_input = false);
ClientConnection* m_client { nullptr }; ClientConnection* m_client { nullptr };

View file

@ -197,7 +197,7 @@ void MenuManager::event(Core::Event& event)
if (hovered_item->is_submenu()) if (hovered_item->is_submenu())
m_current_menu->descend_into_submenu_at_hovered_item(); m_current_menu->descend_into_submenu_at_hovered_item();
else else
m_current_menu->open_hovered_item(); m_current_menu->open_hovered_item(false);
return; return;
} }
m_current_menu->dispatch_event(event); m_current_menu->dispatch_event(event);