From 37c000ad5e444339c98a568dfad2ce5740c38665 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Wed, 18 Feb 2015 09:00:25 +0100 Subject: [PATCH] touchpad: Add support for swipe gestures Add support for swipe gestures. Signed-off-by: Hans de Goede Reviewed-by: Peter Hutterer Acked-by: Jason Gerecke --- src/evdev-mt-touchpad-gestures.c | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c index e85a9d77..e6fde0d6 100644 --- a/src/evdev-mt-touchpad-gestures.c +++ b/src/evdev-mt-touchpad-gestures.c @@ -76,6 +76,8 @@ tp_get_average_touches_delta(struct tp_dispatch *tp) static void tp_gesture_start(struct tp_dispatch *tp, uint64_t time) { + const struct normalized_coords zero = { 0.0, 0.0 }; + if (tp->gesture.started) return; @@ -83,6 +85,13 @@ tp_gesture_start(struct tp_dispatch *tp, uint64_t time) case 2: /* NOP */ break; + case 3: + case 4: + gesture_notify_swipe(&tp->device->base, time, + LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, + tp->gesture.finger_count, + &zero, &zero); + break; } tp->gesture.started = true; } @@ -141,6 +150,23 @@ tp_gesture_post_twofinger_scroll(struct tp_dispatch *tp, uint64_t time) &delta); } +static void +tp_gesture_post_swipe(struct tp_dispatch *tp, uint64_t time) +{ + struct normalized_coords delta, unaccel; + + unaccel = tp_get_average_touches_delta(tp); + delta = tp_filter_motion(tp, &unaccel, time); + + if (!normalized_is_zero(delta) || !normalized_is_zero(unaccel)) { + tp_gesture_start(tp, time); + gesture_notify_swipe(&tp->device->base, time, + LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, + tp->gesture.finger_count, + &delta, &unaccel); + } +} + void tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time) { @@ -165,6 +191,10 @@ tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time) case 2: tp_gesture_post_twofinger_scroll(tp, time); break; + case 3: + case 4: + tp_gesture_post_swipe(tp, time); + break; } } @@ -182,6 +212,8 @@ tp_gesture_stop_twofinger_scroll(struct tp_dispatch *tp, uint64_t time) void tp_gesture_stop(struct tp_dispatch *tp, uint64_t time) { + const struct normalized_coords zero = { 0.0, 0.0 }; + if (!tp->gesture.started) return; @@ -189,6 +221,13 @@ tp_gesture_stop(struct tp_dispatch *tp, uint64_t time) case 2: tp_gesture_stop_twofinger_scroll(tp, time); break; + case 3: + case 4: + gesture_notify_swipe(&tp->device->base, time, + LIBINPUT_EVENT_GESTURE_SWIPE_END, + tp->gesture.finger_count, + &zero, &zero); + break; } tp->gesture.started = false; }