[mutter/wip/carlosg/unthrottled-wayland: 173/180] clutter: Unify picking and device updating




commit a3b3b029c0eb58562711eda7ca4126fadf349ecb
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Jun 25 19:50:26 2021 +0200

    clutter: Unify picking and device updating
    
    Add a clutter_stage_pick_and_update_device() method that is the only
    single entry point for updating a device position as seen by the
    stage.
    
    Also, update all callers to use it.

 clutter/clutter/clutter-main.c          | 41 ++++++++-------------
 clutter/clutter/clutter-stage-private.h | 12 ++++++
 clutter/clutter/clutter-stage.c         | 65 ++++++++++++++++++++-------------
 3 files changed, 67 insertions(+), 51 deletions(-)
---
diff --git a/clutter/clutter/clutter-main.c b/clutter/clutter/clutter-main.c
index e562b3ed2f..c6b38c941c 100644
--- a/clutter/clutter/clutter-main.c
+++ b/clutter/clutter/clutter-main.c
@@ -1193,28 +1193,22 @@ update_device_for_event (ClutterStage *stage,
 {
   ClutterInputDevice *device = clutter_event_get_device (event);
   ClutterEventSequence *sequence = clutter_event_get_event_sequence (event);
-  ClutterActor *new_actor;
+  ClutterDeviceUpdateFlags flags = CLUTTER_DEVICE_UPDATE_NONE;
   graphene_point_t point;
   uint32_t time;
 
   clutter_event_get_coords (event, &point.x, &point.y);
   time = clutter_event_get_time (event);
 
-  new_actor =
-    clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_REACTIVE,
-                                    point.x, point.y);
+  if (emit_crossing)
+    flags |= CLUTTER_DEVICE_UPDATE_EMIT_CROSSING;
 
-  /* Picking should never fail, but if it does, we bail out here */
-  g_return_val_if_fail (new_actor != NULL, NULL);
-
-  clutter_stage_update_device (stage,
-                               device, sequence,
-                               point,
-                               time,
-                               new_actor,
-                               emit_crossing);
-
-  return new_actor;
+  return clutter_stage_pick_and_update_device (stage,
+                                               device,
+                                               sequence,
+                                               flags,
+                                               point,
+                                               time);
 }
 
 /**
@@ -1385,19 +1379,14 @@ clutter_stage_repick_device (ClutterStage       *stage,
                              ClutterInputDevice *device)
 {
   graphene_point_t point;
-  ClutterActor *new_actor;
 
   clutter_stage_get_device_coords (stage, device, NULL, &point);
-  new_actor =
-    clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_REACTIVE,
-                                    point.x, point.y);
-
-  clutter_stage_update_device (stage,
-                               device, NULL,
-                               point,
-                               CLUTTER_CURRENT_TIME,
-                               new_actor,
-                               TRUE);
+  clutter_stage_pick_and_update_device (stage,
+                                        device,
+                                        NULL,
+                                        CLUTTER_DEVICE_UPDATE_EMIT_CROSSING,
+                                        point,
+                                        time);
 }
 
 static void
diff --git a/clutter/clutter/clutter-stage-private.h b/clutter/clutter/clutter-stage-private.h
index a71b5df826..911b2c5eb5 100644
--- a/clutter/clutter/clutter-stage-private.h
+++ b/clutter/clutter/clutter-stage-private.h
@@ -31,6 +31,12 @@
 
 G_BEGIN_DECLS
 
+typedef enum
+{
+  CLUTTER_DEVICE_UPDATE_NONE = 0,
+  CLUTTER_DEVICE_UPDATE_EMIT_CROSSING = 1 << 0,
+} ClutterDeviceUpdateFlags;
+
 /* stage */
 ClutterStageWindow *_clutter_stage_get_default_window    (void);
 
@@ -134,6 +140,12 @@ void clutter_stage_update_device_entry (ClutterStage         *self,
 void clutter_stage_remove_device_entry (ClutterStage         *self,
                                         ClutterInputDevice   *device,
                                         ClutterEventSequence *sequence);
+ClutterActor * clutter_stage_pick_and_update_device (ClutterStage             *stage,
+                                                     ClutterInputDevice       *device,
+                                                     ClutterEventSequence     *sequence,
+                                                     ClutterDeviceUpdateFlags  flags,
+                                                     graphene_point_t          point,
+                                                     uint32_t                  time);
 
 G_END_DECLS
 
diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c
index 6be7dec20e..9dab513842 100644
--- a/clutter/clutter/clutter-stage.c
+++ b/clutter/clutter/clutter-stage.c
@@ -977,22 +977,16 @@ clutter_stage_update_devices (ClutterStage *stage,
     {
       ClutterInputDevice *device = l->data;
       PointerDeviceEntry *entry = NULL;
-      ClutterActor *new_actor;
 
       entry = g_hash_table_lookup (priv->pointer_devices, device);
       g_assert (entry != NULL);
 
-      new_actor = _clutter_stage_do_pick (stage,
-                                          entry->coords.x,
-                                          entry->coords.y,
-                                          CLUTTER_PICK_REACTIVE);
-
-      clutter_stage_update_device (stage,
-                                   device, NULL,
-                                   entry->coords,
-                                   CLUTTER_CURRENT_TIME,
-                                   new_actor,
-                                   TRUE);
+      clutter_stage_pick_and_update_device (stage,
+                                            device,
+                                            NULL,
+                                            CLUTTER_DEVICE_UPDATE_EMIT_CROSSING,
+                                            entry->coords,
+                                            CLUTTER_CURRENT_TIME);
     }
 }
 
@@ -3408,22 +3402,15 @@ on_device_actor_reactive_changed (ClutterActor       *actor,
                                   PointerDeviceEntry *entry)
 {
   ClutterStage *self = entry->stage;
-  ClutterActor *new_device_actor;
 
   g_assert (!clutter_actor_get_reactive (actor));
 
-  new_device_actor =
-    _clutter_stage_do_pick (self,
-                            entry->coords.x,
-                            entry->coords.y,
-                            CLUTTER_PICK_REACTIVE);
-
-  clutter_stage_update_device (self,
-                               entry->device, entry->sequence,
-                               entry->coords,
-                               CLUTTER_CURRENT_TIME,
-                               new_device_actor,
-                               TRUE);
+  clutter_stage_pick_and_update_device (self,
+                                        entry->device,
+                                        entry->sequence,
+                                        CLUTTER_DEVICE_UPDATE_EMIT_CROSSING,
+                                        entry->coords,
+                                        CLUTTER_CURRENT_TIME);
 }
 
 static void
@@ -3597,3 +3584,31 @@ clutter_stage_get_device_coords (ClutterStage         *stage,
   if (entry && coords)
     *coords = entry->coords;
 }
+
+ClutterActor *
+clutter_stage_pick_and_update_device (ClutterStage             *stage,
+                                      ClutterInputDevice       *device,
+                                      ClutterEventSequence     *sequence,
+                                      ClutterDeviceUpdateFlags  flags,
+                                      graphene_point_t          point,
+                                      uint32_t                  time)
+{
+  ClutterActor *new_actor;
+
+  new_actor = _clutter_stage_do_pick (stage,
+                                      point.x,
+                                      point.y,
+                                      CLUTTER_PICK_REACTIVE);
+
+  /* Picking should never fail, but if it does, we bail out here */
+  g_return_val_if_fail (new_actor != NULL, NULL);
+
+  clutter_stage_update_device (stage,
+                               device, sequence,
+                               point,
+                               time,
+                               new_actor,
+                               !!(flags & CLUTTER_DEVICE_UPDATE_EMIT_CROSSING));
+
+  return new_actor;
+}


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