[mutter/wip/carlosg/input-refactors-pt1: 17/30] backends/native: Move relative motion filter to MetaSeatNative altogether




commit b6e01383f42ac2d9ef701b00546fe23c0303c4c4
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 4e46349505..180257a79e 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
@@ -3025,17 +3126,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 7e30ff7d00..27ceaa6e6d 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
 {
@@ -114,9 +108,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;
@@ -269,10 +260,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]