summaryrefslogtreecommitdiff
path: root/Userland/Services
diff options
context:
space:
mode:
authorJean-Baptiste Boric <jblbeurope@gmail.com>2021-02-13 14:24:42 +0100
committerAndreas Kling <kling@serenityos.org>2021-02-15 19:37:14 +0100
commitf8cb068354feff7879c643c374c3d79614fad205 (patch)
treeefc4f7a800ca20be03a6dce0c0e7199ee9615b35 /Userland/Services
parent7ee6c66ee95ad151c24d34c259464db03fb7ea6b (diff)
downloadserenity-f8cb068354feff7879c643c374c3d79614fad205.zip
WindowManager: Select top-level menus with left/right keys
Diffstat (limited to 'Userland/Services')
-rw-r--r--Userland/Services/WindowServer/MenuManager.cpp47
-rw-r--r--Userland/Services/WindowServer/MenuManager.h3
2 files changed, 50 insertions, 0 deletions
diff --git a/Userland/Services/WindowServer/MenuManager.cpp b/Userland/Services/WindowServer/MenuManager.cpp
index 5f57c4dc03..b858927e81 100644
--- a/Userland/Services/WindowServer/MenuManager.cpp
+++ b/Userland/Services/WindowServer/MenuManager.cpp
@@ -167,6 +167,15 @@ void MenuManager::event(Core::Event& event)
// Going "back" a menu should be the previous menu in the stack
if (it.index() > 0)
set_current_menu(m_open_menu_stack.at(it.index() - 1));
+ else {
+ if (m_current_menu->hovered_item())
+ m_current_menu->set_hovered_item(-1);
+ else {
+ auto* target_menu = previous_menu(m_current_menu);
+ if (target_menu)
+ open_menu(*target_menu);
+ }
+ }
close_everyone_not_in_lineage(*m_current_menu);
return;
}
@@ -175,6 +184,13 @@ void MenuManager::event(Core::Event& event)
auto hovered_item = m_current_menu->hovered_item();
if (hovered_item && hovered_item->is_submenu())
m_current_menu->descend_into_submenu_at_hovered_item();
+ else if (m_open_menu_stack.size() <= 1) {
+ auto* target_menu = next_menu(m_current_menu);
+ if (target_menu) {
+ open_menu(*target_menu);
+ close_everyone_not_in_lineage(*target_menu);
+ }
+ }
return;
}
@@ -494,6 +510,37 @@ void MenuManager::set_system_menu(Menu& menu)
set_current_menubar(m_current_menubar);
}
+Menu* MenuManager::previous_menu(Menu* current)
+{
+ Menu* found = nullptr;
+ Menu* previous = nullptr;
+ for_each_active_menubar_menu([&](Menu& menu) {
+ if (current == &menu) {
+ found = previous;
+ return IterationDecision::Break;
+ }
+ previous = &menu;
+ return IterationDecision::Continue;
+ });
+ return found;
+}
+
+Menu* MenuManager::next_menu(Menu* current)
+{
+ Menu* found = nullptr;
+ bool is_next = false;
+ for_each_active_menubar_menu([&](Menu& menu) {
+ if (is_next) {
+ found = &menu;
+ return IterationDecision::Break;
+ }
+ if (current == &menu)
+ is_next = true;
+ return IterationDecision::Continue;
+ });
+ return found;
+}
+
void MenuManager::did_change_theme()
{
++m_theme_index;
diff --git a/Userland/Services/WindowServer/MenuManager.h b/Userland/Services/WindowServer/MenuManager.h
index 0d56f6a8b7..43fc59afe3 100644
--- a/Userland/Services/WindowServer/MenuManager.h
+++ b/Userland/Services/WindowServer/MenuManager.h
@@ -89,6 +89,9 @@ public:
m_current_menubar->for_each_menu(callback);
}
+ Menu* previous_menu(Menu* current);
+ Menu* next_menu(Menu* current);
+
void did_change_theme();
private: