diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2014-09-18 15:10:19 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2014-09-23 10:54:23 +1000 |
commit | c481b47f1776549bbfde325fe68dceb0401b3f59 (patch) | |
tree | b52e59e7b7971be3ba0ddcc8ba3129a11fd12851 | |
parent | fb5f44f7948b72eb9788ac7ccfd837bb9e73356c (diff) |
Add a configuration option for natural scrolling
Natural scrolling is simply inverted scrolling, but I decided to
use the Apple terminology simply because it's easier to google for.
Add the usual quartett of config options for has/set/get/get_default/, as a
boolean option rather than an enum for scroll mode to avoid name collusion
with the (currently in the works) edge scrolling.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
-rw-r--r-- | src/libinput-private.h | 9 | ||||
-rw-r--r-- | src/libinput.c | 36 | ||||
-rw-r--r-- | src/libinput.h | 81 |
3 files changed, 126 insertions, 0 deletions
diff --git a/src/libinput-private.h b/src/libinput-private.h index c922875a..e71e685d 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -117,11 +117,20 @@ struct libinput_device_config_accel { double (*get_default_speed)(struct libinput_device *device); }; +struct libinput_device_config_natural_scroll { + int (*has)(struct libinput_device *device); + enum libinput_config_status (*set_enabled)(struct libinput_device *device, + int enabled); + int (*get_enabled)(struct libinput_device *device); + int (*get_default_enabled)(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_config_natural_scroll *natural_scroll; }; struct libinput_device { diff --git a/src/libinput.c b/src/libinput.c index 18f34967..6ac0d826 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1428,3 +1428,39 @@ libinput_device_config_accel_get_default_speed(struct libinput_device *device) return device->config.accel->get_default_speed(device); } +LIBINPUT_EXPORT int +libinput_device_config_scroll_has_natural_scroll(struct libinput_device *device) +{ + if (!device->config.natural_scroll) + return 0; + + return device->config.natural_scroll->has(device); +} + +LIBINPUT_EXPORT enum libinput_config_status +libinput_device_config_scroll_set_natural_scroll_enabled(struct libinput_device *device, + int enabled) +{ + if (!libinput_device_config_scroll_has_natural_scroll(device)) + return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; + + return device->config.natural_scroll->set_enabled(device, enabled); +} + +LIBINPUT_EXPORT int +libinput_device_config_scroll_get_natural_scroll_enabled(struct libinput_device *device) +{ + if (!device->config.natural_scroll) + return 0; + + return device->config.natural_scroll->get_enabled(device); +} + +LIBINPUT_EXPORT int +libinput_device_config_scroll_get_default_natural_scroll_enabled(struct libinput_device *device) +{ + if (!device->config.natural_scroll) + return 0; + + return device->config.natural_scroll->get_default_enabled(device); +} diff --git a/src/libinput.h b/src/libinput.h index 83e3b37a..8f1dca25 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1842,6 +1842,87 @@ libinput_device_config_accel_get_speed(struct libinput_device *device); double libinput_device_config_accel_get_default_speed(struct libinput_device *device); +/** + * @ingroup config + * + * Return non-zero if the device supports "natural scrolling". + * + * In traditional scroll mode, the movement of fingers on a touchpad when + * scrolling matches the movement of the scroll bars. When the fingers move + * down, the scroll bar moves down, a line of text on the screen moves + * towards the upper end of the screen. This also matches scroll wheels on + * mice (wheel down, content moves up). + * + * Natural scrolling is the term coined by Apple for inverted scrolling. + * In this mode, the effect of scrolling movement of fingers on a touchpad + * resemble physical manipulation of paper. When the fingers move down, a + * line of text on the screen moves down (scrollbars move up). This is the + * opposite of scroll wheels on mice. + * + * A device supporting natural scrolling can be switched between traditional + * scroll mode and natural scroll mode. + * + * @param device The device to configure + * + * @return 0 if natural scrolling is not supported, non-zero if natural + * scrolling is supported by this device + * + * @see libinput_device_config_set_natural_scroll_enabled + * @see libinput_device_config_get_natural_scroll_enabled + * @see libinput_device_config_get_default_natural_scroll_enabled + */ +int +libinput_device_config_scroll_has_natural_scroll(struct libinput_device *device); + +/** + * @ingroup config + * + * Enable or disable natural scrolling on the device. + * + * @param device The device to configure + * @param enable non-zero to enable, zero to disable natural scrolling + * + * @return a config status code + * + * @see libinput_device_config_has_natural_scroll + * @see libinput_device_config_get_natural_scroll_enabled + * @see libinput_device_config_get_default_natural_scroll_enabled + */ +enum libinput_config_status +libinput_device_config_scroll_set_natural_scroll_enabled(struct libinput_device *device, + int enable); +/** + * @ingroup config + * + * Get the current mode for scrolling on this device + * + * @param device The device to configure + * + * @return zero if natural scrolling is disabled, non-zero if enabled + * + * @see libinput_device_config_has_natural_scroll + * @see libinput_device_config_set_natural_scroll_enabled + * @see libinput_device_config_get_default_natural_scroll_enabled + */ +int +libinput_device_config_scroll_get_natural_scroll_enabled(struct libinput_device *device); + +/** + * @ingroup config + * + * Get the default mode for scrolling on this device + * + * @param device The device to configure + * + * @return zero if natural scrolling is disabled by default, non-zero if enabled + * + * @see libinput_device_config_has_natural_scroll + * @see libinput_device_config_set_natural_scroll_enabled + * @see libinput_device_config_get_natural_scroll_enabled + */ +int +libinput_device_config_scroll_get_default_natural_scroll_enabled(struct libinput_device *device); + #ifdef __cplusplus } #endif |