[PATCH libinput 6/9] Push the touchpad magic slowdown to the touchpad accel code

Peter Hutterer peter.hutterer at who-t.net
Mon Mar 16 22:34:30 PDT 2015


This way the unaccelerated deltas returned by libinput are correct.

To maintain the current behavior we slow down the input speed by the magic
factor and likewise the accelerated output speed. This produces virtually the
same accelerated deltas as the previous code.

The magic factor is applied to the default denominator for guessing a
resolution based on the touchpad diagonal. We can't really get around this
without having a resolution from the touchpad; meanwhile this produces
virtually the same coordinates before/after.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev-mt-touchpad.c | 20 ++++++--------------
 src/evdev-mt-touchpad.h |  4 +---
 src/evdev.c             | 11 ++++++-----
 src/evdev.h             |  4 +++-
 src/filter.c            | 21 +++++++++++++++++++++
 src/filter.h            |  5 +++++
 6 files changed, 42 insertions(+), 23 deletions(-)

diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index d0311a4..b7760c2 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -29,7 +29,9 @@
 
 #include "evdev-mt-touchpad.h"
 
-#define DEFAULT_ACCEL_NUMERATOR 1200.0
+/* Number found by trial-and error, seems to be 1200, divided by the
+ * TP_MAGIC_SLOWDOWN in filter.c */
+#define DEFAULT_ACCEL_NUMERATOR 3000.0
 #define DEFAULT_HYSTERESIS_MARGIN_DENOMINATOR 700.0
 #define DEFAULT_TRACKPOINT_ACTIVITY_TIMEOUT 500 /* ms */
 
@@ -974,18 +976,6 @@ tp_init_accel(struct tp_dispatch *tp, double diagonal)
 	if (res_x > 1 && res_y > 1) {
 		tp->accel.x_scale_coeff = (DEFAULT_MOUSE_DPI/25.4) / res_x;
 		tp->accel.y_scale_coeff = (DEFAULT_MOUSE_DPI/25.4) / res_y;
-
-		/* FIXME: once normalized, touchpads see the same
-		   acceleration as mice. that is technically correct but
-		   subjectively wrong, we expect a touchpad to be a lot
-		   slower than a mouse.
-		   For now, apply a magic factor here until this is
-		   fixed in the actual filter code.
-		 */
-		{
-			tp->accel.x_scale_coeff *= TP_MAGIC_SLOWDOWN;
-			tp->accel.y_scale_coeff *= TP_MAGIC_SLOWDOWN;
-		}
 	} else {
 	/*
 	 * For touchpads where the driver does not provide resolution, fall
@@ -995,7 +985,9 @@ tp_init_accel(struct tp_dispatch *tp, double diagonal)
 		tp->accel.y_scale_coeff = DEFAULT_ACCEL_NUMERATOR / diagonal;
 	}
 
-	if (evdev_device_init_pointer_acceleration(tp->device) == -1)
+	if (evdev_device_init_pointer_acceleration(
+                                       tp->device,
+                                       touchpad_accel_profile_linear) == -1)
 		return -1;
 
 	return 0;
diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h
index 04acf21..9980f90 100644
--- a/src/evdev-mt-touchpad.h
+++ b/src/evdev-mt-touchpad.h
@@ -34,10 +34,8 @@
 
 #define VENDOR_ID_APPLE 0x5ac
 
-/* Touchpad slowdown factor, see the FIXME in tp_init_accel() */
-#define TP_MAGIC_SLOWDOWN 0.4
 /* Convert mm to a distance normalized to DEFAULT_MOUSE_DPI */
-#define TP_MM_TO_DPI_NORMALIZED(mm) (DEFAULT_MOUSE_DPI/25.4 * TP_MAGIC_SLOWDOWN  * mm)
+#define TP_MM_TO_DPI_NORMALIZED(mm) (DEFAULT_MOUSE_DPI/25.4 * mm)
 
 enum touchpad_event {
 	TOUCHPAD_EVENT_NONE		= 0,
diff --git a/src/evdev.c b/src/evdev.c
index 570c436..ff7bc37 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -1266,11 +1266,10 @@ evdev_accel_config_get_default_speed(struct libinput_device *device)
 }
 
 int
-evdev_device_init_pointer_acceleration(struct evdev_device *device)
+evdev_device_init_pointer_acceleration(struct evdev_device *device,
+				       accel_profile_func_t profile)
 {
-	device->pointer.filter =
-		create_pointer_accelerator_filter(
-			pointer_accel_profile_linear);
+	device->pointer.filter = create_pointer_accelerator_filter(profile);
 	if (!device->pointer.filter)
 		return -1;
 
@@ -1575,7 +1574,9 @@ evdev_configure_device(struct evdev_device *device)
 	if (udev_tags & EVDEV_UDEV_TAG_MOUSE) {
 		if (!libevdev_has_event_code(evdev, EV_ABS, ABS_X) &&
 		    !libevdev_has_event_code(evdev, EV_ABS, ABS_Y) &&
-		    evdev_device_init_pointer_acceleration(device) == -1)
+		    evdev_device_init_pointer_acceleration(
+					device,
+					pointer_accel_profile_linear) == -1)
 			return -1;
 
 		device->seat_caps |= EVDEV_DEVICE_POINTER;
diff --git a/src/evdev.h b/src/evdev.h
index caafd53..ddaab9f 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -32,6 +32,7 @@
 
 #include "libinput-private.h"
 #include "timer.h"
+#include "filter.h"
 
 /* The HW DPI rate we normalize to before calculating pointer acceleration */
 #define DEFAULT_MOUSE_DPI 1000
@@ -212,7 +213,8 @@ evdev_device_create(struct libinput_seat *seat,
 		    struct udev_device *device);
 
 int
-evdev_device_init_pointer_acceleration(struct evdev_device *device);
+evdev_device_init_pointer_acceleration(struct evdev_device *device,
+				       accel_profile_func_t profile);
 
 struct evdev_dispatch *
 evdev_touchpad_create(struct evdev_device *device);
diff --git a/src/filter.c b/src/filter.c
index 72ef760..306a2fe 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -327,3 +327,24 @@ pointer_accel_profile_linear(struct motion_filter *filter,
 
 	return min(max_accel, s2 > 1 ? s2 : s1);
 }
+
+double
+touchpad_accel_profile_linear(struct motion_filter *filter,
+                              void *data,
+                              double speed_in,
+                              uint64_t time)
+{
+	/* Once normalized, touchpads see the same
+	   acceleration as mice. that is technically correct but
+	   subjectively wrong, we expect a touchpad to be a lot
+	   slower than a mouse. Apply a magic factor here and proceed
+	   as normal.  */
+	const double TP_MAGIC_SLOWDOWN = 0.4;
+	double speed_out;
+
+	speed_in *= TP_MAGIC_SLOWDOWN;
+
+	speed_out = pointer_accel_profile_linear(filter, data, speed_in, time);
+
+	return speed_out * TP_MAGIC_SLOWDOWN;
+}
diff --git a/src/filter.h b/src/filter.h
index 9e90330..f23b691 100644
--- a/src/filter.h
+++ b/src/filter.h
@@ -64,4 +64,9 @@ pointer_accel_profile_linear(struct motion_filter *filter,
 			     void *data,
 			     double speed_in,
 			     uint64_t time);
+double
+touchpad_accel_profile_linear(struct motion_filter *filter,
+			      void *data,
+			      double speed_in,
+			      uint64_t time);
 #endif /* FILTER_H */
-- 
2.3.2



More information about the wayland-devel mailing list