summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2019-06-19 11:57:45 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2019-07-15 13:08:47 +1000
commitd232e44c9fefbb3f54c63edb2cc61868725a92e2 (patch)
tree4f20acac89f21bb6ce8859c59c0c911c7592eee2 /src
parent9e27244e6c3b052824f3b66e81b5c64e02648099 (diff)
touchpad: add helper function for setting the thumb state
This moves the thumb state logging directly into that helper function too. Extracted from Matt Mayfield's thumb detection patches. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'src')
-rw-r--r--src/evdev-mt-touchpad-thumb.c46
-rw-r--r--src/evdev-mt-touchpad.c2
-rw-r--r--src/evdev-mt-touchpad.h5
3 files changed, 34 insertions, 19 deletions
diff --git a/src/evdev-mt-touchpad-thumb.c b/src/evdev-mt-touchpad-thumb.c
index 3c9354c4..b5ce2998 100644
--- a/src/evdev-mt-touchpad-thumb.c
+++ b/src/evdev-mt-touchpad-thumb.c
@@ -46,10 +46,25 @@ thumb_state_to_str(enum tp_thumb_state state)
}
void
-tp_thumb_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
+tp_thumb_set_state(struct tp_dispatch *tp,
+ struct tp_touch *t,
+ enum tp_thumb_state state)
{
- enum tp_thumb_state state = t->thumb.state;
+ if (t->thumb.state == state)
+ return;
+
+ evdev_log_debug(tp->device,
+ "thumb: touch %d, %s → %s\n",
+ t->index,
+ thumb_state_to_str(t->thumb.state),
+ thumb_state_to_str(state));
+
+ t->thumb.state = state;
+}
+void
+tp_thumb_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
+{
/* once a thumb, always a thumb, once ruled out always ruled out */
if (!tp->thumb.detect_thumbs ||
t->thumb.state != THUMB_STATE_MAYBE)
@@ -58,8 +73,8 @@ tp_thumb_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
if (t->point.y < tp->thumb.upper_thumb_line) {
/* if a potential thumb is above the line, it won't ever
* label as thumb */
- t->thumb.state = THUMB_STATE_NO;
- goto out;
+ tp_thumb_set_state(tp, t, THUMB_STATE_NO);
+ return;
}
/* If the thumb moves by more than 7mm, it's not a resting thumb */
@@ -72,8 +87,8 @@ tp_thumb_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
delta = device_delta(t->point, t->thumb.initial);
mm = tp_phys_delta(tp, delta);
if (length_in_mm(mm) > 7) {
- t->thumb.state = THUMB_STATE_NO;
- goto out;
+ tp_thumb_set_state(tp, t, THUMB_STATE_NO);
+ return;
}
}
@@ -91,9 +106,11 @@ tp_thumb_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
continue;
if (other->point.y > tp->thumb.upper_thumb_line) {
- t->thumb.state = THUMB_STATE_NO;
+ tp_thumb_set_state(tp, t, THUMB_STATE_NO);
if (other->thumb.state == THUMB_STATE_MAYBE)
- other->thumb.state = THUMB_STATE_NO;
+ tp_thumb_set_state(tp,
+ other,
+ THUMB_STATE_NO);
break;
}
}
@@ -107,15 +124,15 @@ tp_thumb_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
*/
if (tp->thumb.use_pressure &&
t->pressure > tp->thumb.pressure_threshold) {
- t->thumb.state = THUMB_STATE_YES;
+ tp_thumb_set_state(tp, t, THUMB_STATE_YES);
} else if (tp->thumb.use_size &&
(t->major > tp->thumb.size_threshold) &&
(t->minor < (tp->thumb.size_threshold * 0.6))) {
- t->thumb.state = THUMB_STATE_YES;
+ tp_thumb_set_state(tp, t, THUMB_STATE_YES);
} else if (t->point.y > tp->thumb.lower_thumb_line &&
tp->scroll.method != LIBINPUT_CONFIG_SCROLL_EDGE &&
t->thumb.first_touch_time + THUMB_MOVE_TIMEOUT < time) {
- t->thumb.state = THUMB_STATE_YES;
+ tp_thumb_set_state(tp, t, THUMB_STATE_YES);
}
/* now what? we marked it as thumb, so:
@@ -128,13 +145,6 @@ tp_thumb_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
* - tapping: honour thumb on begin, ignore it otherwise for now,
* this gets a tad complicated otherwise
*/
-out:
- if (t->thumb.state != state)
- evdev_log_debug(tp->device,
- "thumb state: touch %d, %s → %s\n",
- t->index,
- thumb_state_to_str(state),
- thumb_state_to_str(t->thumb.state));
}
void
diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index 929de21c..349f730d 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -1537,7 +1537,7 @@ tp_detect_thumb_while_moving(struct tp_dispatch *tp)
evdev_log_debug(tp->device,
"touch %d is speed-based thumb\n",
second->index);
- second->thumb.state = THUMB_STATE_YES;
+ tp_thumb_set_state(tp, second, THUMB_STATE_YES);
}
/**
diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h
index 74006b4e..12a6b03f 100644
--- a/src/evdev-mt-touchpad.h
+++ b/src/evdev-mt-touchpad.h
@@ -690,4 +690,9 @@ tp_thumb_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time);
void
tp_init_thumb(struct tp_dispatch *tp);
+void
+tp_thumb_set_state(struct tp_dispatch *tp,
+ struct tp_touch *t,
+ enum tp_thumb_state state);
+
#endif