evdev: Move generic scroll code from evdev-mt-touchpad.c to evdev.c
authorHans de Goede <hdegoede@redhat.com>
Tue, 16 Sep 2014 14:22:35 +0000 (16:22 +0200)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 18 Sep 2014 03:29:42 +0000 (13:29 +1000)
So that it can be used for middle button trackpoint scrolling too.

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>
src/evdev-mt-touchpad.c
src/evdev-mt-touchpad.h
src/evdev.c
src/evdev.h

index d9f6fd7..d1e4acd 100644 (file)
@@ -492,47 +492,7 @@ tp_post_twofinger_scroll(struct tp_dispatch *tp, uint64_t time)
        dy /= nchanged;
 
        tp_filter_motion(tp, &dx, &dy, time);
-
-       /* Require at least five px scrolling to start */
-       if (dy <= -5.0 || dy >= 5.0)
-               tp->scroll.direction |= (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
-
-       if (dx <= -5.0 || dx >= 5.0)
-               tp->scroll.direction |= (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
-
-       if (dy != 0.0 &&
-           (tp->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))) {
-               pointer_notify_axis(&tp->device->base,
-                                   time,
-                                   LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
-                                   dy);
-       }
-
-       if (dx != 0.0 &&
-           (tp->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))) {
-               pointer_notify_axis(&tp->device->base,
-                                   time,
-                                   LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
-                                   dx);
-       }
-}
-
-static void
-tp_stop_scroll_events(struct tp_dispatch *tp, uint64_t time)
-{
-       /* terminate scrolling with a zero scroll event */
-       if (tp->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
-               pointer_notify_axis(&tp->device->base,
-                                   time,
-                                   LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
-                                   0);
-       if (tp->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))
-               pointer_notify_axis(&tp->device->base,
-                                   time,
-                                   LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
-                                   0);
-
-       tp->scroll.direction = 0;
+       evdev_post_scroll(tp->device, time, dx, dy);
 }
 
 static int
@@ -548,7 +508,7 @@ tp_post_scroll_events(struct tp_dispatch *tp, uint64_t time)
        }
 
        if (nfingers_down != 2) {
-               tp_stop_scroll_events(tp, time);
+               evdev_stop_scroll(tp->device, time);
                return 0;
        }
 
@@ -567,7 +527,7 @@ tp_post_events(struct tp_dispatch *tp, uint64_t time)
        consumed |= tp_post_button_events(tp, time);
 
        if (consumed) {
-               tp_stop_scroll_events(tp, time);
+               evdev_stop_scroll(tp->device, time);
                return;
        }
 
@@ -847,14 +807,6 @@ tp_init_accel(struct tp_dispatch *tp, double diagonal)
 }
 
 static int
-tp_init_scroll(struct tp_dispatch *tp)
-{
-       tp->scroll.direction = 0;
-
-       return 0;
-}
-
-static int
 tp_init_palmdetect(struct tp_dispatch *tp,
                   struct evdev_device *device)
 {
@@ -909,9 +861,6 @@ tp_init(struct tp_dispatch *tp,
        tp->hysteresis.margin_y =
                diagonal / DEFAULT_HYSTERESIS_MARGIN_DENOMINATOR;
 
-       if (tp_init_scroll(tp) != 0)
-               return -1;
-
        if (tp_init_accel(tp, diagonal) != 0)
                return -1;
 
index b67b063..8671f79 100644 (file)
@@ -200,10 +200,6 @@ struct tp_dispatch {
                } top_area;
        } buttons;                              /* physical buttons */
 
-       struct {
-               enum libinput_pointer_axis direction;
-       } scroll;
-
        enum touchpad_event queued;
 
        struct {
index f7fd2b4..45020ba 100644 (file)
@@ -1081,6 +1081,8 @@ evdev_device_create(struct libinput_seat *seat,
        device->fd = fd;
        device->pending_event = EVDEV_NONE;
        device->devname = libevdev_get_name(device->evdev);
+       device->scroll.threshold = 5.0; /* Default may be overridden */
+       device->scroll.direction = 0;
 
        matrix_init_identity(&device->abs.calibration);
        matrix_init_identity(&device->abs.usermatrix);
@@ -1265,6 +1267,53 @@ evdev_device_get_size(struct evdev_device *device,
        return 0;
 }
 
+void
+evdev_post_scroll(struct evdev_device *device,
+                 uint64_t time,
+                 double dx,
+                 double dy)
+{
+       if (dy <= -device->scroll.threshold || dy >= device->scroll.threshold)
+               device->scroll.direction |= (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
+
+       if (dx <= -device->scroll.threshold || dx >= device->scroll.threshold)
+               device->scroll.direction |= (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
+
+       if (dy != 0.0 &&
+           (device->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))) {
+               pointer_notify_axis(&device->base,
+                                   time,
+                                   LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
+                                   dy);
+       }
+
+       if (dx != 0.0 &&
+           (device->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))) {
+               pointer_notify_axis(&device->base,
+                                   time,
+                                   LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
+                                   dx);
+       }
+}
+
+void
+evdev_stop_scroll(struct evdev_device *device, uint64_t time)
+{
+       /* terminate scrolling with a zero scroll event */
+       if (device->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
+               pointer_notify_axis(&device->base,
+                                   time,
+                                   LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
+                                   0);
+       if (device->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))
+               pointer_notify_axis(&device->base,
+                                   time,
+                                   LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
+                                   0);
+
+       device->scroll.direction = 0;
+}
+
 static void
 release_pressed_keys(struct evdev_device *device)
 {
index f5345fa..311dddc 100644 (file)
@@ -95,6 +95,11 @@ struct evdev_device {
                int dx, dy;
        } rel;
 
+       struct {
+               double threshold;
+               uint32_t direction;
+       } scroll;
+
        enum evdev_event_type pending_event;
        enum evdev_device_seat_capability seat_caps;
        enum evdev_device_tags tags;
@@ -230,6 +235,16 @@ evdev_pointer_notify_button(struct evdev_device *device,
                            enum libinput_button_state state);
 
 void
+evdev_post_scroll(struct evdev_device *device,
+                 uint64_t time,
+                 double dx,
+                 double dy);
+
+
+void
+evdev_stop_scroll(struct evdev_device *device, uint64_t time);
+
+void
 evdev_device_remove(struct evdev_device *device);
 
 void