I've decided to write my own X window manager, despite the fact that X is dying and all that. I'm doing it for fun but also to get more better at scheme (CHICKEN) and C interop, I think... Anyway, I'm going to write about my experiences here. You can view the current state of the project at its git repository. <div>
I thought I should start small and simple. I got lucky that CHICKEN has an xlib egg, but not so lucky that it is pretty much a thin wrapper around Xlib.h and nothing more. Still, the simplest X window manager I know of is tinywm, so that's what I started with.
Because of my inexperience with C (and honestly, Scheme too), plus the bare-bones-ness of CHICKEN's xlib, even translating the repo pretty much directly from tinywm.c was challenging. I started prematurely generalizing the scheme code to be more schemely before realizing, "I just need something that works first." So the code at its current point is not very "schemely," as one friend put it ... most of my work at this point will not be adding features but schemifying the code.
problems!
I ran into a few problems by jamming the very imperative C original into the scheme language:
-
There are two places that tinywm pays attention to keys and buttons:
first, in a call to XGrabKey, then later in the main event loop when it
checks the event. This is because first you have to tell X to listen
for a key or button or whatever, then you check for the
listened-to stuff later on. I'm going to have to figure out how to wrap
that into a single call to a procedure like
define-key
orbind-key
or whatever. (The annotated version says, "... or you can use XSelectInput with KeyPressMask/ButtonPressMask/etc to catch all events of those types and filter them as you receive them," which is delightfully vague. I guess I have some manual pages to read.) -
The way that CHICKEN's xlib wraps the the C code, I can't do the
start = ev.xbutton
trick that tinywm does. In fact, I guess that C does something with copying there that CHICKEN doesn't .. anyway I had a hell of a time gettingstart
to not be equivalent toevent
. Eventually I just manually set the different fields ofstart
that I needed for the rest of the function to work. I'll have to write somecopy-<structure>
code soon... - I had some debugging to do because I forgot that
display
is already a variable name in scheme ... eventually I remembered and changed all of those names in acdwm todpy
. - In general, I have a lot of boilerplate and glue code to write.