X11 programming in Haskell has traditionally been done using the X11 package. Many of these bindings were written by hand and, due to their reliance on FFI, are susceptible to some threading issues. xhb, a newer package, provides low-level bindings to X11 based on the same XML as xcb.

It doesn’t seem as though much has been done with XHB yet. In fact, at the time of writing (Aug 22, 2016), exactly two packages on Hackage depend on xhb. Nevertheless, I believe it hold great promise in the future of X programming in Haskell.

I’ve been working on a set of libraries that allows for layers of abstraction to be staked on top of the low-level xhb bindings. This post will become more fleshed out as I find time to finish up and document the actual libraries, but here’s an overview.

xhb-requests

(haddock here)

Most generated functions in xhb have types similar to those below:

Those requests which expect responses can wait for them as follows:

Some functions are a bit different (request parameters don’t live inside a dedicated type, but are passed directly to the function):

Nevertheless, thanks to disciplined code generation, xhb has a clean and uniform code base. The (in progress) xhb-requests package wraps all of these generated request functions in two classes:

The instances of this class are generated from the xhb code that is itself generated from XML, which sounds ugly, but it worked quite well. This is the foundation for xhb-monad.

xhb-monad

(haddock here)

This package defines the following class:

and the following monad transformer:

This abstraction allows for pure X logic. It also lets us isolate unwieldy layers of computation and bits of state in the usual mtl way. xhb-mapping-state is an example of this.

xhb-mapping-state

(haddock here)

TODO