Tiling window managers can be quite handy. Although I generally use either fluxbox or openbox some of the small tiling window managers can be useful, especially on netbooks.
For those unfamiliar with them, a tiling window manager takes each window and sorts them into their own space. On some of them, including dwm, this is done dynamically, that is, as you open a new window, it will automatically be sized to fit. Looking at some screenshots might help. (The link goes to suckless.org's screenshots--they're the ones who created dwm).
Some folks get put off by the fact that to configure dwm, one has to manually edit the included config.h file and recompile. This really isn't terribly difficult, even if one doesn't know C, and the recompiling only takes a few seconds. Some distributions, for example, Fedora, have a nice wrapper script that will do it for you. If your distribution doesn't have such a script, you're probably better off downloading it and compiling it yourself. It has relatively few dependencies.
One reason to download it rather than install it from your distribution's package manager is that, as mentioned, to customize it, you might want to edit config.h. If your distro installs it as a binary, you might not have that config.h file readily available.
As stated above, Fedora, at least, is an exception to this rule. Your distribution might also have its version of a wrapper script.
This isn't going to be a detailed tutorial, but hopefully, it will make it a little easier for you to use and customize dwm.
Once installed, add to your $HOME/.xinitrc
exec dwm |
and it should start when you run startx.
For those of you who start with graphical login, there should be a way to add it to your login menu, but, as I don't use a gui login, I don't know what it is. I would try googling add dwm to gdm or kdm or whatever login gui that you use. An excellent ArchLinux wiki article gives some tips.
Regardless, we'll assume that you've managed to log into dwm. You will see nothing but a black screen with a gray bar at the top. If using default keybindings (we'll cover this in a minute), hit alt+shift+return and you'll get a terminal that takes up the entire screen. Hit alt+shift+return again, and you'll get a second terminal, with the screen now divided into a left and right half. Do it a third time and the right half of the screen will now have a top and a bottom terminal. Do it a 4th time, and the right half of the screen will now have three terminals, stacked top to bottom. This is known, oddly enough, as stacking.
Note that in Fedora's version, they have changed the mod key from Mod1, alt, to Mod4, the Windows key, between Ctrl and Alt on most US keyboards. So, if you're on Fedora and installed dwm with yum install dwm, substitute the Windows key for alt in all of these shortcuts. The left hand terminal is the master area, the right side is used for stacking. The man page gives the various default keyboard shortcuts. Alt+h will decrease the size of the master area. Alt+l will enlarge it. The keyboard shortcuts are familiar to vi users, l moving a vi cursor to the right and h to the left. (That's a lower case L, not the numeral one.) Alt+j and Alt+k move focus to the window below and above respectively.
Now hit alt+p and you'll see the handy dmenu on the top. Type in a few letters of an application, for example, opera, the web browser.
A new application, whether opened by terminal command or using dmenu, should open in the master area. If I want that application to have more screen, I can use the alt-l shortcut mentioned previously. If I want it to take the full screen, I can hit alt+m, as in monocle layout, meaning that the one window will take the entire workspace. Another use for monocle view might be if you've opened up a bunch of windows. A particular window might be too small to be useful. To fix that, I can hit alt+m and it's maximized to use the whole screen. To return to tile view, I hit alt+t.
If I don't want to switch layout format, hitting alt+return will swap the window with the master area. So, if I have 6 windows on screen, and then open another, but it's too small to see what I need to, I can use the alt-return keybinding. Then, if it's still not big enough, I can enlarge the master area with alt+l. Firefox is a special case. In the config.h file, it is specified that firefox will open full screen in its own tag. To oversimplify a bit, a tag can be thought of as a virtual desktop, or workspace. If we have our screen with the 6 or so windows that we made above, and want a new fresh desktop, we can hit alt+2 which will take us to tag 2. This will give us the same black screen we saw when we first logged in. You can move a window to a new tag by, while focused on it, hitting shift+alt+2, for example, which will move it to tag number 2.
Going back to firefox, the config file has it set to open in tag 9. Sometimes, one will see on a forum that someone is opening firefox in dwm and it's not opening. What's actually happening is that they're in workspace 1, call firefox with dmenu and not realize that it's open on tag 9. When you are in one tag, e.g., 1 and something is open in another tag, you'll see a little square next to that tag. So, in this case, you'd see a little square next to tag 9 in the status bar at the top. So, if in tag 1, I have a terminal running, then start firefox, either with a terminal command or using dmenu, and then go to tag 2 with alt+2, I'll see a little square next to both the 1 and the 9 on the status bar. If, while in tag 9, I have several windows open in that tag, firefox will be tiled, just as opera would be in our earlier example.
This is being written in late November, 2011. The latest version, which, if you have mercurial installed, can be gotten with
hg clone http://hg.suckless.org/dwm |
has added a nice feature (that was apparently there long ago, but dropped) to add and decrease clients in the master area. So if, for example, you have one large terminal in the master area, and 3 smaller ones in the stacking area (the right half of the screen), hitting alt+i will move one of the three on the right to the left, so you would now have two on the left and two on the right. With alt+l and alt+h you can addjust the sizes of the two areas.
For me personally, this is a big plus--it gives me the ability to have 6 or 8 equally sized terminals on screen. If I then want to open a browser, I can go to another workspace, or open the browser and hit alt+m to let it have full focus.
To build dwm you need xlib and xinerama header files. In CentOS, this can be gotten with yum install libX11-devel and libXinerama-devel. You will also, need the basic development tools. At an absolute minimum, I install gcc, gcc-c++, make, automake and kernel-devel.
Once downloaded, if you got the the tarball, untar with with the usual tar xvf dwm-<version>.tar.gz. Then cd into the newly created directory. Copy config.def.h to config.h, and you can edit it if you wish.
There is a howto on the Debian forums that goes through config.h line by line. It explains how you can edit the keybindings, for example, changing the Mod1 to Mod4 to make the Windows key, rather than Alt, your mod key. It also explains how to open a program on a particular tag (workspace). Rather than duplicate that, I'll just point out a few that I find handy.
For example, I like to start chromium browser with Mod+g. So, underneath the line where it defines the terminal command, I put
static const char *chromiumcmd[] = { "chromium", NULL };
|
You will see the pattern in config.h. Their default is uxterm, so the line they use to define the command for it is
static const char *termcmd[] = { "uxter", NULL };
|
(If you prefer another terminal, such as urxvt, you can change uxterm to urxvt)
Next in the file are the key commands. For example, one of their defaults is
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
|
This means the mod key, alt by default, that can be changed as mentioned and shift. Then, the XK_Return is the key combo to open a terminal. The termcmd was defined above as a static constant. You don't have to know C to figure it out once you get the pattern.
If you don't want to use alt+shift, you could edit that line to read
{ MODKEY, XK_Return, spawn, {.v = termcmd } },
|
For my key binding for chromium, I use
{ MODKEY, XK_g, spawn, {.v = chromiumcmd} },
|
(Note that if running a command, you would use spawn. If you look at the default config.h, you will see that spawn is only used when running an actual program, such as terminal or dmenu.)
Many dwm users contribute patches. I find the moveresize patch pretty handy. It allows you to move and resize windows with keystrokes. The patch's author has some reasonable defaults.
According to the page, one just puts the code in dwm.c below the line reading
#include "config.h" |
Then add the keybindings to config.h. However, on ArchLinux at least, I found that it was also necessary to add
static void moveresize(const Arg *arg); |
in an earlier part of the file, where there is a long list of function declarations. (You can tell the part because it begins with a comment reading function declarations. If you're not familiar with C, a comment doesn't begin with a #. It begins with /* and ends with */. In the case of dwm.c, it starts around line 157 at time of writing.
At any rate you'll see a long list of things like static void, static Monitor, etc., one per line. Add that static void movereisze line there, as well as the lines you are instructed to add on the patch's page.
I emailed the patch's author about this, but, although I've seen at least one other mention of it on the Arch forums, the author wasn't able to duplicate the problem. They also were kind enough to tell me that the reason they did it as they do, rather than an actual patch file, is to allow people to customize it. For example, you will see that the author puts a note that if you want to automatically make a client floating, rather than tiled, when resizing, replace the if statement that ends with return with togglefloating(NULL).
The dwm manager is popular amongst Arch and #!Crunchbang users. Both forums are fairly friendly to the inexperienced, and are good places to ask questions. The ArchLinux forum has an 8 page thread on dwm. Those familiar with Arch are probably familiar with the excellence of its wiki, which as mentioned above, also has a page about dwm.