1
0
Fork 0

boxes: Move Rectangle.is_adjacent_to to Mtk

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3501>
This commit is contained in:
Bilal Elmoussaoui 2024-01-06 19:40:18 +01:00 committed by Marge Bot
parent fcc8cfff11
commit 6f9e75b6f2
8 changed files with 62 additions and 63 deletions

View file

@ -381,3 +381,26 @@ mtk_rectangle_scale_double (const MtkRectangle *rect,
graphene_rect_scale (&tmp, scale, scale, &tmp);
mtk_rectangle_from_graphene_rect (&tmp, rounding_strategy, dest);
}
gboolean
mtk_rectangle_is_adjacent_to (const MtkRectangle *rect,
const MtkRectangle *other)
{
int rect_x1 = rect->x;
int rect_y1 = rect->y;
int rect_x2 = rect->x + rect->width;
int rect_y2 = rect->y + rect->height;
int other_x1 = other->x;
int other_y1 = other->y;
int other_x2 = other->x + other->width;
int other_y2 = other->y + other->height;
if ((rect_x1 == other_x2 || rect_x2 == other_x1) &&
!(rect_y2 <= other_y1 || rect_y1 >= other_y2))
return TRUE;
else if ((rect_y1 == other_y2 || rect_y2 == other_y1) &&
!(rect_x2 <= other_x1 || rect_x1 >= other_x2))
return TRUE;
else
return FALSE;
}

View file

@ -136,3 +136,7 @@ void mtk_rectangle_scale_double (const MtkRectangle *rect,
double scale,
MtkRoundingStrategy rounding_strategy,
MtkRectangle *dest);
MTK_EXPORT
gboolean mtk_rectangle_is_adjacent_to (const MtkRectangle *rect,
const MtkRectangle *other);

View file

@ -1898,8 +1898,8 @@ has_adjacent_neighbour (MetaMonitorsConfig *config,
if (logical_monitor_config == other_logical_monitor_config)
continue;
if (meta_rectangle_is_adjacent_to (&logical_monitor_config->layout,
&other_logical_monitor_config->layout))
if (mtk_rectangle_is_adjacent_to (&logical_monitor_config->layout,
&other_logical_monitor_config->layout))
return TRUE;
}

View file

@ -237,10 +237,6 @@ GList* meta_rectangle_find_nonintersected_monitor_edges (
const GList *monitor_rects,
const GSList *all_struts);
META_EXPORT_TEST
gboolean meta_rectangle_is_adjacent_to (MtkRectangle *rect,
MtkRectangle *other);
META_EXPORT_TEST
void meta_rectangle_transform (const MtkRectangle *rect,
MetaMonitorTransform transform,

View file

@ -703,7 +703,7 @@ meta_rectangle_is_adjacent_to_any_in_region (const GList *spanning_rects,
if (rect == other || mtk_rectangle_equal (rect, other))
continue;
if (meta_rectangle_is_adjacent_to (rect, other))
if (mtk_rectangle_is_adjacent_to (rect, other))
return TRUE;
}
@ -1826,29 +1826,6 @@ meta_rectangle_find_nonintersected_monitor_edges (
return ret;
}
gboolean
meta_rectangle_is_adjacent_to (MtkRectangle *rect,
MtkRectangle *other)
{
int rect_x1 = rect->x;
int rect_y1 = rect->y;
int rect_x2 = rect->x + rect->width;
int rect_y2 = rect->y + rect->height;
int other_x1 = other->x;
int other_y1 = other->y;
int other_x2 = other->x + other->width;
int other_y2 = other->y + other->height;
if ((rect_x1 == other_x2 || rect_x2 == other_x1) &&
!(rect_y2 <= other_y1 || rect_y1 >= other_y2))
return TRUE;
else if ((rect_y1 == other_y2 || rect_y2 == other_y1) &&
!(rect_x2 <= other_x1 || rect_x1 >= other_x2))
return TRUE;
else
return FALSE;
}
/**
* meta_rectangle_transform:
* @rect: the #MtkRectangle to be transformed

View file

@ -170,6 +170,36 @@ test_basic_fitting (void)
g_assert (!mtk_rectangle_could_fit_rect (&temp3, &temp2));
}
static void
test_adjacent_to (void)
{
MtkRectangle base = { .x = 10, .y = 10, .width = 10, .height = 10 };
MtkRectangle adjacent[] = {
{ .x = 20, .y = 10, .width = 10, .height = 10 },
{ .x = 0, .y = 10, .width = 10, .height = 10 },
{ .x = 0, .y = 1, .width = 10, .height = 10 },
{ .x = 20, .y = 19, .width = 10, .height = 10 },
{ .x = 10, .y = 20, .width = 10, .height = 10 },
{ .x = 10, .y = 0, .width = 10, .height = 10 },
};
MtkRectangle not_adjacent[] = {
{ .x = 0, .y = 0, .width = 10, .height = 10 },
{ .x = 20, .y = 20, .width = 10, .height = 10 },
{ .x = 21, .y = 10, .width = 10, .height = 10 },
{ .x = 10, .y = 21, .width = 10, .height = 10 },
{ .x = 10, .y = 5, .width = 10, .height = 10 },
{ .x = 11, .y = 10, .width = 10, .height = 10 },
{ .x = 19, .y = 10, .width = 10, .height = 10 },
};
unsigned int i;
for (i = 0; i < G_N_ELEMENTS (adjacent); i++)
g_assert (mtk_rectangle_is_adjacent_to (&base, &adjacent[i]));
for (i = 0; i < G_N_ELEMENTS (not_adjacent); i++)
g_assert (!mtk_rectangle_is_adjacent_to (&base, &not_adjacent[i]));
}
int
main (int argc,
char **argv)
@ -184,6 +214,7 @@ main (int argc,
g_test_add_func ("/mtk/rectangle/equal", test_equal);
g_test_add_func ("/mtk/rectangle/overlap", test_overlap_funcs);
g_test_add_func ("/mtk/rectangle/basic-fitting", test_basic_fitting);
g_test_add_func ("/mtk/rectangle/adjacent-to", test_adjacent_to);
return g_test_run ();
}

View file

@ -200,36 +200,6 @@ meta_test_util_later_schedule_from_later (void)
g_assert_cmpint (data.state, ==, META_TEST_LATER_FINISHED);
}
static void
meta_test_adjacent_to (void)
{
MtkRectangle base = { .x = 10, .y = 10, .width = 10, .height = 10 };
MtkRectangle adjacent[] = {
{ .x = 20, .y = 10, .width = 10, .height = 10 },
{ .x = 0, .y = 10, .width = 10, .height = 10 },
{ .x = 0, .y = 1, .width = 10, .height = 10 },
{ .x = 20, .y = 19, .width = 10, .height = 10 },
{ .x = 10, .y = 20, .width = 10, .height = 10 },
{ .x = 10, .y = 0, .width = 10, .height = 10 },
};
MtkRectangle not_adjacent[] = {
{ .x = 0, .y = 0, .width = 10, .height = 10 },
{ .x = 20, .y = 20, .width = 10, .height = 10 },
{ .x = 21, .y = 10, .width = 10, .height = 10 },
{ .x = 10, .y = 21, .width = 10, .height = 10 },
{ .x = 10, .y = 5, .width = 10, .height = 10 },
{ .x = 11, .y = 10, .width = 10, .height = 10 },
{ .x = 19, .y = 10, .width = 10, .height = 10 },
};
unsigned int i;
for (i = 0; i < G_N_ELEMENTS (adjacent); i++)
g_assert (meta_rectangle_is_adjacent_to (&base, &adjacent[i]));
for (i = 0; i < G_N_ELEMENTS (not_adjacent); i++)
g_assert (!meta_rectangle_is_adjacent_to (&base, &not_adjacent[i]));
}
static void
init_tests (void)
{
@ -237,8 +207,6 @@ init_tests (void)
g_test_add_func ("/util/meta-later/schedule-from-later",
meta_test_util_later_schedule_from_later);
g_test_add_func ("/core/boxes/adjacent-to", meta_test_adjacent_to);
init_monitor_store_tests ();
init_monitor_config_migration_tests ();
init_boxes_tests ();

View file

@ -1359,7 +1359,7 @@ meta_wayland_xdg_popup_post_apply_state (MetaWaylandSurfaceRole *surface_role,
meta_window_get_buffer_rect (window, &buffer_rect);
meta_window_get_buffer_rect (parent_window, &parent_buffer_rect);
if (!mtk_rectangle_overlap (&buffer_rect, &parent_buffer_rect) &&
!meta_rectangle_is_adjacent_to (&buffer_rect, &parent_buffer_rect))
!mtk_rectangle_is_adjacent_to (&buffer_rect, &parent_buffer_rect))
{
g_warning ("Buggy client caused popup to be placed outside of "
"parent window");