In some cases the compositor will want to know which keys (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 <hdego...@redhat.com> --- src/evdev.c | 6 ++++++ src/evdev.h | 3 +++ src/libinput.c | 6 ++++++ src/libinput.h | 13 +++++++++++++ 4 files changed, 28 insertions(+) diff --git a/src/evdev.c b/src/evdev.c index 3aa87a7..b39b484 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -1480,6 +1480,12 @@ evdev_device_get_size(struct evdev_device *device, return 0; } +int +evdev_device_has_key(struct evdev_device *device, uint32_t keycode) +{ + return libevdev_has_event_code(device->evdev, EV_KEY, keycode); +} + void evdev_post_scroll(struct evdev_device *device, uint64_t time, diff --git a/src/evdev.h b/src/evdev.h index 666c8dc..6867db6 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_key(struct evdev_device *device, uint32_t keycode); + double evdev_device_transform_x(struct evdev_device *device, double x, diff --git a/src/libinput.c b/src/libinput.c index 35262dd..abbfb10 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_key(struct libinput_device *device, uint32_t keycode) +{ + return evdev_device_has_key((struct evdev_device *)device, keycode); +} + 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 166c5f3..cdd8186 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1434,6 +1434,19 @@ libinput_device_get_size(struct libinput_device *device, double *width, double *height); +/** + * @ingroup device + * + * Check if a device has a key or button with the passed in keycode + * (see linux/input.h). + * + * @param device A current input device + * @param keycode keycode to check for + * + * @return 1 if the device supports this keycode, or 0 otherwise. + */ +int +libinput_device_has_key(struct libinput_device *device, uint32_t keycode); /** * @defgroup config Device configuration -- 2.1.0 _______________________________________________ wayland-devel mailing list wayland-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/wayland-devel