mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-01-03 06:50:10 +01:00
Add configuration option to select scroll mode
Add a configuration option to allow selecting between 2-finger / edge / none scrolling (for touchpads). 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:
parent
0ce30935d7
commit
71f703c50c
3 changed files with 295 additions and 0 deletions
|
|
@ -132,6 +132,18 @@ struct libinput_device_config_left_handed {
|
|||
int (*get_default)(struct libinput_device *device);
|
||||
};
|
||||
|
||||
struct libinput_device_config_scroll_mode {
|
||||
uint32_t (*get_modes)(struct libinput_device *device);
|
||||
enum libinput_config_status (*set_mode)(struct libinput_device *device,
|
||||
enum libinput_config_scroll_mode mode);
|
||||
enum libinput_config_scroll_mode (*get_mode)(struct libinput_device *device);
|
||||
enum libinput_config_scroll_mode (*get_default_mode)(struct libinput_device *device);
|
||||
enum libinput_config_status (*set_button)(struct libinput_device *device,
|
||||
uint32_t button);
|
||||
uint32_t (*get_button)(struct libinput_device *device);
|
||||
uint32_t (*get_default_button)(struct libinput_device *device);
|
||||
};
|
||||
|
||||
struct libinput_device_config {
|
||||
struct libinput_device_config_tap *tap;
|
||||
struct libinput_device_config_calibration *calibration;
|
||||
|
|
@ -139,6 +151,7 @@ struct libinput_device_config {
|
|||
struct libinput_device_config_accel *accel;
|
||||
struct libinput_device_config_natural_scroll *natural_scroll;
|
||||
struct libinput_device_config_left_handed *left_handed;
|
||||
struct libinput_device_config_scroll_mode *scroll_mode;
|
||||
};
|
||||
|
||||
struct libinput_device {
|
||||
|
|
|
|||
|
|
@ -1531,3 +1531,88 @@ libinput_device_config_buttons_get_default_left_handed(struct libinput_device *d
|
|||
|
||||
return device->config.left_handed->get_default(device);
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT uint32_t
|
||||
libinput_device_config_scroll_get_modes(struct libinput_device *device)
|
||||
{
|
||||
if (device->config.scroll_mode)
|
||||
return device->config.scroll_mode->get_modes(device);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT enum libinput_config_status
|
||||
libinput_device_config_scroll_set_mode(struct libinput_device *device,
|
||||
enum libinput_config_scroll_mode mode)
|
||||
{
|
||||
if ((libinput_device_config_scroll_get_modes(device) & mode) != mode)
|
||||
return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
|
||||
|
||||
/* Check mode is a single valid mode */
|
||||
switch (mode) {
|
||||
case LIBINPUT_CONFIG_SCROLL_NO_SCROLL:
|
||||
case LIBINPUT_CONFIG_SCROLL_2FG:
|
||||
case LIBINPUT_CONFIG_SCROLL_EDGE:
|
||||
case LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN:
|
||||
break;
|
||||
default:
|
||||
return LIBINPUT_CONFIG_STATUS_INVALID;
|
||||
}
|
||||
|
||||
if (device->config.scroll_mode)
|
||||
return device->config.scroll_mode->set_mode(device, mode);
|
||||
else /* mode must be _NO_SCROLL to get here */
|
||||
return LIBINPUT_CONFIG_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT enum libinput_config_scroll_mode
|
||||
libinput_device_config_scroll_get_mode(struct libinput_device *device)
|
||||
{
|
||||
if (device->config.scroll_mode)
|
||||
return device->config.scroll_mode->get_mode(device);
|
||||
else
|
||||
return LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT enum libinput_config_scroll_mode
|
||||
libinput_device_config_scroll_get_default_mode(struct libinput_device *device)
|
||||
{
|
||||
if (device->config.scroll_mode)
|
||||
return device->config.scroll_mode->get_default_mode(device);
|
||||
else
|
||||
return LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT enum libinput_config_status
|
||||
libinput_device_config_scroll_set_button(struct libinput_device *device,
|
||||
uint32_t button)
|
||||
{
|
||||
if ((libinput_device_config_scroll_get_modes(device) &
|
||||
LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) == 0)
|
||||
return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
|
||||
|
||||
if (!libinput_device_has_button(device, button))
|
||||
return LIBINPUT_CONFIG_STATUS_INVALID;
|
||||
|
||||
return device->config.scroll_mode->set_button(device, button);
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT uint32_t
|
||||
libinput_device_config_scroll_get_button(struct libinput_device *device)
|
||||
{
|
||||
if ((libinput_device_config_scroll_get_modes(device) &
|
||||
LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) == 0)
|
||||
return 0;
|
||||
|
||||
return device->config.scroll_mode->get_button(device);
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT uint32_t
|
||||
libinput_device_config_scroll_get_default_button(struct libinput_device *device)
|
||||
{
|
||||
if ((libinput_device_config_scroll_get_modes(device) &
|
||||
LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) == 0)
|
||||
return 0;
|
||||
|
||||
return device->config.scroll_mode->get_default_button(device);
|
||||
}
|
||||
|
|
|
|||
197
src/libinput.h
197
src/libinput.h
|
|
@ -2041,6 +2041,203 @@ libinput_device_config_buttons_get_left_handed(struct libinput_device *device);
|
|||
int
|
||||
libinput_device_config_buttons_get_default_left_handed(struct libinput_device *device);
|
||||
|
||||
/**
|
||||
* The scroll mode of a device selects when to generate scroll axis events
|
||||
* instead of pointer motion events.
|
||||
*/
|
||||
enum libinput_config_scroll_mode {
|
||||
/**
|
||||
* Never send scroll events instead of pointer motion events.
|
||||
* Note scroll wheels, etc. will still send scroll events.
|
||||
*/
|
||||
LIBINPUT_CONFIG_SCROLL_NO_SCROLL = 0,
|
||||
/**
|
||||
* Send scroll events when 2 fingers are down on the device.
|
||||
*/
|
||||
LIBINPUT_CONFIG_SCROLL_2FG = (1 << 0),
|
||||
/**
|
||||
* Send scroll events when a finger is moved along the bottom or
|
||||
* right edge of a device.
|
||||
*/
|
||||
LIBINPUT_CONFIG_SCROLL_EDGE = (1 << 1),
|
||||
/**
|
||||
* Send scroll events when a button is down and the device moves
|
||||
* along a scroll-capable axis.
|
||||
*/
|
||||
LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN = (1 << 2),
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup config
|
||||
*
|
||||
* Check which scroll modes a device supports. The mode defines when to
|
||||
* generate scroll axis events instead of pointer motion events.
|
||||
*
|
||||
* @param device The device to configure
|
||||
*
|
||||
* @return A bitmask of possible modes.
|
||||
*
|
||||
* @see libinput_device_config_scroll_set_mode
|
||||
* @see libinput_device_config_scroll_get_mode
|
||||
* @see libinput_device_config_scroll_get_default_mode
|
||||
* @see libinput_device_config_scroll_set_button
|
||||
* @see libinput_device_config_scroll_get_button
|
||||
* @see libinput_device_config_scroll_get_default_button
|
||||
*/
|
||||
uint32_t
|
||||
libinput_device_config_scroll_get_modes(struct libinput_device *device);
|
||||
|
||||
/**
|
||||
* @ingroup config
|
||||
*
|
||||
* Set the scroll mode for this device. The mode defines when to
|
||||
* generate scroll axis events instead of pointer motion events.
|
||||
*
|
||||
* @note Setting @ref LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN enables
|
||||
* the scroll mode, but scrolling is only activated when the configured
|
||||
* button is held down. If no button is set, i.e.
|
||||
* libinput_device_config_scroll_get_button() returns 0, scrolling
|
||||
* cannot activate.
|
||||
*
|
||||
* @param device The device to configure
|
||||
* @param mode The scroll mode for this device.
|
||||
*
|
||||
* @return A config status code.
|
||||
*
|
||||
* @see libinput_device_config_scroll_get_modes
|
||||
* @see libinput_device_config_scroll_get_mode
|
||||
* @see libinput_device_config_scroll_get_default_mode
|
||||
* @see libinput_device_config_scroll_set_button
|
||||
* @see libinput_device_config_scroll_get_button
|
||||
* @see libinput_device_config_scroll_get_default_button
|
||||
*/
|
||||
enum libinput_config_status
|
||||
libinput_device_config_scroll_set_mode(struct libinput_device *device,
|
||||
enum libinput_config_scroll_mode mode);
|
||||
|
||||
/**
|
||||
* @ingroup config
|
||||
*
|
||||
* Get the scroll mode for this device. The mode defines when to
|
||||
* generate scroll axis events instead of pointer motion events.
|
||||
*
|
||||
* @param device The device to configure
|
||||
* @return The current scroll mode for this device.
|
||||
*
|
||||
* @see libinput_device_config_scroll_get_modes
|
||||
* @see libinput_device_config_scroll_set_mode
|
||||
* @see libinput_device_config_scroll_get_default_mode
|
||||
* @see libinput_device_config_scroll_set_button
|
||||
* @see libinput_device_config_scroll_get_button
|
||||
* @see libinput_device_config_scroll_get_default_button
|
||||
*/
|
||||
enum libinput_config_scroll_mode
|
||||
libinput_device_config_scroll_get_mode(struct libinput_device *device);
|
||||
|
||||
/**
|
||||
* @ingroup config
|
||||
*
|
||||
* Get the default scroll mode for this device. The mode defines when to
|
||||
* generate scroll axis events instead of pointer motion events.
|
||||
*
|
||||
* @param device The device to configure
|
||||
* @return The default scroll mode for this device.
|
||||
*
|
||||
* @see libinput_device_config_scroll_get_modes
|
||||
* @see libinput_device_config_scroll_set_mode
|
||||
* @see libinput_device_config_scroll_get_mode
|
||||
* @see libinput_device_config_scroll_set_button
|
||||
* @see libinput_device_config_scroll_get_button
|
||||
* @see libinput_device_config_scroll_get_default_button
|
||||
*/
|
||||
enum libinput_config_scroll_mode
|
||||
libinput_device_config_scroll_get_default_mode(struct libinput_device *device);
|
||||
|
||||
/**
|
||||
* @ingroup config
|
||||
*
|
||||
* Set the button for the @ref LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN mode
|
||||
* for this device.
|
||||
*
|
||||
* When the current scroll mode is set to @ref
|
||||
* LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN, no button press/release events
|
||||
* will be send for the configured button.
|
||||
*
|
||||
* When the configured button is pressed, any motion events along a
|
||||
* scroll-capable axis are turned into scroll axis events.
|
||||
*
|
||||
* @note Setting the button does not change the scroll mode. To change the
|
||||
* scroll mode call libinput_device_config_scroll_set_mode().
|
||||
*
|
||||
* @param device The device to configure
|
||||
* @param button The button which when pressed switches to sending scroll events
|
||||
*
|
||||
* @return a config status code
|
||||
* @retval LIBINPUT_CONFIG_STATUS_SUCCESS on success
|
||||
* @retval LIBINPUT_CONFIG_STATUS_UNSUPPORTED if @ref LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN is not supported
|
||||
* @retval LIBINPUT_CONFIG_STATUS_INVALID the given button does not
|
||||
* exist on this device
|
||||
*
|
||||
* @see libinput_device_config_scroll_get_modes
|
||||
* @see libinput_device_config_scroll_set_mode
|
||||
* @see libinput_device_config_scroll_get_mode
|
||||
* @see libinput_device_config_scroll_get_default_mode
|
||||
* @see libinput_device_config_scroll_get_button
|
||||
* @see libinput_device_config_scroll_get_default_button
|
||||
*/
|
||||
enum libinput_config_status
|
||||
libinput_device_config_scroll_set_button(struct libinput_device *device,
|
||||
uint32_t button);
|
||||
|
||||
/**
|
||||
* @ingroup config
|
||||
*
|
||||
* Get the button for the @ref LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN mode for
|
||||
* this device.
|
||||
*
|
||||
* If @ref LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN scroll mode is not supported,
|
||||
* or no button is set, this function returns 0.
|
||||
*
|
||||
* @note The return value is independent of the currently selected
|
||||
* scroll-mode. For button scrolling to activate, a device must have the
|
||||
* @ref LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN mode enabled, and a non-zero
|
||||
* button set as scroll button.
|
||||
*
|
||||
* @param device The device to configure
|
||||
* @return The button which when pressed switches to sending scroll events
|
||||
*
|
||||
* @see libinput_device_config_scroll_get_modes
|
||||
* @see libinput_device_config_scroll_set_mode
|
||||
* @see libinput_device_config_scroll_get_mode
|
||||
* @see libinput_device_config_scroll_get_default_mode
|
||||
* @see libinput_device_config_scroll_set_button
|
||||
* @see libinput_device_config_scroll_get_default_button
|
||||
*/
|
||||
uint32_t
|
||||
libinput_device_config_scroll_get_button(struct libinput_device *device);
|
||||
|
||||
/**
|
||||
* @ingroup config
|
||||
*
|
||||
* Get the default button for LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN mode
|
||||
* for this device.
|
||||
*
|
||||
* If @ref LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN scroll mode is not supported,
|
||||
* or no default button is set, this function returns 0.
|
||||
*
|
||||
* @param device The device to configure
|
||||
* @return The default button for LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN mode
|
||||
*
|
||||
* @see libinput_device_config_scroll_get_modes
|
||||
* @see libinput_device_config_scroll_set_mode
|
||||
* @see libinput_device_config_scroll_get_mode
|
||||
* @see libinput_device_config_scroll_get_default_mode
|
||||
* @see libinput_device_config_scroll_set_button
|
||||
* @see libinput_device_config_scroll_get_button
|
||||
*/
|
||||
uint32_t
|
||||
libinput_device_config_scroll_get_default_button(struct libinput_device *device);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue