[mutter/wip/carlosg/input-thread: 60/159] clutter-seat: Handle device events and emit signals
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/carlosg/input-thread: 60/159] clutter-seat: Handle device events and emit signals
- Date: Wed, 12 Aug 2020 17:24:02 +0000 (UTC)
commit 576154384fcd8ff41ce296865856a0a991924140
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Fri Jul 17 17:40:12 2020 +0200
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
clutter/clutter/clutter-main.c | 11 +++++++++++
clutter/clutter/clutter-seat.c | 40 ++++++++++++++++++++++++++++++++++++++++
clutter/clutter/clutter-seat.h | 6 ++++++
3 files changed, 57 insertions(+)
---
diff --git a/clutter/clutter/clutter-main.c b/clutter/clutter/clutter-main.c
index e78a33e2d4..c36e7a77c2 100644
--- a/clutter/clutter/clutter-main.c
+++ b/clutter/clutter/clutter-main.c
@@ -2051,6 +2051,17 @@ _clutter_process_event_details (ClutterActor *stage,
case CLUTTER_CLIENT_MESSAGE:
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:
break;
}
diff --git a/clutter/clutter/clutter-seat.c b/clutter/clutter/clutter-seat.c
index 73672bd361..ba9f2f55aa 100644
--- a/clutter/clutter/clutter-seat.c
+++ b/clutter/clutter/clutter-seat.c
@@ -674,6 +674,46 @@ clutter_seat_compress_motion (ClutterSeat *seat,
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
clutter_seat_warp_pointer (ClutterSeat *seat,
int x,
diff --git a/clutter/clutter/clutter-seat.h b/clutter/clutter/clutter-seat.h
index 7818647af5..aa88d73003 100644
--- a/clutter/clutter/clutter-seat.h
+++ b/clutter/clutter/clutter-seat.h
@@ -106,6 +106,9 @@ struct _ClutterSeatClass
ClutterEvent *event,
const ClutterEvent *to_discard);
+ gboolean (* handle_device_event) (ClutterSeat *seat,
+ ClutterEvent *event);
+
void (* warp_pointer) (ClutterSeat *seat,
int x,
int y);
@@ -181,6 +184,9 @@ void clutter_seat_compress_motion (ClutterSeat *seat,
ClutterEvent *event,
const ClutterEvent *to_discard);
+gboolean clutter_seat_handle_device_event (ClutterSeat *seat,
+ ClutterEvent *event);
+
CLUTTER_EXPORT
void clutter_seat_warp_pointer (ClutterSeat *seat,
int x,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]