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
This commit is contained in:
Carlos Garnacho 2020-10-06 13:44:27 +02:00
parent ea179ed8d4
commit b9e5a2d6e2

View File

@ -1485,31 +1485,42 @@ 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)
@ -2861,6 +2872,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);
}
}
}