summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2014-10-31 10:53:53 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2014-12-03 09:09:39 +1000
commit8b7ef91c1a190fcd8363b0e128520f8d24de4bde (patch)
treebaaa38d28c623df80f301bcac04ba2844cbe1531
parent3c7e3a19735b64eaa7937035d026b62c5fccbf5c (diff)
downloadlibinput-8b7ef91c1a190fcd8363b0e128520f8d24de4bde.tar.gz
Add a function to retrieve the udev_device handle from a libinput device
The libinput device abstracts a number of things but sometimes the underlying device is important. The udev device provides the necessary handle to access that underlying device and various sysfs properties that may be necessary. A function returning the device node would've done the same thing but is more prone to race conditions than the udev_device. https://bugs.freedesktop.org/show_bug.cgi?id=85573 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
-rw-r--r--src/evdev.c6
-rw-r--r--src/evdev.h3
-rw-r--r--src/libinput.c6
-rw-r--r--src/libinput.h18
-rw-r--r--test/device.c13
5 files changed, 46 insertions, 0 deletions
diff --git a/src/evdev.c b/src/evdev.c
index 19b861f4..c2d10d7e 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -1632,6 +1632,12 @@ evdev_device_get_id_vendor(struct evdev_device *device)
return libevdev_get_id_vendor(device->evdev);
}
+struct udev_device *
+evdev_device_get_udev_device(struct evdev_device *device)
+{
+ return udev_device_ref(device->udev_device);
+}
+
void
evdev_device_set_default_calibration(struct evdev_device *device,
const float calibration[6])
diff --git a/src/evdev.h b/src/evdev.h
index e4144ecb..033d4558 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -234,6 +234,9 @@ evdev_device_get_id_product(struct evdev_device *device);
unsigned int
evdev_device_get_id_vendor(struct evdev_device *device);
+struct udev_device *
+evdev_device_get_udev_device(struct evdev_device *device);
+
void
evdev_device_set_default_calibration(struct evdev_device *device,
const float calibration[6]);
diff --git a/src/libinput.c b/src/libinput.c
index c318eeec..96b255a9 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -1226,6 +1226,12 @@ libinput_device_set_seat_logical_name(struct libinput_device *device,
name);
}
+LIBINPUT_EXPORT struct udev_device *
+libinput_device_get_udev_device(struct libinput_device *device)
+{
+ return evdev_device_get_udev_device((struct evdev_device *)device);
+}
+
LIBINPUT_EXPORT void
libinput_device_led_update(struct libinput_device *device,
enum libinput_led leds)
diff --git a/src/libinput.h b/src/libinput.h
index 26d94ff4..d567df44 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -1397,6 +1397,24 @@ libinput_device_set_seat_logical_name(struct libinput_device *device,
const char *name);
/**
+ * Return a udev handle to the device that is this libinput device, if any.
+ * The returned handle has a refcount of at least 1, the caller must call
+ * udev_device_unref() once to release the associated resources.
+ *
+ * Some devices may not have a udev device, or the udev device may be
+ * unobtainable. This function returns NULL if no udev device was available.
+ *
+ * Calling this function multiple times for the same device may not
+ * return the same udev handle each time.
+ *
+ * @param device A previously obtained device
+ * @return A udev handle to the device with a refcount of >= 1 or NULL.
+ * @retval NULL This device is not represented by a udev device
+ */
+struct udev_device *
+libinput_device_get_udev_device(struct libinput_device *device);
+
+/**
* @ingroup device
*
* Update the LEDs on the device, if any. If the device does not have
diff --git a/test/device.c b/test/device.c
index 6843824a..84984f4c 100644
--- a/test/device.c
+++ b/test/device.c
@@ -618,6 +618,17 @@ START_TEST(device_ids)
}
END_TEST
+START_TEST(device_get_udev_handle)
+{
+ struct litest_device *dev = litest_current_device();
+ struct udev_device *udev_device;
+
+ udev_device = libinput_device_get_udev_device(dev->libinput_device);
+ ck_assert_notnull(udev_device);
+ udev_device_unref(udev_device);
+}
+END_TEST
+
int main (int argc, char **argv)
{
litest_add("device:sendevents", device_sendevents_config, LITEST_ANY, LITEST_TOUCHPAD);
@@ -640,5 +651,7 @@ int main (int argc, char **argv)
litest_add("device:sendevents", device_disable_topsoftbutton, LITEST_TOPBUTTONPAD, LITEST_ANY);
litest_add("device:id", device_ids, LITEST_ANY, LITEST_ANY);
+ litest_add("device:udev", device_get_udev_handle, LITEST_ANY, LITEST_ANY);
+
return litest_run(argc, argv);
}