summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Expósito <jose.exposito89@gmail.com>2021-05-27 19:18:54 +0200
committerPeter Hutterer <peter.hutterer@who-t.net>2021-06-09 01:18:58 +0000
commitd5636eb934dba2f9d82255431e9dc23fc15200f6 (patch)
tree3766cde0a154cec872d0b930fcc3d4e3a5cb54de
parentba3e79c9f40711ed19df1df351e820aace823ff5 (diff)
gestures: handle pointer motion as an extra state
Refactor the gesture state machine to integrate pointer motion as an extra state of the state machine. Signed-off-by: José Expósito <jose.exposito89@gmail.com>
-rw-r--r--src/evdev-mt-touchpad-gestures.c42
-rw-r--r--src/evdev-mt-touchpad.h1
2 files changed, 31 insertions, 12 deletions
diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c
index d6c0b4bb..cdf05ab8 100644
--- a/src/evdev-mt-touchpad-gestures.c
+++ b/src/evdev-mt-touchpad-gestures.c
@@ -40,6 +40,7 @@ gesture_state_to_str(enum tp_gesture_state state)
switch (state) {
CASE_RETURN_STRING(GESTURE_STATE_NONE);
CASE_RETURN_STRING(GESTURE_STATE_UNKNOWN);
+ CASE_RETURN_STRING(GESTURE_STATE_POINTER_MOTION);
CASE_RETURN_STRING(GESTURE_STATE_SCROLL);
CASE_RETURN_STRING(GESTURE_STATE_PINCH);
CASE_RETURN_STRING(GESTURE_STATE_SWIPE);
@@ -135,6 +136,8 @@ tp_gesture_start(struct tp_dispatch *tp, uint64_t time)
tp->gesture.finger_count,
&zero, &zero);
break;
+ case GESTURE_STATE_POINTER_MOTION:
+ break;
}
tp->gesture.started = true;
@@ -447,6 +450,13 @@ tp_gesture_detect_motion_gestures(struct tp_dispatch *tp, uint64_t time)
double min_move = 1.5; /* min movement threshold in mm - count this touch */
double max_move = 4.0; /* max movement threshold in mm - ignore other touch */
+ if (tp->gesture.finger_count == 1) {
+ if (tp_has_pending_pointer_motion(tp, time))
+ return GESTURE_STATE_POINTER_MOTION;
+
+ return GESTURE_STATE_UNKNOWN;
+ }
+
/* If we have more fingers than slots, we don't know where the
* fingers are. Default to swipe */
if (tp->gesture.enabled && tp->gesture.finger_count > 2 &&
@@ -602,7 +612,7 @@ tp_gesture_handle_state_none(struct tp_dispatch *tp, uint64_t time)
ntouches = tp_gesture_get_active_touches(tp, touches, 4);
if (ntouches < 2)
- return GESTURE_STATE_NONE;
+ return GESTURE_STATE_UNKNOWN;
if (!tp->gesture.enabled) {
if (ntouches == 2)
@@ -662,6 +672,14 @@ tp_gesture_handle_state_unknown(struct tp_dispatch *tp, uint64_t time)
}
static enum tp_gesture_state
+tp_gesture_handle_state_pointer_motion(struct tp_dispatch *tp, uint64_t time)
+{
+ if (tp->queued & TOUCHPAD_EVENT_MOTION)
+ tp_gesture_post_pointer_motion(tp, time);
+ return GESTURE_STATE_POINTER_MOTION;
+}
+
+static enum tp_gesture_state
tp_gesture_handle_state_scroll(struct tp_dispatch *tp, uint64_t time)
{
struct device_float_coords raw;
@@ -771,6 +789,10 @@ tp_gesture_post_gesture(struct tp_dispatch *tp, uint64_t time)
tp->gesture.state =
tp_gesture_handle_state_unknown(tp, time);
+ if (tp->gesture.state == GESTURE_STATE_POINTER_MOTION)
+ tp->gesture.state =
+ tp_gesture_handle_state_pointer_motion(tp, time);
+
if (tp->gesture.state == GESTURE_STATE_SCROLL)
tp->gesture.state =
tp_gesture_handle_state_scroll(tp, time);
@@ -819,7 +841,10 @@ tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time)
if (tp_tap_dragging(tp) ||
(tp->buttons.is_clickpad && tp->buttons.state &&
tp->thumb.state == THUMB_STATE_FINGER)) {
- tp_gesture_cancel(tp, time);
+ if (tp->gesture.state != GESTURE_STATE_POINTER_MOTION) {
+ tp_gesture_cancel(tp, time);
+ tp->gesture.state = GESTURE_STATE_POINTER_MOTION;
+ }
tp->gesture.finger_count = 1;
tp->gesture.finger_count_pending = 0;
}
@@ -835,17 +860,8 @@ tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time)
tp_gesture_thumb_moved(tp))
tp_thumb_reset(tp);
- switch (tp->gesture.finger_count) {
- case 1:
- if (tp->queued & TOUCHPAD_EVENT_MOTION)
- tp_gesture_post_pointer_motion(tp, time);
- break;
- case 2:
- case 3:
- case 4:
+ if (tp->gesture.finger_count <= 4)
tp_gesture_post_gesture(tp, time);
- break;
- }
}
void
@@ -891,6 +907,8 @@ tp_gesture_end(struct tp_dispatch *tp, uint64_t time, bool cancelled)
tp->gesture.finger_count,
cancelled);
break;
+ case GESTURE_STATE_POINTER_MOTION:
+ break;
}
tp->gesture.started = false;
diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h
index a6a04a9d..46e73573 100644
--- a/src/evdev-mt-touchpad.h
+++ b/src/evdev-mt-touchpad.h
@@ -157,6 +157,7 @@ enum tp_edge_scroll_touch_state {
enum tp_gesture_state {
GESTURE_STATE_NONE,
GESTURE_STATE_UNKNOWN,
+ GESTURE_STATE_POINTER_MOTION,
GESTURE_STATE_SCROLL,
GESTURE_STATE_PINCH,
GESTURE_STATE_SWIPE,