From 781cee2d8bf7dae84d707df0ed99555ddd93b385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= Date: Thu, 27 May 2021 19:19:21 +0200 Subject: [PATCH] gestures: filter motion inside the gesture state machine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At the moment, every gesture is triggered by motion. In order to implement gestures not based on motion, like hold, it is required to filter the unwanted motion inside the gesture state machine so it transits to the correct states. Signed-off-by: José Expósito --- src/evdev-mt-touchpad-gestures.c | 16 ++++++++++------ src/evdev-mt-touchpad.c | 13 +++++++++---- src/evdev-mt-touchpad.h | 3 ++- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c index e526d816..8c239bd7 100644 --- a/src/evdev-mt-touchpad-gestures.c +++ b/src/evdev-mt-touchpad-gestures.c @@ -879,9 +879,11 @@ tp_gesture_handle_state_none(struct tp_dispatch *tp, uint64_t time) } static void -tp_gesture_handle_state_unknown(struct tp_dispatch *tp, uint64_t time) +tp_gesture_handle_state_unknown(struct tp_dispatch *tp, uint64_t time, + bool ignore_motion) { - tp_gesture_detect_motion_gestures(tp, time); + if (!ignore_motion) + tp_gesture_detect_motion_gestures(tp, time); } static void @@ -983,13 +985,14 @@ tp_gesture_handle_state_pinch(struct tp_dispatch *tp, uint64_t time) } static void -tp_gesture_post_gesture(struct tp_dispatch *tp, uint64_t time) +tp_gesture_post_gesture(struct tp_dispatch *tp, uint64_t time, + bool ignore_motion) { if (tp->gesture.state == GESTURE_STATE_NONE) tp_gesture_handle_state_none(tp, time); if (tp->gesture.state == GESTURE_STATE_UNKNOWN) - tp_gesture_handle_state_unknown(tp, time); + tp_gesture_handle_state_unknown(tp, time, ignore_motion); if (tp->gesture.state == GESTURE_STATE_POINTER_MOTION) tp_gesture_handle_state_pointer_motion(tp, time); @@ -1021,7 +1024,8 @@ tp_gesture_thumb_moved(struct tp_dispatch *tp) } void -tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time) +tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time, + bool ignore_motion) { if (tp->gesture.finger_count == 0) return; @@ -1055,7 +1059,7 @@ tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time) tp_thumb_reset(tp); if (tp->gesture.finger_count <= 4) - tp_gesture_post_gesture(tp, time); + tp_gesture_post_gesture(tp, time, ignore_motion); } void diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index 102802d0..40e4b71f 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -1866,18 +1866,23 @@ tp_post_events(struct tp_dispatch *tp, uint64_t time) ignore_motion |= tp_tap_handle_state(tp, time); ignore_motion |= tp_post_button_events(tp, time); - if (ignore_motion || - tp->palm.trackpoint_active || - tp->dwt.keyboard_active) { + if (tp->palm.trackpoint_active || tp->dwt.keyboard_active) { tp_edge_scroll_stop_events(tp, time); tp_gesture_cancel(tp, time); return; } + if (ignore_motion) { + tp_edge_scroll_stop_events(tp, time); + tp_gesture_cancel(tp, time); + tp_gesture_post_events(tp, time, true); + return; + } + if (tp_edge_scroll_post_events(tp, time) != 0) return; - tp_gesture_post_events(tp, time); + tp_gesture_post_events(tp, time, false); } static void diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h index 46e73573..a58ca7f7 100644 --- a/src/evdev-mt-touchpad.h +++ b/src/evdev-mt-touchpad.h @@ -703,7 +703,8 @@ void tp_gesture_handle_state(struct tp_dispatch *tp, uint64_t time); void -tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time); +tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time, + bool ignore_motion); void tp_gesture_stop_twofinger_scroll(struct tp_dispatch *tp, uint64_t time);