mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-25 07:00:06 +01:00
gestures: if a finger is 20mm below the other one, assume a pinch gesture
Pure movement detection is quite unreliable when trying 3-finger pinch gestures, and many gestures are misdetected as swipes. Before looking at the motion, look at the constellation of the fingers. If one finger is 20mm below the other one, assume they're in a pinch position. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
f129c09adb
commit
83f3dbd180
1 changed files with 21 additions and 5 deletions
|
|
@ -312,12 +312,24 @@ tp_gesture_same_directions(int dir1, int dir2)
|
||||||
((dir2 & 0x80) && (dir1 & 0x01));
|
((dir2 & 0x80) && (dir1 & 0x01));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
tp_gesture_init_pinch( struct tp_dispatch *tp)
|
||||||
|
{
|
||||||
|
tp_gesture_get_pinch_info(tp,
|
||||||
|
&tp->gesture.initial_distance,
|
||||||
|
&tp->gesture.angle,
|
||||||
|
&tp->gesture.center);
|
||||||
|
tp->gesture.prev_scale = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
static enum tp_gesture_state
|
static enum tp_gesture_state
|
||||||
tp_gesture_handle_state_unknown(struct tp_dispatch *tp, uint64_t time)
|
tp_gesture_handle_state_unknown(struct tp_dispatch *tp, uint64_t time)
|
||||||
{
|
{
|
||||||
struct tp_touch *first = tp->gesture.touches[0],
|
struct tp_touch *first = tp->gesture.touches[0],
|
||||||
*second = tp->gesture.touches[1];
|
*second = tp->gesture.touches[1];
|
||||||
int dir1, dir2;
|
int dir1, dir2;
|
||||||
|
int yres = tp->device->abs.absinfo_y->resolution;
|
||||||
|
int vert_distance;
|
||||||
|
|
||||||
/* for two-finger gestures, if the fingers stay unmoving for a
|
/* for two-finger gestures, if the fingers stay unmoving for a
|
||||||
* while, assume (slow) scroll */
|
* while, assume (slow) scroll */
|
||||||
|
|
@ -327,6 +339,14 @@ tp_gesture_handle_state_unknown(struct tp_dispatch *tp, uint64_t time)
|
||||||
return GESTURE_STATE_SCROLL;
|
return GESTURE_STATE_SCROLL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Else check if one finger is > 20mm below the others */
|
||||||
|
vert_distance = abs(first->point.y - second->point.y);
|
||||||
|
if (vert_distance > 20 * yres &&
|
||||||
|
tp->gesture.enabled) {
|
||||||
|
tp_gesture_init_pinch(tp);
|
||||||
|
return GESTURE_STATE_PINCH;
|
||||||
|
}
|
||||||
|
|
||||||
/* Else wait for both fingers to have moved */
|
/* Else wait for both fingers to have moved */
|
||||||
dir1 = tp_gesture_get_direction(tp, first);
|
dir1 = tp_gesture_get_direction(tp, first);
|
||||||
dir2 = tp_gesture_get_direction(tp, second);
|
dir2 = tp_gesture_get_direction(tp, second);
|
||||||
|
|
@ -343,11 +363,7 @@ tp_gesture_handle_state_unknown(struct tp_dispatch *tp, uint64_t time)
|
||||||
return GESTURE_STATE_SWIPE;
|
return GESTURE_STATE_SWIPE;
|
||||||
}
|
}
|
||||||
} else if (tp->gesture.enabled) {
|
} else if (tp->gesture.enabled) {
|
||||||
tp_gesture_get_pinch_info(tp,
|
tp_gesture_init_pinch(tp);
|
||||||
&tp->gesture.initial_distance,
|
|
||||||
&tp->gesture.angle,
|
|
||||||
&tp->gesture.center);
|
|
||||||
tp->gesture.prev_scale = 1.0;
|
|
||||||
return GESTURE_STATE_PINCH;
|
return GESTURE_STATE_PINCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue