evdev: Enable natural scrolling by default on Apple
authorHector Martin <marcan@marcan.st>
Sat, 10 Dec 2022 10:40:07 +0000 (19:40 +0900)
committerHector Martin <marcan@marcan.st>
Thu, 6 Apr 2023 06:30:14 +0000 (15:30 +0900)
As suggested by the comment itself. I think most users expect this.

Signed-off-by: Hector Martin <marcan@marcan.st>
src/evdev-mt-touchpad.c
src/evdev.c
test/litest.h
test/test-touchpad.c

index b29a5c56799a5818d4882f9f86c519f9ff95026b..e2ecdea7f978196039209530969d428dfe0ba2ee 100644 (file)
@@ -3137,12 +3137,24 @@ tp_scroll_config_scroll_method_get_default_method(struct libinput_device *device
        return tp_scroll_get_default_method(tp);
 }
 
+static int
+tp_scroll_config_natural_get_default(struct libinput_device *device)
+{
+       struct evdev_device *dev = evdev_device(device);
+
+       return (evdev_device_has_model_quirk(dev, QUIRK_MODEL_APPLE_TOUCHPAD) ||
+               evdev_device_has_model_quirk(dev, QUIRK_MODEL_APPLE_TOUCHPAD_ONEBUTTON));
+}
+
 static void
 tp_init_scroll(struct tp_dispatch *tp, struct evdev_device *device)
 {
        tp_edge_scroll_init(tp, device);
 
        evdev_init_natural_scroll(device);
+       /* Override natural scroll config for Apple touchpads */
+       device->scroll.config_natural.get_default_enabled = tp_scroll_config_natural_get_default;
+       device->scroll.natural_scrolling_enabled = tp_scroll_config_natural_get_default(&device->base);
 
        tp->scroll.config_method.get_methods = tp_scroll_config_scroll_method_get_methods;
        tp->scroll.config_method.set_method = tp_scroll_config_scroll_method_set_method;
index 524ae9a112c47caf14c6c84848dd52109365ccd9..33b3f514556b28fb87e464496a11f389c20f6238 100644 (file)
@@ -957,8 +957,7 @@ evdev_scroll_config_natural_get(struct libinput_device *device)
 static int
 evdev_scroll_config_natural_get_default(struct libinput_device *device)
 {
-       /* could enable this on Apple touchpads. could do that, could
-        * very well do that... */
+       /* Overridden in evdev-mt-touchpad.c for Apple touchpads. */
        return 0;
 }
 
index baba5cbb39991985e1d9bb3e2a2b0885fbaef932..951508314ad339a46374ba3fb9bbc2b011f25da7 100644 (file)
@@ -1064,6 +1064,8 @@ litest_enable_2fg_scroll(struct litest_device *dev)
 
        expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
        litest_assert_int_eq(status, expected);
+
+       libinput_device_config_scroll_set_natural_scroll_enabled(device, 0);
 }
 
 static inline void
@@ -1077,6 +1079,8 @@ litest_enable_edge_scroll(struct litest_device *dev)
 
        expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
        litest_assert_int_eq(status, expected);
+
+       libinput_device_config_scroll_set_natural_scroll_enabled(device, 0);
 }
 
 static inline bool
index c02cb01c74383f7d04a734115b596575cab5473a..d72ae0facafad25892e2a5eceb2f904f1cb1a399 100644 (file)
@@ -611,9 +611,11 @@ START_TEST(touchpad_scroll_natural_defaults)
 {
        struct litest_device *dev = litest_current_device();
 
+       int enabled = libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_APPLE;
+
        ck_assert_int_ge(libinput_device_config_scroll_has_natural_scroll(dev->libinput_device), 1);
-       ck_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), 0);
-       ck_assert_int_eq(libinput_device_config_scroll_get_default_natural_scroll_enabled(dev->libinput_device), 0);
+       ck_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), enabled);
+       ck_assert_int_eq(libinput_device_config_scroll_get_default_natural_scroll_enabled(dev->libinput_device), enabled);
 }
 END_TEST