From 0ce30935d7076207316d503c5fdf9825433f1ffd Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Thu, 6 Nov 2014 12:27:35 +0100 Subject: [PATCH] Add libinput_device_has_button function In some cases the compositor will want to know which buttons a device has. E.g. for scrolling we want the compositor to be able to set a button to change a relative device (e.g. a trackball) into scroll mode, so that it sends scroll-axis events instead of pointer motion events. In order for the compositor to be able to present a sane UI for this, it needs to know which buttons a device has. Signed-off-by: Hans de Goede Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev.c | 9 +++++++++ src/evdev.h | 3 +++ src/libinput.c | 6 ++++++ src/libinput.h | 14 ++++++++++++++ 4 files changed, 32 insertions(+) diff --git a/src/evdev.c b/src/evdev.c index 94daea8d..146c1b70 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -1491,6 +1491,15 @@ evdev_device_get_size(struct evdev_device *device, return 0; } +int +evdev_device_has_button(struct evdev_device *device, uint32_t code) +{ + if (!(device->seat_caps & EVDEV_DEVICE_POINTER)) + return -1; + + return libevdev_has_event_code(device->evdev, EV_KEY, code); +} + static inline bool evdev_is_scrolling(const struct evdev_device *device, enum libinput_pointer_axis axis) diff --git a/src/evdev.h b/src/evdev.h index 279a3aee..49a01494 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -239,6 +239,9 @@ evdev_device_get_size(struct evdev_device *device, double *w, double *h); +int +evdev_device_has_button(struct evdev_device *device, uint32_t code); + double evdev_device_transform_x(struct evdev_device *device, double x, diff --git a/src/libinput.c b/src/libinput.c index 67fa2bdd..a293f0ff 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1254,6 +1254,12 @@ libinput_device_get_size(struct libinput_device *device, height); } +LIBINPUT_EXPORT int +libinput_device_has_button(struct libinput_device *device, uint32_t code) +{ + return evdev_device_has_button((struct evdev_device *)device, code); +} + LIBINPUT_EXPORT struct libinput_event * libinput_event_device_notify_get_base_event(struct libinput_event_device_notify *event) { diff --git a/src/libinput.h b/src/libinput.h index 69a7e525..8bb37800 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1440,6 +1440,20 @@ libinput_device_get_size(struct libinput_device *device, double *width, double *height); +/** + * @ingroup device + * + * Check if a @ref LIBINPUT_DEVICE_CAP_POINTER device has a button with the + * passed in code (see linux/input.h). + * + * @param device A current input device + * @param code button code to check for + * + * @return 1 if the device supports this button code, 0 if it does not, -1 + * on error. + */ +int +libinput_device_has_button(struct libinput_device *device, uint32_t code); /** * @defgroup config Device configuration