From 2cd21f1b20dcec3734db8c11bf9770b1b51c1ad9 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 11 May 2016 22:36:26 +0200 Subject: [PATCH] wayland: Add MetaWaylandTabletSeat API to correlate pads/tablets All pads have one tablet, but a tablet may have multiple pads. Add API to look things up from a MetaWaylandTablet(Pad). --- src/wayland/meta-wayland-tablet-seat.c | 83 ++++++++++++++++++++++++++ src/wayland/meta-wayland-tablet-seat.h | 5 ++ 2 files changed, 88 insertions(+) diff --git a/src/wayland/meta-wayland-tablet-seat.c b/src/wayland/meta-wayland-tablet-seat.c index 6366cc35b..7b9a07e37 100644 --- a/src/wayland/meta-wayland-tablet-seat.c +++ b/src/wayland/meta-wayland-tablet-seat.c @@ -441,3 +441,86 @@ meta_wayland_tablet_seat_notify_tool (MetaWaylandTabletSeat *tablet_seat, if (resource) notify_tool_added (tablet_seat, resource, tool); } + +static GList * +lookup_grouped_devices (ClutterInputDevice *device, + ClutterInputDeviceType type) +{ + ClutterDeviceManager *device_manager; + const GSList *devices, *l; + GList *group = NULL; + MetaBackend *backend = meta_get_backend (); + +#ifdef HAVE_NATIVE_BACKEND + struct libinput_device *dev, *libinput_device; + + if (META_IS_BACKEND_NATIVE (backend)) + dev = clutter_evdev_input_device_get_libinput_device (device); +#endif + device_manager = clutter_device_manager_get_default (); + devices = clutter_device_manager_peek_devices (device_manager); + + for (l = devices; l; l = l->next) + { + if (l->data == device) + continue; + if (clutter_input_device_get_device_type (l->data) != type) + continue; + +#ifdef HAVE_NATIVE_BACKEND + if (META_IS_BACKEND_NATIVE (backend)) + { + libinput_device = clutter_evdev_input_device_get_libinput_device (l->data); + + if (libinput_device_get_device_group (dev) != + libinput_device_get_device_group (libinput_device)) + continue; + } +#endif + + group = g_list_prepend (group, l->data); + } + + return group; +} + +MetaWaylandTablet * +meta_wayland_tablet_seat_lookup_paired_tablet (MetaWaylandTabletSeat *tablet_seat, + MetaWaylandTabletPad *pad) +{ + MetaWaylandTablet *tablet; + GList *devices; + + devices = lookup_grouped_devices (pad->device, CLUTTER_TABLET_DEVICE); + + if (!devices) + return NULL; + + /* We only accept one device here */ + g_warn_if_fail (!devices->next); + + tablet = meta_wayland_tablet_seat_lookup_tablet (pad->tablet_seat, + devices->data); + g_list_free (devices); + + return tablet; +} + +GList * +meta_wayland_tablet_seat_lookup_paired_pads (MetaWaylandTabletSeat *tablet_seat, + MetaWaylandTablet *tablet) +{ + GList *l, *devices, *pads = NULL; + MetaWaylandTabletPad *pad; + + devices = lookup_grouped_devices (tablet->device, CLUTTER_PAD_DEVICE); + + for (l = devices; l; l = l->next) + { + pad = meta_wayland_tablet_seat_lookup_pad (tablet_seat, l->data); + if (pad) + pads = g_list_prepend (pads, pad); + } + + return pads; +} diff --git a/src/wayland/meta-wayland-tablet-seat.h b/src/wayland/meta-wayland-tablet-seat.h index 653f6950d..98ce4a956 100644 --- a/src/wayland/meta-wayland-tablet-seat.h +++ b/src/wayland/meta-wayland-tablet-seat.h @@ -69,4 +69,9 @@ void meta_wayland_tablet_seat_notify_tool (MetaWayland MetaWaylandTabletTool *tool, struct wl_client *client); +MetaWaylandTablet *meta_wayland_tablet_seat_lookup_paired_tablet (MetaWaylandTabletSeat *tablet_seat, + MetaWaylandTabletPad *pad); +GList *meta_wayland_tablet_seat_lookup_paired_pads (MetaWaylandTabletSeat *tablet_seat, + MetaWaylandTablet *tablet); + #endif /* META_WAYLAND_TABLET_SEAT_H */