| From: Yufeng Shen <miletus@chromium.org> |
| Date: Mon, 20 Aug 2012 14:55:57 -0400 |
| Subject: [PATCH] x11-drivers/xf86-input-evdev: Use monotonic timestamps for |
| input events |
| |
| This patch adds the support for xf86-input-evdev to turn on monotonic |
| timestamps if kernel supports it. |
| |
| The clock source is set in EvdevOn() instead of EvdevCache() because the |
| latter is only called once when X registers the input device fd with kernel, |
| and if later X closes and reopens the input device fd (e.g. when the |
| system goes through suspend/resume cycle), the clock source setting |
| will be lost. EvdevOn() is the right place to set clock source since |
| it is called whenever X wants to open the input device and use it. |
| |
| BUG=chrome-os-partner:12187 |
| TEST=On Link, grep "time stamps" /var/log/Xorg.0.log |
| Make sure monotonic timestamp is used for evdev |
| Run "xinput test-xi2" and move fingers on touch device |
| Note that valuator 4 (Touch Timestamp) is using |
| monotonic timestamp. |
| Suspend and resume the device and make sure the timestamp |
| does not change back to real world timestamp. |
| --- |
| src/evdev.c | 16 ++++++++++++++++ |
| src/evdev.h | 1 + |
| 2 files changed, 17 insertions(+), 0 deletions(-) |
| |
| diff --git a/src/evdev.c b/src/evdev.c |
| --- a/src/evdev.c |
| +++ b/src/evdev.c |
| @@ -42,6 +42,7 @@ |
| #include <unistd.h> |
| #include <errno.h> |
| #include <fcntl.h> |
| +#include <time.h> |
| |
| #include <xf86.h> |
| #include <xf86Xinput.h> |
| @@ -61,6 +62,11 @@ |
| #define XI_PROP_VIRTUAL_DEVICE "Virtual Device" |
| #endif |
| |
| +/* Set clockid to be used for timestamps */ |
| +#ifndef EVIOCSCLOCKID |
| +#define EVIOCSCLOCKID _IOW('E', 0xa0, int) |
| +#endif |
| + |
| /* removed from server, purge when dropping support for server 1.10 */ |
| #define XI86_SEND_DRAG_EVENTS 0x08 |
| |
| @@ -1809,6 +1815,12 @@ EvdevInit(DeviceIntPtr device) |
| return Success; |
| } |
| |
| +static int |
| +EvdevEnableMonotonic(InputInfoPtr pInfo) { |
| + unsigned int clk = CLOCK_MONOTONIC; |
| + return (ioctl(pInfo->fd, EVIOCSCLOCKID, &clk) == 0) ? Success : !Success; |
| +} |
| + |
| /** |
| * Init all extras (wheel emulation, etc.) and grab the device. |
| */ |
| @@ -1826,6 +1838,10 @@ EvdevOn(DeviceIntPtr device) |
| if (rc != Success) |
| return rc; |
| |
| + pEvdev->is_monotonic = (EvdevEnableMonotonic(pInfo) == Success); |
| + xf86IDrvMsg(pInfo, X_PROBED, "Using %s input event time stamps\n", |
| + pEvdev->is_monotonic ? "monotonic" : "realtime"); |
| + |
| EvdevGrabDevice(pInfo, 1, 0); |
| |
| xf86FlushInput(pInfo->fd); |
| diff --git a/src/evdev.h b/src/evdev.h |
| --- a/src/evdev.h |
| +++ b/src/evdev.h |
| @@ -173,6 +173,7 @@ typedef struct { |
| BOOL swap_axes; |
| BOOL invert_x; |
| BOOL invert_y; |
| + BOOL is_monotonic; |
| |
| int delta[REL_CNT]; |
| unsigned int abs_queued, rel_queued, prox_queued; |
| -- |
| 1.7.7.3 |
| |