Haskell Xlib bindings

Jeremy Shaw jeremy.shaw at linspireinc.com
Tue Mar 6 19:35:08 EST 2007

At Mon, 5 Feb 2007 00:02:18 +0000,
Ross Paterson wrote:
> On Sun, Feb 04, 2007 at 03:52:36PM -0800, Jeremy Shaw wrote:
> > I have some code that adds support for ClientMessage,
> > peekXButtonEvent, and XGetAtomName:
> > 
> > http://www.n-heptane.com/nhlab/repos/haskell-glx/ClientMessage.hsc
> > 
> > This code is in reasonably good shape (and is only a few lines anyway).
> > 
> > I can follow the library submission guidelines:
> > 
> > http://haskell.org/haskellwiki/Library_submissions
> > 
> > unless there is a better way.
> X11 is a fairly peripheral library, so there's no need for that -- just
> send a patch against the X11 darcs repository, e.g. to me.


I have been working on this a bit, but ran into a problem, Xlib does
not currently have any support for XVisualInfo. Is this intentional?
Or, just another thing that has not been done yet? 

Two of the functions in the glx bindings take or return XVisualInfo as
a parameter:

foreign import ccall unsafe "glXChooseVisual" c_glXChooseVisual :: Display -> ScreenNumber -> AttribList -> IO XVisualInfo
foreign import ccall unsafe "glXCreateContext" c_glXCreateContext :: Display -> XVisualInfo -> Context -> Bool -> IO Context

But, it in the existing Xlib bindings, the XVisualInfo stuff has been omitted:

-- XGetVisualInfo omitted
-- XMatchVisualInfo omitted

In addition to passing around pointers to XVisualInfo, I also needed
to access three members of the XVisualInfo structure:

-- * Access functions for members of XVisualInfo

visual :: XVisualInfo -> Visual
visual (XVisualInfo xvi) = Visual ((#ptr XVisualInfo, visual) xvi)

depth :: XVisualInfo -> IO Int
depth (XVisualInfo xvi) = (#peek XVisualInfo, depth) xvi

visualId :: XVisualInfo -> IO VisualID
visualId (XVisualInfo xvi) = ((#peek XVisualInfo, visualid) xvi)

This 'visual' code no longer works, because the Visual constructor is
no longer exported. However, I am thinking all this stuff belongs in
the Xlib bindings and not the GLX bindngs anway.


More information about the Libraries mailing list