Monad transformer over xhb-monad for more sophisticated event handling
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Graphics/XHB
doc @ 7fc9bd2
.gitmodules
LICENSE
README.md
default.nix
shell.nix
update_doc
xhb-event-queue.cabal

README.md

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.