Allow reviving a thumb that moves sufficiently

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>
This commit is contained in:
novenary 2021-04-04 18:40:09 +03:00 committed by Peter Hutterer
parent 939a022cbc
commit ca3df8a076
3 changed files with 42 additions and 0 deletions

View 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)

View 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;
}

View 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