From 30a3297fed9af3a594aba0875a8f58a0a38b33fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20D=C3=A4nzer?= Date: Mon, 11 Jun 2007 09:23:18 +0200 Subject: [PATCH] mieq queue handling cleanups. In particular, fix handling of wraparounds in mieqEnqueue. --- mi/mieq.c | 22 ++++++---------------- 1 file 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]) {