diff options
author | JoseExposito <jose.exposito89@gmail.com> | 2021-04-07 18:23:06 +0200 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2021-04-13 14:01:11 +1000 |
commit | 3565dafdf1031dba93f0575cdb3e96820ed2151a (patch) | |
tree | ba12ca3dca9d4313870f42953245341a83104209 | |
parent | 73ef2d70c2f60f8dabdc26bf04a959c1f9440669 (diff) | |
download | libinput-3565dafdf1031dba93f0575cdb3e96820ed2151a.tar.gz |
gestures: move the logic to detect gestures to its own function
Move the code in used to detect motion based gestures (scroll, swipe and pinch)
to tp_gesture_detect_motion_gestures.
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
-rw-r--r-- | src/evdev-mt-touchpad-gestures.c | 134 |
1 files changed, 70 insertions, 64 deletions
diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c index 0394f124..2f9e2136 100644 --- a/src/evdev-mt-touchpad-gestures.c +++ b/src/evdev-mt-touchpad-gestures.c @@ -415,70 +415,7 @@ tp_gesture_apply_scroll_constraints(struct tp_dispatch *tp, } static enum tp_gesture_state -tp_gesture_handle_state_none(struct tp_dispatch *tp, uint64_t time) -{ - struct tp_touch *first, *second; - struct tp_touch *touches[4]; - unsigned int ntouches; - unsigned int i; - - ntouches = tp_gesture_get_active_touches(tp, touches, 4); - if (ntouches < 2) - return GESTURE_STATE_NONE; - - if (!tp->gesture.enabled) { - if (ntouches == 2) - return GESTURE_STATE_SCROLL; - return GESTURE_STATE_NONE; - } - - first = touches[0]; - second = touches[1]; - - /* For 3+ finger gestures, we only really need to track two touches. - * The human hand's finger arrangement means that for a pinch, the - * bottom-most touch will always be the thumb, and the top-most touch - * will always be one of the fingers. - * - * For 3+ finger swipes, the fingers will likely (but not necessarily) - * be in a horizontal line. They all move together, regardless, so it - * doesn't really matter which two of those touches we track. - * - * Tracking top and bottom is a change from previous versions, where - * we tracked leftmost and rightmost. This change enables: - * - * - More accurate pinch detection if thumb is near the center - * - Better resting-thumb detection while two-finger scrolling - * - On capable hardware, allow 3- or 4-finger swipes with resting - * thumb or held-down clickpad - */ - if (ntouches > 2) { - second = touches[0]; - - for (i = 1; i < ntouches && i < tp->num_slots; i++) { - if (touches[i]->point.y < first->point.y) - first = touches[i]; - else if (touches[i]->point.y >= second->point.y) - second = touches[i]; - } - - if (first == second) - return GESTURE_STATE_NONE; - - } - - tp->gesture.initial_time = time; - first->gesture.initial = first->point; - second->gesture.initial = second->point; - tp->gesture.touches[0] = first; - tp->gesture.touches[1] = second; - - return GESTURE_STATE_UNKNOWN; -} - - -static enum tp_gesture_state -tp_gesture_handle_state_unknown(struct tp_dispatch *tp, uint64_t time) +tp_gesture_detect_motion_gestures(struct tp_dispatch *tp, uint64_t time) { struct tp_touch *first = tp->gesture.touches[0], *second = tp->gesture.touches[1], @@ -610,6 +547,75 @@ tp_gesture_handle_state_unknown(struct tp_dispatch *tp, uint64_t time) } static enum tp_gesture_state +tp_gesture_handle_state_none(struct tp_dispatch *tp, uint64_t time) +{ + struct tp_touch *first, *second; + struct tp_touch *touches[4]; + unsigned int ntouches; + unsigned int i; + + ntouches = tp_gesture_get_active_touches(tp, touches, 4); + if (ntouches < 2) + return GESTURE_STATE_NONE; + + if (!tp->gesture.enabled) { + if (ntouches == 2) + return GESTURE_STATE_SCROLL; + return GESTURE_STATE_NONE; + } + + first = touches[0]; + second = touches[1]; + + /* For 3+ finger gestures, we only really need to track two touches. + * The human hand's finger arrangement means that for a pinch, the + * bottom-most touch will always be the thumb, and the top-most touch + * will always be one of the fingers. + * + * For 3+ finger swipes, the fingers will likely (but not necessarily) + * be in a horizontal line. They all move together, regardless, so it + * doesn't really matter which two of those touches we track. + * + * Tracking top and bottom is a change from previous versions, where + * we tracked leftmost and rightmost. This change enables: + * + * - More accurate pinch detection if thumb is near the center + * - Better resting-thumb detection while two-finger scrolling + * - On capable hardware, allow 3- or 4-finger swipes with resting + * thumb or held-down clickpad + */ + if (ntouches > 2) { + second = touches[0]; + + for (i = 1; i < ntouches && i < tp->num_slots; i++) { + if (touches[i]->point.y < first->point.y) + first = touches[i]; + else if (touches[i]->point.y >= second->point.y) + second = touches[i]; + } + + if (first == second) + return GESTURE_STATE_NONE; + + } + + tp->gesture.initial_time = time; + first->gesture.initial = first->point; + second->gesture.initial = second->point; + tp->gesture.touches[0] = first; + tp->gesture.touches[1] = second; + + return GESTURE_STATE_UNKNOWN; +} + + +static enum tp_gesture_state +tp_gesture_handle_state_unknown(struct tp_dispatch *tp, uint64_t time) +{ + return tp_gesture_detect_motion_gestures(tp, time); +} + +static enum tp_gesture_state tp_gesture_handle_state_scroll(struct tp_dispatch *tp, uint64_t time) { struct device_float_coords raw; |