소스 검색

WindowServer: Stop exposing open_menu_stack in MenuManager

The open menu stack is an internal data structure that outside classes
shouldn't really need to know about. Add MenuManager::has_open_menu()
so that the WindowManager can still know whether a menu is open or not.
Shannon Booth 5 년 전
부모
커밋
088d7be19c
3개의 변경된 파일7개의 추가작업 그리고 8개의 파일을 삭제
  1. 5 5
      Servers/WindowServer/MenuManager.cpp
  2. 1 2
      Servers/WindowServer/MenuManager.h
  3. 1 1
      Servers/WindowServer/WindowManager.cpp

+ 5 - 5
Servers/WindowServer/MenuManager.cpp

@@ -173,8 +173,8 @@ void MenuManager::handle_mouse_event(MouseEvent& mouse_event)
     if (handled_menubar_event)
         return;
 
-    if (!open_menu_stack().is_empty()) {
-        auto* topmost_menu = open_menu_stack().last().ptr();
+    if (has_open_menu()) {
+        auto* topmost_menu = m_open_menu_stack.last().ptr();
         ASSERT(topmost_menu);
         auto* window = topmost_menu->menu_window();
         ASSERT(window);
@@ -207,7 +207,7 @@ void MenuManager::handle_mouse_event(MouseEvent& mouse_event)
         }
 
         if (mouse_event.type() == Event::MouseMove) {
-            for (auto& menu : open_menu_stack()) {
+            for (auto& menu : m_open_menu_stack) {
                 if (!menu)
                     continue;
                 if (!menu->menu_window()->rect().contains(mouse_event.position()))
@@ -227,7 +227,7 @@ void MenuManager::handle_mouse_event(MouseEvent& mouse_event)
 void MenuManager::handle_menu_mouse_event(Menu& menu, const MouseEvent& event)
 {
     bool is_hover_with_any_menu_open = event.type() == MouseEvent::MouseMove
-        && !m_open_menu_stack.is_empty()
+        && has_open_menu()
         && (m_open_menu_stack.first()->menubar() || m_open_menu_stack.first() == m_system_menu.ptr());
     bool is_mousedown_with_left_button = event.type() == MouseEvent::MouseDown && event.button() == MouseButton::Left;
     bool should_open_menu = &menu != m_current_menu && (is_hover_with_any_menu_open || is_mousedown_with_left_button);
@@ -251,7 +251,7 @@ void MenuManager::set_needs_window_resize()
 
 void MenuManager::close_all_menus_from_client(Badge<ClientConnection>, ClientConnection& client)
 {
-    if (m_open_menu_stack.is_empty())
+    if (!has_open_menu())
         return;
     if (m_open_menu_stack.first()->client() != &client)
         return;

+ 1 - 2
Servers/WindowServer/MenuManager.h

@@ -45,8 +45,7 @@ public:
     void refresh();
 
     bool is_open(const Menu&) const;
-
-    Vector<WeakPtr<Menu>>& open_menu_stack() { return m_open_menu_stack; }
+    bool has_open_menu() const { return !m_open_menu_stack.is_empty(); }
 
     Gfx::Rect menubar_rect() const;
     static int menubar_menu_margin() { return 16; }

+ 1 - 1
Servers/WindowServer/WindowManager.cpp

@@ -748,7 +748,7 @@ void WindowManager::process_mouse_event(MouseEvent& event, Window*& hovered_wind
     }
 
     // FIXME: Now that the menubar has a dedicated window, is this special-casing really necessary?
-    if (!MenuManager::the().open_menu_stack().is_empty() || (!active_window_is_modal() && menubar_rect().contains(event.position()))) {
+    if (MenuManager::the().has_open_menu() || (!active_window_is_modal() && menubar_rect().contains(event.position()))) {
         MenuManager::the().dispatch_event(event);
         return;
     }