wf

My first experience with Xlib

I began to get really invested in writing X11 applications a few days ago (2 months, actually). In this time, I've actually managed to learn a few decent things about Xlib and C in general, mostly by looking at others' code.

I ended up writing 2 things, one is a window manager (which I ended up deleting, because it sucked and I didn't have a need for it), and a launcher. The latter is why this post was written, to document my so-called adventures throughout writing this launcher.

First of all, the Xlib manual helped me a big lot. It cleared up a lot of things I previously didn't know about the structure of the X server and just reading through the manual gave me a pretty big boost. Later, I also went on to read other (and smarter than me!) people and looked up everything I didn't understand. It was, at once, a teaching and a humbling experience, because I ended up looking up a giant amount of things.. seriously.

After reading the manual for about two days, I attempted to write my very first Xlib program, which was a bad unclutter clone. It did, however, compile, and to the then ecstatic me, that was already good enough. Another few days later I also tried to write a window manager, and it took me a solid 4 tries to implement a working event loop. Yup.

After this, I abandoned X11 for the next month or so, feeling pretty bored with what I had. Though I did bring myself to look at the code again every once in a while, it looked really bad, messy and in every way the opposite of idiomatic. I was also consumed by other things at the moment and didn't care much for trying to pick up X11 again.

And then came the turning point, right around the new year. I went back to using wmutils, started digging around X11 a bit more, and I ended up writing more Xlib code. My first attempt was, yet again, a window manager, which failed about as quickly as the first one. The second one was the launcher, the star of the show. I started off by yanking some code from dmenu to have a working window that takes in input, and over the course of the next couple days, implemented most of what the launcher is today, though missing the core feature.

I wrote the launcher to be a replacement for my old one, being interrobang. I was initially very happy with it, after getting it configured to a more or less usable state. But after using it for a week, I figured out it had some key flaws that made me want to use it less and less. At some point today came the breaking point, and I sat down to implement the core feature of interrobang in a few hours, and the sigh of relief I breathed after finally having seen the program compile probably blew a few kilograms of dust out of my keyboard.

In conclusion, Xlib is actually pretty easy to learn and start writing programs in, especially with the amazing manual, and the headaches were definitely worth it. Still wouldn't wish it upon my worst enemy sometimes, though.

This is what I've been talking about the whole post!