gestures: filter motion inside the gesture state machine
authorJosé Expósito <jose.exposito89@gmail.com>
Thu, 27 May 2021 17:19:21 +0000 (19:19 +0200)
committerPeter Hutterer <peter.hutterer@who-t.net>
Wed, 9 Jun 2021 01:18:58 +0000 (01:18 +0000)
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 <jose.exposito89@gmail.com>
src/evdev-mt-touchpad-gestures.c
src/evdev-mt-touchpad.c
src/evdev-mt-touchpad.h

index e526d816e4f3c61e08efe395953d9bcfbcb0af89..8c239bd7a230cf8712bc476117c35630088fccef 100644 (file)
@@ -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
index 102802d0d7cd4f918f5bea533d0bdf184089a1d9..40e4b71f84b75254020b5cb3207501e37ddfce78 100644 (file)
@@ -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
index 46e735735b0c2e774c577217f0e55eac81935893..a58ca7f726835d53674f1115ea0f88ce39ac2f53 100644 (file)
@@ -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);