touchpad: enable natural scrolling for edge scrolling
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 11 Aug 2015 02:40:45 +0000 (12:40 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 11 Aug 2015 22:33:02 +0000 (08:33 +1000)
Instead of going straight to pointer_notify_axis, go through
evdev_notify_axis() which flips the scroll direction around for us.

https://bugs.freedesktop.org/show_bug.cgi?id=91597

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
src/evdev-mt-touchpad-edge-scroll.c
src/evdev.c
src/evdev.h
test/touchpad.c

index 49028087a6103be5af0204c50ed266e397183268..eda62e4d750d952710a435f8238346110cbd40d0 100644 (file)
@@ -342,7 +342,7 @@ tp_edge_scroll_handle_state(struct tp_dispatch *tp, uint64_t time)
 int
 tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time)
 {
-       struct libinput_device *device = &tp->device->base;
+       struct evdev_device *device = tp->device;
        struct tp_touch *t;
        enum libinput_pointer_axis axis;
        double *delta;
@@ -369,7 +369,7 @@ tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time)
                        case EDGE_NONE:
                                if (t->scroll.direction != -1) {
                                        /* Send stop scroll event */
-                                       pointer_notify_axis(device, time,
+                                       evdev_notify_axis(device, time,
                                                AS_MASK(t->scroll.direction),
                                                LIBINPUT_POINTER_AXIS_SOURCE_FINGER,
                                                &zero,
@@ -395,7 +395,7 @@ tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time)
                switch (t->scroll.edge_state) {
                case EDGE_SCROLL_TOUCH_STATE_NONE:
                case EDGE_SCROLL_TOUCH_STATE_AREA:
-                       log_bug_libinput(device->seat->libinput,
+                       log_bug_libinput(tp_libinput_context(tp),
                                         "unexpected scroll state %d\n",
                                         t->scroll.edge_state);
                        break;
@@ -416,11 +416,11 @@ tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time)
                if (*delta == 0.0)
                        continue;
 
-               pointer_notify_axis(device, time,
-                                   AS_MASK(axis),
-                                   LIBINPUT_POINTER_AXIS_SOURCE_FINGER,
-                                   &normalized,
-                                   &zero_discrete);
+               evdev_notify_axis(device, time,
+                                 AS_MASK(axis),
+                                 LIBINPUT_POINTER_AXIS_SOURCE_FINGER,
+                                 &normalized,
+                                 &zero_discrete);
                t->scroll.direction = axis;
 
                tp_edge_scroll_handle_event(tp, t, SCROLL_EVENT_POSTED);
@@ -432,14 +432,14 @@ tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time)
 void
 tp_edge_scroll_stop_events(struct tp_dispatch *tp, uint64_t time)
 {
-       struct libinput_device *device = &tp->device->base;
+       struct evdev_device *device = tp->device;
        struct tp_touch *t;
        const struct normalized_coords zero = { 0.0, 0.0 };
        const struct discrete_coords zero_discrete = { 0.0, 0.0 };
 
        tp_for_each_touch(tp, t) {
                if (t->scroll.direction != -1) {
-                       pointer_notify_axis(device, time,
+                       evdev_notify_axis(device, time,
                                            AS_MASK(t->scroll.direction),
                                            LIBINPUT_POINTER_AXIS_SOURCE_FINGER,
                                            &zero,
index 53ebf9dcaaaaded4f8cc405808cbc3d4c89f4bb6..225c3acc03e408c151a499becb5eb45ecc4cffb7 100644 (file)
@@ -612,7 +612,7 @@ evdev_process_absolute_motion(struct evdev_device *device,
        }
 }
 
-static void
+void
 evdev_notify_axis(struct evdev_device *device,
                  uint64_t time,
                  uint32_t axes,
index 65c5a41a09a6463d361ccce80c793cbdedfa7176..c951671e98b76883a716ed1cc7f903a901a28c9d 100644 (file)
@@ -380,6 +380,13 @@ evdev_pointer_notify_physical_button(struct evdev_device *device,
 void
 evdev_init_natural_scroll(struct evdev_device *device);
 
+void
+evdev_notify_axis(struct evdev_device *device,
+                 uint64_t time,
+                 uint32_t axes,
+                 enum libinput_pointer_axis_source source,
+                 const struct normalized_coords *delta_in,
+                 const struct discrete_coords *discrete_in);
 void
 evdev_post_scroll(struct evdev_device *device,
                  uint64_t time,
index 6e7ea5ff693c242963d94ecd28cfc7eacbefddf2..bbdbc21d9f0458462ed4b78407450f7b2940fc18 100644 (file)
@@ -350,6 +350,35 @@ START_TEST(touchpad_scroll_natural_2fg)
 }
 END_TEST
 
+START_TEST(touchpad_scroll_natural_edge)
+{
+       struct litest_device *dev = litest_current_device();
+       struct libinput *li = dev->libinput;
+
+       litest_enable_edge_scroll(dev);
+       litest_drain_events(li);
+
+       libinput_device_config_scroll_set_natural_scroll_enabled(dev->libinput_device, 1);
+
+       litest_touch_down(dev, 0, 99, 20);
+       litest_touch_move_to(dev, 0, 99, 20, 99, 80, 10, 0);
+       litest_touch_up(dev, 0);
+
+       libinput_dispatch(li);
+       litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -4);
+       litest_assert_empty_queue(li);
+
+       litest_touch_down(dev, 0, 99, 80);
+       litest_touch_move_to(dev, 0, 99, 80, 99, 20, 10, 0);
+       litest_touch_up(dev, 0);
+
+       libinput_dispatch(li);
+       litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 4);
+       litest_assert_empty_queue(li);
+
+}
+END_TEST
+
 START_TEST(touchpad_edge_scroll)
 {
        struct litest_device *dev = litest_current_device();
@@ -3450,6 +3479,7 @@ litest_setup_tests(void)
        litest_add("touchpad:scroll", touchpad_scroll_natural_defaults, LITEST_TOUCHPAD, LITEST_ANY);
        litest_add("touchpad:scroll", touchpad_scroll_natural_enable_config, LITEST_TOUCHPAD, LITEST_ANY);
        litest_add("touchpad:scroll", touchpad_scroll_natural_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
+       litest_add("touchpad:scroll", touchpad_scroll_natural_edge, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
        litest_add("touchpad:scroll", touchpad_scroll_defaults, LITEST_TOUCHPAD, LITEST_ANY);
        litest_add("touchpad:scroll", touchpad_edge_scroll, LITEST_TOUCHPAD, LITEST_ANY);
        litest_add("touchpad:scroll", touchpad_edge_scroll_no_motion, LITEST_TOUCHPAD, LITEST_ANY);