[mutter/wip/carlosg/input-refactors-pt1: 14/28] backends/native: Make seat constrain pointer to monitors out of the box




commit 2c23e313f680a91f7d7511d65714e49329cf195a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Jun 5 12:44:12 2020 +0200

    backends/native: Make seat constrain pointer to monitors out of the box
    
    It does access the MetaMonitorManager directly ATM.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1486

 src/backends/native/meta-backend-native.c | 66 ----------------------------
 src/backends/native/meta-seat-native.c    | 73 +++++++++++++++++++++++++++----
 2 files changed, 65 insertions(+), 74 deletions(-)
---
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index 7873ce9082..306cc04959 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -124,60 +124,6 @@ constrain_to_client_constraint (ClutterInputDevice *device,
                                      time, prev_x, prev_y, x, y);
 }
 
-/*
- * The pointer constrain code is mostly a rip-off of the XRandR code from Xorg.
- * (from xserver/randr/rrcrtc.c, RRConstrainCursorHarder)
- *
- * Copyright © 2006 Keith Packard
- * Copyright 2010 Red Hat, Inc
- *
- */
-
-static void
-constrain_all_screen_monitors (ClutterInputDevice *device,
-                               MetaMonitorManager *monitor_manager,
-                               float              *x,
-                               float              *y)
-{
-  graphene_point_t current;
-  float cx, cy;
-  GList *logical_monitors, *l;
-
-  clutter_input_device_get_coords (device, NULL, &current);
-
-  cx = current.x;
-  cy = current.y;
-
-  /* if we're trying to escape, clamp to the CRTC we're coming from */
-
-  logical_monitors =
-    meta_monitor_manager_get_logical_monitors (monitor_manager);
-  for (l = logical_monitors; l; l = l->next)
-    {
-      MetaLogicalMonitor *logical_monitor = l->data;
-      int left, right, top, bottom;
-
-      left = logical_monitor->rect.x;
-      right = left + logical_monitor->rect.width;
-      top = logical_monitor->rect.y;
-      bottom = top + logical_monitor->rect.height;
-
-      if ((cx >= left) && (cx < right) && (cy >= top) && (cy < bottom))
-        {
-          if (*x < left)
-            *x = left;
-          if (*x >= right)
-            *x = right - 1;
-          if (*y < top)
-            *y = top;
-          if (*y >= bottom)
-            *y = bottom - 1;
-
-          return;
-        }
-    }
-}
-
 static void
 pointer_constrain_callback (ClutterInputDevice *device,
                             guint32             time,
@@ -187,20 +133,8 @@ pointer_constrain_callback (ClutterInputDevice *device,
                             float              *new_y,
                             gpointer            user_data)
 {
-  MetaBackend *backend = meta_get_backend ();
-  MetaMonitorManager *monitor_manager =
-    meta_backend_get_monitor_manager (backend);
-
   /* Constrain to pointer lock */
   constrain_to_client_constraint (device, time, prev_x, prev_y, new_x, new_y);
-
-  /* if we're moving inside a monitor, we're fine */
-  if (meta_monitor_manager_get_logical_monitor_at (monitor_manager,
-                                                   *new_x, *new_y))
-    return;
-
-  /* if we're trying to escape, clamp to the CRTC we're coming from */
-  constrain_all_screen_monitors (device, monitor_manager, new_x, new_y);
 }
 
 static void
diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c
index 916fa2425f..bba5db8137 100644
--- a/src/backends/native/meta-seat-native.c
+++ b/src/backends/native/meta-seat-native.c
@@ -904,6 +904,60 @@ constrain_to_barriers (MetaSeatNative     *seat,
                                        new_x, new_y);
 }
 
+/*
+ * The pointer constrain code is mostly a rip-off of the XRandR code from Xorg.
+ * (from xserver/randr/rrcrtc.c, RRConstrainCursorHarder)
+ *
+ * Copyright © 2006 Keith Packard
+ * Copyright 2010 Red Hat, Inc
+ *
+ */
+
+static void
+constrain_all_screen_monitors (ClutterInputDevice *device,
+                               MetaMonitorManager *monitor_manager,
+                               float              *x,
+                               float              *y)
+{
+  graphene_point_t current;
+  float cx, cy;
+  GList *logical_monitors, *l;
+
+  clutter_input_device_get_coords (device, NULL, &current);
+
+  cx = current.x;
+  cy = current.y;
+
+  /* if we're trying to escape, clamp to the CRTC we're coming from */
+
+  logical_monitors =
+    meta_monitor_manager_get_logical_monitors (monitor_manager);
+  for (l = logical_monitors; l; l = l->next)
+    {
+      MetaLogicalMonitor *logical_monitor = l->data;
+      int left, right, top, bottom;
+
+      left = logical_monitor->rect.x;
+      right = left + logical_monitor->rect.width;
+      top = logical_monitor->rect.y;
+      bottom = top + logical_monitor->rect.height;
+
+      if ((cx >= left) && (cx < right) && (cy >= top) && (cy < bottom))
+        {
+          if (*x < left)
+            *x = left;
+          if (*x >= right)
+            *x = right - 1;
+          if (*y < top)
+            *y = top;
+          if (*y >= bottom)
+            *y = bottom - 1;
+
+          return;
+        }
+    }
+}
+
 void
 meta_seat_native_constrain_pointer (MetaSeatNative     *seat,
                                     ClutterInputDevice *core_pointer,
@@ -913,6 +967,10 @@ meta_seat_native_constrain_pointer (MetaSeatNative     *seat,
                                     float              *new_x,
                                     float              *new_y)
 {
+  MetaBackend *backend = meta_get_backend ();
+  MetaMonitorManager *monitor_manager =
+    meta_backend_get_monitor_manager (backend);
+
   constrain_to_barriers (seat, core_pointer,
                          us2ms (time_us),
                          new_x, new_y);
@@ -925,15 +983,14 @@ meta_seat_native_constrain_pointer (MetaSeatNative     *seat,
                                 new_x, new_y,
                                 seat->constrain_data);
     }
-  else
-    {
-      ClutterActor *stage = CLUTTER_ACTOR (meta_seat_native_get_stage (seat));
-      float stage_width = clutter_actor_get_width (stage);
-      float stage_height = clutter_actor_get_height (stage);
 
-      *new_x = CLAMP (*new_x, 0.f, stage_width - 1);
-      *new_y = CLAMP (*new_y, 0.f, stage_height - 1);
-    }
+  /* if we're moving inside a monitor, we're fine */
+  if (meta_monitor_manager_get_logical_monitor_at (monitor_manager,
+                                                   *new_x, *new_y))
+    return;
+
+  /* if we're trying to escape, clamp to the CRTC we're coming from */
+  constrain_all_screen_monitors (core_pointer, monitor_manager, new_x, new_y);
 }
 
 void


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