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
This commit is contained in:
Shannon Booth 2020-02-19 21:58:11 +13:00 committed by Andreas Kling
parent 6e2a16c8a8
commit 238b6871e0
Notes: sideshowbarker 2024-07-19 09:11:51 +09:00

View file

@ -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()