[PATCH libinput 1/8] evdev: Move generic scroll code from evdev-mt-touchpad.c to evdev.c

Hans de Goede hdegoede at redhat.com
Tue Sep 16 07:22:35 PDT 2014


So that it can be used for middle button trackpoint scrolling too.

Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 src/evdev-mt-touchpad.c | 57 +++----------------------------------------------
 src/evdev-mt-touchpad.h |  4 ----
 src/evdev.c             | 49 ++++++++++++++++++++++++++++++++++++++++++
 src/evdev.h             | 15 +++++++++++++
 4 files changed, 67 insertions(+), 58 deletions(-)

diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index adb3d02..b0318da 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -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;
 
diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h
index b67b063..8671f79 100644
--- a/src/evdev-mt-touchpad.h
+++ b/src/evdev-mt-touchpad.h
@@ -200,10 +200,6 @@ struct tp_dispatch {
 		} top_area;
 	} buttons;				/* physical buttons */
 
-	struct {
-		enum libinput_pointer_axis direction;
-	} scroll;
-
 	enum touchpad_event queued;
 
 	struct {
diff --git a/src/evdev.c b/src/evdev.c
index f7fd2b4..45020ba 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -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)
 {
diff --git a/src/evdev.h b/src/evdev.h
index f5345fa..311dddc 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -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
-- 
2.1.0



More information about the wayland-devel mailing list