Dwm howto/tutorial

by Snake

Lire ceci en français? Intro

First of all, dwm is a window manager for X11, who claims to be ultralight, and therefore ultrafast. It is, as its author describes it, the "little brother" of wmii, another well-known window manager. As for the other technical details without any importance, dwm is coded in C, in less than two thousand lines of code, and blablabla.

I am writting this tutorial mainly because of the difficulty I had to find documentation about this WM (window manager). I searched their official website many times, but even after that, I still had some question unanswered. The only way I could find to get answers to my simple question was to go and insult them on their IRC chan. Which actually worked, but also got me to get called "newb", "beginner", and such.

On their website we can read the following: "This keeps its userbase small and elitist. No novices asking stupid questions." Which, in my opinion, doesn't contribute to erase the negative "snob" image of Linux users.

Compilation

In opposition to the most part of available softwares for GNU/Linux, you won't find any binary package of dwm, and that for a good reason: the only way to ajust the options of dwm is by modifying the source, and compiling again. Sounds like a big hassle like that, but the compilation is very fast and easy.

So first step, get your copy of dwm on the official website. Then:

1) cd /path/to/dwm-4.0.tar.gz
2) tar zxvf dwm-4.0.tar.gz
After that I suggest you go directly with:
3) make clean install (as root)

Which will compile dwm with the default configuration. This will allow you to familiarize with the different options before actually modifying them. There shouldn't be any problem during compilation, it was probably the easiest I've experienced. This will place an executable in /usr/local/bin.

Next, as a complement, you can install dmenu, which we'll see later isn't necessary but is quite useful. So grab the sources here, and about the compilation, it's the exact same thing as for dwm.

Launching dwm

The easiest way to launch dwm, is to modify your .xinitrc and add the following line to it "exec dwm" (and also commenting out the lines launching a previous WM). While this is quick and easy, it is not the best solution in my opinion because it becomes difficult to go back to another WM quickly.

So, as an alternative, we'll add an entry to our current session manager, in this example, GDM. In order:

1) cd /usr/share/xsession
2) nano dwm.desktop (or any other good text editor)
3) Insert the following
[Desktop Entry]
Encoding=UTF-8
Type=XSession
Exec=dwm
TryExec=dwm
Name=DWM
Comment=DWM window manager
4) Save and exit
5) rcxdm restart (as root)

The basic keyboard shortcuts are these:
ALT+SHIFT+ENTER = xterm
ALT+SHIFT+C = close the current window
ALT+SPACE = change the layout
ALT+MOUSE1 = move window
ALT+MOUSE2 = resize window
ALT+P = show dmenu
ALT+SHIFT+Q = quit

Dmenu

If you installed dmenu earlier, you can test it right away using the previous keyboard shortcut, it should appear at the top of the screen, taking the place of the menu bar. Then you can using either the arrows, or type the first letters of a program and hit enter. Dmenu gives you the advantage of not having to open up a term each time you want to launch an application.

Layout

There is two layout that comes with dwm, the first is the classic one that most of the WM use, called "floating". The windows are one over another and can be moved around and resized. But this is not very practical with dwm, and it is therefore better to use the "tile" mode which shows all the power of dwm. It consists of the windows being one beside another coveing the entire screen, and to give to focus to any window, you just move to mouse over it.

Unimportant problems

As you see dwm starting up, you will notice one thing, the upper right corner shows "dwm-4.0" instead of displaying more important informations like the time, or the uptime.

What is shown there is actually the content of the standart input. And that's why it is clever to create a little launch script for dwm:

1) cd /usr/local/bin
2) nano dwm-launch
3) Copy these lines in it or adjust:
while true
do
echo "[`date '+%a %b %d %r'`"]
sleep 2
done | dwm
4) After, fix your dwm.desktop to work with the script, the line Exec=dwm would become Exec=dwm-launch

The second little problem I had was that I could find any way to set a wallpaper. To solve this problem, you have to use a program like feh, xli, qiv like this: "feh --bg-scale image.jpg". You may integrate this command to the launch script.

Personalization

After you have met with the WM, you can start modifying it according to what you like. This is donne by copying the file config.default.h and than renaming it simply to config.h.

The first interesting thing to modify in this file is the "tags" section:

Which will allow you later on to sort the windows by type. So you can modify the number of tags, and their name.

Then, second thing, that is sort of complementary to the tags, the "rules":

Which allows you to send windows on predetermined tags and to put them in floating mode by default, if necessary. It is for programs such as MPlayer, if you fail to do that, you will end up watching movies in fullscreen all the time, or in strangely resized windows. So you replace NULL with the destination tag, and you set TRUE or FALSE, if you want it to be floating.

And finally, the keyboard shortcuts can be modified at will, which comes very handy sometimes.

After you have made modifications to your config.h, don't forget to recompile to see the changements applied.

My config.h

Here is my configuration file:

Here are the notables changements I have made: the colors of the menu bar, the tags, I added a few rules to go with my tags, for programs like Firefox, Vlc and Thunar. I use the Windows key (Super) instead of Alt, this by modifying "Mod1Mask" to "Mod4Mask", and lastly, I added keyboard shortcuts to control mpd (via mpc).

Adding functionalities

There isn't only the config.h file that you are given the opportunity to modify, the rest of the source code is accessible to you, and because it is relatively simple and short, you can add functions and make it better.

For example, I thought it would be nice to have shortcuts that would do "previous tag" and "next tag", however, this wasn't possible in dwm 4.0, so here's what I did to make it possible:

First, add these lines in the dwm.h file, under the "tag.c" section.

Then, edit the tag.c file, and add these two blocks at the end,

And finally, make keyboard shortcuts in your config.h file, like this.

Conclusion

As we can see, there is nothing difficult in installing dwm on your linux distribution, and there is no reason for it to be only for "elitists".