From ArchWiki
Jump to: navigation, search

Related articles

dwm is a dynamic window manager for Xorg. 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 being 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 multihead support for xrandr and Xinerama.


Note: If dwm is not compiled from source, opportunities for customization are lost since dwm's configuration is performed by editing its source code. See #Configuration for more information.

Install the dwm package. Alternatively, compile dwm from source using ABS or the dwm-gitAUR package (for the development version), making changes to the source code as desired. You may also want to install dmenu, a fast and lightweight dynamic menu for Xorg.

Starting dwm

Select Dwm from the menu in a display manager of choice.

Alternatively, to start dwm with startx or the SLiM login manager, simply append the following to ~/.xinitrc:

exec dwm


As mentioned in #Installation, dwm is configured at compile-time by editing some of its source files, namely config.h and config.mk and also dwm.c.

Once changes have been made, update the checksums in the PKGBUILD, see PKGBUILD#Integrity. Alternatively, you can skip integrity checks by calling makepkg with the --skipinteg switch.

Then, compile and reinstall dwm:

$ makepkg -fi

Assuming the configuration changes were valid, the command above 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.

Tip: To recompile easily, make an alias by putting alias redwm='cd ~/dwm; updpkgsums; makepkg -fi --noconfirm && killall dwm' in your .bashrc file.


The official website has a number of patches that can add extra functionality to dwm. These patches primarily make changes to the dwm.c file but also make changes to the config.h file where appropriate. For information on applying patches, see Patching in ABS.

Window tiling patches

The Bottom Stack patch provides an additional tiling mode that splits the screen horizontally, as opposed to the default vertically oriented tiling mode. Similarly, bstack horizontal splits the tiles horizontally. The gaplessgrid patch allows windows to be tiled like a grid.

The default behaviour of dwm is to apply the currently selected layout for all tags. To have different layouts for different tags use the pertag patch.

Customizing config.h

The config.h file is where the general dwm preferences are stored. Most settings within the file should be self-explanatory. For detailed information on these settings, see the dwm website.

Adding custom keybinds/shortcuts

Two entries are needed in config.h to create custom keybinds. One under the /* commands */ section, and another under the static Key keys[] = { section.

static const char *keybindname[]   = { "command", "flags", "arguments", NULL };

keybindname can be anything; command, flags and arguments can be anything but they have to be individually enclosed in "".

Some examples:

{ MODKEY, XK_key, spawn, {.v = keybindname } } would bind Mod+key to the command defined previously.

{ MODKEY|ShiftMask, XK_key, spawn, {.v = keybindname } } would bind Mod+Shift+key Use ControlMask for Ctrl key.

Single keys such as Fn or multimedia keys have to be bound with the hex codes obtainable from the program xev.

{ 0, 0xff00, spawn, {.v = keybindname } } would bind foo key 0xff00 to keybindname.

See Extra keyboard keys#Keycodes for information on finding keycodes.

Customizing config.mk

Warning: Installing software directly from source without creating a package is not recommended as pacman will not be able to track the installed files.

The config.mk file is included by Makefile. It allows you to configure how GNU make is going to compile and install dwm.

If you are installing dwm directly from source, without creating a package first, then be sure to alter config.mk to set the correct prefixes:

Modify PREFIX:

PREFIX = /usr

The X11 include folder:

X11INC = /usr/include/X11

And the the X11 lib directory:

X11LIB = /usr/lib/X11
Tip: If you only wish to test configuration changes without affecting systemwide dwm, change PREFIX to a local directory such as ${HOME}/.local. Note that if you are compiling using the dwm PKGBUILD, you should change the PREFIX in the PKGBUILD instead as this will take precedence over config.mk - see the package() function - and you should also change the pkgname.

Statusbar configuration

Note: The following requires the xorg-xsetroot package to be installed.

Dwm reads the name of the root window and redirects it to the statusbar. The root window is the window within which all other windows are drawn and arranged by the window manager. Like any other window, the root window has a title/name, but it is usually undefined because the root window always runs in the background.

The information that you want dwm to show in the statusbar should be defined with xsetroot -name "" command in ~/.xinitrc or ~/.xprofile (if you are using a display manager). For example:

xsetroot -name "Thanks for all the fish!"

Dynamically updated information should be put in a loop which is forked to background - see the example below:

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

# Autostart section
pcmanfm & 

exec dwm

In this case the date is shown in ISO 8601 format and PCManFM is launched at startup.

Note: It is not recommended to set the update interval equal to zero or remove the "sleep" line entirely since this will cause CPU usage to rise substantially (you can assess the effect with top and powertop).

More examples of statusbars are included on the suckless wiki.

Conky statusbar

Conky can be printed to the statusbar with xsetroot -name:

(conky | while read LINE; do xsetroot -name "$LINE"; done) &
exec dwm

To do this, conky needs to be told to output text to the console only. The following is a sample conkyrc for a dual core CPU, displaying several usage statistics:

conky.config = {
out_to_console = true,
out_to_x = false,
background = false,
update_interval = 2,
total_run_times = 0,
use_spacer = 'none',
conky.text = [[
$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}

For icons and color options, see dzen.

Basic usage

Besides the following sections, also consult the dwm tutorial for information on basic dwm usage.

Using dmenu

To start dmenu, press Mod1 + P (Mod1 should be the Alt key by default). This can be changed if you so desire. Then, simply type in the first few characters of the binary you wish to run until you see it along the top bar. Use your left and right arrow keys to navigate to the binary and press enter.

Controlling windows

Giving another tag to a window

Changing a window's tag is simple. To do so, simply bring the window into focus by hovering over it with your cursor. Then press Shift + Mod1 + x, where x is the number of the tag to which you want to move the window. Mod1 is, by default, the Alt key.

Closing a window

To cleanly close a window using dwm, simply press Shift + Mod1 + c.

Window layouts

By default, dwm will operate in tiled mode. This can be observed by new windows on the same tag growing smaller and smaller as new windows are opened. The windows will, together, take up the entire screen (except for the menu bar) at all times. There are, however, two other modes: floating and monocle. Floating mode should be familiar to users of non-tiling window managers; it allows users to rearrange windows as they please. Monocle mode will keep a single window visible at all times.

To switch to floating mode, simply press Mod1 + F. Mod1 is, by default, the Alt key. To check if you are in floating mode, you should see something like this next to the numbered tags in the top right corner of the screen: ><>.

To switch to monocole mode, press Mod1 + M. To check if you are in monocle mode, you can see an M in square brackets (if no windows are open on that tag) or a number in square brackets (which corresponds with the number of windows open on that tag). Thus, a tag with no windows open would display this: [M], and a tag with 'n' windows open would display this: [n].

To return to tiled mode, press Mod1 + T. You will see a symbol which looks like this: []= .

For using alternate window layouts, see #Window tiling patches.

Exiting dwm

To cleanly exit dwm, press Shift + Mod1 + q.

Tips and tricks

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, see below:

while true; do
    # Log stderror to a file 
    dwm 2> ~/.dwm.log
    # No error logging
    #dwm >/dev/null 2>&1

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

It is a good idea to place the above startup script into a separate file, ~/bin/startdwm for instance, and execute it through ~/.xinitrc. From this point on, when you wish to end the X session, simply execute killall xinit, or bind it to a convenient key. Alternatively, you could setup your dwm session script so that it relaunches dwm only if the binary changes. This could be useful in the case where you change a setting or update the dwm code base.

# relaunch DWM if the binary changes, otherwise bail
csum=$(sha1sum $(which dwm))
while true
    if [ "$csum" != "$new_csum" ]
        exit 0
    new_csum=$(sha1sum $(which dwm))
    sleep 0.5

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

When using Mod4 (the Super/Windows Key) as the MODKEY, it may be equally convenient to have the right Alt key (Alt_R) 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 the startup script (e.g. ~/.xinitrc), changing the keycode 113 if necessary to the result gathered by the previous xmodmap 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

After doing so, any functions that are triggered by the Super_L key press will also be triggered by an Alt_R key press.

Note: There is a #define option in config.h which also allows you to switch the modkey

Space around font in dwm's bar

By default, dwm's bar adds 2px around the size of the font. To change this, modify the following line in dwm.c:

bh = dc.h = dc.font.height + 2;

Disable focus follows mouse behaviour

To disable focus follows mouse behaviour comment out the following line in definiton of struct handler in dwm.c

[EnterNotify] = enternotify,

Note that this change can cause some difficulties; the first click on an inactive window will only bring the focus to it. To interact with window contents (buttons, fields etc) you need to click again. Also, if you have several monitors, you may notice that the keyboard focus does not switch to another monitor activated by clicking.

Make some windows start floating

For some windows, such as preferences dialogs, it does not make sense for these windows to be tiled - they should be free-floating instead. For example, to make Firefox's preferences dialog float, add the following to your rules array in config.h:

 { "Firefox",     NULL,       "Firefox Preferences",        1 << 8,         True,     -1 },


Fixing misbehaving Java applications

As of JRE 6u20, Java applications may misbehave in dwm because dwm is not a known window manager for Java. The misbehavior may include menus closing when the mouse is released and other minor issues. Firstly, install the wmname package.

Now use wmname to set a WM name that Java recognizes:

$ wmname LG3D
Note: This may cause some programs to behave oddly when tiled (specifically Chromium).

This setting is not persistent so you may want to add this command to your .xinitrc or .xprofile.

Alternatively, it is also possible to change enable export _JAVA_AWT_WM_NONREPARENTING=1 in /etc/profile.d/jre.sh

Fixing the extra topbar that does not disappear when changing resolution/monitors

Note: this patch is intended for dwm-6.0 which is currently in the official repositories. The development version of dwm has already implemented this.

When resizing or connecting/disconnecting different monitors there may be a remnant of the topbar stuck on the screen which cannot be removed. To fix this bug, rebuild dwm with this patch.

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 resizehints to False in config.h:

static Bool resizehints = False; /* True 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.

See also