From 58c2f423f761334eef1ab63b55beae3a7bb7edb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sat, 16 Mar 2019 00:19:08 +0100 Subject: [PATCH] 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: --- 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 d39816495..09cbd6e09 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 9a9633e05..a94d0d77f 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,