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 */