[mutter/wip/carlosg/clutter-seat: 6/6] backends: Move warp_pointer() to ClutterSeat



commit 3626571fc677c1a03c961d58528bb0826ff25c37
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Oct 9 18:01:34 2019 +0200

    backends: Move warp_pointer() to ClutterSeat
    
    The onscreen pointer sprite is a per-seat element, so it makes sense
    to move pointer warping over there too.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/852

 clutter/clutter/clutter-seat.c                 | 10 +++++++
 clutter/clutter/clutter-seat.h                 |  9 ++++++
 src/backends/meta-backend-private.h            |  9 ------
 src/backends/meta-backend.c                    | 14 ++-------
 src/backends/native/meta-backend-native.c      | 21 --------------
 src/backends/native/meta-seat-native.c         | 40 +++++++++++---------------
 src/backends/native/meta-seat-native.h         |  5 ----
 src/backends/x11/meta-backend-x11.c            | 17 -----------
 src/backends/x11/meta-seat-x11.c               | 16 +++++++++++
 src/core/window.c                              |  6 ++--
 src/wayland/meta-pointer-confinement-wayland.c |  5 +++-
 src/wayland/meta-wayland-pointer-constraints.c |  7 ++++-
 12 files changed, 67 insertions(+), 92 deletions(-)
---
diff --git a/clutter/clutter/clutter-seat.c b/clutter/clutter/clutter-seat.c
index a1bb4458d..6ff1fffe9 100644
--- a/clutter/clutter/clutter-seat.c
+++ b/clutter/clutter/clutter-seat.c
@@ -546,3 +546,13 @@ clutter_seat_compress_motion (ClutterSeat        *seat,
   if (seat_class->compress_motion)
     seat_class->compress_motion (seat, event, to_discard);
 }
+
+void
+clutter_seat_warp_pointer (ClutterSeat *seat,
+                           int          x,
+                           int          y)
+{
+  g_return_if_fail (CLUTTER_IS_SEAT (seat));
+
+  CLUTTER_SEAT_GET_CLASS (seat)->warp_pointer (seat, x, y);
+}
diff --git a/clutter/clutter/clutter-seat.h b/clutter/clutter/clutter-seat.h
index 916e61d57..f8754f647 100644
--- a/clutter/clutter/clutter-seat.h
+++ b/clutter/clutter/clutter-seat.h
@@ -106,6 +106,10 @@ struct _ClutterSeatClass
                             ClutterEvent       *event,
                             const ClutterEvent *to_discard);
 
+  void (* warp_pointer) (ClutterSeat *seat,
+                         int          x,
+                         int          y);
+
   /* Event platform data */
   void (* copy_event_data) (ClutterSeat        *seat,
                             const ClutterEvent *src,
@@ -166,4 +170,9 @@ void clutter_seat_compress_motion (ClutterSeat        *seat,
                                    ClutterEvent       *event,
                                    const ClutterEvent *to_discard);
 
+CLUTTER_EXPORT
+void clutter_seat_warp_pointer (ClutterSeat *seat,
+                                int          x,
+                                int          y);
+
 #endif /* CLUTTER_SEAT_H */
diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h
index 10858e041..f5423c12b 100644
--- a/src/backends/meta-backend-private.h
+++ b/src/backends/meta-backend-private.h
@@ -82,11 +82,6 @@ struct _MetaBackendClass
   void (* finish_touch_sequence) (MetaBackend          *backend,
                                   ClutterEventSequence *sequence,
                                   MetaSequenceState     state);
-
-  void (* warp_pointer) (MetaBackend *backend,
-                         int          x,
-                         int          y);
-
   MetaLogicalMonitor * (* get_current_logical_monitor) (MetaBackend *backend);
 
   void (* set_keymap) (MetaBackend *backend,
@@ -145,10 +140,6 @@ void meta_backend_finish_touch_sequence (MetaBackend          *backend,
                                          ClutterEventSequence *sequence,
                                          MetaSequenceState     state);
 
-void meta_backend_warp_pointer (MetaBackend *backend,
-                                int          x,
-                                int          y);
-
 MetaLogicalMonitor * meta_backend_get_current_logical_monitor (MetaBackend *backend);
 
 struct xkb_keymap * meta_backend_get_keymap (MetaBackend *backend);
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
index 9d133c5d4..9690d8b65 100644
--- a/src/backends/meta-backend.c
+++ b/src/backends/meta-backend.c
@@ -237,6 +237,7 @@ reset_pointer_position (MetaBackend *backend)
 {
   MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
   MetaMonitorManager *monitor_manager = priv->monitor_manager;
+  ClutterSeat *seat = clutter_backend_get_default_seat (priv->clutter_backend);
   MetaLogicalMonitor *primary;
 
   primary =
@@ -244,7 +245,7 @@ reset_pointer_position (MetaBackend *backend)
 
   /* Move the pointer out of the way to avoid hovering over reactive
    * elements (e.g. users list at login) causing undesired behaviour. */
-  meta_backend_warp_pointer (backend,
+  clutter_seat_warp_pointer (seat,
                              primary->rect.x + primary->rect.width * 0.9,
                              primary->rect.y + primary->rect.height * 0.9);
 }
@@ -1067,17 +1068,6 @@ meta_backend_finish_touch_sequence (MetaBackend          *backend,
                                                              state);
 }
 
-/**
- * meta_backend_warp_pointer: (skip)
- */
-void
-meta_backend_warp_pointer (MetaBackend *backend,
-                           int          x,
-                           int          y)
-{
-  META_BACKEND_GET_CLASS (backend)->warp_pointer (backend, x, y);
-}
-
 MetaLogicalMonitor *
 meta_backend_get_current_logical_monitor (MetaBackend *backend)
 {
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index b0cd1c31a..f29aec16e 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -403,25 +403,6 @@ meta_backend_native_create_input_settings (MetaBackend *backend)
   return g_object_new (META_TYPE_INPUT_SETTINGS_NATIVE, NULL);
 }
 
-static void
-meta_backend_native_warp_pointer (MetaBackend *backend,
-                                  int          x,
-                                  int          y)
-{
-  ClutterSeat *seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
-  ClutterInputDevice *device = clutter_seat_get_pointer (seat);
-  MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
-
-  /* XXX */
-  guint32 time_ = 0;
-
-  /* Warp the input device pointer state. */
-  meta_seat_native_warp_pointer (device, time_, x, y);
-
-  /* Warp displayed pointer cursor. */
-  meta_cursor_tracker_update_position (cursor_tracker, x, y);
-}
-
 static MetaLogicalMonitor *
 meta_backend_native_get_current_logical_monitor (MetaBackend *backend)
 {
@@ -704,8 +685,6 @@ meta_backend_native_class_init (MetaBackendNativeClass *klass)
   backend_class->create_renderer = meta_backend_native_create_renderer;
   backend_class->create_input_settings = meta_backend_native_create_input_settings;
 
-  backend_class->warp_pointer = meta_backend_native_warp_pointer;
-
   backend_class->get_current_logical_monitor = meta_backend_native_get_current_logical_monitor;
 
   backend_class->set_keymap = meta_backend_native_set_keymap;
diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c
index 5e8cb22d2..fd8048ff4 100644
--- a/src/backends/native/meta-seat-native.c
+++ b/src/backends/native/meta-seat-native.c
@@ -32,6 +32,7 @@
 #include <linux/input.h>
 #include <math.h>
 
+#include "backends/meta-cursor-tracker-private.h"
 #include "backends/native/meta-seat-native.h"
 #include "backends/native/meta-event-native.h"
 #include "backends/native/meta-input-device-native.h"
@@ -2612,6 +2613,20 @@ meta_seat_native_compress_motion (ClutterSeat        *seat,
                                          dy_unaccel + dst_dy_unaccel);
 }
 
+static void
+meta_seat_native_warp_pointer (ClutterSeat *seat,
+                               int          x,
+                               int          y)
+{
+  MetaSeatNative *seat_native = META_SEAT_NATIVE (seat);
+  MetaBackend *backend = meta_get_backend ();
+  MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
+
+  notify_absolute_motion (seat_native->core_pointer, 0, x, y, NULL);
+
+  meta_cursor_tracker_update_position (cursor_tracker, x, y);
+}
+
 static void
 meta_seat_native_class_init (MetaSeatNativeClass *klass)
 {
@@ -2635,6 +2650,7 @@ meta_seat_native_class_init (MetaSeatNativeClass *klass)
   seat_class->create_virtual_device = meta_seat_native_create_virtual_device;
   seat_class->get_supported_virtual_device_types = meta_seat_native_get_supported_virtual_device_types;
   seat_class->compress_motion = meta_seat_native_compress_motion;
+  seat_class->warp_pointer = meta_seat_native_warp_pointer;
 
   props[PROP_SEAT_ID] =
     g_param_spec_string ("seat-id",
@@ -2906,30 +2922,6 @@ meta_seat_native_update_xkb_state (MetaSeatNative *seat)
   meta_seat_native_sync_leds (seat);
 }
 
-/**
- * meta_seat_native_warp_pointer:
- * @pointer_device: the pointer device to warp
- * @time: the timestamp for the warp event
- * @x: the new X position of the pointer
- * @y: the new Y position of the pointer
- *
- * Warps the pointer to a new location. Technically, this is
- * processed the same way as an absolute motion event from
- * libinput: it simply generates an absolute motion event that
- * will be processed on the next iteration of the mainloop.
- *
- * The intended use for this is for display servers that need
- * to warp cursor the cursor to a new location.
- */
-void
-meta_seat_native_warp_pointer (ClutterInputDevice   *pointer_device,
-                               uint32_t              time_,
-                               int                   x,
-                               int                   y)
-{
-  notify_absolute_motion (pointer_device, ms2us(time_), x, y, NULL);
-}
-
 gint
 meta_seat_native_acquire_device_id (MetaSeatNative *seat)
 {
diff --git a/src/backends/native/meta-seat-native.h b/src/backends/native/meta-seat-native.h
index af8af1f36..a351d9327 100644
--- a/src/backends/native/meta-seat-native.h
+++ b/src/backends/native/meta-seat-native.h
@@ -295,11 +295,6 @@ void meta_seat_native_remove_filter (MetaSeatNative        *seat,
                                      MetaEvdevFilterFunc    func,
                                      gpointer               data);
 
-void meta_seat_native_warp_pointer (ClutterInputDevice   *pointer_device,
-                                    uint32_t              time_,
-                                    int                   x,
-                                    int                   y);
-
 struct xkb_state * meta_seat_native_get_xkb_state (MetaSeatNative *seat);
 
 void               meta_seat_native_set_keyboard_map   (MetaSeatNative    *seat,
diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c
index 9505f7de4..515d2a8c5 100644
--- a/src/backends/x11/meta-backend-x11.c
+++ b/src/backends/x11/meta-backend-x11.c
@@ -670,22 +670,6 @@ meta_backend_x11_finish_touch_sequence (MetaBackend          *backend,
     }
 }
 
-static void
-meta_backend_x11_warp_pointer (MetaBackend *backend,
-                               int          x,
-                               int          y)
-{
-  MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
-  MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
-
-  XIWarpPointer (priv->xdisplay,
-                 META_VIRTUAL_CORE_POINTER_ID,
-                 None,
-                 meta_backend_x11_get_xwindow (x11),
-                 0, 0, 0, 0,
-                 x, y);
-}
-
 static MetaLogicalMonitor *
 meta_backend_x11_get_current_logical_monitor (MetaBackend *backend)
 {
@@ -862,7 +846,6 @@ meta_backend_x11_class_init (MetaBackendX11Class *klass)
   backend_class->grab_device = meta_backend_x11_grab_device;
   backend_class->ungrab_device = meta_backend_x11_ungrab_device;
   backend_class->finish_touch_sequence = meta_backend_x11_finish_touch_sequence;
-  backend_class->warp_pointer = meta_backend_x11_warp_pointer;
   backend_class->get_current_logical_monitor = meta_backend_x11_get_current_logical_monitor;
   backend_class->get_keymap = meta_backend_x11_get_keymap;
   backend_class->get_keymap_layout_group = meta_backend_x11_get_keymap_layout_group;
diff --git a/src/backends/x11/meta-seat-x11.c b/src/backends/x11/meta-seat-x11.c
index 8c8fdc2f9..9a43a2762 100644
--- a/src/backends/x11/meta-seat-x11.c
+++ b/src/backends/x11/meta-seat-x11.c
@@ -1500,6 +1500,21 @@ meta_seat_x11_get_supported_virtual_device_types (ClutterSeat *seat)
           CLUTTER_VIRTUAL_DEVICE_TYPE_POINTER);
 }
 
+static void
+meta_seat_x11_warp_pointer (ClutterSeat *seat,
+                            int          x,
+                            int          y)
+{
+  MetaSeatX11 *seat_x11 = META_SEAT_X11 (seat);
+
+  XIWarpPointer (clutter_x11_get_default_display (),
+                 seat_x11->pointer_id,
+                 None,
+                 clutter_x11_get_root_window (),
+                 0, 0, 0, 0,
+                 x, y);
+}
+
 static void
 meta_seat_x11_class_init (MetaSeatX11Class *klass)
 {
@@ -1521,6 +1536,7 @@ meta_seat_x11_class_init (MetaSeatX11Class *klass)
   seat_class->apply_kbd_a11y_settings = meta_seat_x11_apply_kbd_a11y_settings;
   seat_class->create_virtual_device = meta_seat_x11_create_virtual_device;
   seat_class->get_supported_virtual_device_types = meta_seat_x11_get_supported_virtual_device_types;
+  seat_class->warp_pointer = meta_seat_x11_warp_pointer;
 
   props[PROP_OPCODE] =
     g_param_spec_int ("opcode",
diff --git a/src/core/window.c b/src/core/window.c
index 7480dfe69..d7d3e1b59 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -6858,8 +6858,10 @@ warp_grab_pointer (MetaWindow          *window,
                               &display->grab_anchor_window_pos);
 
   {
-    MetaBackend *backend = meta_get_backend ();
-    meta_backend_warp_pointer (backend, *x, *y);
+    ClutterSeat *seat;
+
+    seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
+    clutter_seat_warp_pointer (seat, *x, *y);
   }
 
   if (meta_x11_error_trap_pop_with_return (display->x11_display) != Success)
diff --git a/src/wayland/meta-pointer-confinement-wayland.c b/src/wayland/meta-pointer-confinement-wayland.c
index d5491e9f4..7a7b22c22 100644
--- a/src/wayland/meta-pointer-confinement-wayland.c
+++ b/src/wayland/meta-pointer-confinement-wayland.c
@@ -643,6 +643,7 @@ meta_pointer_confinement_wayland_maybe_warp (MetaPointerConfinementWayland *self
       GArray *borders;
       float closest_distance_2 = FLT_MAX;
       MetaBorder *closest_border = NULL;
+      ClutterSeat *seat;
       unsigned int i;
       float x;
       float y;
@@ -667,7 +668,9 @@ meta_pointer_confinement_wayland_maybe_warp (MetaPointerConfinementWayland *self
       warp_to_behind_border (closest_border, &sx, &sy);
 
       meta_wayland_surface_get_absolute_coordinates (surface, sx, sy, &x, &y);
-      meta_backend_warp_pointer (meta_get_backend (), (int)x, (int)y);
+
+      seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
+      clutter_seat_warp_pointer (seat, (int)x, (int)y);
     }
 
   cairo_region_destroy (region);
diff --git a/src/wayland/meta-wayland-pointer-constraints.c b/src/wayland/meta-wayland-pointer-constraints.c
index d0cc92d31..14ac75ee3 100644
--- a/src/wayland/meta-wayland-pointer-constraints.c
+++ b/src/wayland/meta-wayland-pointer-constraints.c
@@ -923,7 +923,12 @@ locked_pointer_destroy (struct wl_client   *client,
   wl_resource_destroy (resource);
 
   if (warp_pointer)
-    meta_backend_warp_pointer (meta_get_backend (), warp_x, warp_y);
+    {
+      ClutterSeat *seat;
+
+      seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
+      clutter_seat_warp_pointer (seat, warp_x, warp_y);
+    }
 }
 
 static void


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