touchpad: extract some bits of thumb detection into helper functions
authorPeter Hutterer <peter.hutterer@who-t.net>
Thu, 20 Jun 2019 00:37:37 +0000 (10:37 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Mon, 15 Jul 2019 03:08:47 +0000 (13:08 +1000)
No functional changes

Extracted from Matt Mayfield's thumb detection patches.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
src/evdev-mt-touchpad-thumb.c

index eb9dc55..89d715e 100644 (file)
@@ -68,6 +68,39 @@ tp_thumb_reset(struct tp_dispatch *tp, struct tp_touch *t)
        t->thumb.state = THUMB_STATE_MAYBE;
 }
 
+static bool
+tp_thumb_in_exclusion_area(const struct tp_dispatch *tp,
+                          const struct tp_touch *t,
+                          uint64_t time)
+{
+       return (t->point.y > tp->thumb.lower_thumb_line &&
+               tp->scroll.method != LIBINPUT_CONFIG_SCROLL_EDGE &&
+               t->thumb.first_touch_time + THUMB_MOVE_TIMEOUT < time);
+
+}
+
+static bool
+tp_thumb_detect_pressure_size(const struct tp_dispatch *tp,
+                             const struct tp_touch *t,
+                             uint64_t time)
+{
+       bool is_thumb = false;
+
+       if (tp->thumb.use_pressure &&
+           t->pressure > tp->thumb.pressure_threshold &&
+           tp_thumb_in_exclusion_area(tp, t, time)) {
+               is_thumb = true;
+       }
+
+       if (tp->thumb.use_size &&
+           (t->major > tp->thumb.size_threshold) &&
+           (t->minor < (tp->thumb.size_threshold * 0.6))) {
+               is_thumb = true;
+       }
+
+       return is_thumb;
+}
+
 void
 tp_thumb_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
 {
@@ -128,18 +161,9 @@ tp_thumb_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
         * A finger that remains at the very bottom of the touchpad becomes
         * a thumb.
         */
-       if (tp->thumb.use_pressure &&
-           t->pressure > tp->thumb.pressure_threshold) {
-               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))) {
+       if (tp_thumb_detect_pressure_size(tp, t, time) ||
+           tp_thumb_in_exclusion_area(tp, t, time))
                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) {
-               tp_thumb_set_state(tp, t, THUMB_STATE_YES);
-       }
 
        /* now what? we marked it as thumb, so:
         *