소스 검색

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
Shannon Booth 5 년 전
부모
커밋
238b6871e0
1개의 변경된 파일6개의 추가작업 그리고 1개의 파일을 삭제
  1. 6 1
      Servers/WindowServer/MenuManager.cpp

+ 6 - 1
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()