From c66a6f131e5c67b3f8e28e99aa8bae24dfb9ec17 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 12 Jan 2020 16:03:41 +1300 Subject: [PATCH] WindowServer: Send key events to menu manager is there is a current menu If there is a current menu, we now redirect all key events from window manager to the menu manager. This allows us to properly navigate a menu even when there is a current menu open. Menu key navigation is now a lot more pleasant to use :^) The action of pressing escape to close a menu has also been moved to its proper home in menu manager in this commit. --- Servers/WindowServer/WSMenuManager.cpp | 21 +++++++++++++++------ Servers/WindowServer/WSWindowManager.cpp | 10 ++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Servers/WindowServer/WSMenuManager.cpp b/Servers/WindowServer/WSMenuManager.cpp index 9a14fbc2a2..ed55f4a579 100644 --- a/Servers/WindowServer/WSMenuManager.cpp +++ b/Servers/WindowServer/WSMenuManager.cpp @@ -270,12 +270,21 @@ void WSMenuManager::event(CEvent& event) } } - if (event.type() == WSEvent::KeyDown) { - for_each_active_menubar_menu([&](WSMenu& menu) { - if (is_open(menu)) - menu.dispatch_event(event); - return IterationDecision::Continue; - }); + if (static_cast(event).is_key_event()) { + auto& key_event = static_cast(event); + + if (key_event.type() == WSEvent::KeyUp && key_event.key() == Key_Escape) { + close_everyone(); + return; + } + + if (event.type() == WSEvent::KeyDown) { + for_each_active_menubar_menu([&](WSMenu& menu) { + if (is_open(menu)) + menu.dispatch_event(event); + return IterationDecision::Continue; + }); + } } return CObject::event(event); diff --git a/Servers/WindowServer/WSWindowManager.cpp b/Servers/WindowServer/WSWindowManager.cpp index 22aab13138..aa7cd1b56b 100644 --- a/Servers/WindowServer/WSWindowManager.cpp +++ b/Servers/WindowServer/WSWindowManager.cpp @@ -949,10 +949,8 @@ void WSWindowManager::event(CEvent& event) return; } - if (key_event.type() == WSEvent::KeyUp && key_event.key() == Key_Escape) { - auto current_menu = WSMenuManager::the().current_menu(); - if (current_menu) - WSMenuManager::the().close_everyone(); + if (WSMenuManager::the().current_menu()) { + WSMenuManager::the().dispatch_event(event); return; } @@ -1004,10 +1002,6 @@ void WSWindowManager::event(CEvent& event) m_active_window->dispatch_event(event); return; } - - // FIXME: We should send events to the MenuManager if a window is open - // This should take priority over sending to a window. - WSMenuManager::the().dispatch_event(event); } CObject::event(event);