summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2020-06-05 12:44:12 +0200
committerJonas Ådahl <jadahl@gmail.com>2020-10-23 18:48:18 +0000
commit90df3c6fa32f96af16c4b6a3d2bf5b956df91de2 (patch)
tree812bca27c30cccb5605c71b2675770ff473f6d5b
parent27ef073432ea9d2d73499343387c0e8a7752528f (diff)
downloadmutter-90df3c6fa32f96af16c4b6a3d2bf5b956df91de2.tar.gz
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
-rw-r--r--src/backends/native/meta-backend-native.c66
-rw-r--r--src/backends/native/meta-seat-native.c73
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 7873ce908..306cc0495 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 6f452a1b3..01f2e3a10 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