[mutter/wip/carlosg/clutter-seat: 62/69] backends: Make meta_backend_update_last_device() take a clutter device



commit fcec5f46183e9bf3589b5a5d7aea36972c3941e6
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Oct 4 18:23:49 2019 +0200

    backends: Make meta_backend_update_last_device() take a clutter device
    
    Instead of a pretty x11 specific device ID. This also updates the argument
    of the ::last-device-changed signal to be a ClutterInputDevice.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/852

 src/backends/meta-backend-private.h |  4 ++--
 src/backends/meta-backend.c         | 30 ++++++++++--------------------
 src/backends/x11/meta-backend-x11.c | 11 +++++++++--
 src/core/events.c                   |  5 +----
 4 files changed, 22 insertions(+), 28 deletions(-)
---
diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h
index 397c5f382..2e6ba8609 100644
--- a/src/backends/meta-backend-private.h
+++ b/src/backends/meta-backend-private.h
@@ -151,8 +151,8 @@ void meta_backend_freeze_updates (MetaBackend *backend);
 
 void meta_backend_thaw_updates (MetaBackend *backend);
 
-void meta_backend_update_last_device (MetaBackend *backend,
-                                      int          device_id);
+void meta_backend_update_last_device (MetaBackend        *backend,
+                                      ClutterInputDevice *device);
 
 gboolean meta_backend_get_relative_motion_deltas (MetaBackend *backend,
                                                   const        ClutterEvent *event,
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
index c5e091fe8..3f4afb572 100644
--- a/src/backends/meta-backend.c
+++ b/src/backends/meta-backend.c
@@ -148,7 +148,7 @@ struct _MetaBackendPrivate
 
   GHashTable *device_monitors;
 
-  int current_device_id;
+  ClutterInputDevice *current_device;
 
   MetaPointerConstraint *client_pointer_constraint;
   MetaDnd *dnd;
@@ -426,13 +426,13 @@ on_device_removed (ClutterDeviceManager *device_manager,
   /* If the device the user last interacted goes away, check again pointer
    * visibility.
    */
-  if (priv->current_device_id == device_id)
+  if (priv->current_device == device)
     {
       MetaCursorTracker *cursor_tracker = priv->cursor_tracker;
       gboolean has_touchscreen, has_pointing_device;
       ClutterInputDeviceType device_type;
 
-      priv->current_device_id = 0;
+      priv->current_device = NULL;
 
       device_type = clutter_input_device_get_device_type (device);
       has_touchscreen = check_has_slave_touchscreen (device_manager);
@@ -771,7 +771,7 @@ meta_backend_class_init (MetaBackendClass *klass)
                   G_SIGNAL_RUN_LAST,
                   0,
                   NULL, NULL, NULL,
-                  G_TYPE_NONE, 1, G_TYPE_INT);
+                  G_TYPE_NONE, 1, CLUTTER_TYPE_INPUT_DEVICE);
   signals[LID_IS_CLOSED_CHANGED] =
     g_signal_new ("lid-is-closed-changed",
                   G_TYPE_FROM_CLASS (object_class),
@@ -1158,17 +1158,12 @@ update_last_device (MetaBackend *backend)
   MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
   MetaCursorTracker *cursor_tracker = priv->cursor_tracker;
   ClutterInputDeviceType device_type;
-  ClutterDeviceManager *manager;
-  ClutterInputDevice *device;
 
   priv->device_update_idle_id = 0;
-  manager = clutter_device_manager_get_default ();
-  device = clutter_device_manager_get_device (manager,
-                                              priv->current_device_id);
-  device_type = clutter_input_device_get_device_type (device);
+  device_type = clutter_input_device_get_device_type (priv->current_device);
 
   g_signal_emit (backend, signals[LAST_DEVICE_CHANGED], 0,
-                 priv->current_device_id);
+                 priv->current_device);
 
   switch (device_type)
     {
@@ -1186,24 +1181,19 @@ update_last_device (MetaBackend *backend)
 }
 
 void
-meta_backend_update_last_device (MetaBackend *backend,
-                                 int          device_id)
+meta_backend_update_last_device (MetaBackend        *backend,
+                                 ClutterInputDevice *device)
 {
   MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-  ClutterDeviceManager *manager;
-  ClutterInputDevice *device;
 
-  if (priv->current_device_id == device_id)
+  if (priv->current_device == device)
     return;
 
-  manager = clutter_device_manager_get_default ();
-  device = clutter_device_manager_get_device (manager, device_id);
-
   if (!device ||
       clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_MASTER)
     return;
 
-  priv->current_device_id = device_id;
+  priv->current_device = device;
 
   if (priv->device_update_idle_id == 0)
     {
diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c
index a0fd2f5e0..7dc26f940 100644
--- a/src/backends/x11/meta-backend-x11.c
+++ b/src/backends/x11/meta-backend-x11.c
@@ -46,6 +46,7 @@
 #include "backends/meta-stage-private.h"
 #include "backends/x11/meta-clutter-backend-x11.h"
 #include "backends/x11/meta-event-x11.h"
+#include "backends/x11/meta-seat-x11.h"
 #include "backends/x11/meta-stage-x11.h"
 #include "backends/x11/meta-renderer-x11.h"
 #include "clutter/clutter.h"
@@ -230,6 +231,9 @@ handle_device_change (MetaBackendX11 *x11,
                       XIEvent        *event)
 {
   XIDeviceChangedEvent *device_changed;
+  ClutterInputDevice *device;
+  ClutterBackend *backend;
+  ClutterSeat *seat;
 
   if (event->evtype != XI_DeviceChanged)
     return;
@@ -239,8 +243,11 @@ handle_device_change (MetaBackendX11 *x11,
   if (device_changed->reason != XISlaveSwitch)
     return;
 
-  meta_backend_update_last_device (META_BACKEND (x11),
-                                   device_changed->sourceid);
+  backend = meta_backend_get_clutter_backend (META_BACKEND (x11));
+  seat = clutter_backend_get_default_seat (backend);
+  device = meta_seat_x11_lookup_device_id (META_SEAT_X11 (seat),
+                                           device_changed->sourceid);
+  meta_backend_update_last_device (META_BACKEND (x11), device);
 }
 
 /* Clutter makes the assumption that there is only one X window
diff --git a/src/core/events.c b/src/core/events.c
index d38377862..65a7792ee 100644
--- a/src/core/events.c
+++ b/src/core/events.c
@@ -273,10 +273,7 @@ meta_display_handle_event (MetaDisplay        *display,
   source = clutter_event_get_source_device (event);
 
   if (source)
-    {
-      meta_backend_update_last_device (backend,
-                                       clutter_input_device_get_device_id (source));
-    }
+    meta_backend_update_last_device (backend, source);
 
 #ifdef HAVE_WAYLAND
   if (meta_is_wayland_compositor () && event->type == CLUTTER_MOTION)


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