[mutter] pointer-constraints: Move min edge distance from backend to Wayland



commit 6d46ffccbc84fa87e8661b7c48807cfb25b97116
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Mon Jun 13 10:23:40 2022 +0200

    pointer-constraints: Move min edge distance from backend to Wayland
    
    The min distance to the right/bottom edge depends on Wayland concepts
    (wl_fixed_t) and eventually geometry scale. Move the logic the Wayland
    side of the pointer constraints machinery to avoid the backend trying to
    figure this out without the proper data.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2460>

 src/backends/meta-pointer-constraint.c             | 11 ++++++++-
 src/backends/meta-pointer-constraint.h             |  6 ++++-
 src/backends/native/meta-backend-native.c          |  7 +++++-
 .../native/meta-pointer-constraint-native.c        | 27 ++++++++++++----------
 .../native/meta-pointer-constraint-native.h        |  3 ++-
 src/wayland/meta-pointer-confinement-wayland.c     |  4 +++-
 src/wayland/meta-pointer-lock-wayland.c            |  2 +-
 7 files changed, 42 insertions(+), 18 deletions(-)
---
diff --git a/src/backends/meta-pointer-constraint.c b/src/backends/meta-pointer-constraint.c
index 7682b14b05..0bc57a4c4a 100644
--- a/src/backends/meta-pointer-constraint.c
+++ b/src/backends/meta-pointer-constraint.c
@@ -50,6 +50,7 @@ struct _MetaPointerConstraint
 {
   GObject parent_instance;
   cairo_region_t *region;
+  double min_edge_distance;
 };
 
 G_DEFINE_TYPE (MetaPointerConstraint, meta_pointer_constraint, G_TYPE_OBJECT);
@@ -82,12 +83,14 @@ meta_pointer_constraint_class_init (MetaPointerConstraintClass *klass)
 
 
 MetaPointerConstraint *
-meta_pointer_constraint_new (const cairo_region_t *region)
+meta_pointer_constraint_new (const cairo_region_t *region,
+                             double                min_edge_distance)
 {
   MetaPointerConstraint *constraint;
 
   constraint = g_object_new (META_TYPE_POINTER_CONSTRAINT, NULL);
   constraint->region = cairo_region_copy (region);
+  constraint->min_edge_distance = min_edge_distance;
 
   return constraint;
 }
@@ -98,6 +101,12 @@ meta_pointer_constraint_get_region (MetaPointerConstraint *constraint)
   return constraint->region;
 }
 
+double
+meta_pointer_constraint_get_min_edge_distance (MetaPointerConstraint *constraint)
+{
+  return constraint->min_edge_distance;
+}
+
 static void
 meta_pointer_constraint_impl_init (MetaPointerConstraintImpl *constraint_impl)
 {
diff --git a/src/backends/meta-pointer-constraint.h b/src/backends/meta-pointer-constraint.h
index b47eda4903..83be1a8e9d 100644
--- a/src/backends/meta-pointer-constraint.h
+++ b/src/backends/meta-pointer-constraint.h
@@ -35,9 +35,13 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (MetaPointerConstraint, meta_pointer_constraint,
                       META, POINTER_CONSTRAINT, GObject);
 
-MetaPointerConstraint * meta_pointer_constraint_new (const cairo_region_t *region);
+MetaPointerConstraint * meta_pointer_constraint_new (const cairo_region_t *region,
+                                                     double                min_edge_distance);
+
 cairo_region_t * meta_pointer_constraint_get_region (MetaPointerConstraint *constraint);
 
+double meta_pointer_constraint_get_min_edge_distance (MetaPointerConstraint *constraint);
+
 #define META_TYPE_POINTER_CONSTRAINT_IMPL (meta_pointer_constraint_impl_get_type ())
 G_DECLARE_DERIVABLE_TYPE (MetaPointerConstraintImpl, meta_pointer_constraint_impl,
                           META, POINTER_CONSTRAINT_IMPL, GObject);
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index 2245387876..eb5687375c 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -407,9 +407,14 @@ meta_backend_native_set_pointer_constraint (MetaBackend           *backend,
 
   if (constraint)
     {
+      double min_edge_distance;
+
       region = meta_pointer_constraint_get_region (constraint);
+      min_edge_distance =
+        meta_pointer_constraint_get_min_edge_distance (constraint);
       constraint_impl = meta_pointer_constraint_impl_native_new (constraint,
-                                                                 region);
+                                                                 region,
+                                                                 min_edge_distance);
     }
 
   meta_seat_native_set_pointer_constraint (META_SEAT_NATIVE (seat),
diff --git a/src/backends/native/meta-pointer-constraint-native.c 
b/src/backends/native/meta-pointer-constraint-native.c
index 93f75a2839..1992006735 100644
--- a/src/backends/native/meta-pointer-constraint-native.c
+++ b/src/backends/native/meta-pointer-constraint-native.c
@@ -35,6 +35,7 @@ struct _MetaPointerConstraintImplNative
   MetaPointerConstraintImpl parent;
   MetaPointerConstraint *constraint;
   cairo_region_t *region;
+  double min_edge_distance;
 };
 
 G_DEFINE_TYPE (MetaPointerConstraintImplNative,
@@ -402,18 +403,13 @@ get_closest_border (GArray    *borders,
 static void
 clamp_to_border (MetaBorder *border,
                  MetaLine2  *motion,
-                 uint32_t   *motion_dir)
+                 uint32_t   *motion_dir,
+                 double      min_edge_distance)
 {
-  /*
-   * When clamping either rightward or downward motions, the motion needs to be
-   * clamped so that the destination coordinate does not end up on the border
-   * (see weston_pointer_clamp_event_to_region). Do this by clamping such
-   * motions to the border minus the smallest possible wl_fixed_t value.
-   */
   if (meta_border_is_horizontal (border))
     {
       if (*motion_dir & META_BORDER_MOTION_DIRECTION_POSITIVE_Y)
-        motion->b.y = border->line.a.y - wl_fixed_to_double (1);
+        motion->b.y = border->line.a.y - min_edge_distance;
       else
         motion->b.y = border->line.a.y;
       *motion_dir &= ~(META_BORDER_MOTION_DIRECTION_POSITIVE_Y |
@@ -422,7 +418,7 @@ clamp_to_border (MetaBorder *border,
   else
     {
       if (*motion_dir & META_BORDER_MOTION_DIRECTION_POSITIVE_X)
-        motion->b.x = border->line.a.x - wl_fixed_to_double (1);
+        motion->b.x = border->line.a.x - min_edge_distance;
       else
         motion->b.x = border->line.a.x;
       *motion_dir &= ~(META_BORDER_MOTION_DIRECTION_POSITIVE_X |
@@ -510,9 +506,14 @@ meta_pointer_constraint_impl_native_constraint (MetaPointerConstraintImpl *const
                                            &motion,
                                            directions);
       if (closest_border)
-        clamp_to_border (closest_border, &motion, &directions);
+        {
+          clamp_to_border (closest_border, &motion, &directions,
+                           constraint_impl_native->min_edge_distance);
+        }
       else
-        break;
+        {
+          break;
+        }
     }
 
   *x_inout = motion.b.x;
@@ -671,7 +672,8 @@ meta_pointer_constraint_impl_native_class_init (MetaPointerConstraintImplNativeC
 
 MetaPointerConstraintImpl *
 meta_pointer_constraint_impl_native_new (MetaPointerConstraint *constraint,
-                                         const cairo_region_t  *region)
+                                         const cairo_region_t  *region,
+                                         double                 min_edge_distance)
 {
   MetaPointerConstraintImplNative *constraint_impl;
 
@@ -679,6 +681,7 @@ meta_pointer_constraint_impl_native_new (MetaPointerConstraint *constraint,
                                   NULL);
   constraint_impl->constraint = constraint;
   constraint_impl->region = cairo_region_copy (region);
+  constraint_impl->min_edge_distance = min_edge_distance;
 
   return META_POINTER_CONSTRAINT_IMPL (constraint_impl);
 }
diff --git a/src/backends/native/meta-pointer-constraint-native.h 
b/src/backends/native/meta-pointer-constraint-native.h
index 83a2e575d5..e95a0bd145 100644
--- a/src/backends/native/meta-pointer-constraint-native.h
+++ b/src/backends/native/meta-pointer-constraint-native.h
@@ -39,7 +39,8 @@ G_DECLARE_FINAL_TYPE (MetaPointerConstraintImplNative,
                       MetaPointerConstraintImpl)
 
 MetaPointerConstraintImpl * meta_pointer_constraint_impl_native_new (MetaPointerConstraint *constraint_impl,
-                                                                     const cairo_region_t  *region);
+                                                                     const cairo_region_t  *region,
+                                                                     double                 
min_edge_distance);
 
 G_END_DECLS
 
diff --git a/src/wayland/meta-pointer-confinement-wayland.c b/src/wayland/meta-pointer-confinement-wayland.c
index 3df6ed0ab3..a54faf00cb 100644
--- a/src/wayland/meta-pointer-confinement-wayland.c
+++ b/src/wayland/meta-pointer-confinement-wayland.c
@@ -212,6 +212,7 @@ meta_pointer_confinement_wayland_create_constraint (MetaPointerConfinementWaylan
   MetaWaylandSurface *surface;
   cairo_region_t *region;
   float dx, dy;
+  double min_edge_distance;
 
   priv = meta_pointer_confinement_wayland_get_instance_private (confinement);
 
@@ -222,7 +223,8 @@ meta_pointer_confinement_wayland_create_constraint (MetaPointerConfinementWaylan
   meta_wayland_surface_get_absolute_coordinates (surface, 0, 0, &dx, &dy);
   cairo_region_translate (region, dx, dy);
 
-  constraint = meta_pointer_constraint_new (region);
+  min_edge_distance = wl_fixed_to_double (1);
+  constraint = meta_pointer_constraint_new (region, min_edge_distance);
   cairo_region_destroy (region);
 
   return constraint;
diff --git a/src/wayland/meta-pointer-lock-wayland.c b/src/wayland/meta-pointer-lock-wayland.c
index 9e0e8bcb8c..a07a4baafc 100644
--- a/src/wayland/meta-pointer-lock-wayland.c
+++ b/src/wayland/meta-pointer-lock-wayland.c
@@ -74,7 +74,7 @@ meta_pointer_lock_wayland_create_constraint (MetaPointerConfinementWayland *conf
   meta_wayland_surface_get_absolute_coordinates (surface, sx, sy, &x, &y);
   region = cairo_region_create_rectangle (&(cairo_rectangle_int_t) { (int) x, (int) y, 1 , 1 });
 
-  constraint = meta_pointer_constraint_new (region);
+  constraint = meta_pointer_constraint_new (region, 0.0);
   cairo_region_destroy (region);
 
   return constraint;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]