1
0
Fork 0

mtk: Move Rectangle.equal from Meta

Moves equal the equal function and removes the clutter equivalent. The
tests were not moved until all the remaining helper functions are moved.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3128>
This commit is contained in:
Bilal Elmoussaoui 2023-07-19 17:14:13 +02:00
parent 918ae0f4d4
commit 9b2cba4e86
23 changed files with 87 additions and 91 deletions

View file

@ -222,9 +222,6 @@ gboolean _clutter_util_rectangle_intersection (const MtkRectangle *src1,
const MtkRectangle *src2,
MtkRectangle *dest);
gboolean clutter_util_rectangle_equal (const MtkRectangle *src1,
const MtkRectangle *src2);
CLUTTER_EXPORT
PangoDirection _clutter_pango_unichar_direction (gunichar ch);

View file

@ -943,7 +943,7 @@ maybe_mark_full_redraw (ClutterStageView *view,
MtkRectangle region_extents;
cairo_region_get_extents (*region, &region_extents);
if (clutter_util_rectangle_equal (&priv->layout, &region_extents))
if (mtk_rectangle_equal (&priv->layout, &region_extents))
g_clear_pointer (region, cairo_region_destroy);
}
}
@ -970,7 +970,7 @@ clutter_stage_view_add_redraw_clip (ClutterStageView *view,
if (!priv->redraw_clip)
{
if (!clutter_util_rectangle_equal (&priv->layout, clip))
if (!mtk_rectangle_equal (&priv->layout, clip))
priv->redraw_clip = cairo_region_create_rectangle (clip);
}
else

View file

@ -227,16 +227,6 @@ _clutter_util_rectangle_intersection (const MtkRectangle *src1,
}
}
gboolean
clutter_util_rectangle_equal (const MtkRectangle *src1,
const MtkRectangle *src2)
{
return ((src1->x == src2->x) &&
(src1->y == src2->y) &&
(src1->width == src2->width) &&
(src1->height == src2->height));
}
typedef struct
{
GType value_type;

View file

@ -36,3 +36,22 @@ mtk_rectangle_free (MtkRectangle *rect)
G_DEFINE_BOXED_TYPE (MtkRectangle, mtk_rectangle,
mtk_rectangle_copy, mtk_rectangle_free);
/**
* mtk_rectangle_equal:
* @src1: The first rectangle
* @src2: The second rectangle
*
* Compares the two rectangles
*
* Returns: Whether the two rectangles are equal
*/
gboolean
mtk_rectangle_equal (const MtkRectangle *src1,
const MtkRectangle *src2)
{
return ((src1->x == src2->x) &&
(src1->y == src2->y) &&
(src1->width == src2->width) &&
(src1->height == src2->height));
}

View file

@ -64,3 +64,7 @@ MtkRectangle * mtk_rectangle_copy (const MtkRectangle *rect);
MTK_EXPORT
void mtk_rectangle_free (MtkRectangle *rect);
MTK_EXPORT
gboolean mtk_rectangle_equal (const MtkRectangle *src1,
const MtkRectangle *src2);

View file

@ -925,7 +925,7 @@ ensure_logical_monitor (GList **logical_monitor_configs,
{
MetaLogicalMonitorConfig *logical_monitor_config = l->data;
if (meta_rectangle_equal (&logical_monitor_config->layout, layout))
if (mtk_rectangle_equal (&logical_monitor_config->layout, layout))
return logical_monitor_config;
}

View file

@ -177,7 +177,7 @@ logical_monitor_from_layout (MetaMonitorManager *manager,
{
MetaLogicalMonitor *logical_monitor = l->data;
if (meta_rectangle_equal (layout, &logical_monitor->rect))
if (mtk_rectangle_equal (layout, &logical_monitor->rect))
return logical_monitor;
}
@ -326,7 +326,7 @@ derive_scale_from_config (MetaMonitorManager *manager,
{
MetaLogicalMonitorConfig *logical_monitor_config = l->data;
if (meta_rectangle_equal (layout, &logical_monitor_config->layout))
if (mtk_rectangle_equal (layout, &logical_monitor_config->layout))
return logical_monitor_config->scale;
}

View file

@ -56,8 +56,8 @@ update_monitor (MetaScreenCastMonitorStream *monitor_stream,
if (!new_logical_monitor)
return FALSE;
if (!meta_rectangle_equal (&new_logical_monitor->rect,
&monitor_stream->logical_monitor->rect))
if (!mtk_rectangle_equal (&new_logical_monitor->rect,
&monitor_stream->logical_monitor->rect))
return FALSE;
g_set_object (&monitor_stream->monitor, new_monitor);

View file

@ -215,7 +215,7 @@ meta_kms_crtc_state_changes (MetaKmsCrtcState *state,
if (state->is_active != other_state->is_active)
return META_KMS_RESOURCE_CHANGE_FULL;
if (!meta_rectangle_equal (&state->rect, &other_state->rect))
if (!mtk_rectangle_equal (&state->rect, &other_state->rect))
return META_KMS_RESOURCE_CHANGE_FULL;
if (state->is_drm_mode_valid != other_state->is_drm_mode_valid)

View file

@ -465,8 +465,8 @@ apply_edge_resistance_to_each_side (MetaEdgeResistanceData *edge_data,
MetaEdgeResistanceFlags flags,
gboolean is_resize)
{
MetaRectangle modified_rect;
gboolean modified;
MetaRectangle modified_rect;
gboolean modified;
int new_left, new_right, new_top, new_bottom;
gboolean auto_snap, keyboard_op;
@ -621,7 +621,7 @@ apply_edge_resistance_to_each_side (MetaEdgeResistanceData *edge_data,
new_top,
new_right - new_left,
new_bottom - new_top);
modified = !meta_rectangle_equal (new_outer, &modified_rect);
modified = !mtk_rectangle_equal (new_outer, &modified_rect);
*new_outer = modified_rect;
return modified;
}

View file

@ -1255,11 +1255,11 @@ meta_shaped_texture_is_opaque (MetaShapedTexture *stex)
meta_shaped_texture_ensure_size_valid (stex);
return meta_rectangle_equal (&opaque_rect,
&(MetaRectangle) {
.width = stex->dst_width,
.height = stex->dst_height
});
return mtk_rectangle_equal (&opaque_rect,
&(MetaRectangle) {
.width = stex->dst_width,
.height = stex->dst_height
});
}
void

View file

@ -4,7 +4,7 @@
* Copyright (C) 2005, 2006 Elijah Newren
* [meta_rectangle_intersect() is copyright the GTK+ Team according to Havoc,
* see gdkrectangle.c. As far as Havoc knows, he probably wrote
* meta_rectangle_equal(), and I'm guessing it's (C) Red Hat. So...]
* mtk_rectangle_equal(), and I'm guessing it's (C) Red Hat. So...]
* Copyright (C) 1995-2000 GTK+ Team
* Copyright (C) 2002 Red Hat, Inc.
*
@ -200,16 +200,6 @@ meta_rectangle_intersect (const MetaRectangle *src1,
return return_val;
}
gboolean
meta_rectangle_equal (const MetaRectangle *src1,
const MetaRectangle *src2)
{
return ((src1->x == src2->x) &&
(src1->y == src2->y) &&
(src1->width == src2->width) &&
(src1->height == src2->height));
}
/**
* meta_rectangle_union:
* @rect1: a #MetaRectangle
@ -884,7 +874,7 @@ meta_rectangle_is_adjacent_to_any_in_region (const GList *spanning_rects,
{
MetaRectangle *other = (MetaRectangle *) l->data;
if (rect == other || meta_rectangle_equal (rect, other))
if (rect == other || mtk_rectangle_equal (rect, other))
continue;
if (meta_rectangle_is_adjacent_to (rect, other))

View file

@ -969,8 +969,8 @@ constrain_custom_rule (MetaWindow *window,
meta_rectangle_intersect (&adjusted_unconstrained, &info->work_area_monitor,
&intersection);
constraint_satisfied = (meta_rectangle_equal (&info->current,
&adjusted_unconstrained) &&
constraint_satisfied = (mtk_rectangle_equal (&info->current,
&adjusted_unconstrained) &&
is_custom_rule_satisfied (&adjusted_unconstrained,
placement_rule,
&intersection));
@ -1352,7 +1352,7 @@ constrain_fullscreen (MetaWindow *window,
/* Determine whether constraint is already satisfied; exit if it is */
constraint_already_satisfied =
meta_rectangle_equal (&info->current, &monitor);
mtk_rectangle_equal (&info->current, &monitor);
if (check_only || constraint_already_satisfied)
return constraint_already_satisfied;

View file

@ -2813,7 +2813,7 @@ meta_window_is_monitor_sized (MetaWindow *window)
meta_window_get_frame_rect (window, &window_rect);
meta_display_get_monitor_geometry (window->display, window->monitor->number, &monitor_rect);
if (meta_rectangle_equal (&window_rect, &monitor_rect))
if (mtk_rectangle_equal (&window_rect, &monitor_rect))
return TRUE;
}

View file

@ -1032,7 +1032,7 @@ strut_lists_equal (GSList *l,
MetaStrut *b = m->data;
if (a->side != b->side ||
!meta_rectangle_equal (&a->rect, &b->rect))
!mtk_rectangle_equal (&a->rect, &b->rect))
return FALSE;
}

View file

@ -122,10 +122,6 @@ gboolean meta_rectangle_intersect (const MetaRectangle *src1,
const MetaRectangle *src2,
MetaRectangle *dest);
META_EXPORT
gboolean meta_rectangle_equal (const MetaRectangle *src1,
const MetaRectangle *src2);
/* Find the bounding box of the union of two rectangles */
META_EXPORT
void meta_rectangle_union (const MetaRectangle *rect1,

View file

@ -143,7 +143,7 @@ test_intersect (void)
meta_rectangle_intersect (&a, &b, &temp);
temp2 = meta_rect (100, 200, 10, 2);
g_assert (meta_rectangle_equal (&temp, &temp2));
g_assert (mtk_rectangle_equal (&temp, &temp2));
g_assert (meta_rectangle_area (&temp) == 20);
meta_rectangle_intersect (&a, &c, &temp);
@ -153,7 +153,7 @@ test_intersect (void)
g_assert (meta_rectangle_area (&temp) == 0);
meta_rectangle_intersect (&b, &d, &b);
g_assert (meta_rectangle_equal (&b, &b_intersect_d));
g_assert (mtk_rectangle_equal (&b, &b_intersect_d));
}
static void
@ -166,11 +166,11 @@ test_equal (void)
MetaRectangle e = {10, 62, 4, 18};
MetaRectangle f = {27, 12, 4, 18};
g_assert ( meta_rectangle_equal (&a, &b));
g_assert (!meta_rectangle_equal (&a, &c));
g_assert (!meta_rectangle_equal (&a, &d));
g_assert (!meta_rectangle_equal (&a, &e));
g_assert (!meta_rectangle_equal (&a, &f));
g_assert ( mtk_rectangle_equal (&a, &b));
g_assert (!mtk_rectangle_equal (&a, &c));
g_assert (!mtk_rectangle_equal (&a, &d));
g_assert (!mtk_rectangle_equal (&a, &e));
g_assert (!mtk_rectangle_equal (&a, &f));
}
static void
@ -855,35 +855,35 @@ test_clipping_to_region (void)
meta_rectangle_clip_to_region (region,
fixed_directions,
&rect);
g_assert (meta_rectangle_equal (region->data, &rect));
g_assert (mtk_rectangle_equal (region->data, &rect));
rect = meta_rect (300, 1000, 400, 200);
temp = meta_rect (300, 1000, 400, 150);
meta_rectangle_clip_to_region (region,
fixed_directions,
&rect);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
rect = meta_rect (400, 1000, 300, 200);
temp = meta_rect (450, 1000, 250, 200);
meta_rectangle_clip_to_region (region,
fixed_directions,
&rect);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
rect = meta_rect (400, 1000, 300, 200);
temp = meta_rect (400, 1000, 300, 150);
meta_rectangle_clip_to_region (region,
FIXED_DIRECTION_X,
&rect);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
rect = meta_rect (400, 1000, 300, 200);
temp = meta_rect (400, 1000, 300, 150);
meta_rectangle_clip_to_region (region,
FIXED_DIRECTION_X,
&rect);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
meta_rectangle_free_list_and_elements (region);
}
@ -916,42 +916,42 @@ test_shoving_into_region (void)
meta_rectangle_shove_into_region (region,
fixed_directions,
&rect);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
rect = meta_rect (425, 1000, 300, 200);
temp = meta_rect (450, 1000, 300, 200);
meta_rectangle_shove_into_region (region,
fixed_directions,
&rect);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
rect = meta_rect (425, 1000, 300, 200);
temp = meta_rect (425, 950, 300, 200);
meta_rectangle_shove_into_region (region,
FIXED_DIRECTION_X,
&rect);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
rect = meta_rect ( 300, 1000, 400, 200);
temp = meta_rect (1200, 1000, 400, 200);
meta_rectangle_shove_into_region (region,
FIXED_DIRECTION_Y,
&rect);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
rect = meta_rect ( 800, 1150, 400, 50); /* Completely "offscreen" :) */
temp = meta_rect ( 800, 1050, 400, 50);
meta_rectangle_shove_into_region (region,
0,
&rect);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
rect = meta_rect (-1000, 0, 400, 150); /* Offscreen in 2 directions */
temp = meta_rect ( 0, 20, 400, 150);
meta_rectangle_shove_into_region (region,
0,
&rect);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
meta_rectangle_free_list_and_elements (region);
}
@ -966,7 +966,7 @@ verify_edge_lists_are_equal (GList *code, GList *answer)
MetaEdge *a = code->data;
MetaEdge *b = answer->data;
if (!meta_rectangle_equal (&a->rect, &b->rect) ||
if (!mtk_rectangle_equal (&a->rect, &b->rect) ||
a->side_type != b->side_type ||
a->edge_type != b->edge_type)
{
@ -1236,7 +1236,7 @@ test_gravity_resize (void)
META_GRAVITY_NORTH_WEST,
20,
5);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
rect = meta_rect ( 50, 300, 250, 400);
temp = meta_rect (165, 300, 20, 5);
@ -1245,7 +1245,7 @@ test_gravity_resize (void)
META_GRAVITY_NORTH,
20,
5);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
rect = meta_rect ( 50, 300, 250, 400);
temp = meta_rect (280, 300, 20, 5);
@ -1254,7 +1254,7 @@ test_gravity_resize (void)
META_GRAVITY_NORTH_EAST,
20,
5);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
rect = meta_rect ( 50, 300, 250, 400);
temp = meta_rect ( 50, 695, 50, 5);
@ -1263,7 +1263,7 @@ test_gravity_resize (void)
META_GRAVITY_SOUTH_WEST,
50,
5);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
rect = meta_rect ( 50, 300, 250, 400);
temp = meta_rect (150, 695, 50, 5);
@ -1272,7 +1272,7 @@ test_gravity_resize (void)
META_GRAVITY_SOUTH,
50,
5);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
rect = meta_rect ( 50, 300, 250, 400);
temp = meta_rect (250, 695, 50, 5);
@ -1281,7 +1281,7 @@ test_gravity_resize (void)
META_GRAVITY_SOUTH_EAST,
50,
5);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
rect = meta_rect (167, 738, 237, 843);
temp = meta_rect (167, 1113, 832, 93);
@ -1290,7 +1290,7 @@ test_gravity_resize (void)
META_GRAVITY_WEST,
832,
93);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
rect = meta_rect ( 167, 738, 237, 843);
temp = meta_rect (-131, 1113, 833, 93);
@ -1299,7 +1299,7 @@ test_gravity_resize (void)
META_GRAVITY_CENTER,
832,
93);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
rect = meta_rect (300, 1000, 400, 200);
temp = meta_rect (270, 994, 430, 212);
@ -1308,7 +1308,7 @@ test_gravity_resize (void)
META_GRAVITY_EAST,
430,
211);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
rect = meta_rect (300, 1000, 400, 200);
temp = meta_rect (300, 1000, 430, 211);
@ -1317,7 +1317,7 @@ test_gravity_resize (void)
META_GRAVITY_STATIC,
430,
211);
g_assert (meta_rectangle_equal (&rect, &temp));
g_assert (mtk_rectangle_equal (&rect, &temp));
}
#define EPSILON 0.000000001

View file

@ -216,7 +216,7 @@ logical_monitor_from_layout (MetaMonitorManager *monitor_manager,
{
MetaLogicalMonitor *logical_monitor = l->data;
if (meta_rectangle_equal (layout, &logical_monitor->rect))
if (mtk_rectangle_equal (layout, &logical_monitor->rect))
return logical_monitor;
}

View file

@ -142,8 +142,8 @@ check_monitor_store_configuration (MetaMonitorConfigStore *config_store,
GList *k;
int j;
g_assert (meta_rectangle_equal (&logical_monitor_config->layout,
&config_expect->logical_monitors[i].layout));
g_assert (mtk_rectangle_equal (&logical_monitor_config->layout,
&config_expect->logical_monitors[i].layout));
g_assert_cmpfloat (logical_monitor_config->scale,
==,
config_expect->logical_monitors[i].scale);

View file

@ -100,7 +100,7 @@ assert_crtc_state_equals (const MetaKmsCrtcState *crtc_state1,
const MetaKmsCrtcState *crtc_state2)
{
g_assert_cmpint (crtc_state1->is_active, ==, crtc_state2->is_active);
g_assert (meta_rectangle_equal (&crtc_state1->rect, &crtc_state2->rect));
g_assert (mtk_rectangle_equal (&crtc_state1->rect, &crtc_state2->rect));
g_assert_cmpint (crtc_state1->is_drm_mode_valid,
==,
crtc_state2->is_drm_mode_valid);
@ -297,7 +297,7 @@ meta_test_kms_device_mode_set (void)
g_assert_true (crtc_state.is_active);
g_assert_true (crtc_state.is_drm_mode_valid);
mode_rect = meta_get_mode_rect (mode);
g_assert (meta_rectangle_equal (&crtc_state.rect, &mode_rect));
g_assert (mtk_rectangle_equal (&crtc_state.rect, &mode_rect));
g_assert_nonnull (meta_kms_connector_get_current_state (connector));
connector_state =

View file

@ -907,7 +907,7 @@ meta_wayland_xdg_toplevel_post_apply_state (MetaWaylandSurfaceRole *surface_rol
surface_role_class->post_apply_state (surface_role, pending);
window_geometry = meta_wayland_xdg_surface_get_window_geometry (xdg_surface);
geometry_changed = !meta_rectangle_equal (&old_geometry, &window_geometry);
geometry_changed = !mtk_rectangle_equal (&old_geometry, &window_geometry);
if (geometry_changed ||
pending->derived.surface_size_changed ||
@ -1350,7 +1350,7 @@ meta_wayland_xdg_popup_post_apply_state (MetaWaylandSurfaceRole *surface_role,
window_geometry = meta_wayland_xdg_surface_get_window_geometry (xdg_surface);
old_geometry = xdg_surface_priv->geometry;
if (!meta_rectangle_equal (&old_geometry, &window_geometry) ||
if (!mtk_rectangle_equal (&old_geometry, &window_geometry) ||
pending->derived.surface_size_changed ||
pending->has_acked_configure_serial)
meta_window_wayland_finish_move_resize (window, window_geometry, pending);
@ -1805,7 +1805,7 @@ meta_wayland_xdg_surface_post_apply_state (MetaWaylandSurfaceRole *surface_role
meta_wayland_shell_surface_calculate_geometry (shell_surface,
&new_geometry);
if (!meta_rectangle_equal (&new_geometry, &priv->geometry))
if (!mtk_rectangle_equal (&new_geometry, &priv->geometry))
{
pending->has_new_geometry = TRUE;
priv->geometry = new_geometry;

View file

@ -1247,7 +1247,7 @@ meta_xwayland_set_primary_output (MetaX11Display *x11_display)
XRRFreeCrtcInfo (crtc_info);
if (meta_rectangle_equal (&crtc_geometry, &primary_monitor->rect))
if (mtk_rectangle_equal (&crtc_geometry, &primary_monitor->rect))
{
XRRSetOutputPrimary (xdisplay, DefaultRootWindow (xdisplay),
output_id);

View file

@ -1694,7 +1694,7 @@ meta_window_x11_update_struts (MetaWindow *window)
MetaStrut *new_strut = (MetaStrut*) new_iter->data;
if (old_strut->side != new_strut->side ||
!meta_rectangle_equal (&old_strut->rect, &new_strut->rect))
!mtk_rectangle_equal (&old_strut->rect, &new_strut->rect))
break;
old_iter = old_iter->next;
@ -2797,7 +2797,7 @@ meta_window_move_resize_request (MetaWindow *window,
*/
if (meta_prefs_get_force_fullscreen() &&
(window->decorated || !meta_window_is_client_decorated (window)) &&
meta_rectangle_equal (&rect, &monitor_rect) &&
mtk_rectangle_equal (&rect, &monitor_rect) &&
window->has_fullscreen_func &&
!window->fullscreen)
{
@ -4266,7 +4266,7 @@ meta_window_x11_can_unredirect (MetaWindowX11 *window_x11)
logical_monitor_layout =
meta_logical_monitor_get_layout (logical_monitor);
if (meta_rectangle_equal (&window_rect, &logical_monitor_layout))
if (mtk_rectangle_equal (&window_rect, &logical_monitor_layout))
return TRUE;
}