xhb-event-queue
This package provides a monad transformer that allows for operations on the xhb event queue, along with some useful such cases:
class Monad m => EventQueueCtx m where
stateEventQueue :: (EventQueue -> (a, EventQueue)) -> m a
Example
C program reacting to a MotionNotify
event might use something like the following to only use the most recent MotionNotify
event (because ones from the past are useless and can cause lag):
while(XCheckTypedEvent(dpy, MotionNotify, &ev));
This package contains the following function:
skipEventsByType :: (MonadX x m, EventQueueCtx m, Event e) => m (Maybe e)
which can be used to the effect of XCheckTypedEvent
like so:
onMotionNotify :: (MonadX IO m, EventQueueCtx m) => MotionNotifyEvent -> m ()
onMotionNotify ev = do
flushEventQueue -- move events from xhb channel to our state
MkMotionNotifyEvent{..} <- fromMaybe ev <$> skipEventsByType
...
Documentation
This article describes this package and some of its friends in detail.
Haddock can be found here.