From ArchWiki
Revision as of 16:44, 23 December 2009 by Pwd (talk | contribs) (Basic statusbar: simplify syntax)
Jump to navigation Jump to search

Template:Article summary start Template:Article summary text Template:Article summary heading Template:I18n entry Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary end

dwm is a dynamic window manager for X. It manages windows in tiled, stacked, and full-screen layouts, as well as many others with the help of 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.


These instructions will install dwm using makepkg along with the Arch Build System, or ABS for short. This will allow reconfiguring it at a later time without complications. If only interested in installing dwm for a test drive, simply install the binary package from the repositories instead:

# pacman -S dwm

Note that by omitting compiling dwm from source a great deal of customizability is lost, since dwm's entire configuration is performed by editing its source code. Taking this in mind, the rest of the article assumes that dwm has been compiled from source as explained in the entirety of this section.


Basic programming tools present in Template:Package Official are needed in order to compile dwm and build a package for it, and the Template:Package Official package is also a requisite for fetching 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

Use Template:Codeline by switching 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.

Tip: If this directory (Template:Filename) is saved, it can be posteriorly used for making changes to the default configuration.


dwm, as mentioned before, is exclusively configured at compile-time via some of its source files, namely Template:Filename and Template:Filename. While the initial configuration provides a good set of defaults, it's realistic to expect that at some point potential users will probably want to make adjustments to their setups.

Method 1: ABS rebuild (recommended)

Modifying dwm is quite simple using this route.

Customizing config.h

Browse to the dwm source code directory saved during the installation process; Template:Filename in the example. The Template:Filename found within this directory is where the general dwm preferences are stored. Most settings within the file should be self-explanatory, while others may not share the same trait. For detailed information on these settings, see the dwm website.

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

Once 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 the new revised copy.

Now, compile and reinstall:

$ makepkg -efi

Assuming the configuration changes were valid, this command will compile dwm, build and reinstall the resulting package. If problems were encountered, review the output for specific information.

Finally, restart dwm in order to apply the changes.


From now on, instead of updating the md5sums for every Template:Filename revision, which are known to become frequent, one may erase the md5sums array and build dwm with the Template:Codeline option:

$ makepkg -efi --skipinteg

And after adding a few lines to dwm's start-up script, it is possible to restart dwm without logging out or closing programs.

Method 2: Mercurial (advanced)

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

Before building dwm from the Mercurial sources, be sure to alter config.mk accordingly, because failure to do so may result in X crashes. Here are the values that need changing:

Modify Template:Codeline:

PREFIX = /usr

The X11 include folder:

X11INC = /usr/include/X11

And the the X11 lib directory:

X11LIB = /usr/lib/X11

Starting dwm

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

exec dwm

For GDM, add it to Template:Filename instead, and select "Run XClient Script" from the Sessions menu.

Statusbar configuration

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

Basic statusbar

This example prints the date in ISO 8601 format. Add it to files Template:Filename or Template:Filename:

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

Here is an example intended for laptops that depends on the Template:Package Official package for showing battery information:

while true 
    xsetroot -name "$( acpi -b | awk '{ print $3, $4 }' | tr -d ',' )"
done &
exec dwm

The script displays the amount of battery remaining and its charging status by using the awk command to trim away the unneeded text from acpi, and tr to remove the commas.

An alternative to the above is to selectively show the battery status depending on the current charging state:

_battery_main() {
  acpi -b | awk '{ print $3, $4 }' | tr -d ','

_battery_display() {
  if ! _battery_main | grep -e 'Charging' -e 'Unknown' -e 'Charged' >/dev/null; then
    echo "$( _battery_main | awk '{ print $2 }' ) | "

while true; do
  xsetroot -name "$( _battery_display )$( date +"%R" )"
  sleep 1m
done &

Finally, make sure there is only one instance of dwm in Template:Filename or Template:Filename. So combining everything together should resemble this:

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

Conky statusbar

Available from the AUR, Template:Package AUR is a special build of conky which prints to stdout. If already accustomed to conky, a statusbar rich with information can be ready within minutes. Once conky has been configured to preference, 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}

Extended usage

Patches & additional tiling modes

The official website is full of patches that can add extra functionality to dwm. Users can easily customize dwm by applying the modifications they like. The Bottom Stack patch provides an additional tiling mode that splits the screen horizontally, as opposed to the default vertically oriented tiling mode.

Fixing gaps around terminal windows

If there are empty gaps of desktop space outside terminal windows, it is likely due to the terminal's font size. Either adjust the size until finding the ideal scale that closes the gap, or toggle Template:Codeline to False in Template:Filename:

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

This will cause dwm to ignore resize requests from all client windows, not just terminals. The downside to this workaround is that some terminals may suffer redraw anomalies, such as ghost lines and premature line wraps, among others.


Another choice for urxvt users is applying the hints patch and regressing to dwm's original behaviour:

static Bool resizehints = True;

Restart dwm without logging out or closing programs

For restarting dwm without logging out or closing applications, change or add a startup script so that it loads dwm in a while loop, like this:

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

dwm can now be restarted without destroying other X windows by pressing the usual Mod-Shift-Q combination.

It's a good idea to place the above startup script into a separate file, Template:Filename for instance, and execute it through Template:Filename. From this point on, when desiring to actually end the X session simply execute Template:Codeline, or bind it to a convenient key.

Make the right Alt key work as if it were Mod4 (Windows Key)

When using Mod4 (aka Super/Windows Key) as the Template:Codeline, it may be equally convenient to have the right Alt key (Alt_R) act as Mod4. This will allow performing 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 the startup script (e.g. Template:Filename), changing the keycode 113 if necessary to the result gathered by the previous Template:Codeline command:

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.