views:

177

answers:

5

I want to create a simple stacking window manager (in C) for private use, mainly for the purpose of learning and challenging myself.

I've looked through twm's source code which has relatively few bells and whistles but it seems very low level since it's not based on a widget toolkit.[1] Would using a toolkit such as GTK+ be preferable? I'm afraid that some of the code and libraries in twm might be too antiquated (edit: deprecated) and I want the window manager to use relatively modern libraries. For the sake of understanding I would also be interested in suggestions how to start a window manager from scratch — there aren't many tutorials for this purpose.

+1  A: 

http://code.google.com/p/partiwm/ is an attempt to write a window manager (tiling, not stacking) from scratch, it might be useful to you to read through the code.

Zack
+2  A: 

A very minimalistic WM is wm2. I haven't read the source code and hence I don't know if it is a teaching example. Of course you can use libraries that already do much of the abstraction and drawing work for you like gdk and gtk. But since this project is only for personal learning, I'd go the hard way and use Xlib directly.

Here are some links that might be useful for you:

quinmars
I'll use Xlib then. Do you know of any window managers that use something like GTK+ for "abstraction and drawing work"?
Baldur
Serge recommends using XCB
Baldur
AFAIK, the API of xcb is not stable yet, since you do not plan to release your WM ever this shouldn't be a show stopper.
quinmars
There are several WMs using gtk to draw their widgets, like Metacity, the xfce wm, lxde. I don't know how far they are using gdk. Or if they are using xlib or xcb directly.
quinmars
A: 

metacity uses gtk for certain UI elements. See its HACKING and README.

see also http://stackoverflow.com/questions/3266521/where-are-some-good-xlib-programming-guides/3314886#3314886

Havoc P
+2  A: 

Whatever you do, use XCB and not Xlib. It' modern, asynchronous, simpler and gives you direct access to the X11 protocol.

Serge
See this was one of the reasons I asked! `quinmars` recommended I use `Xlib` which most window managers seem to use, I haven't seen any window managers that use `XCB` (except Awesome) — is that just because all the other window mangers are old or is there a reason to use `XCB` nowadays when starting from scratch? The `Xlib` code in `twm` still works some twenty years later with the newest verion og Xorg — will `XCB` code still work in that time?
Baldur
To help other people who might be interested in doing the same thing I'd recommend the `mcwm` (http://hack.org/mc/hacks/mcwm/) which is based entirely on `XCB`.
Baldur
A: 

Xmonad might be a good place to start.

Gaius