[PATCH libinput 10/11] touchpad: Refactor tp_get_*_touches_delta

Hans de Goede hdegoede at redhat.com
Wed Feb 18 04:26:53 PST 2015


The two tp_get_*_touches_delta functions are almost identical, refactor
them into one function.

Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 src/evdev-mt-touchpad-gestures.c | 29 +++++------------------------
 1 file changed, 5 insertions(+), 24 deletions(-)

diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c
index 8ebdf33..e429efe 100644
--- a/src/evdev-mt-touchpad-gestures.c
+++ b/src/evdev-mt-touchpad-gestures.c
@@ -32,7 +32,7 @@
 #define DEFAULT_GESTURE_SWITCH_TIMEOUT 100 /* ms */
 
 static void
-tp_get_average_touches_delta(struct tp_dispatch *tp, double *dx, double *dy)
+tp_get_touches_delta(struct tp_dispatch *tp, double *dx, double *dy, bool average)
 {
 	struct tp_touch *t;
 	unsigned int i, nchanged = 0;
@@ -53,7 +53,7 @@ tp_get_average_touches_delta(struct tp_dispatch *tp, double *dx, double *dy)
 		}
 	}
 
-	if (nchanged == 0)
+	if (!average || nchanged == 0)
 		return;
 
 	*dx /= nchanged;
@@ -61,25 +61,6 @@ tp_get_average_touches_delta(struct tp_dispatch *tp, double *dx, double *dy)
 }
 
 static void
-tp_get_combined_touches_delta(struct tp_dispatch *tp, double *dx, double *dy)
-{
-	struct tp_touch *t;
-	double tdx, tdy;
-	unsigned int i;
-
-	for (i = 0; i < tp->real_touches; i++) {
-		t = &tp->touches[i];
-
-		if (!tp_touch_active(tp, t) || !t->dirty)
-			continue;
-
-		tp_get_delta(t, &tdx, &tdy);
-		*dx += tdx;
-		*dy += tdy;
-	}
-}
-
-static void
 tp_gesture_start(struct tp_dispatch *tp, uint64_t time)
 {
 	if (tp->gesture.started)
@@ -101,9 +82,9 @@ tp_gesture_post_pointer_motion(struct tp_dispatch *tp, uint64_t time)
 
 	/* When a clickpad is clicked, combine motion of all active touches */
 	if (tp->buttons.is_clickpad && tp->buttons.state)
-		tp_get_combined_touches_delta(tp, &dx, &dy);
+		tp_get_touches_delta(tp, &dx, &dy, false);
 	else
-		tp_get_average_touches_delta(tp, &dx, &dy);
+		tp_get_touches_delta(tp, &dx, &dy, true);
 
 	tp_filter_motion(tp, &dx, &dy, &dx_unaccel, &dy_unaccel, time);
 
@@ -118,7 +99,7 @@ tp_gesture_post_twofinger_scroll(struct tp_dispatch *tp, uint64_t time)
 {
 	double dx = 0, dy =0;
 
-	tp_get_average_touches_delta(tp, &dx, &dy);
+	tp_get_touches_delta(tp, &dx, &dy, true);
 	tp_filter_motion(tp, &dx, &dy, NULL, NULL, time);
 
 	if (dx == 0.0 && dy == 0.0)
-- 
2.1.0



More information about the wayland-devel mailing list