From a1effa1676473e4d0fdcba8c282cc2798ce21539 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 25 Jul 2018 14:41:38 +1000 Subject: [PATCH] touchpad: clean up the thumb pressure handling out a bit 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 --- src/evdev-mt-touchpad.c | 28 +++++++++++++++------------- src/evdev-mt-touchpad.h | 4 +++- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index 291b632..f939971 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -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 diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h index 00332ad..f0f6145 100644 --- a/src/evdev-mt-touchpad.h +++ b/src/evdev-mt-touchpad.h @@ -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 { -- 2.7.4