mtk: Move Rectangle.[contains|could_fit]_rect from Meta

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3128>
This commit is contained in:
Bilal Elmoussaoui 2023-07-20 01:02:07 +02:00
parent eafe07de31
commit aec8e50df8
8 changed files with 65 additions and 54 deletions

View File

@ -243,3 +243,36 @@ mtk_rectangle_horiz_overlap (const MtkRectangle *rect1,
return (rect1->x < rect2->x + rect2->width &&
rect2->x < rect1->x + rect1->width);
}
/**
* mtk_rectangle_could_fit_rect:
* @outer_rect: The outer rectangle
* @inner_rect: The inner rectangle
*
* Returns: Whether the inner rectangle could fit inside the outer one
*/
gboolean
mtk_rectangle_could_fit_rect (const MtkRectangle *outer_rect,
const MtkRectangle *inner_rect)
{
return (outer_rect->width >= inner_rect->width &&
outer_rect->height >= inner_rect->height);
}
/**
* mtk_rectangle_contains_rect:
* @outer_rect: The outer rectangle
* @inner_rect: The inner rectangle
*
* Returns: Whether the outer rectangle contains the inner one
*/
gboolean
mtk_rectangle_contains_rect (const MtkRectangle *outer_rect,
const MtkRectangle *inner_rect)
{
return
inner_rect->x >= outer_rect->x &&
inner_rect->y >= outer_rect->y &&
inner_rect->x + inner_rect->width <= outer_rect->x + outer_rect->width &&
inner_rect->y + inner_rect->height <= outer_rect->y + outer_rect->height;
}

View File

@ -110,3 +110,11 @@ MTK_EXPORT
gboolean mtk_rectangle_horiz_overlap (const MtkRectangle *rect1,
const MtkRectangle *rect2);
MTK_EXPORT
gboolean mtk_rectangle_could_fit_rect (const MtkRectangle *outer_rect,
const MtkRectangle *inner_rect);
MTK_EXPORT
gboolean mtk_rectangle_contains_rect (const MtkRectangle *outer_rect,
const MtkRectangle *inner_rect);

View File

@ -134,25 +134,6 @@ meta_rectangle_edge_list_to_string (GList *edge_list,
return output;
}
gboolean
meta_rectangle_could_fit_rect (const MetaRectangle *outer_rect,
const MetaRectangle *inner_rect)
{
return (outer_rect->width >= inner_rect->width &&
outer_rect->height >= inner_rect->height);
}
gboolean
meta_rectangle_contains_rect (const MetaRectangle *outer_rect,
const MetaRectangle *inner_rect)
{
return
inner_rect->x >= outer_rect->x &&
inner_rect->y >= outer_rect->y &&
inner_rect->x + inner_rect->width <= outer_rect->x + outer_rect->width &&
inner_rect->y + inner_rect->height <= outer_rect->y + outer_rect->height;
}
void
meta_rectangle_resize_with_gravity (const MetaRectangle *old_rect,
MetaRectangle *rect,
@ -283,12 +264,12 @@ merge_spanning_rects_in_region (GList *region)
g_assert (b->width > 0 && b->height > 0);
/* If a contains b, just remove b */
if (meta_rectangle_contains_rect (a, b))
if (mtk_rectangle_contains_rect (a, b))
{
delete_me = other;
}
/* If b contains a, just remove a */
else if (meta_rectangle_contains_rect (b, a))
else if (mtk_rectangle_contains_rect (b, a))
{
delete_me = compare;
}
@ -685,7 +666,7 @@ meta_rectangle_could_fit_in_region (const GList *spanning_rects,
could_fit = FALSE;
while (!could_fit && temp != NULL)
{
could_fit = could_fit || meta_rectangle_could_fit_rect (temp->data, rect);
could_fit = could_fit || mtk_rectangle_could_fit_rect (temp->data, rect);
temp = temp->next;
}
@ -703,7 +684,7 @@ meta_rectangle_contained_in_region (const GList *spanning_rects,
contained = FALSE;
while (!contained && temp != NULL)
{
contained = contained || meta_rectangle_contains_rect (temp->data, rect);
contained = contained || mtk_rectangle_contains_rect (temp->data, rect);
temp = temp->next;
}

View File

@ -1345,8 +1345,8 @@ constrain_fullscreen (MetaWindow *window,
monitor = info->entire_monitor;
get_size_limits (window, &min_size, &max_size);
too_big = !meta_rectangle_could_fit_rect (&monitor, &min_size);
too_small = !meta_rectangle_could_fit_rect (&max_size, &monitor);
too_big = !mtk_rectangle_could_fit_rect (&monitor, &min_size);
too_small = !mtk_rectangle_could_fit_rect (&max_size, &monitor);
if (too_big || too_small)
return TRUE;
@ -1464,14 +1464,14 @@ constrain_size_limits (MetaWindow *window,
max_size.width = MAX (max_size.width, info->current.width);
if (window->maximized_vertically)
max_size.height = MAX (max_size.height, info->current.height);
too_small = !meta_rectangle_could_fit_rect (&info->current, &min_size);
too_big = !meta_rectangle_could_fit_rect (&max_size, &info->current);
too_small = !mtk_rectangle_could_fit_rect (&info->current, &min_size);
too_big = !mtk_rectangle_could_fit_rect (&max_size, &info->current);
constraint_already_satisfied = !too_big && !too_small;
if (check_only || constraint_already_satisfied)
return constraint_already_satisfied;
/*** Enforce constraint ***/
new_width = CLAMP (info->current.width, min_size.width, max_size.width);
new_width = CLAMP (info->current.width, min_size.width, max_size.width);
new_height = CLAMP (info->current.height, min_size.height, max_size.height);
start_rect = get_start_rect_for_resize (window, info);

View File

@ -606,7 +606,7 @@ find_first_fit (MetaWindow *window,
center_tile_rect_in_area (&rect, &work_area);
if (meta_rectangle_contains_rect (&work_area, &rect) &&
if (mtk_rectangle_contains_rect (&work_area, &rect) &&
!rectangle_overlaps_some_window (&rect, windows))
{
*new_x = rect.x;
@ -629,7 +629,7 @@ find_first_fit (MetaWindow *window,
rect.x = frame_rect.x;
rect.y = frame_rect.y + frame_rect.height;
if (meta_rectangle_contains_rect (&work_area, &rect) &&
if (mtk_rectangle_contains_rect (&work_area, &rect) &&
!rectangle_overlaps_some_window (&rect, below_sorted))
{
*new_x = rect.x;
@ -658,7 +658,7 @@ find_first_fit (MetaWindow *window,
rect.x = frame_rect.x - rect.width;
rect.y = frame_rect.y;
if (meta_rectangle_contains_rect (&work_area, &rect) &&
if (mtk_rectangle_contains_rect (&work_area, &rect) &&
!rectangle_overlaps_some_window (&rect, end_sorted))
{
*new_x = rect.x;

View File

@ -4012,7 +4012,7 @@ meta_window_move_between_rects (MetaWindow *window,
new_x = new_area->x;
new_y = new_area->y;
}
else if (meta_rectangle_contains_rect (old_area, &window->unconstrained_rect) &&
else if (mtk_rectangle_contains_rect (old_area, &window->unconstrained_rect) &&
old_area->width > window->unconstrained_rect.width &&
old_area->height > window->unconstrained_rect.height &&
new_area->width >= window->unconstrained_rect.width &&

View File

@ -100,14 +100,3 @@ MetaRectangle *meta_rectangle_copy (const MetaRectangle *rect);
META_EXPORT
void meta_rectangle_free (MetaRectangle *rect);
/* could_fit_rect determines whether "outer_rect" is big enough to contain
* inner_rect. contains_rect checks whether it actually contains it.
*/
META_EXPORT
gboolean meta_rectangle_could_fit_rect (const MetaRectangle *outer_rect,
const MetaRectangle *inner_rect);
META_EXPORT
gboolean meta_rectangle_contains_rect (const MetaRectangle *outer_rect,
const MetaRectangle *inner_rect);

View File

@ -201,20 +201,20 @@ test_basic_fitting (void)
{
get_random_rect (&temp1);
get_random_rect (&temp2);
g_assert (meta_rectangle_contains_rect (&temp1, &temp2) == FALSE ||
meta_rectangle_could_fit_rect (&temp1, &temp2) == TRUE);
g_assert (meta_rectangle_contains_rect (&temp2, &temp1) == FALSE ||
meta_rectangle_could_fit_rect (&temp2, &temp1) == TRUE);
g_assert (mtk_rectangle_contains_rect (&temp1, &temp2) == FALSE ||
mtk_rectangle_could_fit_rect (&temp1, &temp2) == TRUE);
g_assert (mtk_rectangle_contains_rect (&temp2, &temp1) == FALSE ||
mtk_rectangle_could_fit_rect (&temp2, &temp1) == TRUE);
}
temp1 = MTK_RECTANGLE_INIT ( 0, 0, 10, 10);
temp2 = MTK_RECTANGLE_INIT ( 5, 5, 5, 5);
temp3 = MTK_RECTANGLE_INIT ( 8, 2, 3, 7);
g_assert ( meta_rectangle_contains_rect (&temp1, &temp2));
g_assert (!meta_rectangle_contains_rect (&temp2, &temp1));
g_assert (!meta_rectangle_contains_rect (&temp1, &temp3));
g_assert ( meta_rectangle_could_fit_rect (&temp1, &temp3));
g_assert (!meta_rectangle_could_fit_rect (&temp3, &temp2));
g_assert ( mtk_rectangle_contains_rect (&temp1, &temp2));
g_assert (!mtk_rectangle_contains_rect (&temp2, &temp1));
g_assert (!mtk_rectangle_contains_rect (&temp1, &temp3));
g_assert ( mtk_rectangle_could_fit_rect (&temp1, &temp3));
g_assert (!mtk_rectangle_could_fit_rect (&temp3, &temp2));
}
static void
@ -401,14 +401,14 @@ test_merge_regions (void)
#endif
/* If a contains b, just remove b */
if (meta_rectangle_contains_rect (a, b))
if (mtk_rectangle_contains_rect (a, b))
{
delete_me = other;
num_contains++;
num_merged++;
}
/* If b contains a, just remove a */
else if (meta_rectangle_contains_rect (a, b))
else if (mtk_rectangle_contains_rect (a, b))
{
delete_me = compare;
num_contains++;