[mutter/wip/carlosg/initialization-device-events] backends/native: Wait to have an stage before emitting CLUTTER_DEVICE_ADDED




commit ecec931eb7d2bc8f2641e1a28289168095919c30
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Oct 6 13:44:27 2020 +0200

    backends/native: Wait to have an stage before emitting CLUTTER_DEVICE_ADDED
    
    During seat initialization, we process early libinput events (adding all known
    devices) before the seat gets a stage assigned. This causes warnings when trying
    to handle the corresponding CLUTTER_DEVICE_ADDED events, as they are sent
    stageless.
    
    As it is definitely too soon to have those events sent meaningfully, filter
    those events out and instead handle the CLUTTER_DEVICE_ADDED emission for all
    known devices after the seat receives an stage. This makes the events guaranteed
    to be emitted early in initialization, but not so soon that they can't be
    handled yet.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1472

 src/backends/native/meta-seat-native.c | 36 +++++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 7 deletions(-)
---
diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c
index 022f56983f..bcf0f55d78 100644
--- a/src/backends/native/meta-seat-native.c
+++ b/src/backends/native/meta-seat-native.c
@@ -1485,33 +1485,45 @@ process_base_event (MetaSeatNative        *seat,
                     struct libinput_event *event)
 {
   ClutterInputDevice *device = NULL;
-  ClutterEvent *device_event;
+  ClutterEvent *device_event = NULL;
   struct libinput_device *libinput_device;
+  ClutterStage *stage;
+
+  stage = meta_seat_native_get_stage (seat);
 
   switch (libinput_event_get_type (event))
     {
     case LIBINPUT_EVENT_DEVICE_ADDED:
       libinput_device = libinput_event_get_device (event);
-
       device = evdev_add_device (seat, libinput_device);
-      device_event = clutter_event_new (CLUTTER_DEVICE_ADDED);
-      clutter_event_set_device (device_event, device);
+
+      if (stage)
+        {
+          device_event = clutter_event_new (CLUTTER_DEVICE_ADDED);
+          clutter_event_set_device (device_event, device);
+        }
       break;
 
     case LIBINPUT_EVENT_DEVICE_REMOVED:
       libinput_device = libinput_event_get_device (event);
 
       device = libinput_device_get_user_data (libinput_device);
-      device_event = clutter_event_new (CLUTTER_DEVICE_REMOVED);
-      clutter_event_set_device (device_event, device);
+
+      if (stage)
+        {
+          device_event = clutter_event_new (CLUTTER_DEVICE_REMOVED);
+          clutter_event_set_device (device_event, device);
+        }
+
       evdev_remove_device (seat,
                            META_INPUT_DEVICE_NATIVE (device));
       break;
 
     default:
-      device_event = NULL;
+      break;
     }
 
+
   if (device_event)
     {
       device_event->device.stage = _clutter_input_device_get_stage (device);
@@ -2861,6 +2873,16 @@ meta_seat_native_set_stage (MetaSeatNative *seat,
       ClutterInputDevice *device = l->data;
 
       _clutter_input_device_set_stage (device, stage);
+
+      if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_PHYSICAL)
+        {
+          ClutterEvent *device_event;
+
+          device_event = clutter_event_new (CLUTTER_DEVICE_ADDED);
+          clutter_event_set_device (device_event, device);
+          device_event->device.stage = stage;
+          queue_event (device_event);
+        }
     }
 }
 


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