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 <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Hans de Goede 2014-11-06 12:27:35 +01:00 committed by Peter Hutterer
parent 5ba5c32813
commit 0ce30935d7
4 changed files with 32 additions and 0 deletions

View file

@ -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)

View file

@ -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,

View file

@ -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)
{

View file

@ -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