[PATCH libinput 7/9] touchpad: add touch-size-based palm detection

Peter Hutterer peter.hutterer at who-t.net
Wed Mar 29 04:59:06 UTC 2017


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev-mt-touchpad.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 src/evdev-mt-touchpad.h |  3 +++
 2 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index b2c22ff..08014f6 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -680,6 +680,34 @@ tp_palm_detect_multifinger(struct tp_dispatch *tp, struct tp_touch *t, uint64_t
 }
 
 static inline bool
+tp_palm_detect_touch_size_triggered(struct tp_dispatch *tp,
+				    struct tp_touch *t,
+				    uint64_t time)
+{
+	const struct rthreshold *thr = &tp->palm.threshold;
+	int angle;
+
+	if (!tp->touch_size.use_touch_size)
+		return false;
+
+	/* If a finger size is large enough for palm, we stick with that and
+	 * force the user to release and reset the finger */
+	if (t->palm.state != PALM_NONE && t->palm.state != PALM_TOUCH_SIZE)
+		return false;
+
+	angle = abs(t->orientation) * tp->touch_size.orientation_to_angle;
+
+	if (angle > 45 && t->major > rthreshold_at_angle(thr, angle)) {
+		evdev_log_debug(tp->device,
+				"palm: touch size exceeded\n");
+		t->palm.state = PALM_TOUCH_SIZE;
+		return true;
+	}
+
+	return false;
+}
+
+static inline bool
 tp_palm_detect_edge(struct tp_dispatch *tp,
 		    struct tp_touch *t,
 		    uint64_t time)
@@ -739,6 +767,9 @@ tp_palm_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
 	if (tp_palm_detect_trackpoint_triggered(tp, t, time))
 		goto out;
 
+	if (tp_palm_detect_touch_size_triggered(tp, t, time))
+		goto out;
+
 	if (tp_palm_detect_edge(tp, t, time))
 		goto out;
 
@@ -757,6 +788,9 @@ out:
 	case PALM_TRACKPOINT:
 		palm_state = "trackpoint";
 		break;
+	case PALM_TOUCH_SIZE:
+		palm_state = "touch size";
+		break;
 	case PALM_NONE:
 	default:
 		abort();
@@ -2310,14 +2344,22 @@ tp_init_palmdetect(struct tp_dispatch *tp,
 	tp->palm.right_edge = INT_MAX;
 	tp->palm.left_edge = INT_MIN;
 
+	if (tp->touch_size.use_touch_size) {
+		const int mm = 17;
+		int xres = device->abs.absinfo_x->resolution,
+		    yres = device->abs.absinfo_y->resolution;
+
+		tp->palm.threshold = rthreshold_init(mm, xres, yres);
+	}
+
 	if (device->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD &&
 	    !tp_is_tpkb_combo_below(device))
 		return;
 
 	evdev_device_get_size(device, &width, &height);
 
-	/* Enable palm detection on touchpads >= 70 mm. Anything smaller
-	   probably won't need it, until we find out it does */
+	/* Enable edge palm detection on touchpads >= 70 mm. Anything
+	 * smaller probably won't need it, until we find out it does */
 	if (width < 70.0)
 		return;
 
diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h
index 5282b67..ee0c9d5 100644
--- a/src/evdev-mt-touchpad.h
+++ b/src/evdev-mt-touchpad.h
@@ -66,6 +66,7 @@ enum touch_palm_state {
 	PALM_EDGE,
 	PALM_TYPING,
 	PALM_TRACKPOINT,
+	PALM_TOUCH_SIZE,
 };
 
 enum button_event {
@@ -360,6 +361,8 @@ struct tp_dispatch {
 		uint64_t trackpoint_last_event_time;
 		uint32_t trackpoint_event_count;
 		bool monitor_trackpoint;
+
+		struct rthreshold threshold;
 	} palm;
 
 	struct {
-- 
2.9.3



More information about the wayland-devel mailing list