[libinput] How I get to device's bustype using libinput API?

Peter Hutterer peter.hutterer at who-t.net
Tue Aug 2 06:45:51 UTC 2016


On Tue, Aug 02, 2016 at 01:42:37PM +0900, ������ wrote:
> Hello, guys.
> 
> I have a one question about the libinput API.
> 
> I want to get device's bustype to know how this device is connected.
> But there is no thie API and that API is supported only in libevdev.
> 
> But other APIs to get device information are supported(abstracted) in
> libinput.
> libevdev_get_id_product() -> libinput_device_get_id_product()
> libevdev_get_id_vendor()  ->  libinput_device_get_id_vendor()
> 
> I don't know why libevdev_get_id_bustype() is not abstracted.
> There is a another way to get bustype?
> If it is exist, please let me know.

the main reason is that vid/pid is a fairly common way of filtering devices
(e.g. "all wacom devices" or "all apple devices"). bustype isn't quite that
important which is why we didn't add it initially. moreover, any client
smart enough to handle bustype will likely need extra information like
bluetooth connection status, etc. In that case you can get that information
through the udev device - together with the bustype.

I can't remember a specific reason why bustype couldn't be exported as well
but out of interest, why do you need it?

> But if it isn't exist how about add a new API to get bustype like my patch
> file?
> I attached my patch file and if it looks good, I update to it using git.
> 
> My patch file like below.
> 
> Please give me opinions.
> Thanks and regards,
> JengHyun Kang.
> 
> ============================================================================
> ===========
> 
> From 0fb1727621932a24ea33795c1da3988f134974df Mon Sep 17 00:00:00 2001
> From: JengHyun Kang <jhyuni.kang at samsung.com>
> Date: Tue, 2 Aug 2016 12:27:21 +0900
> Subject: [PATCH] evdev: Support a API to provide bustype information
> 
> There are APIs to get device's specific information,
> such as libinput_device_get_id_product() and
> libinput_device_get_id_vendor().
> These APIs abstract libevdev APIs,
> such as libevdev_get_id_product() and
> libevdev_get_id_vendor().
> But there is no abstraction API to get bustype.
> 
> Bustype sometimes provides proper information to know
> how this device is connected.
> So I added this API to get device's bustype.
> ---
>  src/evdev.c      |  6 ++++++
>  src/evdev.h      |  3 +++
>  src/libinput.c   |  6 ++++++
>  src/libinput.h   | 11 +++++++++++
>  src/libinput.sym |  1 +
>  5 files changed, 27 insertions(+)
> 
> diff --git a/src/evdev.c b/src/evdev.c
> index 375d0a5..0378401 100644
> --- a/src/evdev.c
> +++ b/src/evdev.c
> @@ -2560,6 +2560,12 @@ evdev_device_get_id_vendor(struct evdev_device
> *device)
>  	return libevdev_get_id_vendor(device->evdev);
>  }
>  
> +unsigned int
> +evdev_device_get_id_bustype(struct evdev_device *device)
> +{
> +	return libevdev_get_id_bustype(device->evdev);
> +}
> +
>  struct udev_device *
>  evdev_device_get_udev_device(struct evdev_device *device)
>  {
> diff --git a/src/evdev.h b/src/evdev.h
> index f73b88b..ec389c1 100644
> --- a/src/evdev.h
> +++ b/src/evdev.h
> @@ -356,6 +356,9 @@ evdev_device_get_id_product(struct evdev_device
> *device);
>  unsigned int
>  evdev_device_get_id_vendor(struct evdev_device *device);
>  
> +unsigned int
> +evdev_device_get_id_bustype(struct evdev_device *device);
> +
>  struct udev_device *
>  evdev_device_get_udev_device(struct evdev_device *device);
>  
> diff --git a/src/libinput.c b/src/libinput.c
> index a8240bd..610a01b 100644
> --- a/src/libinput.c
> +++ b/src/libinput.c
> @@ -2775,6 +2775,12 @@ libinput_device_get_id_vendor(struct libinput_device
> *device)
>  	return evdev_device_get_id_vendor((struct evdev_device *) device);
>  }
>  
> +LIBINPUT_EXPORT unsigned int
> +libinput_device_get_id_bustype(struct libinput_device *device)
> +{
> +	return evdev_device_get_id_bustype((struct evdev_device *) device);
> +}
> +
>  LIBINPUT_EXPORT const char *
>  libinput_device_get_output_name(struct libinput_device *device)
>  {
> diff --git a/src/libinput.h b/src/libinput.h
> index 83e58b6..fb94bac 100644
> --- a/src/libinput.h
> +++ b/src/libinput.h
> @@ -3355,6 +3355,17 @@ libinput_device_get_id_vendor(struct libinput_device
> *device);
>  /**
>   * @ingroup device
>   *
> + * Get the bustype ID for this device.
> + *
> + * @param device A previously obtained device
> + * @return The bustype ID of this device
> + */
> +unsigned int
> +libinput_device_get_id_bustype(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/src/libinput.sym b/src/libinput.sym
> index cb3f2b8..faf4ce0 100644
> --- a/src/libinput.sym
> +++ b/src/libinput.sym
> @@ -42,6 +42,7 @@ global:
>  	libinput_device_get_device_group;
>  	libinput_device_get_id_product;
>  	libinput_device_get_id_vendor;
> +	libinput_device_get_id_bustype;

you have to start a new block for this. adding it here breaks the ABI
versioning (see the rest of the file, you can only add new version blocks
but not modify existing ones)

plus, I notice the tests for the new API must've gotten lost in a rebase ;)

Cheers,
   Peter

>  	libinput_device_get_name;
>  	libinput_device_get_output_name;
>  	libinput_device_get_seat;
> -- 
> 1.9.1
> 


More information about the wayland-devel mailing list