[PATCH libinput 5/5] touchpad: normalize the touchpad resolution to 400dpi, not 10 units/mm

Peter Hutterer peter.hutterer at who-t.net
Mon Jul 7 21:20:42 PDT 2014


In an attempt to bring method into the madness, normalize the touchpad deltas
to those of a USB mouse with 400 dpi. This way the data we're dealing with in
the acceleration code is of a known quantity.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
An extra comment on this: this changes the speed of the touchpad and should
in theory at least provide the same speed on a touchpad and a 400 dpi mouse.
I'm not against the idea of having differnent speeds for touchpad and mouse,
but it should be explicit in the code by applying different acceleration
methods or settings. So far it was hidden by the touchpad having a
different resolution which is not ideal.

 src/evdev-mt-touchpad.c | 15 +++++++++------
 src/filter.c            |  9 ++++++++-
 src/filter.h            |  2 +-
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index cf97eae..b3265fb 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -663,14 +663,17 @@ tp_init_accel(struct tp_dispatch *tp, double diagonal)
 
 	/*
 	 * Not all touchpads report the same amount of units/mm (resolution).
-	 * Normalize motion events to a resolution of 10 units/mm as base
-	 * (unaccelerated) speed. This also evens out any differences in x
-	 * and y resolution, so that a circle on the touchpad does not turn
-	 * into an elipse on the screen.
+	 * Normalize motion events to a resolution of 15.74 units/mm
+	 * (== 400 dpi) as base (unaccelerated) speed. This also evens out any
+	 * differences in x and y resolution, so that a circle on the
+	 * touchpad does not turn into an elipse on the screen.
+	 *
+	 * We pick 400dpi as thats one of the many default resolutions
+	 * for USB mice, so we end up with a similar base speed on the device.
 	 */
 	if (res_x > 1 && res_y > 1) {
-		tp->accel.x_scale_coeff = 10.0 / res_x;
-		tp->accel.y_scale_coeff = 10.0 / res_y;
+		tp->accel.x_scale_coeff = (400/25.4) / res_x;
+		tp->accel.y_scale_coeff = (400/25.4) / res_y;
 	} else {
 	/*
 	 * For touchpads where the driver does not provide resolution, fall
diff --git a/src/filter.c b/src/filter.c
index 9e605d3..2822bec 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -341,7 +341,14 @@ pointer_accel_profile_smooth_simple(struct motion_filter *filter,
 	if (accel < 1.0)
 		accel = 1.0;
 
-
+	/* We use units/ms as velocity but it has no real meaning unless all
+	   devices have the same resolution. For touchpads, we normalize to
+	   400dpi (15.75 units/mm), but the resolution on USB mice is all
+	   over the place. Though most mice these days have either 400
+	   dpi (15.75 units/mm), 800 dpi or 1000dpi, excluding gaming mice
+	   that can usually adjust it on the fly anyway and currently go up
+	   to 8200dpi.
+	  */
 	if (velocity < (threshold / 2.0))
 		return calc_penumbral_gradient(0.5 + velocity / threshold) * 2.0 - 1.0;
 
diff --git a/src/filter.h b/src/filter.h
index e670e1b..c0b27d0 100644
--- a/src/filter.h
+++ b/src/filter.h
@@ -26,7 +26,7 @@
 #include "config.h"
 
 struct motion_params {
-	double dx, dy;
+	double dx, dy; /* in units/ms @ 400dpi */
 };
 
 struct motion_filter;
-- 
1.9.3



More information about the wayland-devel mailing list