Преглед на файлове

WindowServer: Process window mouse events in the correct z-order.

Andreas Kling преди 6 години
родител
ревизия
4f33fb3a1a
променени са 2 файла, в които са добавени 24 реда и са изтрити 21 реда
  1. 23 21
      WindowServer/WSWindowManager.cpp
  2. 1 0
      WindowServer/WSWindowManager.h

+ 23 - 21
WindowServer/WSWindowManager.cpp

@@ -504,34 +504,32 @@ void WSWindowManager::process_mouse_event(WSMouseEvent& event)
         }
     }
 
-    for (auto* window = m_windows_in_order.tail(); window; window = window->prev()) {
-        if (!window->is_visible())
-            continue;
-        if (window->type() != WSWindowType::Menu && title_bar_rect(window->rect()).contains(event.position())) {
+    for_each_visible_window([&] (WSWindow& window) {
+        if (window.type() != WSWindowType::Menu && title_bar_rect(window.rect()).contains(event.position())) {
             if (event.type() == WSMessage::MouseDown) {
-                move_to_front(*window);
-                set_active_window(window);
+                move_to_front(window);
+                set_active_window(&window);
             }
-            if (close_button_rect_for_window(window->rect()).contains(event.position())) {
-                handle_close_button_mouse_event(*window, event);
+            if (close_button_rect_for_window(window.rect()).contains(event.position())) {
+                handle_close_button_mouse_event(window, event);
                 return;
             }
-            handle_titlebar_mouse_event(*window, event);
+            handle_titlebar_mouse_event(window, event);
             return;
         }
 
-        if (window->rect().contains(event.position())) {
-            if (window->type() != WSWindowType::Menu && event.type() == WSMessage::MouseDown) {
-                move_to_front(*window);
-                set_active_window(window);
+        if (window.rect().contains(event.position())) {
+            if (window.type() != WSWindowType::Menu && event.type() == WSMessage::MouseDown) {
+                move_to_front(window);
+                set_active_window(&window);
             }
             // FIXME: Should we just alter the coordinates of the existing MouseEvent and pass it through?
-            Point position { event.x() - window->rect().x(), event.y() - window->rect().y() };
+            Point position { event.x() - window.rect().x(), event.y() - window.rect().y() };
             auto local_event = make<WSMouseEvent>(event.type(), position, event.buttons(), event.button());
-            window->on_message(*local_event);
+            window.on_message(*local_event);
             return;
         }
-    }
+    });
 }
 
 template<typename Callback>
@@ -546,6 +544,13 @@ void WSWindowManager::for_each_visible_window_of_type(WSWindowType type, Callbac
     }
 }
 
+template<typename Callback>
+void WSWindowManager::for_each_visible_window(Callback callback)
+{
+    for_each_visible_window_of_type(WSWindowType::Normal, callback);
+    for_each_visible_window_of_type(WSWindowType::Menu, callback);
+}
+
 void WSWindowManager::compose()
 {
     LOCKER(m_lock);
@@ -588,7 +593,7 @@ void WSWindowManager::compose()
             m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect);
     }
 
-    auto blit_dirty_rects_of_window = [&] (WSWindow& window) {
+    for_each_visible_window([&] (WSWindow& window) {
         WSWindowLocker locker(window);
         RetainPtr<GraphicsBitmap> backing = window.backing();
         if (!backing)
@@ -609,10 +614,7 @@ void WSWindowManager::compose()
             m_back_painter->clear_clip_rect();
         }
         m_back_painter->clear_clip_rect();
-    };
-
-    for_each_visible_window_of_type(WSWindowType::Normal, blit_dirty_rects_of_window);
-    for_each_visible_window_of_type(WSWindowType::Menu, blit_dirty_rects_of_window);
+    });
 
     draw_menubar();
     draw_cursor();

+ 1 - 0
WindowServer/WSWindowManager.h

@@ -77,6 +77,7 @@ private:
 
     void set_active_window(WSWindow*);
     template<typename Callback> void for_each_visible_window_of_type(WSWindowType, Callback);
+    template<typename Callback> void for_each_visible_window(Callback);
     template<typename Callback> void for_each_active_menubar_menu(Callback);
     void close_current_menu();
     WSMenu& create_menu(String&& name);