[PATCH libinput] touchpad: fix clickfinger behavior with a thumb being present
Friedrich Schöller
code at schoeller.se
Tue May 16 20:44:22 UTC 2017
With a thumb on the touchpad, a two-finger click was incorrectly
treated as a middle-click. This patch takes the thumb into account and
treats the click as a right-click.
---
src/evdev-mt-touchpad-buttons.c | 44 ++++++++++++++++++-----------------------
1 file changed, 19 insertions(+), 25 deletions(-)
diff --git a/src/evdev-mt-touchpad-buttons.c b/src/evdev-mt-touchpad-buttons.c
index 895cf0e..ffb6a58 100644
--- a/src/evdev-mt-touchpad-buttons.c
+++ b/src/evdev-mt-touchpad-buttons.c
@@ -981,23 +981,24 @@ out:
static uint32_t
tp_clickfinger_set_button(struct tp_dispatch *tp)
{
- uint32_t button;
+ bool thumb_detected = false;
unsigned int nfingers = tp->nfingers_down;
struct tp_touch *t;
struct tp_touch *first = NULL,
*second = NULL;
- if (nfingers != 2)
- goto out;
+ if (nfingers < 2)
+ return BTN_LEFT;
- /* two fingers down on the touchpad. Check for distance
- * between the fingers. */
tp_for_each_touch(tp, t) {
if (t->state != TOUCH_BEGIN && t->state != TOUCH_UPDATE)
continue;
- if (t->thumb.state == THUMB_STATE_YES)
+ if (t->thumb.state == THUMB_STATE_YES) {
+ thumb_detected = true;
+ nfingers--;
continue;
+ }
if (!first)
first = t;
@@ -1005,27 +1006,20 @@ tp_clickfinger_set_button(struct tp_dispatch *tp)
second = t;
}
- if (!first || !second) {
- nfingers = 1;
- goto out;
- }
+ if (nfingers < 2)
+ return BTN_LEFT;
+ else if (nfingers > 2)
+ return BTN_MIDDLE;
- if (tp_clickfinger_within_distance(tp, first, second))
- nfingers = 2;
+ /* Two fingers (not counting thumbs) are on the touchpad. If no
+ * additional thumb was detected, we check the distance between the
+ * touches. Some touchpads can not report more than two finger positions
+ * so we do not check the distance if an additional thumb was detected.
+ */
+ if (thumb_detected || tp_clickfinger_within_distance(tp, first, second))
+ return BTN_RIGHT;
else
- nfingers = 1;
-
-out:
- switch (nfingers) {
- case 0:
- case 1: button = BTN_LEFT; break;
- case 2: button = BTN_RIGHT; break;
- default:
- button = BTN_MIDDLE; break;
- break;
- }
-
- return button;
+ return BTN_LEFT;
}
static int
--
2.9.4
More information about the wayland-devel
mailing list