diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2017-04-26 12:38:28 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2017-04-26 12:38:28 +1000 |
commit | 3ecdab130a9305518edb9b0f61fa5d74a052d16c (patch) | |
tree | dd3fc7eeb5b9e8962fe45413b7e4d485d5c39bda /src | |
parent | 97d3ddb070ffb72d011f3eeb8f471b83499e94cc (diff) | |
parent | fe4e2aef0459241234788b7fe4251b17b9a3f4ef (diff) |
Merge branch 'wip/touchpad-custom-pressure-values'
Diffstat (limited to 'src')
-rw-r--r-- | src/evdev-mt-touchpad.c | 44 | ||||
-rw-r--r-- | src/evdev-mt-touchpad.h | 9 | ||||
-rw-r--r-- | src/libinput-util.c | 36 | ||||
-rw-r--r-- | src/libinput-util.h | 1 |
4 files changed, 69 insertions, 21 deletions
diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index 8585351..54a3c8e 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -2456,8 +2456,9 @@ tp_init_pressure(struct tp_dispatch *tp, struct evdev_device *device) { const struct input_absinfo *abs; - unsigned int range; unsigned int code = ABS_PRESSURE; + const char *prop; + int hi, lo; if (tp->has_mt) code = ABS_MT_PRESSURE; @@ -2467,25 +2468,44 @@ tp_init_pressure(struct tp_dispatch *tp, return; } - tp->pressure.use_pressure = true; - abs = libevdev_get_abs_info(device->evdev, code); assert(abs); - range = abs->maximum - abs->minimum; + prop = udev_device_get_property_value(device->udev_device, + "LIBINPUT_ATTR_PRESSURE_RANGE"); + if (prop) { + if (!parse_pressure_range_property(prop, &hi, &lo)) { + evdev_log_bug_client(device, + "discarding invalid pressure range '%s'\n", + prop); + return; + } - if (device->model_flags & EVDEV_MODEL_ELANTECH_TOUCHPAD) { - tp->pressure.high = 24; - tp->pressure.low = 10; - } else if (device->model_flags & EVDEV_MODEL_CYAPA) { - tp->pressure.high = 10; - tp->pressure.low = 8; + if (hi == 0 && lo == 0) { + evdev_log_info(device, + "pressure-based touch detection disabled\n"); + return; + } } else { + unsigned int range = abs->maximum - abs->minimum; + /* Approximately the synaptics defaults */ - tp->pressure.high = abs->minimum + 0.12 * range; - tp->pressure.low = abs->minimum + 0.10 * range; + hi = abs->minimum + 0.12 * range; + lo = abs->minimum + 0.10 * range; + } + + if (hi > abs->maximum || hi < abs->minimum || + lo > abs->maximum || lo < abs->minimum) { + evdev_log_bug_libinput(device, + "discarding out-of-bounds pressure range %d:%d\n", + hi, lo); + return; } + tp->pressure.use_pressure = true; + tp->pressure.high = hi; + tp->pressure.low = lo; + evdev_log_debug(device, "using pressure-based touch detection\n"); } diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h index 93dd37b..8d5bbc4 100644 --- a/src/evdev-mt-touchpad.h +++ b/src/evdev-mt-touchpad.h @@ -44,15 +44,6 @@ enum touchpad_event { TOUCHPAD_EVENT_OTHERAXIS = (1 << 3), }; -enum touchpad_model { - MODEL_UNKNOWN = 0, - MODEL_SYNAPTICS, - MODEL_ALPS, - MODEL_APPLETOUCH, - MODEL_ELANTECH, - MODEL_UNIBODY_MACBOOK -}; - enum touch_state { TOUCH_NONE = 0, TOUCH_HOVERING, diff --git a/src/libinput-util.c b/src/libinput-util.c index 351bbe4..38594fa 100644 --- a/src/libinput-util.c +++ b/src/libinput-util.c @@ -360,6 +360,42 @@ parse_tpkbcombo_layout_poperty(const char *prop, } /** + * Parses a string of the format "a:b" where both a and b must be integer + * numbers and a > b. Also allowed is the special string vaule "none" which + * amounts to unsetting the property. + * + * @param prop The value of the property + * @param hi Set to the first digit or 0 in case of 'none' + * @param lo Set to the second digit or 0 in case of 'none' + * @return true on success, false otherwise + */ +bool +parse_pressure_range_property(const char *prop, int *hi, int *lo) +{ + int first, second; + + if (!prop) + return false; + + if (streq(prop, "none")) { + *hi = 0; + *lo = 0; + return true; + } + + if (sscanf(prop, "%d:%d", &first, &second) != 2) + return false; + + if (second >= first) + return false; + + *hi = first; + *lo = second; + + return true; +} + +/** * 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 3fe0a02..4e97e01 100644 --- a/src/libinput-util.h +++ b/src/libinput-util.h @@ -393,6 +393,7 @@ int parse_mouse_wheel_click_count_property(const char *prop); double parse_trackpoint_accel_property(const char *prop); bool parse_dimension_property(const char *prop, size_t *width, size_t *height); bool parse_calibration_property(const char *prop, float calibration[6]); +bool parse_pressure_range_property(const char *prop, int *hi, int *lo); enum tpkbcombo_layout { TPKBCOMBO_LAYOUT_UNKNOWN, |