Fix jumpy touchpads by updating old_vals only when reported by the device.

Remember whether ABS_X or ABS_Y were reported before the SYN event and only
update the old_vals[0, 1] if we got data for them.
Touchpads that reported pressure data before x/y would otherwise update
old_x/y with bogus values, leading to jumps when the first x/y coordinates
were actually reported.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer
2009-03-17 14:08:29 +10:00
parent b11439a176
commit d9809d7edd

View File

@@ -343,6 +343,9 @@ EvdevReopenTimer(OsTimerPtr timer, CARD32 time, pointer arg)
return 100; /* come back in 100 ms */
}
#define ABS_X_VALUE 0x1
#define ABS_Y_VALUE 0x2
#define ABS_VALUE 0x4
/**
* Take one input event and process it accordingly.
*/
@@ -393,7 +396,12 @@ EvdevProcessEvent(InputInfoPtr pInfo, struct input_event *ev)
if (ev->code > ABS_MAX)
break;
pEvdev->vals[pEvdev->axis_map[ev->code]] = value;
abs = 1;
if (ev->code == ABS_X)
abs |= ABS_X_VALUE;
else if (ev->code == ABS_Y)
abs |= ABS_Y_VALUE;
else
abs |= ABS_VALUE;
break;
case EV_KEY:
@@ -444,18 +452,20 @@ EvdevProcessEvent(InputInfoPtr pInfo, struct input_event *ev)
case EV_SYN:
/* convert to relative motion for touchpads */
if (abs && (pEvdev->flags & EVDEV_TOUCHPAD)) {
abs = 0;
rel = 1;
if (pEvdev->tool) { /* meaning, touch is active */
if (pEvdev->old_vals[0] != -1)
delta[REL_X] = pEvdev->vals[0] - pEvdev->old_vals[0];
if (pEvdev->old_vals[1] != -1)
delta[REL_Y] = pEvdev->vals[1] - pEvdev->old_vals[1];
pEvdev->old_vals[0] = pEvdev->vals[0];
pEvdev->old_vals[1] = pEvdev->vals[1];
if (abs & ABS_X_VALUE)
pEvdev->old_vals[0] = pEvdev->vals[0];
if (abs & ABS_Y_VALUE)
pEvdev->old_vals[1] = pEvdev->vals[1];
} else {
pEvdev->old_vals[0] = pEvdev->old_vals[1] = -1;
}
abs = 0;
rel = 1;
}
if (rel) {
@@ -538,6 +548,10 @@ EvdevProcessEvent(InputInfoPtr pInfo, struct input_event *ev)
}
}
#undef ABS_X_VALUE
#undef ABS_Y_VALUE
#undef ABS_VALUE
/* just a magic number to reduce the number of reads */
#define NUM_EVENTS 16