[PATCH evdev 1/2] Use monotonic timestamps for input events #59702

Chung-yih Wang cywang at chromium.org
Tue Jan 22 01:50:00 PST 2013


From: Yufeng Shen <miletus at chromium.org>

This patch adds the support for xf86-input-evdev to turn on monotonic
timestamps if kernel supports it.

And it corrects a previous similar patch by setting the clock source
at the right place in EvdevOn() instead of EvdevCache(). EvdevCache()
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.

Signed-off-by: Chung-yih Wang <cywang at chromium.org>
---
 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
index 5667dc1..6564cd0 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -43,6 +43,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <time.h>
 
 #include <xf86.h>
 #include <xf86Xinput.h>
@@ -62,6 +63,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
 
@@ -1792,6 +1798,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.
  */
@@ -1809,6 +1821,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
index 51b7fa0..58a3fa3 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -177,6 +177,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



More information about the xorg-devel mailing list