[PATCH libinput 3/3] Use LIBINPUT_DEVICE_GROUP from udev as group identifier

Benjamin Tissoires benjamin.tissoires at gmail.com
Thu Feb 12 12:27:52 PST 2015


On Tue, Feb 10, 2015 at 1:50 AM, Peter Hutterer
<peter.hutterer at who-t.net> wrote:
> From: Benjamin Tissoires <benjamin.tissoires at gmail.com>
>
> Store it as identifier in the device group, any two devices that have a
> the same non-NULL identifier share the group.
>
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---

This one diverged quite a lot from my first patch :)

Anyway, it is Signed-off-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>

>  doc/device-configuration-via-udev.dox |  5 +++++
>  src/evdev.c                           | 42 ++++++++++++++++++++++++++++++-----
>  src/libinput-private.h                |  3 ++-
>  src/libinput.c                        | 17 +++++++++++---
>  src/libinput.h                        |  3 +++
>  5 files changed, 61 insertions(+), 9 deletions(-)
>
> diff --git a/doc/device-configuration-via-udev.dox b/doc/device-configuration-via-udev.dox
> index bee3659..68a45af 100644
> --- a/doc/device-configuration-via-udev.dox
> +++ b/doc/device-configuration-via-udev.dox
> @@ -12,6 +12,11 @@ The following udev properties are supported:
>  <dd>Sets the calibration matrix, see
>  libinput_device_config_calibration_get_default_matrix(). If unset,
>  defaults to the identity matrix.</dd>
> +<dt>LIBINPUT_DEVICE_GROUP</dt>
> +<dd>A string identifying the @ref libinput_device_group for this device. Two
> +devices with the same property value are grouped into the same device group,
> +the value itself is irrelevant otherwise.
> +</dd>
>  <dt>ID_SEAT</dt>
>  <dd>Assigns the physical seat for this device. See
>  libinput_seat_get_physical_name(). Defaults to "seat0".</dd>
> diff --git a/src/evdev.c b/src/evdev.c
> index c2d172f..cce4df6 100644
> --- a/src/evdev.c
> +++ b/src/evdev.c
> @@ -1579,6 +1579,42 @@ out:
>         return rc;
>  }
>
> +static int
> +evdev_set_device_group(struct evdev_device *device,
> +                      struct udev_device *udev_device)
> +{
> +       struct libinput_device_group *group = NULL;
> +       const char *udev_group;
> +
> +       udev_group = udev_device_get_property_value(udev_device,
> +                                                   "LIBINPUT_DEVICE_GROUP");
> +       if (udev_group) {
> +               struct libinput_device *d;
> +
> +               list_for_each(d, &device->base.seat->devices_list, link) {
> +                       const char *identifier = d->group->identifier;
> +
> +                       if (identifier &&
> +                           strcmp(identifier, udev_group) == 0) {
> +                               group = d->group;
> +                               break;
> +                       }
> +               }
> +       }
> +
> +       if (!group) {
> +               group = libinput_device_group_create(udev_group);
> +               if (!group)
> +                       return 1;
> +               libinput_device_set_device_group(&device->base, group);
> +               libinput_device_group_unref(group);
> +       } else {
> +               libinput_device_set_device_group(&device->base, group);
> +       }
> +
> +       return 0;
> +}
> +
>  struct evdev_device *
>  evdev_device_create(struct libinput_seat *seat,
>                     struct udev_device *udev_device)
> @@ -1589,7 +1625,6 @@ evdev_device_create(struct libinput_seat *seat,
>         int fd;
>         int unhandled_device = 0;
>         const char *devnode = udev_device_get_devnode(udev_device);
> -       struct libinput_device_group *group;
>
>         /* Use non-blocking mode so that we can loop on read on
>          * evdev_device_data() until all events on the fd are
> @@ -1660,11 +1695,8 @@ evdev_device_create(struct libinput_seat *seat,
>         if (!device->source)
>                 goto err;
>
> -       group = libinput_device_group_create();
> -       if (!group)
> +       if (evdev_set_device_group(device, udev_device))
>                 goto err;
> -       libinput_device_set_device_group(&device->base, group);
> -       libinput_device_group_unref(group);
>
>         list_insert(seat->devices_list.prev, &device->base.link);
>
> diff --git a/src/libinput-private.h b/src/libinput-private.h
> index 23f66e4..14f5d67 100644
> --- a/src/libinput-private.h
> +++ b/src/libinput-private.h
> @@ -168,6 +168,7 @@ struct libinput_device_config {
>  struct libinput_device_group {
>         int refcount;
>         void *user_data;
> +       char *identifier; /* unique identifier or NULL for singletons */
>  };
>
>  struct libinput_device {
> @@ -247,7 +248,7 @@ libinput_device_init(struct libinput_device *device,
>                      struct libinput_seat *seat);
>
>  struct libinput_device_group *
> -libinput_device_group_create(void);
> +libinput_device_group_create(const char *identifier);
>
>  void
>  libinput_device_set_device_group(struct libinput_device *device,
> diff --git a/src/libinput.c b/src/libinput.c
> index 81862d5..634bd0f 100644
> --- a/src/libinput.c
> +++ b/src/libinput.c
> @@ -1401,13 +1401,23 @@ libinput_device_group_ref(struct libinput_device_group *group)
>  }
>
>  struct libinput_device_group *
> -libinput_device_group_create(void)
> +libinput_device_group_create(const char *identifier)
>  {
>         struct libinput_device_group *group;
>
>         group = zalloc(sizeof *group);
> -       if (group)
> -               group->refcount = 1;
> +       if (!group)
> +               return NULL;
> +
> +       group->refcount = 1;
> +       if (identifier) {
> +               group->identifier = strdup(identifier);
> +               if (!group->identifier) {
> +                       free(group);
> +                       group = NULL;
> +               }
> +       }
> +
>         return group;
>  }
>
> @@ -1422,6 +1432,7 @@ libinput_device_set_device_group(struct libinput_device *device,
>  static void
>  libinput_device_group_destroy(struct libinput_device_group *group)
>  {
> +       free(group->identifier);
>         free(group);
>  }
>
> diff --git a/src/libinput.h b/src/libinput.h
> index 577c006..7c7324c 100644
> --- a/src/libinput.h
> +++ b/src/libinput.h
> @@ -1471,6 +1471,9 @@ libinput_device_get_context(struct libinput_device *device);
>   * libinput_device_group_unref() to continue using the handle outside of the
>   * immediate scope.
>   *
> + * Device groups are assigned based on the <b>LIBINPUT_DEVICE_GROUP</b> udev
> + * property, see @ref udev_config.
> + *
>   * @return The device group this device belongs to
>   */
>  struct libinput_device_group *
> --
> 2.1.0
>


More information about the wayland-devel mailing list