[PATCH libinput v2 02/11] Add libinput_device_has_button function
Hans de Goede
hdegoede at redhat.com
Mon Nov 10 02:59:13 PST 2014
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 at redhat.com>
---
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 272d165..9ce93fe 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -1500,6 +1500,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);
+}
+
void
evdev_post_scroll(struct evdev_device *device,
uint64_t time,
diff --git a/src/evdev.h b/src/evdev.h
index eefbb79..3a02384 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -237,6 +237,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 67fa2bd..a293f0f 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 c0e6583..b9a889b 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -1434,6 +1434,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
--
2.1.0
More information about the wayland-devel
mailing list