dwm: A Minimalist Tiling Window Manager For Linux

dwm-tilting-window-manager-featured

Tiling window managers have several advantages over their more popular cousins such as Gnome, KDE, XFCE, or Fluxbox. The feature of this post, dwm, takes these advantages to their most extreme.

While most tiling managers strive to be lightweight, dwm keeps itself on a starvation diet of 2000 lines of code or fewer. All its configuration is done when it’s compiled, so it doesn’t read a runtime configuration file. It uses tags (the numbers 1 through 9), rather than arbitrarily-named window spaces, to group programs together. It can also be run entirely with keyboard commands, though it does incorporate mouse support for selecting and dragging windows when appropriate.

If you’re looking for a bare-bones experience or a foil to your current desktop environment, dwm can offer exactly that. Let’s get started with installation before trying some of its features.

Also read: 5 Useful Patches to Improve Your dwm Experience

Installation

Grabbing the source code is straightforward with git:

git clone https://git.suckless.org/dwm

From here you can edit dwm’s “config.mk” file to change its install directory (“/usr/local/” by default) and its “config.h” file to change keybindings as you see fit. Then you can install with make clean install.

Some Linux distributions offer precompiled binaries, such as Ubuntu and Arch. For Ubuntu, install with:

sudo apt-get install dwm

For Arch you’ll need to visit its user repository and build/install with makepkg.

Beware, however, that precompiled binaries often come attached to their respective program managers, such as Ubuntu’s APT and Arch’s Pacman, which will install fresh copies of “config.mk” and “config.h” when dwm is updated. Therefore, any updates will write on top of any changes you made to those config files. Arch suggests making your own package to save your changes.

Dwm has a few dependencies other than X libraries. You’ll want to grab dmenu, a menu tool, and st, a terminal, if you installed dwm from source. If you’re using a package manager, it should have picked up those extra packages already.

Starting dwm

After installation, if you’re on Ubuntu, you can select “dwm” from the menu in your login screen. For other window managers, it may be easier to edit the X config file “.xinitrc.”

That config file tells the X display server which window manager to use. You can edit the file after first locating it in your home folder.

Open “/home/username/.xinitrc” and scroll to the bottom to find entries like “exec gnome-session.” You must replace any “exec …” you find with “exec dwm” to launch dwm when you start X. In this example changes will look like this:

#exec gnome-session
exec dwm

The “#” in front of any text in .xinitrc will comment out that line, so X won’t read it. By commenting and not deleting the “exec gnome-session” line, you can return to it later, uncomment it, place a comment on “exec dwm”, and resume your use of Gnome.

Window Layouts

If everything went well in installation and startup, you should be staring at a (mostly) blank screen. Dwm starts with little more than a toolbar at the top of its display.

It uses three layouts — Tiled, Monocle, and Floating — to display windows. To open programs in those layouts, you’ll need to learn some commands.

Using dmenu

By default, dwm uses dmenu to open programs available on your system. The keyboard command that opens dmenu and searches for new programs is Mod1 + p, which usually translates to the left Alt + p key.

Dmenu will present a toolbar at the top of your screen. You simply type in the name of your program (ignore caps, like “firefox”) and, when you have found it, press Enter.

Tiled Layout

Open three programs, like Firefox, feh, and a text editor, and you may end up with something that looks geometrically like the following image.

dwm tiled mode

This is dwm’s default mode: Tiled. If you’re in any other mode, press Mod1 + t to get here.

This mode will display, at once, all the programs you have opened. In the screenshot above you can see that Firefox sits in the “Master” area on the left and that the text editor sits in the “Stacking” area on the right.

Unless you change it, Tiled mode puts one program in “Master” and the rest in the “Stack.” In that same screen you can move more tiles to “Master” with Mod1 + i and decrease them with Mod1 + d. Adding a few spaces in the “Master” area, and opening a few more windows, will look something like the following image.

dwm tiled mode 2

You will know you’re in Tiled mode when, in your toolbar, a “[ ]=” is printed after the numbers 1-9.

You can change focus to any window in the area by using Mod1 + j to move forward and Mod1 + k to move backward. You can also select a window by moving your mouse on top of it. Pressing Mod1 + Enter will move a focused window into the “Master” area.

Monocle Layout

Monocle layout does away with the “Master” and “Stacking” areas. It instead presents each window in fullscreen. The remaining windows sit behind the window in focus.

You can switch to Monocle layout with Mod1 + m. This will change the insignia to “[3]” in your toolbar. The number in the insignia will change with the number of windows you have open.

dwm monocle mode

This screenshot shows the same number of programs open from the first Tiled screenshot, but it presents only the active window. Switch active windows with Mod1 + j and Mod1 + k.

Floating Layout

Some programs work better when the windows can float around the screen. Switch to Floating mode with Mod1 + f and see the insignia change to “><>.”

This shot shows Gimp in Floating mode.

dwm floating mode

With your mouse in this mode, you can move and resize windows. Hold Mod1 while using the left mouse button to drag a window; use the right mouse button to resize a window.

Miscellaneous Commands

Make note of these other commands to assist your navigation:

  • Open the st terminal: Mod1 + Shift + Enter
  • Switch your view to a new virtual desktop: Mod1 + [number 1-9]
  • Move the active window to a new virtual desktop: Mod1 + Shift + [number 1-9]
  • Quit dwm: Mod1 + Shift + q

Read the dwm manual page in your terminal with man dwm for help with these commands and others.

Conclusion

This may seem like a lot of effort at first, but dwm is quite easy to use once you get the hang of it.

Don’t Mod1 + Shift + q too quickly. The work you put in now will be rewarded with simplicity, predictability, and speed as you complete your daily tasks.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Casey Houser

I have worked as a professional writer since 2011. I like to compose my articles in Vim, which I also use for hobbyist C and Ruby projects. When I'm not in front of a text editor, I run, bike, and play tennis until I'm too tired to move.