clutter-seat: Handle device events and emit signals

Clutter device events are special events coming from the backend when an
input device is added or removed.

When such events are processed, we should make the seat to handle them by
calling vfunc that can be implemented by each backend and eventually
emitting the appropriate signal.

If a device is removed, we can also safely dispose it, as it can be
considered stale at this point.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1371
This commit is contained in:
Marco Trevisan (Treviño) 2020-07-17 17:40:12 +02:00 committed by Carlos Garnacho
parent cd00e69ce3
commit 5563bfe7d9
3 changed files with 57 additions and 0 deletions

View File

@ -1954,6 +1954,17 @@ _clutter_process_event_details (ClutterActor *stage,
case CLUTTER_CLIENT_MESSAGE: case CLUTTER_CLIENT_MESSAGE:
break; break;
case CLUTTER_DEVICE_ADDED:
case CLUTTER_DEVICE_REMOVED:
if (!_clutter_event_process_filters (event))
{
ClutterSeat *seat;
seat = clutter_backend_get_default_seat (context->backend);
clutter_seat_handle_device_event (seat, event);
}
break;
case CLUTTER_EVENT_LAST: case CLUTTER_EVENT_LAST:
break; break;
} }

View File

@ -674,6 +674,46 @@ clutter_seat_compress_motion (ClutterSeat *seat,
seat_class->compress_motion (seat, event, to_discard); seat_class->compress_motion (seat, event, to_discard);
} }
gboolean
clutter_seat_handle_device_event (ClutterSeat *seat,
ClutterEvent *event)
{
ClutterSeatClass *seat_class;
ClutterInputDevice *device;
g_return_val_if_fail (CLUTTER_IS_SEAT (seat), FALSE);
g_return_val_if_fail (event, FALSE);
g_assert (event->type == CLUTTER_DEVICE_ADDED ||
event->type == CLUTTER_DEVICE_REMOVED);
seat_class = CLUTTER_SEAT_GET_CLASS (seat);
if (seat_class->handle_device_event)
{
if (!seat_class->handle_device_event (seat, event))
return FALSE;
}
device = clutter_event_get_source_device (event);
g_assert_true (CLUTTER_IS_INPUT_DEVICE (device));
switch (event->type)
{
case CLUTTER_DEVICE_ADDED:
g_signal_emit (seat, signals[DEVICE_ADDED], 0, device);
break;
case CLUTTER_DEVICE_REMOVED:
g_signal_emit (seat, signals[DEVICE_REMOVED], 0, device);
g_object_run_dispose (G_OBJECT (device));
break;
default:
break;
}
return TRUE;
}
void void
clutter_seat_warp_pointer (ClutterSeat *seat, clutter_seat_warp_pointer (ClutterSeat *seat,
int x, int x,

View File

@ -106,6 +106,9 @@ struct _ClutterSeatClass
ClutterEvent *event, ClutterEvent *event,
const ClutterEvent *to_discard); const ClutterEvent *to_discard);
gboolean (* handle_device_event) (ClutterSeat *seat,
ClutterEvent *event);
void (* warp_pointer) (ClutterSeat *seat, void (* warp_pointer) (ClutterSeat *seat,
int x, int x,
int y); int y);
@ -181,6 +184,9 @@ void clutter_seat_compress_motion (ClutterSeat *seat,
ClutterEvent *event, ClutterEvent *event,
const ClutterEvent *to_discard); const ClutterEvent *to_discard);
gboolean clutter_seat_handle_device_event (ClutterSeat *seat,
ClutterEvent *event);
CLUTTER_EXPORT CLUTTER_EXPORT
void clutter_seat_warp_pointer (ClutterSeat *seat, void clutter_seat_warp_pointer (ClutterSeat *seat,
int x, int x,