[PATCH libinput 13/14] gestures: if a finger is 20mm below the other one, assume a pinch gesture

Peter Hutterer peter.hutterer at who-t.net
Thu Jan 7 20:11:17 PST 2016


Pure movement detection is quite unreliable when trying 3-finger pinch
gestures, and many gestures are misdetected as swipes. Before looking at the
motion, look at the constellation of the fingers. If one finger is 20mm below
the other one, assume they're in a pinch position.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev-mt-touchpad-gestures.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c
index e7b75ac..93581f4 100644
--- a/src/evdev-mt-touchpad-gestures.c
+++ b/src/evdev-mt-touchpad-gestures.c
@@ -312,12 +312,24 @@ tp_gesture_same_directions(int dir1, int dir2)
 		((dir2 & 0x80) && (dir1 & 0x01));
 }
 
+static inline void
+tp_gesture_init_pinch( struct tp_dispatch *tp)
+{
+	tp_gesture_get_pinch_info(tp,
+				  &tp->gesture.initial_distance,
+				  &tp->gesture.angle,
+				  &tp->gesture.center);
+	tp->gesture.prev_scale = 1.0;
+}
+
 static enum tp_gesture_state
 tp_gesture_handle_state_unknown(struct tp_dispatch *tp, uint64_t time)
 {
 	struct tp_touch *first = tp->gesture.touches[0],
 			*second = tp->gesture.touches[1];
 	int dir1, dir2;
+	int yres = tp->device->abs.absinfo_y->resolution;
+	int vert_distance;
 
 	/* for two-finger gestures, if the fingers stay unmoving for a
 	 * while, assume (slow) scroll */
@@ -327,6 +339,14 @@ tp_gesture_handle_state_unknown(struct tp_dispatch *tp, uint64_t time)
 		return GESTURE_STATE_SCROLL;
 	}
 
+	/* Else check if one finger is > 20mm below the others */
+	vert_distance = abs(first->point.y - second->point.y);
+	if (vert_distance > 20 * yres &&
+	    tp->gesture.enabled) {
+		tp_gesture_init_pinch(tp);
+		return GESTURE_STATE_PINCH;
+	}
+
 	/* Else wait for both fingers to have moved */
 	dir1 = tp_gesture_get_direction(tp, first);
 	dir2 = tp_gesture_get_direction(tp, second);
@@ -343,11 +363,7 @@ tp_gesture_handle_state_unknown(struct tp_dispatch *tp, uint64_t time)
 			return GESTURE_STATE_SWIPE;
 		}
 	} else if (tp->gesture.enabled) {
-		tp_gesture_get_pinch_info(tp,
-					  &tp->gesture.initial_distance,
-					  &tp->gesture.angle,
-					  &tp->gesture.center);
-		tp->gesture.prev_scale = 1.0;
+		tp_gesture_init_pinch(tp);
 		return GESTURE_STATE_PINCH;
 	}
 
-- 
2.5.0



More information about the wayland-devel mailing list