From 80d29475b9a2ebbb303a8e324e09a15c528d5556 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Wed, 21 Mar 2007 00:10:38 +0200 Subject: mieq: Allow event handlers for arbitrary events to be set Allow arbitrary events to use mieq by letting custom handlers be set. --- mi/mieq.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'mi/mieq.c') diff --git a/mi/mieq.c b/mi/mieq.c index 507cdd337..5bd87ebdb 100644 --- a/mi/mieq.c +++ b/mi/mieq.c @@ -74,6 +74,7 @@ typedef struct _EventQueue { EventRec events[QUEUE_SIZE]; /* static allocation for signals */ ScreenPtr pEnqueueScreen; /* screen events are being delivered to */ ScreenPtr pDequeueScreen; /* screen events are being dispatched to */ + mieqHandler handlers[128]; /* custom event handler */ } EventQueueRec, *EventQueuePtr; static EventQueueRec miEventQueue; @@ -81,11 +82,15 @@ static EventQueueRec miEventQueue; Bool mieqInit() { + int i; + miEventQueue.head = miEventQueue.tail = 0; miEventQueue.lastEventTime = GetTimeInMillis (); miEventQueue.lastMotion = FALSE; miEventQueue.pEnqueueScreen = screenInfo.screens[0]; miEventQueue.pDequeueScreen = miEventQueue.pEnqueueScreen; + for (i = 0; i < 128; i++) + miEventQueue.handlers[i] = NULL; SetInputCheck(&miEventQueue.head, &miEventQueue.tail); return TRUE; } @@ -178,6 +183,16 @@ mieqSwitchScreen(ScreenPtr pScreen, Bool fromDIX) miEventQueue.pDequeueScreen = pScreen; } +void +mieqSetHandler(int event, mieqHandler handler) +{ + if (handler && miEventQueue.handlers[event]) + ErrorF("mieq: warning: overriding existing handler %p with %p for " + "event %d\n", miEventQueue.handlers[event], handler, event); + + miEventQueue.handlers[event] = handler; +} + /* Call this from ProcessInputEvents(). */ void mieqProcessInputEvents() @@ -215,6 +230,15 @@ mieqProcessInputEvents() else ++miEventQueue.head; + /* If someone's registered a custom event handler, let them + * steal it. */ + if (miEventQueue.handlers[e->event->u.u.type]) { + miEventQueue.handlers[e->event->u.u.type](miEventQueue.pDequeueScreen->myNum, + e->event, dev, + e->nevents); + return; + } + /* If this is a core event, make sure our keymap, et al, is * changed to suit. */ if (e->event[0].u.u.type == KeyPress || -- cgit v1.2.3