touchpad: add timestamp-based jump detection
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 21 Aug 2018 05:43:38 +0000 (15:43 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Fri, 31 Aug 2018 01:12:42 +0000 (11:12 +1000)
commit1f5c0119e4774471ab7b77dcedbfb0335b38e084
tree84752dca1ec27c923dda49fb6cbc53983717923e
parent0e2f1babc58cc2f38b8be77b63047df2f0d2b813
touchpad: add timestamp-based jump detection

On Dell i2c touchpads, the controller appears to go to sleep after about 1s of
inactivity on the touchpad. The wakeup takes a while so on the next touch, we
may see a pointer jump, specifially on the third event (i.e. touch down,
event, event+jump). The MSC_TIMESTAMP value carries a hint for what's
happening here, the event sequence for a touchpad with scanout intervals
7300µs is:

...
MSC_TIMESTAMP 0
SYN_REPORT
...
MSC_TIMESTAMP 7300
SYN_REPORT +2ms
...
MSC_TIMESTAMP 123456
SYN_REPORT +7ms
...
MSC_TIMESTAMP 123456+7300
SYN_REPORT +8ms

Note how the SYN_REPORT timestamps don't reflect the MSC_TIMESTAMPS.

This patch adds a quirk activate MSC_TIMESTAMP watching. When we do so, we
monitor for a 0 MSC_TIMESTAMP. Let's assume that the first event after that is
the interval, then check the third event. If that third event's timestamp is too
large rewrite the touches' motion history to reflect the correct timestamps,
i.e. instead of the SYN_REPORT timestamps the motion history now uses
"third-event SYN_REPORT timestamps minus MSC_TIMESTAMP values".

The pointer accel filter code uses absolute timestamps (#123) so we have to
restart the pointer acceleration filter when we detect this jump. This allows
us to reset the 0 time for the filter to the previous event's MSC_TIMESTAMP
time, so that our new large delta has the correct time delta too. This
calculates the acceleration correctly for that window.

The result is that the pointer is still delayed by the wake-up window (not
fixable in libinput) but at least it ends up where it should've.

There are a few side-effects: thumb, gesture, and hysteresis all still use the
unmodified SYN_REPORT time. There is a potential for false detection of either
of these now, but we'll have to fix those as they come up.

Fixes #36

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
src/evdev-mt-touchpad.c
src/evdev-mt-touchpad.h
src/evdev.c