summaryrefslogtreecommitdiff
path: root/mi
diff options
context:
space:
mode:
authorMichel Dänzer <michel@tungstengraphics.com>2007-06-11 09:23:18 +0200
committerMichel Dänzer <michel@tungstengraphics.com>2007-06-11 09:23:18 +0200
commit30a3297fed9af3a594aba0875a8f58a0a38b33fc (patch)
treeec8c1961b06ceeb8a03780be6ffa7eeb59620fd5 /mi
parentc1a49a9269f14b6975a1a2c751bb179757373f11 (diff)
mieq queue handling cleanups.
In particular, fix handling of wraparounds in mieqEnqueue.
Diffstat (limited to 'mi')
-rw-r--r--mi/mieq.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/mi/mieq.c b/mi/mieq.c
index a03fff1f0..f64e5404d 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -108,7 +108,8 @@ mieqEnqueue(DeviceIntPtr pDev, xEvent *e)
HWEventQueueType oldtail = miEventQueue.tail, newtail;
int isMotion = 0;
deviceValuator *v = (deviceValuator *) e;
- EventPtr laste = &miEventQueue.events[oldtail - 1];
+ EventPtr laste = &miEventQueue.events[(oldtail - 1) %
+ QUEUE_SIZE];
deviceKeyButtonPointer *lastkbp = (deviceKeyButtonPointer *)
&laste->event[0];
@@ -139,14 +140,10 @@ mieqEnqueue(DeviceIntPtr pDev, xEvent *e)
if (isMotion && isMotion == miEventQueue.lastMotion &&
oldtail != miEventQueue.head) {
- if (oldtail == 0)
- oldtail = QUEUE_SIZE;
- oldtail = oldtail - 1;
+ oldtail = (oldtail - 1) % QUEUE_SIZE;
}
else {
- newtail = oldtail + 1;
- if (newtail == QUEUE_SIZE)
- newtail = 0;
+ newtail = (oldtail + 1) % QUEUE_SIZE;
/* Toss events which come in late. Usually this means your server's
* stuck in an infinite loop somewhere, but SIGIO is still getting
* handled. */
@@ -214,22 +211,15 @@ mieqProcessInputEvents(void)
e = &miEventQueue.events[miEventQueue.head];
/* Assumption - screen switching can only occur on motion events. */
+ miEventQueue.head = (miEventQueue.head + 1) % QUEUE_SIZE;
+
if (e->pScreen != miEventQueue.pDequeueScreen) {
miEventQueue.pDequeueScreen = e->pScreen;
x = e->event[0].u.keyButtonPointer.rootX;
y = e->event[0].u.keyButtonPointer.rootY;
- if (miEventQueue.head == QUEUE_SIZE - 1)
- miEventQueue.head = 0;
- else
- ++miEventQueue.head;
NewCurrentScreen (miEventQueue.pDequeueScreen, x, y);
}
else {
- if (miEventQueue.head == QUEUE_SIZE - 1)
- miEventQueue.head = 0;
- else
- ++miEventQueue.head;
-
/* If someone's registered a custom event handler, let them
* steal it. */
if (miEventQueue.handlers[e->event->u.u.type]) {