From 6a97e545fbc53d63813df7fa7e436a7083e19c2f Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 22 Apr 2015 12:25:13 +1000 Subject: [PATCH libinput] filter: enforce minimum velocity In the current code, a timeout or direction change on the first tracker will result in a velocity of 0. Really slow movements will thus always be zero, and the first event after a direction is swallowed. Enforce a minimum velocity: In the case of a timeout, assume the current velocity is that of distance/timeout. In the case of a direction change, the velocity is simply that since the last tracker. Signed-off-by: Peter Hutterer --- src/filter.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/filter.c b/src/filter.c index b446221..e9aaf7b 100644 --- a/src/filter.c +++ b/src/filter.c @@ -142,6 +142,24 @@ calculate_tracker_velocity(struct pointer_tracker *tracker, uint64_t time) return normalized_length(tracker->delta) / tdelta; /* units/ms */ } +static inline double +calculate_velocity_after_timeout(struct pointer_tracker *tracker) +{ + /* First movement after timeout needs special handling. + * + * When we trigger the timeout, the last event is too far in the + * past to use it for velocity calculation across multiple tracker + * values. + * + * Use the motion timeout itself to calculate the speed rather than + * the last tracker time. This errs on the side of being too fast + * for really slow movements but provides much more useful initial + * movement in normal use-cases (pause, move, pause, move) + */ + return calculate_tracker_velocity(tracker, + tracker->time + MOTION_TIMEOUT); +} + static double calculate_velocity(struct pointer_accelerator *accel, uint64_t time) { @@ -161,15 +179,23 @@ calculate_velocity(struct pointer_accelerator *accel, uint64_t time) /* Stop if too far away in time */ if (time - tracker->time > MOTION_TIMEOUT || - tracker->time > time) + tracker->time > time) { + if (offset == 1) + result = calculate_velocity_after_timeout(tracker); break; + } + + velocity = calculate_tracker_velocity(tracker, time); /* Stop if direction changed */ dir &= tracker->dir; - if (dir == 0) + if (dir == 0) { + /* First movement after dirchange - velocity is that + * of the last movement */ + if (offset == 1) + result = velocity; break; - - velocity = calculate_tracker_velocity(tracker, time); + } if (initial_velocity == 0.0) { result = initial_velocity = velocity; -- 2.3.5