[mutter/wip/carlosg/input-refactors-pt1: 10/23] backends/native: Move relative motion filter to MetaSeatNative altogether
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/carlosg/input-refactors-pt1: 10/23] backends/native: Move relative motion filter to MetaSeatNative altogether
- Date: Fri, 23 Oct 2020 16:38:34 +0000 (UTC)
commit e74b5b83a991e3a1a24d703546055ceb982ec816
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Jun 5 12:54:51 2020 +0200
backends/native: Move relative motion filter to MetaSeatNative altogether
And drop the relative motion filter API. The seat will handle relative motion
across outputs with different scales. This accesses the MetaMonitorManager
ATM.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1486
src/backends/native/meta-backend-native.c | 117 -----------------------------
src/backends/native/meta-seat-native.c | 118 ++++++++++++++++++++++++++----
src/backends/native/meta-seat-native.h | 13 ----
3 files changed, 104 insertions(+), 144 deletions(-)
---
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index 306cc04959..8002e40512 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -137,120 +137,6 @@ pointer_constrain_callback (ClutterInputDevice *device,
constrain_to_client_constraint (device, time, prev_x, prev_y, new_x, new_y);
}
-static void
-relative_motion_across_outputs (MetaMonitorManager *monitor_manager,
- MetaLogicalMonitor *current,
- float cur_x,
- float cur_y,
- float *dx_inout,
- float *dy_inout)
-{
- MetaLogicalMonitor *cur = current;
- float x = cur_x, y = cur_y;
- float target_x = cur_x, target_y = cur_y;
- float dx = *dx_inout, dy = *dy_inout;
- MetaDisplayDirection direction = -1;
-
- while (cur)
- {
- MetaLine2 left, right, top, bottom, motion;
- MetaVector2 intersection;
-
- motion = (MetaLine2) {
- .a = { x, y },
- .b = { x + (dx * cur->scale), y + (dy * cur->scale) }
- };
- left = (MetaLine2) {
- { cur->rect.x, cur->rect.y },
- { cur->rect.x, cur->rect.y + cur->rect.height }
- };
- right = (MetaLine2) {
- { cur->rect.x + cur->rect.width, cur->rect.y },
- { cur->rect.x + cur->rect.width, cur->rect.y + cur->rect.height }
- };
- top = (MetaLine2) {
- { cur->rect.x, cur->rect.y },
- { cur->rect.x + cur->rect.width, cur->rect.y }
- };
- bottom = (MetaLine2) {
- { cur->rect.x, cur->rect.y + cur->rect.height },
- { cur->rect.x + cur->rect.width, cur->rect.y + cur->rect.height }
- };
-
- target_x = motion.b.x;
- target_y = motion.b.y;
-
- if (direction != META_DISPLAY_RIGHT &&
- meta_line2_intersects_with (&motion, &left, &intersection))
- direction = META_DISPLAY_LEFT;
- else if (direction != META_DISPLAY_LEFT &&
- meta_line2_intersects_with (&motion, &right, &intersection))
- direction = META_DISPLAY_RIGHT;
- else if (direction != META_DISPLAY_DOWN &&
- meta_line2_intersects_with (&motion, &top, &intersection))
- direction = META_DISPLAY_UP;
- else if (direction != META_DISPLAY_UP &&
- meta_line2_intersects_with (&motion, &bottom, &intersection))
- direction = META_DISPLAY_DOWN;
- else
- /* We reached the dest logical monitor */
- break;
-
- x = intersection.x;
- y = intersection.y;
- dx -= intersection.x - motion.a.x;
- dy -= intersection.y - motion.a.y;
-
- cur = meta_monitor_manager_get_logical_monitor_neighbor (monitor_manager,
- cur, direction);
- }
-
- *dx_inout = target_x - cur_x;
- *dy_inout = target_y - cur_y;
-}
-
-static void
-relative_motion_filter (ClutterInputDevice *device,
- float x,
- float y,
- float *dx,
- float *dy,
- gpointer user_data)
-{
- MetaMonitorManager *monitor_manager = user_data;
- MetaLogicalMonitor *logical_monitor, *dest_logical_monitor;
- float new_dx, new_dy;
-
- if (meta_is_stage_views_scaled ())
- return;
-
- logical_monitor = meta_monitor_manager_get_logical_monitor_at (monitor_manager,
- x, y);
- if (!logical_monitor)
- return;
-
- new_dx = (*dx) * logical_monitor->scale;
- new_dy = (*dy) * logical_monitor->scale;
-
- dest_logical_monitor = meta_monitor_manager_get_logical_monitor_at (monitor_manager,
- x + new_dx,
- y + new_dy);
- if (dest_logical_monitor &&
- dest_logical_monitor != logical_monitor)
- {
- /* If we are crossing monitors, attempt to bisect the distance on each
- * axis and apply the relative scale for each of them.
- */
- new_dx = *dx;
- new_dy = *dy;
- relative_motion_across_outputs (monitor_manager, logical_monitor,
- x, y, &new_dx, &new_dy);
- }
-
- *dx = new_dx;
- *dy = new_dy;
-}
-
static ClutterBackend *
meta_backend_native_create_clutter_backend (MetaBackend *backend)
{
@@ -302,9 +188,6 @@ meta_backend_native_post_init (MetaBackend *backend)
meta_seat_native_set_pointer_constrain_callback (META_SEAT_NATIVE (seat),
pointer_constrain_callback,
NULL, NULL);
- meta_seat_native_set_relative_motion_filter (META_SEAT_NATIVE (seat),
- relative_motion_filter,
- meta_backend_get_monitor_manager (backend));
META_BACKEND_CLASS (meta_backend_native_parent_class)->post_init (backend);
diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c
index bba5db8137..022714a9a0 100644
--- a/src/backends/native/meta-seat-native.c
+++ b/src/backends/native/meta-seat-native.c
@@ -993,6 +993,78 @@ meta_seat_native_constrain_pointer (MetaSeatNative *seat,
constrain_all_screen_monitors (core_pointer, monitor_manager, new_x, new_y);
}
+static void
+relative_motion_across_outputs (MetaMonitorManager *monitor_manager,
+ MetaLogicalMonitor *current,
+ float cur_x,
+ float cur_y,
+ float *dx_inout,
+ float *dy_inout)
+{
+ MetaLogicalMonitor *cur = current;
+ float x = cur_x, y = cur_y;
+ float target_x = cur_x, target_y = cur_y;
+ float dx = *dx_inout, dy = *dy_inout;
+ MetaDisplayDirection direction = -1;
+
+ while (cur)
+ {
+ MetaLine2 left, right, top, bottom, motion;
+ MetaVector2 intersection;
+
+ motion = (MetaLine2) {
+ .a = { x, y },
+ .b = { x + (dx * cur->scale), y + (dy * cur->scale) }
+ };
+ left = (MetaLine2) {
+ { cur->rect.x, cur->rect.y },
+ { cur->rect.x, cur->rect.y + cur->rect.height }
+ };
+ right = (MetaLine2) {
+ { cur->rect.x + cur->rect.width, cur->rect.y },
+ { cur->rect.x + cur->rect.width, cur->rect.y + cur->rect.height }
+ };
+ top = (MetaLine2) {
+ { cur->rect.x, cur->rect.y },
+ { cur->rect.x + cur->rect.width, cur->rect.y }
+ };
+ bottom = (MetaLine2) {
+ { cur->rect.x, cur->rect.y + cur->rect.height },
+ { cur->rect.x + cur->rect.width, cur->rect.y + cur->rect.height }
+ };
+
+ target_x = motion.b.x;
+ target_y = motion.b.y;
+
+ if (direction != META_DISPLAY_RIGHT &&
+ meta_line2_intersects_with (&motion, &left, &intersection))
+ direction = META_DISPLAY_LEFT;
+ else if (direction != META_DISPLAY_LEFT &&
+ meta_line2_intersects_with (&motion, &right, &intersection))
+ direction = META_DISPLAY_RIGHT;
+ else if (direction != META_DISPLAY_DOWN &&
+ meta_line2_intersects_with (&motion, &top, &intersection))
+ direction = META_DISPLAY_UP;
+ else if (direction != META_DISPLAY_UP &&
+ meta_line2_intersects_with (&motion, &bottom, &intersection))
+ direction = META_DISPLAY_DOWN;
+ else
+ /* We reached the dest logical monitor */
+ break;
+
+ x = intersection.x;
+ y = intersection.y;
+ dx -= intersection.x - motion.a.x;
+ dy -= intersection.y - motion.a.y;
+
+ cur = meta_monitor_manager_get_logical_monitor_neighbor (monitor_manager,
+ cur, direction);
+ }
+
+ *dx_inout = target_x - cur_x;
+ *dy_inout = target_y - cur_y;
+}
+
void
meta_seat_native_filter_relative_motion (MetaSeatNative *seat,
ClutterInputDevice *device,
@@ -1001,11 +1073,40 @@ meta_seat_native_filter_relative_motion (MetaSeatNative *seat,
float *dx,
float *dy)
{
- if (!seat->relative_motion_filter)
+ MetaBackend *backend = meta_get_backend ();
+ MetaMonitorManager *monitor_manager =
+ meta_backend_get_monitor_manager (backend);
+ MetaLogicalMonitor *logical_monitor, *dest_logical_monitor;
+ float new_dx, new_dy;
+
+ if (meta_is_stage_views_scaled ())
return;
- seat->relative_motion_filter (device, x, y, dx, dy,
- seat->relative_motion_filter_user_data);
+ logical_monitor = meta_monitor_manager_get_logical_monitor_at (monitor_manager,
+ x, y);
+ if (!logical_monitor)
+ return;
+
+ new_dx = (*dx) * logical_monitor->scale;
+ new_dy = (*dy) * logical_monitor->scale;
+
+ dest_logical_monitor = meta_monitor_manager_get_logical_monitor_at (monitor_manager,
+ x + new_dx,
+ y + new_dy);
+ if (dest_logical_monitor &&
+ dest_logical_monitor != logical_monitor)
+ {
+ /* If we are crossing monitors, attempt to bisect the distance on each
+ * axis and apply the relative scale for each of them.
+ */
+ new_dx = *dx;
+ new_dy = *dy;
+ relative_motion_across_outputs (monitor_manager, logical_monitor,
+ x, y, &new_dx, &new_dy);
+ }
+
+ *dx = new_dx;
+ *dy = new_dy;
}
static void
@@ -3050,17 +3151,6 @@ meta_seat_native_set_pointer_constrain_callback (MetaSeatNative *s
seat->constrain_data_notify = user_data_notify;
}
-void
-meta_seat_native_set_relative_motion_filter (MetaSeatNative *seat,
- MetaRelativeMotionFilter filter,
- gpointer user_data)
-{
- g_return_if_fail (META_IS_SEAT_NATIVE (seat));
-
- seat->relative_motion_filter = filter;
- seat->relative_motion_filter_user_data = user_data;
-}
-
void
meta_seat_native_update_xkb_state (MetaSeatNative *seat)
{
diff --git a/src/backends/native/meta-seat-native.h b/src/backends/native/meta-seat-native.h
index b19d3493de..73e6101da1 100644
--- a/src/backends/native/meta-seat-native.h
+++ b/src/backends/native/meta-seat-native.h
@@ -59,12 +59,6 @@ typedef void (* MetaPointerConstrainCallback) (ClutterInputDevice *device,
float *x,
float *y,
gpointer user_data);
-typedef void (* MetaRelativeMotionFilter) (ClutterInputDevice *device,
- float x,
- float y,
- float *dx,
- float *dy,
- gpointer user_data);
struct _MetaTouchState
{
@@ -115,9 +109,6 @@ struct _MetaSeatNative
gpointer constrain_data;
GDestroyNotify constrain_data_notify;
- MetaRelativeMotionFilter relative_motion_filter;
- gpointer relative_motion_filter_user_data;
-
MetaKeymapNative *keymap;
GUdevClient *udev_client;
@@ -270,10 +261,6 @@ void meta_seat_native_set_pointer_constrain_callback (MetaSeatNative
gpointer user_data,
GDestroyNotify user_data_notify);
-void meta_seat_native_set_relative_motion_filter (MetaSeatNative *seat,
- MetaRelativeMotionFilter filter,
- gpointer user_data);
-
struct xkb_state * meta_seat_native_get_xkb_state (MetaSeatNative *seat);
void meta_seat_native_set_keyboard_map (MetaSeatNative *seat,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]