touchpad: clean up the thumb pressure handling out a bit
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 25 Jul 2018 04:41:38 +0000 (14:41 +1000)
committerMatt Mayfield <mdmayfield@users.noreply.github.com>
Wed, 29 Aug 2018 21:35:07 +0000 (16:35 -0500)
Use a boolean for whether we need to use it and drop the unneded absinfo
assignment (together with the goto).

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

index 291b632..f939971 100644 (file)
@@ -1132,7 +1132,8 @@ 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 (t->pressure > tp->thumb.threshold)
+       if (tp->thumb.use_pressure &&
+           t->pressure > tp->thumb.pressure_threshold)
                t->thumb.state = THUMB_STATE_YES;
        else if (t->point.y > tp->thumb.lower_thumb_line &&
                 tp->scroll.method != LIBINPUT_CONFIG_SCROLL_EDGE &&
@@ -3082,7 +3083,6 @@ static void
 tp_init_thumb(struct tp_dispatch *tp)
 {
        struct evdev_device *device = tp->device;
-       const struct input_absinfo *abs;
        double w = 0.0, h = 0.0;
        struct device_coords edges;
        struct phys_coords mm = { 0.0, 0.0 };
@@ -3101,7 +3101,8 @@ tp_init_thumb(struct tp_dispatch *tp)
                return;
 
        tp->thumb.detect_thumbs = true;
-       tp->thumb.threshold = INT_MAX;
+       tp->thumb.use_pressure = false;
+       tp->thumb.pressure_threshold = INT_MAX;
 
        /* detect thumbs by pressure in the bottom 15mm, detect thumbs by
         * lingering in the bottom 8mm */
@@ -3113,22 +3114,23 @@ tp_init_thumb(struct tp_dispatch *tp)
        edges = evdev_device_mm_to_units(device, &mm);
        tp->thumb.lower_thumb_line = edges.y;
 
-       abs = libevdev_get_abs_info(device->evdev, ABS_MT_PRESSURE);
-       if (!abs)
-               goto out;
-
        quirks = evdev_libinput_context(device)->quirks;
        q = quirks_fetch_for_device(quirks, device->udev_device);
-       if (quirks_get_uint32(q,
-                             QUIRK_ATTR_THUMB_PRESSURE_THRESHOLD,
-                             &threshold))
-               tp->thumb.threshold = threshold;
+
+       if (libevdev_has_event_code(device->evdev, EV_ABS, ABS_MT_PRESSURE)) {
+               if (quirks_get_uint32(q,
+                                     QUIRK_ATTR_THUMB_PRESSURE_THRESHOLD,
+                                     &threshold)) {
+                       tp->thumb.use_pressure = true;
+                       tp->thumb.pressure_threshold = threshold;
+               }
+       }
+
        quirks_unref(q);
 
-out:
        evdev_log_debug(device,
                        "thumb: enabled thumb detection%s\n",
-                       tp->thumb.threshold != INT_MAX ? " (+pressure)" : "");
+                       tp->thumb.use_pressure ? " (+pressure)" : "");
 }
 
 static bool
index 00332ad..f0f6145 100644 (file)
@@ -441,9 +441,11 @@ struct tp_dispatch {
 
        struct {
                bool detect_thumbs;
-               int threshold;
                int upper_thumb_line;
                int lower_thumb_line;
+
+               bool use_pressure;
+               int pressure_threshold;
        } thumb;
 
        struct {