Add a configuration option for natural scrolling
authorPeter Hutterer <peter.hutterer@who-t.net>
Thu, 18 Sep 2014 05:10:19 +0000 (15:10 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 23 Sep 2014 00:54:23 +0000 (10:54 +1000)
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>
src/libinput-private.h
src/libinput.c
src/libinput.h

index c922875..e71e685 100644 (file)
@@ -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 {
index 18f3496..6ac0d82 100644 (file)
@@ -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);
+}
index 83e3b37..8f1dca2 100644 (file)
@@ -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