[PATCH libinput] Add functions to get the device name, PID and VID
Peter Hutterer
peter.hutterer at who-t.net
Sun Jun 29 16:15:34 PDT 2014
On Fri, Jun 27, 2014 at 10:10:30AM -0700, Jason Gerecke wrote:
> On Thu, Jun 26, 2014 at 8:02 PM, Peter Hutterer
> <peter.hutterer at who-t.net> wrote:
> > Those three are the ones that matter for logging or device identification in
> > callers, so let's provide them.
> >
> > Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
>
> Have you thought about how to handle identification for non-USB
> devices? We're starting to see tablet PC OEMs use I2C hardware, and
> from the little bit I've looked into things see that they use
> ACPI-style rather than USB-style IDs (e.g. WCOM0009 instead of
> 056a:0123). I think its possible to get USB-style IDs from the
> hardware, but TBH I've not yet been successful in getting any of those
> systems to boot into Linux to check :/
tbh, my hope was that the kernel drivers convert this into a bustype BUS_I2C
and then fill in the vendor/product IDs accordingly but looking at the
current drivers it looks like no driver does this short of a few generic
ones.
We can add a complement though to get the string ID as above and make
VID/PID return 0. For the wl protocol it's probably best to export it as a
single string as we we did in libwacom: "usb:056a:009", "i2c:WOM0009"...
Cheers,
Peter
> > ---
> > src/evdev.c | 18 ++++++++++++++++++
> > src/evdev.h | 9 +++++++++
> > src/libinput.c | 18 ++++++++++++++++++
> > src/libinput.h | 34 ++++++++++++++++++++++++++++++++++
> > test/misc.c | 20 ++++++++++++++++++++
> > 5 files changed, 99 insertions(+)
> >
> > diff --git a/src/evdev.c b/src/evdev.c
> > index f72bd43..183c200 100644
> > --- a/src/evdev.c
> > +++ b/src/evdev.c
> > @@ -857,6 +857,24 @@ evdev_device_get_sysname(struct evdev_device *device)
> > return device->sysname;
> > }
> >
> > +const char *
> > +evdev_device_get_name(struct evdev_device *device)
> > +{
> > + return device->devname;
> > +}
> > +
> > +unsigned int
> > +evdev_device_get_id_product(struct evdev_device *device)
> > +{
> > + return libevdev_get_id_product(device->evdev);
> > +}
> > +
> > +unsigned int
> > +evdev_device_get_id_vendor(struct evdev_device *device)
> > +{
> > + return libevdev_get_id_vendor(device->evdev);
> > +}
> > +
> > void
> > evdev_device_calibrate(struct evdev_device *device, float calibration[6])
> > {
> > diff --git a/src/evdev.h b/src/evdev.h
> > index 4a83a78..fad1f84 100644
> > --- a/src/evdev.h
> > +++ b/src/evdev.h
> > @@ -141,6 +141,15 @@ evdev_device_get_output(struct evdev_device *device);
> > const char *
> > evdev_device_get_sysname(struct evdev_device *device);
> >
> > +const char *
> > +evdev_device_get_name(struct evdev_device *device);
> > +
> > +unsigned int
> > +evdev_device_get_id_product(struct evdev_device *device);
> > +
> > +unsigned int
> > +evdev_device_get_id_vendor(struct evdev_device *device);
> > +
> > void
> > evdev_device_calibrate(struct evdev_device *device, float calibration[6]);
> >
> > diff --git a/src/libinput.c b/src/libinput.c
> > index 44f4f23..1918b48 100644
> > --- a/src/libinput.c
> > +++ b/src/libinput.c
> > @@ -1162,6 +1162,24 @@ libinput_device_get_sysname(struct libinput_device *device)
> > }
> >
> > LIBINPUT_EXPORT const char *
> > +libinput_device_get_name(struct libinput_device *device)
> > +{
> > + return evdev_device_get_name((struct evdev_device *) device);
> > +}
> > +
> > +LIBINPUT_EXPORT unsigned int
> > +libinput_device_get_id_product(struct libinput_device *device)
> > +{
> > + return evdev_device_get_id_product((struct evdev_device *) device);
> > +}
> > +
> > +LIBINPUT_EXPORT unsigned int
> > +libinput_device_get_id_vendor(struct libinput_device *device)
> > +{
> > + return evdev_device_get_id_vendor((struct evdev_device *) device);
> > +}
> > +
> > +LIBINPUT_EXPORT const char *
> > libinput_device_get_output_name(struct libinput_device *device)
> > {
> > return evdev_device_get_output((struct evdev_device *) device);
> > diff --git a/src/libinput.h b/src/libinput.h
> > index 99a3b2f..e8b87da 100644
> > --- a/src/libinput.h
> > +++ b/src/libinput.h
> > @@ -1257,6 +1257,40 @@ libinput_device_get_sysname(struct libinput_device *device);
> > /**
> > * @ingroup device
> > *
> > + * The lifetime of the returned string is tied to the struct
> > + * libinput_device.
> > + *
> > + * @param device A previously obtained device
> > + * @return The device name
> > + */
> > +const char *
> > +libinput_device_get_name(struct libinput_device *device);
> > +
> > +/**
> > + * @ingroup device
> > + *
> > + * Get the product ID for this device.
> > + *
> > + * @param device A previously obtained device
> > + * @return The product ID of this device
> > + */
> > +unsigned int
> > +libinput_device_get_id_product(struct libinput_device *device);
> > +
> > +/**
> > + * @ingroup device
> > + *
> > + * Get the vendor ID for this device.
> > + *
> > + * @param device A previously obtained device
> > + * @return The vendor ID of this device
> > + */
> > +unsigned int
> > +libinput_device_get_id_vendor(struct libinput_device *device);
> > +
> > +/**
> > + * @ingroup device
> > + *
> > * A device may be mapped to a single output, or all available outputs. If a
> > * device is mapped to a single output only, a relative device may not move
> > * beyond the boundaries of this output. An absolute device has its input
> > diff --git a/test/misc.c b/test/misc.c
> > index bea7e88..e467a5c 100644
> > --- a/test/misc.c
> > +++ b/test/misc.c
> > @@ -390,6 +390,25 @@ START_TEST(context_ref_counting)
> > }
> > END_TEST
> >
> > +START_TEST(device_ids)
> > +{
> > + struct litest_device *dev = litest_current_device();
> > + const char *name;
> > + int pid, vid;
> > +
> > + name = libevdev_get_name(dev->evdev);
> > + pid = libevdev_get_id_product(dev->evdev);
> > + vid = libevdev_get_id_vendor(dev->evdev);
> > +
> > + ck_assert_str_eq(name,
> > + libinput_device_get_name(dev->libinput_device));
> > + ck_assert_int_eq(pid,
> > + libinput_device_get_id_product(dev->libinput_device));
> > + ck_assert_int_eq(vid,
> > + libinput_device_get_id_vendor(dev->libinput_device));
> > +}
> > +END_TEST
> > +
> > int main (int argc, char **argv) {
> > litest_add_no_device("events:conversion", event_conversion_device_notify);
> > litest_add_no_device("events:conversion", event_conversion_pointer);
> > @@ -397,6 +416,7 @@ int main (int argc, char **argv) {
> > litest_add_no_device("events:conversion", event_conversion_key);
> > litest_add_no_device("events:conversion", event_conversion_touch);
> > litest_add_no_device("context:refcount", context_ref_counting);
> > + litest_add("device:id", device_ids, LITEST_ANY, LITEST_ANY);
> >
> > return litest_run(argc, argv);
> > }
> > --
> > 1.9.3
> >
> > _______________________________________________
> > wayland-devel mailing list
> > wayland-devel at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>
More information about the wayland-devel
mailing list