[mutter/wip/carlosg/input-thread: 53/91] core: Centralize cursor renderer and tracker updates




commit af125b051340649175decb08b959ab4207a90a2a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Jul 13 14:09:44 2020 +0200

    core: Centralize cursor renderer and tracker updates
    
    These use now more of a "pull" model, where they receive update
    notifications and the relevant input position is queried, instead
    of the coordinates being passed along.
    
    This allows to treat cursor renderers all the same independently
    of the device they track. This notifying of position changes should
    ideally be more backend-y than core-y, a better location will be
    figured out in future commits.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403

 src/backends/meta-cursor-renderer.c        | 10 +++++-----
 src/backends/meta-cursor-renderer.h        |  4 +---
 src/backends/meta-cursor-tracker-private.h |  4 +---
 src/backends/meta-cursor-tracker.c         | 26 ++------------------------
 src/backends/native/meta-seat-native.c     |  5 ++++-
 src/backends/x11/meta-cursor-tracker-x11.c |  4 +---
 src/core/events.c                          | 19 +++++++++----------
 src/wayland/meta-wayland-tablet-manager.c  | 27 ---------------------------
 src/wayland/meta-wayland-tablet-manager.h  |  3 ---
 src/wayland/meta-wayland-tablet-tool.c     |  9 ---------
 src/wayland/meta-wayland-tablet-tool.h     |  4 ----
 11 files changed, 23 insertions(+), 92 deletions(-)
---
diff --git a/src/backends/meta-cursor-renderer.c b/src/backends/meta-cursor-renderer.c
index ba27eb848e..b80081774a 100644
--- a/src/backends/meta-cursor-renderer.c
+++ b/src/backends/meta-cursor-renderer.c
@@ -444,14 +444,14 @@ meta_cursor_renderer_force_update (MetaCursorRenderer *renderer)
 }
 
 void
-meta_cursor_renderer_set_position (MetaCursorRenderer *renderer,
-                                   float               x,
-                                   float               y)
+meta_cursor_renderer_update_position (MetaCursorRenderer *renderer)
 {
   MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer);
+  graphene_point_t pos;
 
-  priv->current_x = x;
-  priv->current_y = y;
+  clutter_input_device_get_coords (priv->device, NULL, &pos);
+  priv->current_x = pos.x;
+  priv->current_y = pos.y;
 
   meta_cursor_renderer_update_cursor (renderer, priv->displayed_cursor);
 }
diff --git a/src/backends/meta-cursor-renderer.h b/src/backends/meta-cursor-renderer.h
index 2156d91253..37ddb9100d 100644
--- a/src/backends/meta-cursor-renderer.h
+++ b/src/backends/meta-cursor-renderer.h
@@ -60,9 +60,7 @@ MetaCursorRenderer * meta_cursor_renderer_new (MetaBackend        *backend,
 void meta_cursor_renderer_set_cursor (MetaCursorRenderer *renderer,
                                       MetaCursorSprite   *cursor_sprite);
 
-void meta_cursor_renderer_set_position (MetaCursorRenderer *renderer,
-                                        float               x,
-                                        float               y);
+void meta_cursor_renderer_update_position (MetaCursorRenderer *renderer);
 void meta_cursor_renderer_force_update (MetaCursorRenderer *renderer);
 
 MetaCursorSprite * meta_cursor_renderer_get_cursor (MetaCursorRenderer *renderer);
diff --git a/src/backends/meta-cursor-tracker-private.h b/src/backends/meta-cursor-tracker-private.h
index 779c2fe521..fafc129a37 100644
--- a/src/backends/meta-cursor-tracker-private.h
+++ b/src/backends/meta-cursor-tracker-private.h
@@ -41,9 +41,7 @@ void     meta_cursor_tracker_unset_window_cursor (MetaCursorTracker *tracker);
 void     meta_cursor_tracker_set_root_cursor     (MetaCursorTracker *tracker,
                                                   MetaCursorSprite  *cursor_sprite);
 
-void     meta_cursor_tracker_update_position (MetaCursorTracker *tracker,
-                                              float              new_x,
-                                              float              new_y);
+void     meta_cursor_tracker_update_position (MetaCursorTracker *tracker);
 
 void meta_cursor_tracker_track_position (MetaCursorTracker *tracker);
 
diff --git a/src/backends/meta-cursor-tracker.c b/src/backends/meta-cursor-tracker.c
index 3c6f6a0c43..8ca962c0e7 100644
--- a/src/backends/meta-cursor-tracker.c
+++ b/src/backends/meta-cursor-tracker.c
@@ -428,31 +428,9 @@ meta_cursor_tracker_set_root_cursor (MetaCursorTracker *tracker,
 }
 
 void
-meta_cursor_tracker_update_position (MetaCursorTracker *tracker,
-                                     float              new_x,
-                                     float              new_y)
+meta_cursor_tracker_update_position (MetaCursorTracker *tracker)
 {
-  MetaCursorTrackerPrivate *priv =
-    meta_cursor_tracker_get_instance_private (tracker);
-  MetaCursorRenderer *cursor_renderer =
-    meta_backend_get_cursor_renderer (priv->backend);
-  gboolean position_changed;
-
-  if (priv->x != new_x || priv->y != new_y)
-    {
-      position_changed = TRUE;
-      priv->x = new_x;
-      priv->y = new_y;
-    }
-  else
-    {
-      position_changed = FALSE;
-    }
-
-  meta_cursor_renderer_set_position (cursor_renderer, new_x, new_y);
-
-  if (position_changed)
-    g_signal_emit (tracker, signals[CURSOR_MOVED], 0);
+  g_signal_emit (tracker, signals[CURSOR_MOVED], 0);
 }
 
 void
diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c
index 80ffe19896..c24c837961 100644
--- a/src/backends/native/meta-seat-native.c
+++ b/src/backends/native/meta-seat-native.c
@@ -2785,11 +2785,14 @@ meta_seat_native_warp_pointer (ClutterSeat *seat,
 {
   MetaSeatNative *seat_native = META_SEAT_NATIVE (seat);
   MetaBackend *backend = meta_get_backend ();
+  MetaCursorRenderer *cursor_renderer =
+    meta_backend_get_cursor_renderer (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);
+  meta_cursor_renderer_update_position (cursor_renderer);
+  meta_cursor_tracker_update_position (cursor_tracker);
 }
 
 static gboolean
diff --git a/src/backends/x11/meta-cursor-tracker-x11.c b/src/backends/x11/meta-cursor-tracker-x11.c
index 1e6c39e71d..26e2cae4cc 100644
--- a/src/backends/x11/meta-cursor-tracker-x11.c
+++ b/src/backends/x11/meta-cursor-tracker-x11.c
@@ -69,10 +69,8 @@ static void
 update_position (MetaCursorTrackerX11 *tracker_x11)
 {
   MetaCursorTracker *tracker = META_CURSOR_TRACKER (tracker_x11);
-  graphene_point_t point;
 
-  meta_cursor_tracker_get_pointer (tracker, &point, NULL);
-  meta_cursor_tracker_update_position (tracker, point.x, point.y);
+  meta_cursor_tracker_update_position (tracker);
 }
 
 static gboolean
diff --git a/src/core/events.c b/src/core/events.c
index 438beda5cb..288ba499f4 100644
--- a/src/core/events.c
+++ b/src/core/events.c
@@ -285,22 +285,21 @@ meta_display_handle_event (MetaDisplay        *display,
 #ifdef HAVE_WAYLAND
   if (meta_is_wayland_compositor () && event->type == CLUTTER_MOTION)
     {
-      MetaWaylandCompositor *compositor;
+      MetaCursorRenderer *cursor_renderer;
+      ClutterInputDevice *device;
 
-      compositor = meta_wayland_compositor_get_default ();
+      device = clutter_event_get_device (event);
+      cursor_renderer = meta_backend_get_cursor_renderer_for_device (backend,
+                                                                     device);
+      if (cursor_renderer)
+        meta_cursor_renderer_update_position (cursor_renderer);
 
-      if (meta_wayland_tablet_manager_consumes_event (compositor->tablet_manager, event))
-        {
-          meta_wayland_tablet_manager_update_cursor_position (compositor->tablet_manager, event);
-        }
-      else
+      if (device == clutter_seat_get_pointer (clutter_input_device_get_seat (device)))
         {
           MetaCursorTracker *cursor_tracker =
             meta_backend_get_cursor_tracker (backend);
 
-          meta_cursor_tracker_update_position (cursor_tracker,
-                                               event->motion.x,
-                                               event->motion.y);
+          meta_cursor_tracker_update_position (cursor_tracker);
         }
     }
 #endif
diff --git a/src/wayland/meta-wayland-tablet-manager.c b/src/wayland/meta-wayland-tablet-manager.c
index 38cec064e9..9c81d5afc2 100644
--- a/src/wayland/meta-wayland-tablet-manager.c
+++ b/src/wayland/meta-wayland-tablet-manager.c
@@ -242,30 +242,3 @@ meta_wayland_tablet_manager_ensure_seat (MetaWaylandTabletManager *manager,
 
   return tablet_seat;
 }
-
-void
-meta_wayland_tablet_manager_update_cursor_position (MetaWaylandTabletManager *manager,
-                                                    const ClutterEvent       *event)
-{
-  MetaWaylandTabletSeat *tablet_seat = NULL;
-  MetaWaylandTabletTool *tool = NULL;
-  ClutterInputDeviceTool *device_tool;
-  ClutterInputDevice *device;
-
-  device = clutter_event_get_source_device (event);
-  device_tool = clutter_event_get_device_tool (event);
-
-  if (device)
-    tablet_seat = meta_wayland_tablet_manager_lookup_seat (manager, device);
-
-  if (tablet_seat && device_tool)
-    tool = meta_wayland_tablet_seat_lookup_tool (tablet_seat, device_tool);
-
-  if (tool)
-    {
-      gfloat new_x, new_y;
-
-      clutter_event_get_coords (event, &new_x, &new_y);
-      meta_wayland_tablet_tool_set_cursor_position (tool, new_x, new_y);
-    }
-}
diff --git a/src/wayland/meta-wayland-tablet-manager.h b/src/wayland/meta-wayland-tablet-manager.h
index 5d4b28c2d6..83f9d3d0f4 100644
--- a/src/wayland/meta-wayland-tablet-manager.h
+++ b/src/wayland/meta-wayland-tablet-manager.h
@@ -50,7 +50,4 @@ MetaWaylandTabletSeat *
          meta_wayland_tablet_manager_ensure_seat    (MetaWaylandTabletManager *manager,
                                                      MetaWaylandSeat          *seat);
 
-void     meta_wayland_tablet_manager_update_cursor_position (MetaWaylandTabletManager *manager,
-                                                             const ClutterEvent       *event);
-
 #endif /* META_WAYLAND_TABLET_MANAGER_H */
diff --git a/src/wayland/meta-wayland-tablet-tool.c b/src/wayland/meta-wayland-tablet-tool.c
index 9a89a3f4b3..d37d349b9e 100644
--- a/src/wayland/meta-wayland-tablet-tool.c
+++ b/src/wayland/meta-wayland-tablet-tool.c
@@ -984,15 +984,6 @@ meta_wayland_tablet_tool_handle_event (MetaWaylandTabletTool *tool,
   return CLUTTER_EVENT_STOP;
 }
 
-void
-meta_wayland_tablet_tool_set_cursor_position (MetaWaylandTabletTool *tool,
-                                              float                  new_x,
-                                              float                  new_y)
-{
-  if (tool->cursor_renderer)
-    meta_cursor_renderer_set_position (tool->cursor_renderer, new_x, new_y);
-}
-
 static gboolean
 tablet_tool_can_grab_surface (MetaWaylandTabletTool *tool,
                               MetaWaylandSurface    *surface)
diff --git a/src/wayland/meta-wayland-tablet-tool.h b/src/wayland/meta-wayland-tablet-tool.h
index 7cf1d90770..e9ad7db40c 100644
--- a/src/wayland/meta-wayland-tablet-tool.h
+++ b/src/wayland/meta-wayland-tablet-tool.h
@@ -78,10 +78,6 @@ void     meta_wayland_tablet_tool_update              (MetaWaylandTabletTool  *t
 gboolean meta_wayland_tablet_tool_handle_event        (MetaWaylandTabletTool  *tool,
                                                        const ClutterEvent     *event);
 
-void     meta_wayland_tablet_tool_set_cursor_position (MetaWaylandTabletTool  *tool,
-                                                       float                   new_x,
-                                                       float                   new_y);
-
 gboolean meta_wayland_tablet_tool_can_grab_surface (MetaWaylandTabletTool *tool,
                                                     MetaWaylandSurface    *surface,
                                                     uint32_t               serial);


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