[PATCH libinput 11/13] filter: revamp the touchpad's acceleration code

Peter Hutterer peter.hutterer at who-t.net
Mon Dec 19 05:21:02 UTC 2016


The previous code had three main issues:
* acceleration kicked in too early, so even slow movements were accelerated
* acceleration kicked in too quickly, there was only a very narrow window
  where we would have less than the max acceleration factor
* the max accel factor was too low for fast movements, so they still fell
  short of expectations

This patch revamps most of the acceleration though it keeps the basic shape of
the acceleration curve.

* The threshold is increased significantly so that faster movement
  still map to the finger movement. Acceleration doesn't kick in until we get
  to something that's really fast like a flick.
* The incline is dropped, so acceleration kicks in slower than before, i.e.
  the difference between the first speed that is accelerated and the speed
  that reaches the maximum is higher than before.
* The maximum acceleration is increased so ever faster movements get ever
  faster. The max is effectively out of reach now, if you move fast enough to
  hit this speed, your cursor will end up on the moon anyway.

A couple of other changes apply now too, specifically:
* The incline remains the same regardless of the speed
* The max accel factor remains the same regardless of the speed

The caculated factor changes with the speed set so that the base speed changes
with the desired speed.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/filter.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/src/filter.c b/src/filter.c
index 7865c7e..ab503cf 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -135,9 +135,9 @@ filter_get_type(struct motion_filter *filter)
 #define DEFAULT_INCLINE 1.1			/* unitless factor */
 
 /* Touchpad acceleration */
-#define TOUCHPAD_DEFAULT_THRESHOLD 40		/* mm/s */
-#define TOUCHPAD_MINIMUM_THRESHOLD 20		/* mm/s */
-#define TOUCHPAD_ACCELERATION 2.0		/* unitless factor */
+#define TOUCHPAD_DEFAULT_THRESHOLD 254		/* mm/s */
+#define TOUCHPAD_THRESHOLD_RANGE 184		/* mm/s */
+#define TOUCHPAD_ACCELERATION 9.0		/* unitless factor */
 #define TOUCHPAD_INCLINE 0.011			/* unitless factor */
 
 /* for the Lenovo x230 custom accel. do not touch */
@@ -521,19 +521,13 @@ touchpad_accelerator_set_speed(struct motion_filter *filter,
 	/* Note: the numbers below are nothing but trial-and-error magic,
 	   don't read more into them other than "they mostly worked ok" */
 
-	/* delay when accel kicks in */
+	/* adjust when accel kicks in */
 	accel_filter->threshold = TOUCHPAD_DEFAULT_THRESHOLD -
-					v_ms2us(0.25) * speed_adjustment;
-	if (accel_filter->threshold < TOUCHPAD_MINIMUM_THRESHOLD)
-		accel_filter->threshold = TOUCHPAD_MINIMUM_THRESHOLD;
-
-	/* adjust max accel factor */
-	accel_filter->accel = TOUCHPAD_ACCELERATION + speed_adjustment * 1.5;
-
-	/* higher speed -> faster to reach max */
-	accel_filter->incline = TOUCHPAD_INCLINE + speed_adjustment * 0.75;
-
+		TOUCHPAD_THRESHOLD_RANGE * speed_adjustment;
+	accel_filter->accel = TOUCHPAD_ACCELERATION;
+	accel_filter->incline = TOUCHPAD_INCLINE;
 	filter->speed_adjustment = speed_adjustment;
+
 	return true;
 }
 
@@ -805,6 +799,9 @@ touchpad_accel_profile_linear(struct motion_filter *filter,
 	/* Cap at the maximum acceleration factor */
 	factor = min(max_accel, factor);
 
+	/* Scale everything depending on the acceleration set */
+	factor *= 1 + 0.5 * filter->speed_adjustment;
+
 	return factor * TP_MAGIC_SLOWDOWN;
 }
 
-- 
2.9.3



More information about the wayland-devel mailing list