Difference between revisions of "Dwm"

From ArchWiki
Jump to navigation Jump to search
(→‎Patches & additional tiling modes: Added information about pertag patch)
(→‎Crashes due to Emojis in some fonts: Add more info (upstream bug report) and proposed fix (reference patched AUR packages by wtemple))
 
(314 intermediate revisions by 75 users not shown)
Line 1: Line 1:
[[Category:Dynamic WMs (English)]]
 
[[Category:HOWTOs (English)]]
 
{{i18n|dwm}}
 
{{Article summary start|Summary}}
 
{{Article summary text|Information on installing dwm and increasing its potential}}
 
{{Article summary heading|Related}}
 
{{Article summary wiki|dmenu}}
 
{{Article summary wiki|wmii}}
 
{{Article summary end}}
 
 
{{DISPLAYTITLE:dwm}}
 
{{DISPLAYTITLE:dwm}}
[http://dwm.suckless.org/ 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.
+
[[Category:Dynamic WMs]]
 +
[[Category:Suckless]]
 +
[[de:Dwm]]
 +
[[es:Dwm]]
 +
[[fr:DWM]]
 +
[[ja:Dwm]]
 +
[[ru:Dwm]]
 +
[[zh-hans:Dwm]]
 +
{{Related articles start}}
 +
{{Related|dmenu}}
 +
{{Related|wmii}}
 +
{{Related articles end}}
 +
[https://dwm.suckless.org/ 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.
  
==Installing==
+
== Installation ==
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.
+
dwm can be installed with {{AUR|dwm}} or {{AUR|dwm-git}}. Make any required [[#Configuration]] changes '''before''' building and installing, see [[makepkg]].
  
===Requirements===
+
=== Configuration ===
Basic programming tools present in {{package Official|base-devel}} are needed in order to compile dwm and build a package for it, and the {{package Official|abs}} package is also a requisite for fetching the necessary build scripts:
 
# pacman -S base-devel abs
 
  
===Download build scripts with ABS===
+
dwm is configured at compile-time by editing some of its source files, specifically {{ic|config.h}}. For detailed information on these settings see the included, well-commented {{ic|config.def.h}} as well as the [https://dwm.suckless.org/customisation/ customisation section] on the dwm website.
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:
+
The official website has a number of [http://dwm.suckless.org/patches/ patches] that can add extra functionality to dwm. These patches primarily make changes to the {{ic|dwm.c}} file but also make changes to the {{ic|config.h}} file where appropriate. For information on applying patches, see the [[Patching packages]] article.
$ cp -r /var/abs/community/dwm ~/dwm
 
  
===Build and install package===
+
== Starting ==
Use {{Codeline|cd}} by switching to the directory containing the build scripts (the example above used {{Filename|~/dwm}}). 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.
+
Select ''Dwm'' from the menu in a [[display manager]] of choice. Alternatively, to start dwm with [[startx]] append {{ic|exec dwm}} to {{ic|~/.xinitrc}} and prepend other programs to execute them as well, for example:
  
{{Tip|If this directory ({{filename|~/dwm}}) is saved, it can subsequently be used for making changes to the default configuration.}}
+
redshift -O3500; xset r rate 300 50; exec dwm
  
==Configuring==
+
== Usage ==
dwm, as mentioned before, is exclusively configured at compile-time via some of its source files, namely {{Filename|config.h}} and {{Filename|config.mk}}. 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)===
+
See the [https://dwm.suckless.org/tutorial dwm tutorial] for information on basic dwm usage.
Modifying dwm is quite simple using this route.
 
  
====Customizing config.h====
+
== Tips and tricks ==
Browse to the dwm source code directory saved during the [[#Installing|installation process]]; {{filename|~/dwm}} in the example. The {{filename|config.h}} 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 [http://www.suckless.org/dwm/ dwm website].
 
  
{{note|Be sure to make a backup copy of config.h before modifying it, just in case something goes wrong.}}
+
=== Statusbar configuration ===
  
Once changes have been made, pipe the new md5sums into the [[PKGBUILD]]:
+
For more examples of status bars see [https://dwm.suckless.org/status_monitor/].
$ makepkg -g >> PKGBUILD
 
This will eliminate a checksum mismatch between the official config.h and the new revised copy.
 
  
Now, compile and reinstall:
+
{{Note|The following requires the {{Pkg|xorg-xsetroot}} package to be installed.}}
$ 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.
+
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.  
  
Finally, restart dwm in order to apply the changes.
+
The information that you want dwm to show in the statusbar should be defined with {{ic|xsetroot -name ""}} command in {{ic|~/.xinitrc}} or {{ic|~/.xprofile}} (if you are using a [[display manager]]). For example:
 +
{{bc|xsetroot -name "Thanks for all the fish!"}}
  
====Notes====
+
Dynamically updated information should be put in a loop which is forked to background - see the example below:
From now on, instead of updating the md5sums for every {{filename|config.h}} revision, which are known to become frequent, one may erase the md5sums array and build dwm with the {{codeline|--skipinteg}} option:
+
{{bc|
$ makepkg -efi --skipinteg
+
# Statusbar loop
 +
while true; do
 +
  xsetroot -name "$( date +"%F %R" )"
 +
  sleep 1m    # Update time every minute
 +
done &
  
And after adding a few lines to dwm's start-up script, it is possible to [[#Restart dwm without logging out or closing programs|restart dwm without logging out or closing programs]].
+
# Autostart section
 +
pcmanfm &
  
===Method 2: Mercurial (advanced)===
+
exec dwm
dwm is maintained upstream within a [http://www.selenic.com/mercurial/wiki/ Mercurial] version control system at [http://hg.suckless.org/dwm suckless.org]. Those already familiar with Mercurial may find it more convenient to maintain configurations and patches within this system. A [http://www.suckless.org/dwm/customisation/patch_queue.html detailed tutorial] on this method is available at the dwm website.
+
}}
 +
In this case the date is shown in [[wikipedia:ISO_8601|ISO 8601]] format and [[PCManFM]] is launched at startup.  
  
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:
+
{{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]]).}}
  
Modify {{codeline|PREFIX}}:
+
==== Conky statusbar ====
PREFIX = /usr
 
The X11 include folder:
 
X11INC = /usr/include/X11
 
And the the X11 lib directory:
 
X11LIB = /usr/lib/X11
 
  
==Starting dwm==
+
[[Conky]] can be printed to the statusbar with {{Ic|xsetroot -name}}:
To start dwm with {{Codeline|startx}} or the [[SLIM]] login manager, simply append the following to {{Filename|~/.xinitrc}}:  
+
(conky | while read LINE; do xsetroot -name "$LINE"; done) &
 
  exec dwm
 
  exec dwm
  
For [[GDM]], add it to {{Filename|~/.Xclients}} instead, and select "Run XClient Script" from the Sessions menu.
+
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:
 +
{{bc|
 +
<nowiki>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}
 +
]];</nowiki>
 +
}}
  
==Statusbar configuration==
+
For icons and color options, see [[dzen]].
dwm uses {{Codeline|xsetroot -name}} to display information in its statusbar.
 
  
===Basic statusbar===
+
=== Restart dwm ===
This example prints the date in [http://en.wikipedia.org/wiki/ISO_8601 ISO 8601] format. Add it to files {{filename|~/.xinitrc}} or {{filename|~/.Xclients}}:
+
 
<pre>
+
To restart dwm without logging out or closing applications, change or add a startup script so that it loads dwm in a ''while'' loop, for example:
 +
{{bc|
 
while true; do
 
while true; do
  xsetroot -name "$( date +"%F %R" )"
+
    # Log stderror to a file
  sleep 1m    # Update time every minute
+
    dwm 2> ~/.dwm.log
done &
+
    # No error logging
exec dwm
+
    #dwm >/dev/null 2>&1
</pre>
+
done
 +
}}
 +
 
 +
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, {{ic|~/bin/startdwm}} for instance, and execute it through {{ic|~/.xinitrc}}. From this point on, when you wish to end the X session, simply execute {{Ic|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.
 +
 
 +
{{bc|1=
 +
# relaunch DWM if the binary changes, otherwise bail
 +
csum=$(sha1sum $(which dwm))
 +
new_csum=""
 +
while true
 +
do
 +
    if [ "$csum" != "$new_csum" ]
 +
    then
 +
        csum=$new_csum
 +
        dwm
 +
    else
 +
        exit 0
 +
    fi
 +
    new_csum=$(sha1sum $(which dwm))
 +
    sleep 0.5
 +
done
 +
}}
 +
 
 +
=== Bind the right Alt key to Mod4 ===
 +
 
 +
When using Mod4 (the Super/Windows Key) as the {{Ic|MODKEY}}, it may be equally convenient to have the right {{ic|Alt}} key ({{ic|Alt_R}}) act as {{ic|Mod4}}. This will allow you to perform otherwise awkward keystrokes one-handed, such as zooming with {{ic|Alt_R}}+{{ic|Enter}}.
 +
 
 +
First, find out which keycode is assigned to {{ic|Alt_R}}:
 +
xmodmap -pke | grep Alt_R
 +
 
 +
Then simply add the following to the startup script (e.g. {{ic|~/.xinitrc}}), changing the keycode ''113'' if necessary to the result gathered by the previous {{Ic|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
  
Here is an example intended for laptops that depends on the {{Package Official|acpi}} package for showing battery information:
+
After doing so, any functions that are triggered by the {{ic|Super_L}} key press will also be triggered by an {{ic|Alt_R}} key press.
<pre>
 
while true ; do
 
    xsetroot -name "$( acpi -b | awk '{ print $3, $4 }' | tr -d ',' )"
 
done &
 
exec dwm
 
</pre>
 
  
The script displays the amount of battery remaining besides its charging status by using the awk command to trim away the unneeded text from acpi, and tr to remove the commas.
+
{{note|There is a {{ic|#define}} option in [[#Configuration|config.h]] which also allows you to switch the modkey.}}
  
An alternative to the above is to selectively show the battery status depending on the current charging state:
+
=== Space around font in dwm's bar ===
<pre>
 
while sleep 1m; do
 
  batt=`LC_ALL=C acpi -b`
 
  
  case $batt in
+
By default, dwm's bar adds 2px around the size of the font. To change this, modify the following line in {{ic|dwm.c}}:
    *Discharging*) batt=${batt_main#* * * }; batt="${batt%%, *} " ;;
+
{{bc|1=bh = dc.h = dc.font.height + 2;}}
    *)            batt=''                                        ;;
 
  esac
 
  
  xsetroot -name "$batt`date +"%R"`"
+
=== Disable focus follows mouse ===
done &
 
exec dwm
 
</pre>
 
  
Finally, make sure there is only one instance of dwm in {{filename|~/.xinitrc}} or {{filename|~/.Xclients}}, so combining everything together should resemble this:
+
To disable focus follows mouse behaviour  comment out the following line in definiton of struct handler in {{ic|dwm.c}}  
~/.setbg
+
{{bc|1=[EnterNotify] = enternotify, }}
autocutsel &
+
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.
termirssi &
 
urxvt &
 
 
while true; do
 
    xsetroot -name "$(date +"%F %R")"
 
    sleep 1m    # Update time every minute
 
done &
 
'''exec dwm'''
 
  
===Conky statusbar===
+
=== Floating layout for some windows ===
Available from the [[AUR]], {{package AUR|conky-cli}} is a special build of conky which prints to <tt>stdout</tt>. 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 with {{Codeline|xsetroot -name}}:
 
conky | while read -r; do xsetroot -name "$REPLY"; done &
 
exec dwm
 
  
The following is a sample conkyrc for a dual core CPU, displaying several stats:
+
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 {{ic|config.h}}:
<pre>
 
background no
 
out_to_console yes
 
update_interval 2
 
total_run_times 0
 
use_spacer none
 
  
TEXT
+
  { "Firefox",    NULL,      "Firefox Preferences",        1 << 8,        True,    -1 },
$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}
 
</pre>
 
  
==Extended usage==
+
== Troubleshooting ==
  
===Patches & additional tiling modes===
+
=== Fixing misbehaving Java applications ===
The official website is full of [http://www.suckless.org/dwm/patches patches] that can add extra functionality to dwm. Users can easily customize dwm by applying the modifications they like. The [http://www.suckless.org/dwm/patches/bottom_stack.html Bottom Stack] patch provides an additional tiling mode that splits the screen horizontally, as opposed to the default vertically oriented tiling mode.
 
Very simmilar to this patch is bstack horizontal which further splits the tiles horizontally.
 
  
The[http://dwm.suckless.org/patches/gapless_grid gaplessgrid patch] allows windows to be tiled like a grid.
+
Try setting <code>export _JAVA_AWT_WM_NONREPARENTING=1</code>. Also see the [[Java#Non-reparenting_window_managers_.2F_Grey_window_.2F_Programs_not_drawing_properly|Java]]{{Broken section link}} page.
  
====Enable one layout per tag====
+
=== Fixing gaps around terminal windows ===
The default behaviour of dwm is to apply the currently selected layout for all tags.To have different layouts for different tags use the [http://dwm.suckless.org/patches/pertag pertag] 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 {{Ic|resizehints}} to ''0'' in {{ic|config.h}}.
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 {{Codeline|resizehints}} to ''False'' in {{filename|config.h}}:
 
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.
 
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.
  
====Urxvt====
+
Alternatively, if you use the [[st]] terminal emulator, you can apply the [https://st.suckless.org/patches/anysize/ anysize] patch and recompile st.
Another choice for [[urxvt]] users is applying the [[urxvt#Fix maximized window gaps|hints patch]] and regressing to dwm's original behaviour:
 
static Bool resizehints = '''True''';
 
  
===Restart dwm without logging out or closing programs===
+
== Known issues ==
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:
 
<pre>
 
while true; do
 
    # Log stderror to a file
 
    dwm 2> ~/.dwm.log
 
    # No error logging
 
    #dwm >/dev/null 2>&1
 
done
 
</pre>
 
  
dwm can now be restarted without destroying other X windows by pressing the usual Mod-Shift-Q combination.
+
=== Crashes due to Emojis in some fonts ===
  
It's a good idea to place the above startup script into a separate file, {{Filename|~/bin/startdwm}} for instance, and execute it through {{filename|~/.xinitrc}}. From this point on, when desiring to actually end the X session simply execute {{Codeline|killall startdwm}}, or bind it to a convenient key.
+
Emojis in title bars may cause dwm to crash with an error similar to the following:
  
===Make the right Alt key work as if it were Mod4 (Windows Key)===
+
dwm: fatal error: request code=140, error code=16
When using Mod4 (aka Super/Windows Key) as the {{codeline|MODKEY}}, 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.
+
X Error of failed request: BadLength (poly request too large or internal Xlib length error)
 +
  Major opcode of failed request: 140 (RENDER)
 +
  Minor opcode of failed request: 20 (RenderAddGlyphs)
 +
  Serial number of failed request: 4319
 +
  Current serial number in output stream: 4331
  
First, find out which keycode is assigned to Alt_R:
+
This only occurs with some fonts, such as {{pkg|noto-fonts-emoji}} and {{pkg|bdf-unifont}}. See [https://lists.suckless.org/dev/1608/30245.html], [https://lists.suckless.org/dev/1610/30710.html], [https://bbs.archlinux.org/viewtopic.php?id=226928], [https://www.reddit.com/r/archlinux/comments/703ayu/anyone_with_dwm_and_notofontsemoji/], and the upstream bug report [https://gitlab.freedesktop.org/xorg/lib/libxft/issues/6]. Possible workarounds are using a different font or the patch in [https://lists.suckless.org/dev/1610/30720.html].
xmodmap -pke | grep Alt_R
 
  
Then simply add the following to the startup script (e.g. {{filename|~/.xinitrc}}), changing the keycode ''113'' if necessary to the result gathered by the previous {{codeline|xmodmap}} command:
+
An upstream fix has been proposed [https://gitlab.freedesktop.org/xorg/lib/libxft/merge_requests/1], but as of writing has not been merged. See {{AUR|libxft-bgra}} and {{AUR|lib32-libxft-bgra}} for patched versions of libXft, properly displaying emoji without crashing.
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.
+
== See also ==
===Disable focus follows mouse behaviour===
 
To disable focus follows mouse behaviour  comment out the following line in definiton of struct handler in dwm.c
 
<pre>[EnterNotify] = enternotify, </pre>
 
  
==Resources==
+
* [https://dwm.suckless.org/ dwm's official website]
* [http://www.suckless.org/dwm dwm's official website]
+
* [http://www.youtube.com/watch?v=GQ5s6T25jCc Introduction to dwm video]
 
* [[dmenu]] - Simple application launcher from the developers of dwm
 
* [[dmenu]] - Simple application launcher from the developers of dwm
* The [http://bbs.archlinux.org/viewtopic.php?id=57549/ dwm thread] on the forums
+
* The [https://bbs.archlinux.org/viewtopic.php?id=57549/ dwm thread] on the forums
* [http://www.flickr.com/photos/cinderwick/sets/72157604733895131/ dwm wallpapers] and the forums' [http://bbs.archlinux.org/viewtopic.php?id=57768/ wallpaper thread] for a selection of dwm wallpapers
+
* [https://bbs.archlinux.org/viewtopic.php?id=92895/ Hacking dwm thread]
* [http://www.xsnake.net/howto/dwm/dwm-eng.php HowTo by Snake]
+
* Check out the forums' [https://bbs.archlinux.org/viewtopic.php?id=57768/ wallpaper thread] for a selection of dwm wallpapers
* [http://0x80.org/blog/?p=72 Moved to dwm]
+
*[https://bbs.archlinux.org/viewtopic.php?id=74599 Show off your dwm configuration forum thread]

Latest revision as of 19:02, 16 February 2020

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.

Installation

dwm can be installed with dwmAUR or dwm-gitAUR. Make any required #Configuration changes before building and installing, see makepkg.

Configuration

dwm is configured at compile-time by editing some of its source files, specifically config.h. For detailed information on these settings see the included, well-commented config.def.h as well as the customisation section on the dwm website.

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 the Patching packages article.

Starting

Select Dwm from the menu in a display manager of choice. Alternatively, to start dwm with startx append exec dwm to ~/.xinitrc and prepend other programs to execute them as well, for example:

redshift -O3500; xset r rate 300 50; exec dwm

Usage

See the dwm tutorial for information on basic dwm usage.

Tips and tricks

Statusbar configuration

For more examples of status bars see [1].

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).

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.

Restart dwm

To restart dwm without logging out or closing applications, change or add a startup script so that it loads dwm in a while loop, for example:

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

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))
new_csum=""
while true
do
    if [ "$csum" != "$new_csum" ]
    then
        csum=$new_csum
        dwm
    else
        exit 0
    fi
    new_csum=$(sha1sum $(which dwm))
    sleep 0.5
done

Bind the right Alt key to Mod4

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

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.

Floating layout for some windows

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 },

Troubleshooting

Fixing misbehaving Java applications

Try setting export _JAVA_AWT_WM_NONREPARENTING=1. Also see the Java[broken link: invalid section] page.

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 0 in config.h.

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.

Alternatively, if you use the st terminal emulator, you can apply the anysize patch and recompile st.

Known issues

Crashes due to Emojis in some fonts

Emojis in title bars may cause dwm to crash with an error similar to the following:

dwm: fatal error: request code=140, error code=16
X Error of failed request: BadLength (poly request too large or internal Xlib length error)
  Major opcode of failed request: 140 (RENDER)
  Minor opcode of failed request: 20 (RenderAddGlyphs)
  Serial number of failed request: 4319
  Current serial number in output stream: 4331

This only occurs with some fonts, such as noto-fonts-emoji and bdf-unifont. See [2], [3], [4], [5], and the upstream bug report [6]. Possible workarounds are using a different font or the patch in [7].

An upstream fix has been proposed [8], but as of writing has not been merged. See libxft-bgraAUR and lib32-libxft-bgraAUR for patched versions of libXft, properly displaying emoji without crashing.

See also