From d791a7ab093435172194716647cb6792a7ba7029 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jonas=20=C3=85dahl?= Date: Sun, 15 Dec 2013 17:45:02 +0100 Subject: [PATCH] Introduce libinput_device_has_capability() API MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonas Ådahl --- src/evdev.c | 16 ++++++++++++++++ src/evdev.h | 4 ++++ src/libinput.c | 8 ++++++++ src/libinput.h | 11 +++++++++++ 4 files changed, 39 insertions(+) diff --git a/src/evdev.c b/src/evdev.c index 029f029..7d023c0 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -693,6 +693,22 @@ evdev_device_calibrate(struct evdev_device *device, float calibration[6]) memcpy(device->abs.calibration, calibration, sizeof device->abs.calibration); } +int +evdev_device_has_capability(struct evdev_device *device, + enum libinput_device_capability capability) +{ + switch (capability) { + case LIBINPUT_DEVICE_CAP_POINTER: + return !!(device->seat_caps & EVDEV_DEVICE_POINTER); + case LIBINPUT_DEVICE_CAP_KEYBOARD: + return !!(device->seat_caps & EVDEV_DEVICE_KEYBOARD); + case LIBINPUT_DEVICE_CAP_TOUCH: + return !!(device->seat_caps & EVDEV_DEVICE_TOUCH); + default: + return 0; + } +} + void evdev_device_remove(struct evdev_device *device) { diff --git a/src/evdev.h b/src/evdev.h index 3fa8e1d..e11af5d 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -152,6 +152,10 @@ evdev_device_get_output(struct evdev_device *device); void evdev_device_calibrate(struct evdev_device *device, float calibration[6]); +int +evdev_device_has_capability(struct evdev_device *device, + enum libinput_device_capability capability); + void evdev_device_remove(struct evdev_device *device); diff --git a/src/libinput.c b/src/libinput.c index c738eeb..a563e94 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -961,3 +961,11 @@ libinput_device_calibrate(struct libinput_device *device, { evdev_device_calibrate((struct evdev_device *) device, calibration); } + +LIBINPUT_EXPORT int +libinput_device_has_capability(struct libinput_device *device, + enum libinput_device_capability capability) +{ + return evdev_device_has_capability((struct evdev_device *) device, + capability); +} diff --git a/src/libinput.h b/src/libinput.h index f24d49d..b591bd0 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -667,4 +667,15 @@ void libinput_device_calibrate(struct libinput_device *device, float calibration[6]); +/** + * @ingroup device + * + * Check if the given device has the specified capability + * + * @return 1 if the given device has the capability or 0 if not + */ +int +libinput_device_has_capability(struct libinput_device *device, + enum libinput_device_capability capability); + #endif /* LIBINPUT_H */ -- 2.7.4