summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Brosziewski <bru@cvs.openbsd.org>2021-03-24 18:28:25 +0000
committerUlf Brosziewski <bru@cvs.openbsd.org>2021-03-24 18:28:25 +0000
commit8f7bfecca9a387c255b40cd99da398c6156428db (patch)
treebc2f0735508bdfd216d219815ff957869280e143
parent6e9c87aa2b86b26465985d433f57d9336080e195 (diff)
Improve the tap detection mechanism.
Revision 1.29 of wstpad.c has removed the 'maxdist' checks for multi-finger taps. While this change makes tap detection more reliable, and does not affect inputs intended for pointer movement, it might interfere with short scroll gestures. This version reorganizes the filtering code, and reintroduces a weaker version of those checks for MT touchpads.
-rw-r--r--sys/dev/wscons/wstpad.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/sys/dev/wscons/wstpad.c b/sys/dev/wscons/wstpad.c
index 65cd6b73f7f..57e46dedebf 100644
--- a/sys/dev/wscons/wstpad.c
+++ b/sys/dev/wscons/wstpad.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wstpad.c,v 1.29 2021/03/24 07:40:37 bru Exp $ */
+/* $OpenBSD: wstpad.c,v 1.30 2021/03/24 18:28:24 bru Exp $ */
/*
* Copyright (c) 2015, 2016 Ulf Brosziewski
@@ -655,21 +655,30 @@ int
wstpad_is_tap(struct wstpad *tp, struct tpad_touch *t)
{
struct timespec ts;
+
+ timespecsub(&tp->time, &t->orig.time, &ts);
+ return (timespeccmp(&ts, &tp->tap.maxtime, <));
+}
+
+/*
+ * At least one MT touch must remain close to its origin and end
+ * in the main area. The same conditions apply to one-finger taps
+ * on single-touch devices.
+ */
+void
+wstpad_tap_filter(struct wstpad *tp, struct tpad_touch *t)
+{
int dx, dy, dist = 0;
- /* Try to distinguish one-finger taps from short movements. */
- if (tp->tap.contacts == (tp->ignore ? 2 : 1)) {
+ if (IS_MT(tp) || tp->tap.contacts == 1) {
dx = abs(t->x - t->orig.x) << 12;
dy = abs(t->y - t->orig.y) * tp->ratio;
dist = (dx >= dy ? dx + 3 * dy / 8 : dy + 3 * dx / 8);
}
- if (dist <= (tp->tap.maxdist << 12)) {
- timespecsub(&tp->time, &t->orig.time, &ts);
- return (timespeccmp(&ts, &tp->tap.maxtime, <));
- }
- return (0);
+ tp->tap.centered = (CENTERED(t) && dist <= (tp->tap.maxdist << 12));
}
+
/*
* Return the oldest touch in the TOUCH_END state, or NULL.
*/
@@ -685,8 +694,8 @@ wstpad_tap_touch(struct wsmouseinput *input)
lifted = (input->mt.sync[MTS_TOUCH] & ~input->mt.touches);
FOREACHBIT(lifted, slot) {
s = &tp->tpad_touches[slot];
- if (tp->tap.state == TAP_DETECT)
- tp->tap.centered |= CENTERED(s);
+ if (tp->tap.state == TAP_DETECT && !tp->tap.centered)
+ wstpad_tap_filter(tp, s);
if (t == NULL || timespeccmp(&t->orig.time,
&s->orig.time, >))
t = s;
@@ -694,8 +703,8 @@ wstpad_tap_touch(struct wsmouseinput *input)
} else {
if (tp->t->state == TOUCH_END) {
t = tp->t;
- if (tp->tap.state == TAP_DETECT)
- tp->tap.centered = CENTERED(t);
+ if (tp->tap.state == TAP_DETECT && !tp->tap.centered)
+ wstpad_tap_filter(tp, t);
}
}