[PATCH libinput] touchpad: replace the hardcoded thumb threshold with a udev prop
Peter Hutterer
peter.hutterer at who-t.net
Fri May 25 07:21:56 UTC 2018
LIBINPUT_ATTR_THUMB_PRESSURE_THRESHOLD now determines whether we do thumb
pressure detection or not. Much better than having a hardcoded default that
may or may not be correct on any given device.
This patch is likely to break thumb detection on some touchpads, the only
property so far is to restore the default of 100 for all Lenovo Thinkpad
touchpads. More rules are needed, we'll just wait until someone shouts.
https://bugs.freedesktop.org/show_bug.cgi?id=106458
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
src/evdev-mt-touchpad.c | 37 +++++++++++++++++++++++--------------
src/libinput-util.c | 25 +++++++++++++++++++++++++
src/libinput-util.h | 1 +
udev/90-libinput-model-quirks.hwdb | 4 ++++
4 files changed, 53 insertions(+), 14 deletions(-)
diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index 02b75531..33c52ba4 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -3041,6 +3041,25 @@ tp_init_sendevents(struct tp_dispatch *tp,
tp_keyboard_timeout, tp);
}
+static int
+tp_read_thumb_pressure_prop(struct tp_dispatch *tp,
+ const struct evdev_device *device)
+{
+ struct udev_device *udev_device = device->udev_device;
+ const char *prop;
+ int threshold;
+ const int default_thumb_threshold = 0;
+
+ prop = udev_device_get_property_value(udev_device,
+ "LIBINPUT_ATTR_THUMB_PRESSURE_THRESHOLD");
+ if (!prop)
+ return default_thumb_threshold;
+
+ threshold = parse_thumb_pressure_property(prop);
+
+ return threshold > 0 ? threshold : default_thumb_threshold;
+}
+
static void
tp_init_thumb(struct tp_dispatch *tp)
{
@@ -3049,8 +3068,7 @@ tp_init_thumb(struct tp_dispatch *tp)
double w = 0.0, h = 0.0;
struct device_coords edges;
struct phys_coords mm = { 0.0, 0.0 };
- int xres, yres;
- double threshold;
+ int threshold;
if (!tp->buttons.is_clickpad)
return;
@@ -3079,20 +3097,11 @@ tp_init_thumb(struct tp_dispatch *tp)
if (!abs)
goto out;
- if (abs->maximum - abs->minimum < 255)
+ threshold = tp_read_thumb_pressure_prop(tp, device);
+ if (threshold == 0)
goto out;
- /* Our reference touchpad is the T440s with 42x42 resolution.
- * Higher-res touchpads exhibit higher pressure for the same
- * interaction. On the T440s, the threshold value is 100, you don't
- * reach that with a normal finger interaction.
- * Note: "thumb" means massive touch that should not interact, not
- * "using the tip of my thumb for a pinch gestures".
- */
- xres = tp->device->abs.absinfo_x->resolution;
- yres = tp->device->abs.absinfo_y->resolution;
- threshold = 100.0 * hypot(xres, yres)/hypot(42, 42);
- tp->thumb.threshold = max(100, threshold);
+ tp->thumb.threshold = threshold;
out:
evdev_log_debug(device,
diff --git a/src/libinput-util.c b/src/libinput-util.c
index 80ed489a..eb6e3ecf 100644
--- a/src/libinput-util.c
+++ b/src/libinput-util.c
@@ -456,6 +456,31 @@ parse_palm_size_property(const char *prop)
return thr;
}
+/**
+ * Helper function to parse the LIBINPUT_ATTR_THUMB_PRESSURE_THRESHOLD
+ * property from udev. Property is of the form:
+ * LIBINPUT_ATTR_THUMB_PRESSURE_THRESHOLD=<integer>
+ * Where the number indicates the minimum threshold to consider a touch to
+ * be a thumb.
+ *
+ * @param prop The value of the udev property (without the
+ * LIBINPUT_ATTR_THUMB_PRESSURE_THRESHOLD=)
+ * @return The pressure threshold or 0 on error
+ */
+int
+parse_thumb_pressure_property(const char *prop)
+{
+ int threshold = 0;
+
+ if (!prop)
+ return 0;
+
+ if (!safe_atoi(prop, &threshold) || threshold < 0)
+ return 0;
+
+ return threshold;
+}
+
/**
* Return the next word in a string pointed to by state before the first
* separator character. Call repeatedly to tokenize a whole string.
diff --git a/src/libinput-util.h b/src/libinput-util.h
index c6759718..92e7cf73 100644
--- a/src/libinput-util.h
+++ b/src/libinput-util.h
@@ -419,6 +419,7 @@ bool parse_calibration_property(const char *prop, float calibration[6]);
bool parse_range_property(const char *prop, int *hi, int *lo);
int parse_palm_pressure_property(const char *prop);
int parse_palm_size_property(const char *prop);
+int parse_thumb_pressure_property(const char *prop);
enum tpkbcombo_layout {
TPKBCOMBO_LAYOUT_UNKNOWN,
diff --git a/udev/90-libinput-model-quirks.hwdb b/udev/90-libinput-model-quirks.hwdb
index e3ba8929..a066dbde 100644
--- a/udev/90-libinput-model-quirks.hwdb
+++ b/udev/90-libinput-model-quirks.hwdb
@@ -251,6 +251,10 @@ libinput:name:SynPS/2 Synaptics TouchPad:dmi:*svnLENOVO:*:pvrThinkPadX1Carbon3rd
LIBINPUT_MODEL_LENOVO_T450_TOUCHPAD=1
LIBINPUT_ATTR_PALM_PRESSURE_THRESHOLD=150
+# Lenovo ThinkPad series
+libinput:name:*Synaptics*:dmi:*svnLENOVO:*:pvrThinkPad*:*
+ LIBINPUT_ATTR_THUMB_PRESSURE_THRESHOLD=100
+
# Lenovo ThinkPad Compact USB Keyboard with TrackPoint
libinput:keyboard:input:b0003v17EFp6047*
LIBINPUT_ATTR_KEYBOARD_INTEGRATION=external
--
2.14.3
More information about the wayland-devel
mailing list