From 238b6871e030958e064ae0d56847b1a3bbec6131 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Wed, 19 Feb 2020 21:58:11 +1300 Subject: [PATCH] WindowServer: Fix not all menus closing after system menu toggle We were failing to check if the current menu being set was already open. This could result in multiple occurrences of the menu in the open menu stack. When we close all menus descending from a menu we only delete the first occurrence of a given menu from the menu stack (a fair assumption to make as a menu should only be open once). Because of this a menu (or multiple instances of it) could remain in the open menu stack when it should actually be closed, leading to goofy behaviour. Fixes #1238 --- Servers/WindowServer/MenuManager.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Servers/WindowServer/MenuManager.cpp b/Servers/WindowServer/MenuManager.cpp index 242cad0c28..4a6ac43cda 100644 --- a/Servers/WindowServer/MenuManager.cpp +++ b/Servers/WindowServer/MenuManager.cpp @@ -178,6 +178,7 @@ void MenuManager::handle_mouse_event(MouseEvent& mouse_event) ASSERT(topmost_menu); auto* window = topmost_menu->menu_window(); ASSERT(window); + ASSERT(window->is_visible()); bool event_is_inside_current_menu = window->rect().contains(mouse_event.position()); if (event_is_inside_current_menu) { @@ -340,6 +341,9 @@ void MenuManager::open_menu(Menu& menu) void MenuManager::set_current_menu(Menu* menu, bool is_submenu) { + if (menu == m_current_menu) + return; + if (!is_submenu) { if (menu) close_everyone_not_in_lineage(*menu); @@ -352,8 +356,9 @@ void MenuManager::set_current_menu(Menu* menu, bool is_submenu) return; } - m_open_menu_stack.append(menu->make_weak_ptr()); m_current_menu = menu->make_weak_ptr(); + if (m_open_menu_stack.find([menu](auto& other) { return menu == other.ptr(); }).is_end()) + m_open_menu_stack.append(menu->make_weak_ptr()); } void MenuManager::close_bar()