[PATCH libinput 3/4] filter: calculate the time delta correctly

Peter Hutterer peter.hutterer at who-t.net
Wed Mar 18 20:11:54 PDT 2015


If the delta is 0, the distance is the number of units (within this ms). Delta
1 means velocity across 2 ms, etc.

Bonus: this doesn't return infinite speed anymore if we get more than one
event per ms. This can happen on any device approaching 1000Hz poll rate, but
definitely got triggered by the test suite.

Actual effect was limited, since we cap out acceleration at max_accel we just
hit this earlier and it stayed there.

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

diff --git a/src/filter.c b/src/filter.c
index 7e935bf..dc29928 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -138,9 +138,10 @@ static double
 calculate_tracker_velocity(struct pointer_tracker *tracker, uint64_t time)
 {
 	double distance;
+	double tdelta = time - tracker->time + 1;
 
 	distance = hypot(tracker->delta.x, tracker->delta.y);
-	return distance / (double)(time - tracker->time); /* units/ms */
+	return distance / tdelta; /* units/ms */
 }
 
 static double
-- 
2.3.2



More information about the wayland-devel mailing list