[PATCH libinput 06/10] Add a pointer acceleration API
Peter Hutterer
peter.hutterer at who-t.net
Thu Sep 18 22:44:31 PDT 2014
Only exposes one knob - speed, normalized to a [-1, 1] range with 0 being the
neutral "this is what we think is normal" speed. -1 and 1 reflect the
slowest/fastest reasonable speed on this device.
Note: with this API we commit to having any pointer accelerating as a true
gliding scale. We cannot map the [-1,1] range into a discrete set of steps
as we do not communicate to the caller whether a specific value has changed
the acceleration. Without that, a caller may assume that acceleration has
changed even when it is not visible to the user.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
src/libinput-private.h | 9 ++++++++
src/libinput.c | 40 ++++++++++++++++++++++++++++++++++
src/libinput.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 108 insertions(+)
diff --git a/src/libinput-private.h b/src/libinput-private.h
index cf03c03..614e8e1 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -109,10 +109,19 @@ struct libinput_device_config_send_events {
enum libinput_config_send_events_mode (*get_default_mode)(struct libinput_device *device);
};
+struct libinput_device_config_accel {
+ int (*available)(struct libinput_device *device);
+ enum libinput_config_status (*set_speed)(struct libinput_device *device,
+ double speed);
+ double (*get_speed)(struct libinput_device *device);
+ double (*get_default_speed)(struct libinput_device *device);
+};
+
struct libinput_device_config {
struct libinput_device_config_tap *tap;
struct libinput_device_config_calibration *calibration;
struct libinput_device_config_send_events *sendevents;
+ struct libinput_device_config_accel *accel;
};
struct libinput_device {
diff --git a/src/libinput.c b/src/libinput.c
index 14f0257..18f3496 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -1388,3 +1388,43 @@ libinput_device_config_send_events_get_default_mode(struct libinput_device *devi
{
return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
}
+
+
+LIBINPUT_EXPORT int
+libinput_device_config_accel_is_available(struct libinput_device *device)
+{
+ return device->config.accel ?
+ device->config.accel->available(device) : 0;
+}
+
+LIBINPUT_EXPORT enum libinput_config_status
+libinput_device_config_accel_set_speed(struct libinput_device *device,
+ double speed)
+{
+ if (!libinput_device_config_accel_is_available(device))
+ return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
+
+ if (speed < -1.0 || speed > 1.0)
+ return LIBINPUT_CONFIG_STATUS_INVALID;
+
+ return device->config.accel->set_speed(device, speed);
+}
+
+LIBINPUT_EXPORT double
+libinput_device_config_accel_get_speed(struct libinput_device *device)
+{
+ if (!libinput_device_config_accel_is_available(device))
+ return 0;
+
+ return device->config.accel->get_speed(device);
+}
+
+LIBINPUT_EXPORT double
+libinput_device_config_accel_get_default_speed(struct libinput_device *device)
+{
+ if (!libinput_device_config_accel_is_available(device))
+ return 0;
+
+ return device->config.accel->get_default_speed(device);
+}
+
diff --git a/src/libinput.h b/src/libinput.h
index 806e1ab..83e3b37 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -1783,6 +1783,65 @@ libinput_device_config_send_events_get_mode(struct libinput_device *device);
enum libinput_config_send_events_mode
libinput_device_config_send_events_get_default_mode(struct libinput_device *device);
+/**
+ * @ingroup config
+ *
+ * Check if a device uses libinput-internal pointer-acceleration.
+ *
+ * @param device The device to configure
+ *
+ * @return 0 if the device is not accelerated, nonzero if it is accelerated
+ */
+int
+libinput_device_config_accel_is_available(struct libinput_device *device);
+
+/**
+ * @ingroup config
+ *
+ * Set the pointer acceleration speed of this pointer device within a range
+ * of [-1, 1], where 0 is the default acceleration for this device, -1 is
+ * the slowest acceleration and 1 is the maximum acceleration available on
+ * this device. The actual pointer acceleration mechanism is
+ * implementation-dependent, as is the number of steps available within the
+ * range. libinput picks the semantically closest acceleration step if the
+ * requested value does not match a discreet setting.
+ *
+ * @param device The device to configure
+ * @param speed The normalized speed, in a range of [-1, 1]
+ *
+ * @return A config status code
+ */
+enum libinput_config_status
+libinput_device_config_accel_set_speed(struct libinput_device *device,
+ double speed);
+
+/**
+ * @ingroup config
+ *
+ * Get the current pointer acceleration setting for this pointer device. The
+ * returned value is normalized to a range of [-1, 1].
+ * See libinput_device_config_accel_set_speed() for details.
+ *
+ * @param device The device to configure
+ *
+ * @return The current speed, range -1 to 1
+ */
+double
+libinput_device_config_accel_get_speed(struct libinput_device *device);
+
+/**
+ * @ingroup config
+ *
+ * Return the default speed setting for this device, normalized to a range
+ * of [-1, 1].
+ * See libinput_device_config_accel_set_speed() for details.
+ *
+ * @param device The device to configure
+ * @return The default speed setting for this device.
+ */
+double
+libinput_device_config_accel_get_default_speed(struct libinput_device *device);
+
#ifdef __cplusplus
}
#endif
--
1.9.3
More information about the wayland-devel
mailing list