[PATCH 4/7] dix: provide accessor methods for the last device event time

Peter Hutterer peter.hutterer at who-t.net
Wed Oct 16 20:58:17 PDT 2013


And now that we have the accessors, localize it. No functional changes, just
preparing for a future change.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 Xext/saver.c        |  6 ++----
 Xext/sync.c         |  2 +-
 dix/events.c        | 41 ++++++++++++++++++++++++++++++-----------
 dix/globals.c       |  1 -
 dix/window.c        |  4 +---
 include/dix.h       |  5 +++++
 include/dixstruct.h |  1 -
 os/WaitFor.c        |  2 +-
 os/xdmcp.c          |  2 +-
 9 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/Xext/saver.c b/Xext/saver.c
index fe81bc4..e06f408 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -392,9 +392,7 @@ ScreenSaverFreeSuspend(pointer value, XID id)
             DeviceIntPtr dev;
             UpdateCurrentTimeIf();
             nt_list_for_each_entry(dev, inputInfo.devices, next)
-                lastDeviceEventTime[dev->id] = currentTime;
-            lastDeviceEventTime[XIAllDevices] = currentTime;
-            lastDeviceEventTime[XIAllMasterDevices] = currentTime;
+                NoticeTime(dev, currentTime);
             SetScreenSaverTimer();
         }
     }
@@ -681,7 +679,7 @@ ProcScreenSaverQueryInfo(ClientPtr client)
     pPriv = GetScreenPrivate(pDraw->pScreen);
 
     UpdateCurrentTime();
-    lastInput = GetTimeInMillis() - lastDeviceEventTime[XIAllDevices].milliseconds;
+    lastInput = GetTimeInMillis() - LastEventTime(XIAllDevices).milliseconds;
 
     rep = (xScreenSaverQueryInfoReply) {
         .type = X_Reply,
diff --git a/Xext/sync.c b/Xext/sync.c
index f8eb02a..ed891b1 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -2605,7 +2605,7 @@ IdleTimeQueryValue(pointer pCounter, CARD64 * pValue_return)
     }
     else
         deviceid = XIAllDevices;
-    idle = GetTimeInMillis() - lastDeviceEventTime[deviceid].milliseconds;
+    idle = GetTimeInMillis() - LastEventTime(deviceid).milliseconds;
     XSyncIntsToValue(pValue_return, idle, 0);
 }
 
diff --git a/dix/events.c b/dix/events.c
index 7a1b1c3..c803721 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -262,6 +262,8 @@ InputInfo inputInfo;
 
 EventSyncInfoRec syncEvents;
 
+static TimeStamp lastDeviceEventTime[MAXDEVICES];
+
 /**
  * The root window the given device is currently on.
  */
@@ -1043,33 +1045,47 @@ XineramaGetCursorScreen(DeviceIntPtr pDev)
 #define TIMESLOP (5 * 60 * 1000)        /* 5 minutes */
 
 static void
-MonthChangedOrBadTime(InternalEvent *ev)
+MonthChangedOrBadTime(CARD32 *ms)
 {
     /* If the ddx/OS is careless about not processing timestamped events from
      * different sources in sorted order, then it's possible for time to go
      * backwards when it should not.  Here we ensure a decent time.
      */
-    if ((currentTime.milliseconds - ev->any.time) > TIMESLOP)
+    if ((currentTime.milliseconds - *ms) > TIMESLOP)
         currentTime.months++;
     else
-        ev->any.time = currentTime.milliseconds;
+        *ms = currentTime.milliseconds;
 }
 
-static void
-NoticeTime(InternalEvent *ev, DeviceIntPtr dev)
+void
+NoticeTime(const DeviceIntPtr dev, TimeStamp time)
 {
-    if (ev->any.time < currentTime.milliseconds)
-        MonthChangedOrBadTime(ev);
-    currentTime.milliseconds = ev->any.time;
     lastDeviceEventTime[XIAllDevices] = currentTime;
     lastDeviceEventTime[dev->id] = currentTime;
 }
 
+static void
+NoticeTimeMillis(const DeviceIntPtr dev, CARD32 *ms)
+{
+    TimeStamp time;
+    if (*ms < currentTime.milliseconds)
+        MonthChangedOrBadTime(ms);
+    time.months = currentTime.months;
+    time.milliseconds = *ms;
+    NoticeTime(dev, time);
+}
+
 void
 NoticeEventTime(InternalEvent *ev, DeviceIntPtr dev)
 {
     if (!syncEvents.playingEvents)
-        NoticeTime(ev, dev);
+        NoticeTimeMillis(dev, &ev->any.time);
+}
+
+TimeStamp
+LastEventTime(int deviceid)
+{
+    return lastDeviceEventTime[deviceid];
 }
 
 /**************************************************************************
@@ -1093,7 +1109,7 @@ EnqueueEvent(InternalEvent *ev, DeviceIntPtr device)
     if (!xorg_list_is_empty(&syncEvents.pending))
         tail = xorg_list_last_entry(&syncEvents.pending, QdEventRec, next);
 
-    NoticeTime((InternalEvent *)event, device);
+    NoticeTimeMillis(device, &ev->any.time);
 
     /* Fix for key repeating bug. */
     if (device->key != NULL && device->key->xkbInfo != NULL &&
@@ -5276,8 +5292,11 @@ InitEvents(void)
     inputInfo.pointer = (DeviceIntPtr) NULL;
 
     for (i = 0; i < MAXDEVICES; i++) {
+        DeviceIntRec dummy;
         memcpy(&event_filters[i], default_filter, sizeof(default_filter));
-        lastDeviceEventTime[i] = currentTime;
+
+        dummy.id = i;
+        NoticeTime(&dummy, currentTime);
     }
 
     syncEvents.replayDev = (DeviceIntPtr) NULL;
diff --git a/dix/globals.c b/dix/globals.c
index 332b91f..ad9145b 100644
--- a/dix/globals.c
+++ b/dix/globals.c
@@ -122,7 +122,6 @@ Bool party_like_its_1989 = FALSE;
 Bool whiteRoot = FALSE;
 
 TimeStamp currentTime;
-TimeStamp lastDeviceEventTime[MAXDEVICES];
 
 int defaultColorVisualClass = -1;
 int monitorResolution = 0;
diff --git a/dix/window.c b/dix/window.c
index cff341b..92df1eb 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -3089,9 +3089,7 @@ dixSaveScreens(ClientPtr client, int on, int mode)
             DeviceIntPtr dev;
             UpdateCurrentTimeIf();
             nt_list_for_each_entry(dev, inputInfo.devices, next)
-                lastDeviceEventTime[dev->id] = currentTime;
-            lastDeviceEventTime[XIAllDevices] = currentTime;
-            lastDeviceEventTime[XIAllMasterDevices] = currentTime;
+                NoticeTime(dev, currentTime);
         }
         SetScreenSaverTimer();
     }
diff --git a/include/dix.h b/include/dix.h
index 171e56e..fd2490f 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -315,8 +315,13 @@ extern _X_EXPORT WindowPtr
 GetSpriteWindow(DeviceIntPtr pDev);
 
 extern _X_EXPORT void
+NoticeTime(const DeviceIntPtr dev,
+           TimeStamp time);
+extern _X_EXPORT void
 NoticeEventTime(InternalEvent *ev,
                 DeviceIntPtr dev);
+extern _X_EXPORT TimeStamp
+LastEventTime(int deviceid);
 
 extern void
 EnqueueEvent(InternalEvent * /* ev */ ,
diff --git a/include/dixstruct.h b/include/dixstruct.h
index 0be7f0e..7711cde 100644
--- a/include/dixstruct.h
+++ b/include/dixstruct.h
@@ -144,7 +144,6 @@ typedef struct _WorkQueue {
 } WorkQueueRec;
 
 extern _X_EXPORT TimeStamp currentTime;
-extern _X_EXPORT TimeStamp lastDeviceEventTime[MAXDEVICES];
 
 extern _X_EXPORT int
 CompareTimeStamps(TimeStamp /*a */ ,
diff --git a/os/WaitFor.c b/os/WaitFor.c
index 393890f..c5f4cd7 100644
--- a/os/WaitFor.c
+++ b/os/WaitFor.c
@@ -561,7 +561,7 @@ NextDPMSTimeout(INT32 timeout)
 static CARD32
 ScreenSaverTimeoutExpire(OsTimerPtr timer, CARD32 now, pointer arg)
 {
-    INT32 timeout = now - lastDeviceEventTime[XIAllDevices].milliseconds;
+    INT32 timeout = now - LastEventTime(XIAllDevices).milliseconds;
     CARD32 nextTimeout = 0;
 
 #ifdef DPMSExtension
diff --git a/os/xdmcp.c b/os/xdmcp.c
index 0538ac5..11f1133 100644
--- a/os/xdmcp.c
+++ b/os/xdmcp.c
@@ -1391,7 +1391,7 @@ recv_alive_msg(unsigned length)
         if (SessionRunning && AliveSessionID == SessionID) {
             /* backoff dormancy period */
             state = XDM_RUN_SESSION;
-            if ((GetTimeInMillis() - lastDeviceEventTime[XIAllDevices].milliseconds) >
+            if ((GetTimeInMillis() - LastEventTime(XIAllDevices).milliseconds) >
                 keepaliveDormancy * 1000) {
                 keepaliveDormancy <<= 1;
                 if (keepaliveDormancy > XDM_MAX_DORMANCY)
-- 
1.8.3.1



More information about the xorg-devel mailing list