From c0537096c242d120b9625f7fc57bb6526e6f38ad Mon Sep 17 00:00:00 2001 From: Sebastian Keller Date: Fri, 10 May 2024 20:36:37 +0200 Subject: [PATCH] pointer-constraints/native: Consider origin when checking constraints Since 07d24fe50 regions are not translated to their on-screen coordinates anymore, but are relative to the origin stored in the constraint. This origin however was not considered when checking whether the pointer was within the constraint region. This meant that the constraint region would appear to always be placed at 0,0 instead of on the surface. Fix this by using the cursor position relative to the origin. Fixes: 07d24fe50 ("backends/native: Allow infinitely small pointer constraint regions") Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/3409 Part-of: --- .../native/meta-pointer-constraint-native.c | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/backends/native/meta-pointer-constraint-native.c b/src/backends/native/meta-pointer-constraint-native.c index 94ad24379..e3bbdd739 100644 --- a/src/backends/native/meta-pointer-constraint-native.c +++ b/src/backends/native/meta-pointer-constraint-native.c @@ -496,12 +496,12 @@ meta_pointer_constraint_impl_native_constraint (MetaPointerConstraintImpl *const motion = (MetaLine2) { .a = (MetaVector2) { - .x = prev_x, - .y = prev_y, + .x = prev_x - constraint_impl_native->origin.x, + .y = prev_y - constraint_impl_native->origin.y, }, .b = (MetaVector2) { - .x = x, - .y = y, + .x = x - constraint_impl_native->origin.x, + .y = y - constraint_impl_native->origin.y, }, }; directions = get_motion_directions (&motion); @@ -522,8 +522,8 @@ meta_pointer_constraint_impl_native_constraint (MetaPointerConstraintImpl *const } } - *x_inout = motion.b.x; - *y_inout = motion.b.y; + *x_inout = motion.b.x + constraint_impl_native->origin.x; + *y_inout = motion.b.y + constraint_impl_native->origin.y; } static float @@ -602,6 +602,8 @@ meta_pointer_constraint_impl_native_ensure_constrained (MetaPointerConstraintImp g_autoptr (MtkRegion) region = NULL; float x; float y; + float rel_x; + float rel_y; constraint_impl_native = META_POINTER_CONSTRAINT_IMPL_NATIVE (constraint_impl); region = mtk_region_ref (constraint_impl_native->region); @@ -610,6 +612,8 @@ meta_pointer_constraint_impl_native_ensure_constrained (MetaPointerConstraintImp clutter_seat_query_state (seat, device, NULL, &point, NULL); x = point.x; y = point.y; + rel_x = x - constraint_impl_native->origin.x; + rel_y = y - constraint_impl_native->origin.y; if (mtk_region_is_empty (region)) { @@ -617,9 +621,7 @@ meta_pointer_constraint_impl_native_ensure_constrained (MetaPointerConstraintImp y != constraint_impl_native->origin.y) clutter_seat_warp_pointer (seat, x, y); } - else if (!mtk_region_contains_point (region, - (int) x - constraint_impl_native->origin.x, - (int) y - constraint_impl_native->origin.y)) + else if (!mtk_region_contains_point (region, (int) rel_x, (int) rel_y)) { g_autoptr (GArray) borders = NULL; float closest_distance_2 = FLT_MAX; @@ -635,7 +637,7 @@ meta_pointer_constraint_impl_native_ensure_constrained (MetaPointerConstraintImp MetaBorder *border = &g_array_index (borders, MetaBorder, i); float distance_2; - distance_2 = point_to_border_distance_2 (border, x, y); + distance_2 = point_to_border_distance_2 (border, rel_x, rel_y); if (distance_2 < closest_distance_2) { closest_border = border; @@ -643,9 +645,11 @@ meta_pointer_constraint_impl_native_ensure_constrained (MetaPointerConstraintImp } } - closest_point_behind_border (closest_border, &x, &y); + closest_point_behind_border (closest_border, &rel_x, &rel_y); - clutter_seat_warp_pointer (seat, x, y); + clutter_seat_warp_pointer (seat, + rel_x + constraint_impl_native->origin.x, + rel_y + constraint_impl_native->origin.y); } }