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

강정현 jhyuni.kang at samsung.com
Tue Aug 2 04:42:37 UTC 2016


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.

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;
 	libinput_device_get_name;
 	libinput_device_get_output_name;
 	libinput_device_get_seat;
-- 
1.9.1

============================================================================
===========

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-evdev-Support-a-API-to-provide-bustype-information.patch
Type: application/octet-stream
Size: 3332 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20160802/8e74e822/attachment.obj>


More information about the wayland-devel mailing list