Allow reviving a thumb that moves sufficiently
authornovenary <streetwalkermc@gmail.com>
Sun, 4 Apr 2021 15:40:09 +0000 (18:40 +0300)
committerPeter Hutterer <peter.hutterer@who-t.net>
Wed, 19 May 2021 05:12:58 +0000 (05:12 +0000)
When pinching, the thumb tends to move slower than the finger, so we may
suppress it too early.

Add a grace period during which it may be revived.

Signed-off-by: novenary <streetwalkermc@gmail.com>
src/evdev-mt-touchpad-gestures.c
src/evdev-mt-touchpad-thumb.c
src/evdev-mt-touchpad.h

index 16841308dd93c2164bd546a1b0e915c3b69bb9a5..23259ee06da3f44076c8f8855cce927701799085 100644 (file)
@@ -773,6 +773,22 @@ tp_gesture_post_gesture(struct tp_dispatch *tp, uint64_t time)
                                gesture_state_to_str(tp->gesture.state));
 }
 
+static bool
+tp_gesture_thumb_moved(struct tp_dispatch *tp)
+{
+       struct tp_touch *thumb;
+       struct phys_coords thumb_moved;
+       double thumb_mm;
+
+       thumb = tp_thumb_get_touch(tp);
+       if (!thumb)
+               return false;
+
+       thumb_moved = tp_gesture_mm_moved(tp, thumb);
+       thumb_mm = hypot(thumb_moved.x, thumb_moved.y);
+       return thumb_mm >= PINCH_DISAMBIGUATION_MOVE_THRESHOLD;
+}
+
 void
 tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time)
 {
@@ -795,6 +811,13 @@ tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time)
        if (tp->gesture.finger_count_pending)
                return;
 
+       /* When pinching, the thumb tends to move slower than the finger,
+        * so we may suppress it too early. Give it some time to move.
+        */
+       if (time < (tp->gesture.initial_time + DEFAULT_GESTURE_PINCH_TIMEOUT) &&
+           tp_gesture_thumb_moved(tp))
+               tp_thumb_reset(tp);
+
        switch (tp->gesture.finger_count) {
        case 1:
                if (tp->queued & TOUCHPAD_EVENT_MOTION)
index 17b324e25e0ccaa1fe4b978b59d591f68b6eafc0..ceb123efac90c8c1ec79f4d968ed0f71ba6e5dae 100644 (file)
@@ -447,3 +447,19 @@ tp_init_thumb(struct tp_dispatch *tp)
                        tp->thumb.use_pressure ? ", pressure" : "",
                        tp->thumb.use_size ? ", size" : "");
 }
+
+struct tp_touch*
+tp_thumb_get_touch(struct tp_dispatch *tp)
+{
+       struct tp_touch *thumb;
+
+       if (tp->thumb.index == UINT_MAX)
+               return NULL;
+
+       tp_for_each_touch(tp, thumb) {
+               if (thumb->index == tp->thumb.index)
+                       return thumb;
+       }
+
+       return NULL;
+}
index abd051147469157935f245d441810dbfa07dab9f..a6a04a9d26c2c891a09e361627681629cd5af711 100644 (file)
@@ -743,4 +743,7 @@ tp_thumb_update_multifinger(struct tp_dispatch *tp);
 void
 tp_init_thumb(struct tp_dispatch *tp);
 
+struct tp_touch*
+tp_thumb_get_touch(struct tp_dispatch *tp);
+
 #endif