How to Configure and Master `dwm` Key Bindings in Linux
dwm (dynamic window manager) relies on keyboard-driven window management and compile-time configuration in C. Instead of editing a runtime config file and reloading it on the fly, you define key bindings inside a C header file and recompile dwm whenever you make changes.
1. Essential Default Key Bindings#
In a vanilla dwm setup, MODKEY defaults to Mod1Mask (Alt). These core shortcuts cover daily navigation and window control:
| Key Binding | Action |
|---|---|
Mod + Shift + Return | Launch a terminal (st by default) |
Mod + p | Open dmenu to launch applications |
Mod + j / Mod + k | Focus next / previous window in the current stack |
Mod + h / Mod + l | Decrease / increase master area width |
Mod + i / Mod + d | Increase / decrease number of windows in the master area |
Mod + Return | Zoom/promote focused window to (or from) the master area |
Mod + Shift + c | Close (kill) the focused window |
Mod + b | Toggle the top status bar on or off |
Mod + Shift + q | Quit dwm cleanly |
2. Layouts and Floating Windows#
dwm ships with three built-in layouts: tiled ([]=), floating (><>), and monocle ([M]).
- Switch to tiled layout:
Mod + t - Switch to floating layout:
Mod + f - Switch to monocle (fullscreen-like stack) layout:
Mod + m - Toggle previous layout:
Mod + Space - Toggle floating state on focused window:
Mod + Shift + Space - Move or resize floating windows with the mouse: Hold
Mod+ Left Click to drag, orMod+ Right Click to resize.
3. Tags and Multi-Monitor Navigation#
Rather than fixed virtual desktops, dwm uses tags (1 through 9 by default):
- View tag
N:Mod + [1-9] - Move focused window to tag
N:Mod + Shift + [1-9] - Toggle viewing tag
Nalongside current tags:Mod + Ctrl + [1-9] - Toggle tag
Non focused window:Mod + Ctrl + Shift + [1-9] - View windows from all tags:
Mod + 0 - Focus previous / next monitor:
Mod + ,/Mod + . - Send focused window to previous / next monitor:
Mod + Shift + ,/Mod + Shift + .
4. How Key Bindings Work in config.h#
Open your dwm source directory and copy config.def.h to config.h if you have not already done so. Keeping config.def.h untouched makes applying patches much cleaner later.
Inside config.h, bindings are defined in the static const Key keys[] array using this structure:
/* modifier key function argument */
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
{ MODKEY, XK_b, togglebar, {0} },
{ MODKEY, XK_j, focusstack, {.i = +1 } },
{ MODKEY, XK_k, focusstack, {.i = -1 } },