From ArchWiki
Revision as of 01:25, 28 October 2009 by Gog (talk | contribs)
Jump to navigation Jump to search

dwm is a dynamic window manager for X. It manages windows in tiled, stacked, and full-screen layouts (as well as many others with optional patches). Layouts can be applied dynamically, optimizing the environment for the application in use and the task performed. dwm is extremely lightweight and fast, written in C and with a stated design goal of remaining under 2000 source lines of code. It provides multi-head support for xrandr and Xinerama


Method 1: Repositories

dwm is available from the standard repositories. If you're just taking dwm for a test spin, this is the easiest way to do so:

# pacman -S dwm

Method 2: ABS Installation (recommended)

This method will install dwm using the Arch Build System (ABS). This will allow you to reconfigure it at a later time with minimal fuss.


You'll need some basic programming tools in order to compile dwm and build a package for it. You'll also need the ABS package to fetch the necessary build scripts:

# pacman -S base-devel abs

Download build scripts with ABS

Once the required packages are installed, use ABS to fetch the latest build scripts from the repositories:

# abs

Lastly, copy the dwm build scripts from the ABS tree to a temporary directory. For example:

$ mkdir ~/dwm
$ cp -r /var/abs/community/dwm ~/dwm

Build and install package

Open a terminal and Template:Codeline to the directory containing the build scripts (the example above used Template:Filename). Then run:

$ makepkg -i

This will compile dwm, build an Arch Linux package containing the resulting files, and install the package file all in one step. If problems are encountered, review the output for specific information.

Note: If you save this directory (~/dwm) you can use it again to make changes to the default configuration as described below.


dwm is configured at compile-time via its source (Template:Filename and Template:Filename) and must be recompiled whenever making changes. The initial configuration provides a good set of defaults, but at some point you'll probably want to make changes. For patches, customisations, etc., please visit the dwm website.

Method: ABS Rebuild (recommended)

If you followed method 2 of the installation phase, then modifying dwm is quite simple.

Customizing config.h

Browse to the dwm source code directory you saved during the installation process (~/dwm in the example). The config.h found within this directory is where the general dwm preferences are stored. Some settings within the file should be self-explanatory, while others may not be. For detailed information on these settings, see the dwm website.

Be sure to make a backup copy of config.h before modifying it, just in case something goes wrong.

Once your changes have been made, pipe the new md5sums into the PKGBUILD:

$ makepkg -g >> PKGBUILD

This will eliminate a checksum mismatch between the official config.h and your revised copy. Template:Tip:You can also erase the md5sum array and build dwm with the --skipinteg option (eg. makepkg -efi --skipinteg).

Now to compile and reinstall:

$ makepkg -efi

Assuming your changes were valid, this command will compile dwm, build and reinstall the resulting package (see makepkg -h for details). As before, if problems were encountered, review the output for specific information.

Restart dwm in order to apply the changes.

Tip: To restart dwm without logging out or closing applications, see the section: Starting dwm

Method: Mercurial (advanced)

dwm is maintained upstream within a Mercurial version control system. If you are already familiar with mercurial, then maintaining your configurations and patches within this system may be more convenient. A detailed tutorial on this method is available at the dwm website.

If you would like to build dwm from the Mercurial sources, be sure to change config.mk accordingly. Failure to do so may result in X crashes. Change the following values:

Change PREFIX to:

PREFIX = /usr

Change the X11 include folder to:

X11INC = /usr/include/X11

Change the X11 lib to:

X11LIB = /usr/lib/X11

Patches & Additional tiling modes

The patches page in the official website is full of patches that can add extra functionality to dwm. Users can easily customize dwm applying the patches they like. The Bottom Stack patch provides an additional tiling mode that splits the screen horizontally (opposed to the default tiling mode).

Starting dwm

To start dwm via Template:Codeline or the SLIM login manager, simply append the following to Template:Filename:

exec dwm

Starting dwm with GDM

For GDM, append the following to Template:Filename and select "Run XClient Script" from the Sessions menu:

exec dwm

Statusbar configuration

Piping stdin from another command into dwm will output the results of that command in the status bar.

Basic statusbar

dwm uses Template:Codeline to display information in its statusbar.

This example prints the date in ISO 8601 format. Add this to your ~/.xinitrc or ~/.Xclients file:

while true
   xsetroot -name "$(date +"%F %R")"
   sleep 1m    # Update time every minute
done &
exec dwm

Here is another example for a laptop (make sure you have the Template:Package Official package installed):

while true 
    xsetroot -name "$(acpi | awk '{ print $3, $4 }' | sed s/","//g)"
done &
exec dwm

This displays the amount of battery remaining and its status (charging/discharging). The awk command trims away the unneeded text from acpi, and sed removes the commas.

Make sure there is only one instance of dwm in ~/.xinitrc or ~/.Xclients. Combining everything together, it should look something like:

while true
   xsetroot -name "$(date +"%F %R")"
   sleep 1m    # Update time every minute
done &
exec dwm

Conky statusbar

conky-cli, available from the AUR is a special build of conky which prints to stdout. If you're already familiar with conky, a statusbar rich with information can be ready within minutes. Once you have configured conky to your liking, simply print it to the statusbar via the Template:Codeline argument:

conky | while true; read line; do xsetroot -name "$line"; done &
exec dwm

The following is a sample conkyrc for a dual core CPU, displaying several stats:

background no
out_to_console yes
update_interval 2
total_run_times 0
use_spacer none

$mpd_smart :: ${cpu cpu1}% / ${cpu cpu2}%  ${loadavg 1} ${loadavg 2 3} :: ${acpitemp}c :: $memperc% ($mem) :: ${downspeed eth0}K/s ${upspeed eth0}K/s :: ${time %a %b %d %I:%M%P}

Tips & Tricks

Fixing gaps around terminal windows

If you find that there are empty gaps of desktop space outside your terminal windows, it is likely due to your terminal font size. You can either tweak the size until you find a sweet spot that closes the gap, or you can toggle Template:Codeline to False in your config.h file:

static Bool resizehints = False; /* False means respect size hints in tiled resizals */

This will cause dwm to ignore resize requests from client windows--this will affect all windows, not just terminals. The downside to this workaround is that some terminals may suffer redraw anomalies (ghost lines, premature line wraps, etc.).

Restart dwm without logging out or closing programs

If you would like to restart dwm without logging out or closing applications, change your startup script to load dwm in a while loop, like this:

conky | while read line; do
    xsetroot -name "$line"; 
# log stderror to a file 
done | while true; do dwm 2> ~/.dwm.log; done;
# no error logging
#done | while true; do dwm > /dev/null; done;

Now, you can restart dwm without destroying other X windows by pressing the usual Mod-Shift-Q.

It's a good idea to place the above startup script into a separate file, such as Template:Filename and execute it via ~/.xinitrc. Then when you want to actually end your session you can simply execute Template:Codeline (better yet, bind it to a key).

Make Alt_R key work as if it were Mod4 (Windows Key)

If you use Mod4 (aka Super/Windows Key) as your MODKEY, you might find it equally convenient to have your Right Alt key act as Mod4. This will allow you to perform otherwise awkward keystrokes one-handed, such as zooming with Alt_R+Enter.

First, find out which keycode is assigned to Alt_R:

xmodmap -pke | grep Alt_R

Then simply add the following to your startup script (e.g. ~/.xinitrc), changing the keycode 113 if necessary to the above result:

xmodmap -e "keycode 113 = Super_L"  # reassign Alt_R to Super_L
xmodmap -e "remove mod1 = Super_L"  # make sure X keeps it out of the mod1 group

Now any functions that are triggered by a Super_L (Windows) key press will also be triggered by an Alt_R key press.

More Resources

dwm's official website
simple application launcher from the developers of dwm
simple dwm wallpapers

Tutorials and other articles