[metacity/wip/muktupavels/docks] display: avoid unnecessary stack changes




commit 236c0a1029389920dfc90321a9264c392cee8aee
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Tue Oct 4 19:33:17 2022 +0300

    display: avoid unnecessary stack changes
    
    Currently docks are raised when a mouse enters the window and are
    lowered when mouse leaves it. Typically this will make unnecessary
    stack changes and unneeded screen redraw.
    
    Functions meta_window_raise and meta_window_lower raises or lowers
    windows within the window layer. For dock windows that means that
    raising/lowering happens between windows in META_LAYER_BOTTOM layer
    or META_LAYER_DOCK/META_LAYER_TOP layers.
    
    In typical configuration with top and bottom panels this means that
    rasing/lowering happens between both panels for no reason. Stop doing
    that if dock does not overlap with other windows in same layer.
    
    Dock raising was added in commit 7be4c63ee459 when panel was put in
    the nromal layer.

 src/core/display.c | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)
---
diff --git a/src/core/display.c b/src/core/display.c
index 17a4eaf7..b71402c3 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -1717,6 +1717,42 @@ handle_window_focus_event (MetaDisplay *display,
     }
 }
 
+static gboolean
+dock_has_overlaps (MetaWindow *dock,
+                   GList      *windows)
+{
+  MetaRectangle dock_rect;
+  GList *tmp;
+
+  if (dock->type != META_WINDOW_DOCK)
+    return FALSE;
+
+  meta_window_get_input_rect (dock, &dock_rect);
+
+  tmp = windows;
+  while (tmp != NULL)
+    {
+      MetaWindow *other;
+      MetaRectangle other_rect;
+
+      other = tmp->data;
+      tmp = tmp->next;
+
+      if (dock == other)
+        continue;
+
+      if (dock->layer != other->layer)
+        continue;
+
+      meta_window_get_input_rect (other, &other_rect);
+
+      if (meta_rectangle_overlap (&dock_rect, &other_rect))
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
 /**
  * This is the most important function in the whole program. It is the heart,
  * it is the nexus, it is the Grand Central Station of Metacity's world.
@@ -2191,7 +2227,8 @@ event_callback (XEvent   *event,
               break;
             }
 
-          if (window->type == META_WINDOW_DOCK)
+          if (window->type == META_WINDOW_DOCK &&
+              dock_has_overlaps (window, screen->stack->sorted))
             meta_window_raise (window);
         }
       break;
@@ -2202,6 +2239,7 @@ event_callback (XEvent   *event,
       else if (window != NULL)
         {
           if (window->type == META_WINDOW_DOCK &&
+              dock_has_overlaps (window, screen->stack->sorted) &&
               event->xcrossing.mode != NotifyGrab &&
               event->xcrossing.mode != NotifyUngrab &&
               !window->has_focus)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]