mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-05-08 17:08:07 +02:00
Add a pointer acceleration API
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@who-t.net> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
parent
a721292c25
commit
339f3dc979
3 changed files with 108 additions and 0 deletions
|
|
@ -109,10 +109,19 @@ struct libinput_device_config_send_events {
|
||||||
enum libinput_config_send_events_mode (*get_default_mode)(struct libinput_device *device);
|
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 {
|
||||||
struct libinput_device_config_tap *tap;
|
struct libinput_device_config_tap *tap;
|
||||||
struct libinput_device_config_calibration *calibration;
|
struct libinput_device_config_calibration *calibration;
|
||||||
struct libinput_device_config_send_events *sendevents;
|
struct libinput_device_config_send_events *sendevents;
|
||||||
|
struct libinput_device_config_accel *accel;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct libinput_device {
|
struct libinput_device {
|
||||||
|
|
|
||||||
|
|
@ -1388,3 +1388,43 @@ libinput_device_config_send_events_get_default_mode(struct libinput_device *devi
|
||||||
{
|
{
|
||||||
return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1783,6 +1783,65 @@ libinput_device_config_send_events_get_mode(struct libinput_device *device);
|
||||||
enum libinput_config_send_events_mode
|
enum libinput_config_send_events_mode
|
||||||
libinput_device_config_send_events_get_default_mode(struct libinput_device *device);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue