Writing an X11 Window Manager
This summer I decided to write a window manager. I was taking classes and TA’ing at the University of Washington and wanted something interesting and challenging to fill my spare time. This is going to be a short article documenting my experiences and my advice for anyone attempting their first large project.
Why write a window manager?
Like I said, I wanted something to fill my free time that was both challenging and engaging. As any software developer knows, finishing side-projects is notoriously difficult. You often lose interest and decide to work on something more “fulfilling”, only to later leave that project for another one. As a full-time Linux user, I figured that building something I could use everyday would be motivating and give me a clear idea of what I wanted to project to accomplish.
Additionally, I really wanted to do a project in a low level language. I had never worked in C before, so I chose it for this project to familiarize myself with the language.
Getting Started
I began the project by looking at documentation for XLib - the library I would be using to interface with the X server. The main reference, The XLib Programming Manual is as archaic as it is long and dull. The whole thing comes out to just under 500 pages and is very dense. Instead, I opted to start by writing an incredibly minimal window manager and build up from there.
My first stop was tinywm, a window manager written in less than 50 lines of C. The project was minimal but provided a nice guide to getting started with XLib. I also read How X Window Managers Work, and How to Write One. This was a more in-depth reference and gave me some intuition with regards to how applications interface with the window manager.
Now that I had a foothold on very basic window management I started planning my project.
I’ve used probably a dozen window managers in my time, from windowchef
and dwm
to
herbstluftwm
and xmonad
.
I hadn’t been incredibly satisfied with any of them, so I started writing down features that
I wanted my own window manager to have.
I came up with the following list:
- Stacking windows
- Controllable entirely via the keyboard
- Decoration management
- Controlled via a command-line client
- Small, hackable source code
The only thing I needed to do before getting started was think of a name.
I finally settled on berry
- a healthy, bite-sized window manager written in C.
I might have been hungry when I thought of the name.
Development
I wrote berry
primarily after summer quarter was over at coffee shops around the
university.
Each day I would try adding a new feature - window decorations, virtual workspaces,
cycle focusing, and more.
The whole process took me about two weeks and left me with a minimal window manager at around
2000 LOC that had all the primary features I had wanted.
I’m no expert in development strategies, but I tried to use iterative development as best I could. I would pick one feature at a time and test it extensively before adding a new one. This helped keep debugging times down and narrow down problematic functions when a bug would pop up.
Results
The end result was a minimal, fun window manager that I could use everyday.