diff --git a/src/libinput-private.h b/src/libinput-private.h index d3672d00..c922875a 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 14f02574..18f34967 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 806e1abb..83e3b37a 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