summaryrefslogtreecommitdiff
path: root/Servers
diff options
context:
space:
mode:
authorShannon Booth <shannon.ml.booth@gmail.com>2020-02-19 21:58:11 +1300
committerAndreas Kling <kling@serenityos.org>2020-02-20 15:11:31 +0100
commit238b6871e030958e064ae0d56847b1a3bbec6131 (patch)
treedb5e8340f44d7a98a24de94f4c020cf10d93a07a /Servers
parent6e2a16c8a8c955d478dfb0f178b3ed23450f721d (diff)
downloadserenity-238b6871e030958e064ae0d56847b1a3bbec6131.zip
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
Diffstat (limited to 'Servers')
-rw-r--r--Servers/WindowServer/MenuManager.cpp7
1 files changed, 6 insertions, 1 deletions
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()