Haskell wlroots bindings

I’ve been looking a little more at wlroots (and especially their tinywl example compositor), and I think the following APIs are most important to prioritise:

  • From libwayland: wl_display, wl_list, wl_listener
  • Basic interfaces: wlr_backend, wlr_renderer, wlr_allocator, wlr_output
  • Compositing: wlr_compositor, wlr_subcompositor, wlr_scene
  • Window management: wlr_xdg_shell
  • Input: wlr_input_device, wlr_keyboard
  • Pointer: wlr_pointer, wlr_cursor, wlr_xcursor_manager
  • Clipboard: wlr_data_device
  • Logging: wlr_log

If we implement these, we should be able to reimplement tinywl in Haskell! It looks like a lot, but most wlroots interfaces look reasonably small and self-contained, so it should be doable.

I’ve also been looking at existing C bindings, in particular sdl2 and botan. (Incidentally, thanks to @ApothecaLabs and @BurningWitness for their work there!) Both are based on low-level, simple wrappers around individual C functions, which is very reasonable. Insofar as I can tell, sdl2 implements a more Haskelly interface directly on top of these, whereas botan has an intermediate ‘safer low-level’ layer; I guess it’s hard to know ahead of time which approach would be best for wlroots.

For actually writing the bindings, it would probably be easiest to use hsc2hs: wlroots makes use of a lot of big structs, and writing Storable instances manually would be an utter pain. There’s two approaches to the FFI itself, namely ccall and capi. It looks like the latter is more modern and more featureful, whereas ccall is simpler. sdl2 uses ccall; botan started off with ccall, but is busy switching to capi. I’m not entirely sure which would be best for wlroots, but I’m leaning towards capi given the experience of botan.

3 Likes