[mutter] boxes: Add function to check if rectangle is adjacent to region



commit 58c2f423f761334eef1ab63b55beae3a7bb7edb4
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Sat Mar 16 00:19:08 2019 +0100

    boxes: Add function to check if rectangle is adjacent to region
    
    We may need to check if rectangles region has adjacent neighbors and
    so if there are no gaps in between monitors.
    
    This can be done by checking if each monitor is adjacent to any other in
    the same region.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/522>

 src/core/boxes-private.h |  4 ++++
 src/core/boxes.c         | 19 +++++++++++++++++++
 2 files changed, 23 insertions(+)
---
diff --git a/src/core/boxes-private.h b/src/core/boxes-private.h
index d398164957..09cbd6e091 100644
--- a/src/core/boxes-private.h
+++ b/src/core/boxes-private.h
@@ -158,6 +158,10 @@ gboolean meta_rectangle_overlaps_with_region (
                                          const GList         *spanning_rects,
                                          const MetaRectangle *rect);
 
+gboolean meta_rectangle_is_adjacent_to_any_in_region (
+                                         const GList   *spanning_rects,
+                                         MetaRectangle *rect);
+
 /* Make the rectangle small enough to fit into one of the spanning_rects,
  * but make it no smaller than min_size.
  */
diff --git a/src/core/boxes.c b/src/core/boxes.c
index 9a9633e052..a94d0d77f3 100644
--- a/src/core/boxes.c
+++ b/src/core/boxes.c
@@ -899,6 +899,25 @@ meta_rectangle_overlaps_with_region (const GList         *spanning_rects,
   return overlaps;
 }
 
+gboolean
+meta_rectangle_is_adjacent_to_any_in_region (const GList   *spanning_rects,
+                                             MetaRectangle *rect)
+{
+  const GList *l;
+
+  for (l = spanning_rects; l; l = l->next)
+    {
+      MetaRectangle *other = (MetaRectangle *) l->data;
+
+      if (rect == other || meta_rectangle_equal (rect, other))
+        continue;
+
+      if (meta_rectangle_is_adjacent_to (rect, other))
+        return TRUE;
+    }
+
+  return FALSE;
+}
 
 void
 meta_rectangle_clamp_to_fit_into_region (const GList         *spanning_rects,


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