[PATCH libinput 07/12] Use typesafe coordinates for scrolling events

Peter Hutterer peter.hutterer at who-t.net
Thu Mar 12 01:36:38 PDT 2015


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev-mt-touchpad-edge-scroll.c |  8 ++--
 src/evdev-mt-touchpad-gestures.c    |  2 +-
 src/evdev.c                         | 81 +++++++++++++++++++++----------------
 src/evdev.h                         |  6 +--
 src/libinput-private.h              |  3 +-
 src/libinput.c                      |  6 +--
 6 files changed, 58 insertions(+), 48 deletions(-)

diff --git a/src/evdev-mt-touchpad-edge-scroll.c b/src/evdev-mt-touchpad-edge-scroll.c
index 92973e1..d33f4fd 100644
--- a/src/evdev-mt-touchpad-edge-scroll.c
+++ b/src/evdev-mt-touchpad-edge-scroll.c
@@ -314,6 +314,7 @@ tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time)
 	double *delta;
 	double initial_dx, initial_dy, *initial_delta;
 	struct normalized_coords normalized;
+	const struct normalized_coords zero = { 0.0, 0.0 };
 
 	if (tp->scroll.method != LIBINPUT_CONFIG_SCROLL_EDGE)
 		return 0;
@@ -329,7 +330,7 @@ tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time)
 					pointer_notify_axis(device, time,
 						AS_MASK(t->scroll.direction),
 						LIBINPUT_POINTER_AXIS_SOURCE_FINGER,
-						0.0, 0.0,
+						&zero,
 						0, 0);
 					t->scroll.direction = -1;
 				}
@@ -381,7 +382,7 @@ tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time)
 		pointer_notify_axis(device, time,
 				    AS_MASK(axis),
 				    LIBINPUT_POINTER_AXIS_SOURCE_FINGER,
-				    normalized.x, normalized.y,
+				    &normalized,
 				    0, 0);
 		t->scroll.direction = axis;
 
@@ -396,13 +397,14 @@ tp_edge_scroll_stop_events(struct tp_dispatch *tp, uint64_t time)
 {
 	struct libinput_device *device = &tp->device->base;
 	struct tp_touch *t;
+	const struct normalized_coords zero = { 0.0, 0.0 };
 
 	tp_for_each_touch(tp, t) {
 		if (t->scroll.direction != -1) {
 			pointer_notify_axis(device, time,
 					    AS_MASK(t->scroll.direction),
 					    LIBINPUT_POINTER_AXIS_SOURCE_FINGER,
-					    0.0, 0.0,
+					    &zero,
 					    0.0, 0.0);
 			t->scroll.direction = -1;
 		}
diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c
index 85b22ff..1456731 100644
--- a/src/evdev-mt-touchpad-gestures.c
+++ b/src/evdev-mt-touchpad-gestures.c
@@ -123,7 +123,7 @@ tp_gesture_post_twofinger_scroll(struct tp_dispatch *tp, uint64_t time)
 	evdev_post_scroll(tp->device,
 			  time,
 			  LIBINPUT_POINTER_AXIS_SOURCE_FINGER,
-			  delta.x, delta.y);
+			  &delta);
 }
 
 void
diff --git a/src/evdev.c b/src/evdev.c
index e1a1a97..0a2f1f8 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -244,7 +244,7 @@ evdev_flush_pending_event(struct evdev_device *device, uint64_t time)
 	int seat_slot;
 	struct libinput_device *base = &device->base;
 	struct libinput_seat *seat = base->seat;
-	struct normalized_coords normalized;
+	struct normalized_coords accel, unaccel;
 	struct device_coords point;
 
 	slot = device->mt.slot;
@@ -253,7 +253,7 @@ evdev_flush_pending_event(struct evdev_device *device, uint64_t time)
 	case EVDEV_NONE:
 		return;
 	case EVDEV_RELATIVE_MOTION:
-		normalize_delta(device, &device->rel, &normalized);
+		normalize_delta(device, &device->rel, &unaccel);
 		device->rel.x = 0;
 		device->rel.y = 0;
 
@@ -263,23 +263,25 @@ evdev_flush_pending_event(struct evdev_device *device, uint64_t time)
 			if (device->scroll.button_scroll_active)
 				evdev_post_scroll(device, time,
 						  LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS,
-						  normalized.x, normalized.y);
+						  &unaccel);
 			break;
 		}
 
 		/* Apply pointer acceleration. */
-		motion.dx = normalized.x;
-		motion.dy = normalized.y;
+		motion.dx = unaccel.x;
+		motion.dy = unaccel.y;
 		filter_dispatch(device->pointer.filter, &motion, device, time);
+		accel.x = motion.dx;
+		accel.y = motion.dy;
 
-		if (motion.dx == 0.0 && motion.dy == 0.0 &&
-		    normalized.x == 0.0 && normalized.y == 0.0) {
+		if (accel.x == 0.0 && accel.y == 0.0 &&
+		    unaccel.x == 0.0 && unaccel.y == 0.0) {
 			break;
 		}
 
 		pointer_notify_motion(base, time,
-				      motion.dx, motion.dy,
-				      normalized.x, normalized.x);
+				      accel.x, accel.y,
+				      unaccel.x, unaccel.x);
 		break;
 	case EVDEV_ABSOLUTE_MT_DOWN:
 		if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
@@ -588,12 +590,14 @@ evdev_notify_axis(struct evdev_device *device,
 		  uint64_t time,
 		  uint32_t axes,
 		  enum libinput_pointer_axis_source source,
-		  double x, double y,
+		  const struct normalized_coords *delta_in,
 		  double x_discrete, double y_discrete)
 {
+	struct normalized_coords delta = *delta_in;
+
 	if (device->scroll.natural_scrolling_enabled) {
-		x *= -1;
-		y *= -1;
+		delta.x *= -1;
+		delta.y *= -1;
 		x_discrete *= -1;
 		y_discrete *= -1;
 	}
@@ -602,7 +606,7 @@ evdev_notify_axis(struct evdev_device *device,
 			    time,
 			    axes,
 			    source,
-			    x, y,
+			    &delta,
 			    x_discrete, y_discrete);
 }
 
@@ -610,6 +614,8 @@ static inline void
 evdev_process_relative(struct evdev_device *device,
 		       struct input_event *e, uint64_t time)
 {
+	struct normalized_coords wheel_degrees = { 0.0, 0.0 };
+
 	switch (e->code) {
 	case REL_X:
 		if (device->pending_event != EVDEV_RELATIVE_MOTION)
@@ -625,25 +631,26 @@ evdev_process_relative(struct evdev_device *device,
 		break;
 	case REL_WHEEL:
 		evdev_flush_pending_event(device, time);
+		wheel_degrees.y = -1 * e->value *
+					device->scroll.wheel_click_angle;
 		evdev_notify_axis(
 			device,
 			time,
 			AS_MASK(LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL),
 			LIBINPUT_POINTER_AXIS_SOURCE_WHEEL,
-			0.0,
-			-1 * e->value * device->scroll.wheel_click_angle,
+			&wheel_degrees,
 			0.0,
 			-1 * e->value);
 		break;
 	case REL_HWHEEL:
 		evdev_flush_pending_event(device, time);
+		wheel_degrees.x = e->value * device->scroll.wheel_click_angle;
 		evdev_notify_axis(
 			device,
 			time,
 			AS_MASK(LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL),
 			LIBINPUT_POINTER_AXIS_SOURCE_WHEEL,
-			e->value * device->scroll.wheel_click_angle,
-			0.0,
+			&wheel_degrees,
 			e->value,
 			0.0);
 		break;
@@ -1922,20 +1929,19 @@ void
 evdev_post_scroll(struct evdev_device *device,
 		  uint64_t time,
 		  enum libinput_pointer_axis_source source,
-		  double dx,
-		  double dy)
+		  const struct normalized_coords *delta)
 {
-	double trigger_horiz, trigger_vert;
+	const struct normalized_coords *trigger;
+	struct normalized_coords event;
 
 	if (!evdev_is_scrolling(device,
 				LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
-		device->scroll.buildup_vertical += dy;
+		device->scroll.buildup.y += delta->y;
 	if (!evdev_is_scrolling(device,
 				LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))
-		device->scroll.buildup_horizontal += dx;
+		device->scroll.buildup.x += delta->x;
 
-	trigger_vert = device->scroll.buildup_vertical;
-	trigger_horiz = device->scroll.buildup_horizontal;
+	trigger = &device->scroll.buildup;
 
 	/* If we're not scrolling yet, use a distance trigger: moving
 	   past a certain distance starts scrolling */
@@ -1943,42 +1949,45 @@ evdev_post_scroll(struct evdev_device *device,
 				LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL) &&
 	    !evdev_is_scrolling(device,
 				LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) {
-		if (fabs(trigger_vert) >= device->scroll.threshold)
+		if (fabs(trigger->y) >= device->scroll.threshold)
 			evdev_start_scrolling(device,
 					      LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
-		if (fabs(trigger_horiz) >= device->scroll.threshold)
+		if (fabs(trigger->x) >= device->scroll.threshold)
 			evdev_start_scrolling(device,
 					      LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
 	/* We're already scrolling in one direction. Require some
 	   trigger speed to start scrolling in the other direction */
 	} else if (!evdev_is_scrolling(device,
 			       LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) {
-		if (fabs(dy) >= device->scroll.threshold)
+		if (fabs(delta->y) >= device->scroll.threshold)
 			evdev_start_scrolling(device,
 				      LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
 	} else if (!evdev_is_scrolling(device,
 				LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) {
-		if (fabs(dx) >= device->scroll.threshold)
+		if (fabs(delta->x) >= device->scroll.threshold)
 			evdev_start_scrolling(device,
 				      LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
 	}
 
+	event = *delta;
+
 	/* We use the trigger to enable, but the delta from this event for
 	 * the actual scroll movement. Otherwise we get a jump once
 	 * scrolling engages */
 	if (!evdev_is_scrolling(device,
 			       LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
-		dy = 0.0;
+		event.y = 0.0;
+
 	if (!evdev_is_scrolling(device,
 			       LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))
-		dx = 0.0;
+		event.x = 0.0;
 
-	if (dx != 0.0 || dy != 0.0)
+	if (event.x != 0.0 || event.y != 0.0)
 		evdev_notify_axis(device,
 				  time,
 				  device->scroll.direction,
 				  source,
-				  dx, dy,
+				  &event,
 				  0.0, 0.0);
 }
 
@@ -1987,17 +1996,19 @@ evdev_stop_scroll(struct evdev_device *device,
 		  uint64_t time,
 		  enum libinput_pointer_axis_source source)
 {
+	const struct normalized_coords zero = { 0.0, 0.0 };
+
 	/* terminate scrolling with a zero scroll event */
 	if (device->scroll.direction != 0)
 		pointer_notify_axis(&device->base,
 				    time,
 				    device->scroll.direction,
 				    source,
-				    0.0, 0.0,
+				    &zero,
 				    0.0, 0.0);
 
-	device->scroll.buildup_horizontal = 0;
-	device->scroll.buildup_vertical = 0;
+	device->scroll.buildup.x = 0;
+	device->scroll.buildup.y = 0;
 	device->scroll.direction = 0;
 }
 
diff --git a/src/evdev.h b/src/evdev.h
index a0a7f59..caafd53 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -114,8 +114,7 @@ struct evdev_device {
 		bool button_scroll_active;
 		double threshold;
 		uint32_t direction;
-		double buildup_vertical;
-		double buildup_horizontal;
+		struct normalized_coords buildup;
 
 		struct libinput_device_config_natural_scroll config_natural;
 		/* set during device init if we want natural scrolling,
@@ -304,8 +303,7 @@ void
 evdev_post_scroll(struct evdev_device *device,
 		  uint64_t time,
 		  enum libinput_pointer_axis_source source,
-		  double dx,
-		  double dy);
+		  const struct normalized_coords *delta);
 
 void
 evdev_stop_scroll(struct evdev_device *device,
diff --git a/src/libinput-private.h b/src/libinput-private.h
index c15f7d8..d5fb696 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -312,8 +312,7 @@ pointer_notify_axis(struct libinput_device *device,
 		    uint64_t time,
 		    uint32_t axes,
 		    enum libinput_pointer_axis_source source,
-		    double x,
-		    double y,
+		    const struct normalized_coords *delta,
 		    double x_discrete,
 		    double y_discrete);
 
diff --git a/src/libinput.c b/src/libinput.c
index 42354ba..3317797 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -1042,7 +1042,7 @@ pointer_notify_axis(struct libinput_device *device,
 		    uint64_t time,
 		    uint32_t axes,
 		    enum libinput_pointer_axis_source source,
-		    double x, double y,
+		    const struct normalized_coords *delta,
 		    double x_discrete, double y_discrete)
 {
 	struct libinput_event_pointer *axis_event;
@@ -1053,8 +1053,8 @@ pointer_notify_axis(struct libinput_device *device,
 
 	*axis_event = (struct libinput_event_pointer) {
 		.time = time,
-		.x = x,
-		.y = y,
+		.x = delta->x,
+		.y = delta->y,
 		.source = source,
 		.axes = axes,
 		.x_discrete = x_discrete,
-- 
2.1.0



More information about the wayland-devel mailing list