/articles/‎ > ‎

DWM: A newbie's guide



Background and Prerequisites

    So you've decided to jump into the wonderful world of tiling window managers. It may seem like a daunting task but just remember two things: (1) in general to make changes to your set-up (your custom keybinded shortcuts, or the padding of your window tiles) you will need to find the appropriate configuration file to edit. Second, there's always a man page or a resource on the interwebs to help you change your files.

    If you got a copy of DWM from your local package manager then un-install it right away. It is better to compile from source which can be found at suckless's website. Once you got a copy, extract the contents and boot up a terminal and cd into the dwm folder. For this tutorial we will be using Ubuntu's repos (12.10 to be exact); similar packages can be found for your specific distro (all you need is a bit of googling).

    You're gonna need the following packages to compile and install DWM:

sudo apt-get install build-essential

sudo apt-get install xorg-dev


   
    Once installed you are now ready to compile DWM. Look at the config.mk file first though; any of these look familiar? If not, then simply ignore it. But for veteran users, this where you can change the build paths if you have a customised system. This is also where'd you would go to mess with Xinerama for multiple screen support, but it is beyond the nature of this article. We're just about ready to compile all you have to do now is input sudo make install clean and you officially have it now!

Starting DWM

The Ubuntu Way

    Or should I say the LightDM way. If you use the LightDM login manager, you will need to make your own .desktop ( found at /usr/share/xsessions/ ) session to boot up into DWM, if it's not already donefor you. Actually, you will most certainly need to create a .desktop session if you want to have a custom start-up script or a status bar with your own preset statuses (like time, temperatures, now playing data). Anyway let us make our own .desktop session just for DWM. Make a file dwm.desktop (make sure you are root since you are modifying a protected directory) and paste this:

[Desktop Entry]
Name=The Name of your Sesssion
Comment=The comment you want to appear when hovered
Exec=
Type=Application

    The most important part here is Exec which executes the desired start up script you would like. This will be your own script, with your own start-up programs which gives you utmost control on the desktop session level (which is enough for casual or intermediate users!)

    Now we must create our start up script, let's name is dwmstart. Ensure it has proper permissions by running chmod +x dwmstart on your terminal. Open up your file with your favourite editor. Since this is essentially a bash script you must add the HashBang  #! /bin/bash at the very first line of your script. And at the very core (with no start-up apps or anything your script should have two lines):

## my start up script dwmstart

#! /bin/bash

exec dwm


    At this point you are technically done. You can do basic tasks, launching apps from the terminal. This is the core dwm experience with none of your customisation. Note that there is no network manager, no wallpaper set, and the status bar simply reads dwm-X.X. It is crucial to know the base dwm system, so if you ever need to fall back you know where you are!

The .xinitrc way

    Pretty much the same instructions as above without the need to make a .desktop session. .xinitrc is the start-up script for when you run startx. Now onto the fun part!

Customisation

Startup Script

This is what decides what launches when you boot into your dwm session. For internet connectivity, launch your desired program wicd or nm-applet. You can set your default wallpaper here as well, using nitrogen or feh. It is crucial that you add & at the end of each line before exec dwm. This pretty much makes the program run in the background. So for restoring the wallpaper you would have nitrogen --restore &

Status Bar

By default you have dwm-X.X showing at your status bar at the top right. This can be changed with xsetroot -name. Here we have a few simple examples of status bars:

Just the time

while true; do

xsetroot -name "` date +"%R"`"

done &


Battery level and status
BATT=$( acpi -b | sed 's/.*[charging|unknown], \([0-9]*\)%.*/\1/gi' )

STATUS=$( acpi -b | sed 's/.*: \([a-zA-Z]*\),.*/\1/gi' )
while true; do

xsetroot -name "`echo $BATT $STATUS`"

done &


Cmus now-playing


CMAS () {
artest=$( cmus-remote -Q | grep "tag artist" | sed s/"tag artist"/""/g | sed '1s/^.//')
title=$( cmus-remote -Q | grep "tag title" | sed s/"tag title"/""/g )
status=$( cmus-remote -Q | grep "status" | sed s/"tag title"/""/g )
track=$( echo -e "$artest -$title")
if  [[ "$status" != "status playing" ]]; then
cm=""
cmcolor=$(echo -e "$cm")
else
trackc=$( echo -e "$track")
echo "$trackc"
fi
}

while true; do

xsetroot -name "`CMAS`"

done &

Colors & Fonts

    Changing any of DWM's configuration requires you to edit config.def.h (then copying it to config.h). Changing the colors and the panel font involves editing the appearance section of the header file. Don't worry you don't need to know C. It's pretty readable, provided you have the patience.

    Changing the font is another task in itself. Boot up a terminal and run xfontsel and see what fonts are available to you. Otherwise you can add your own x11 fonts by doing the following:

1) Get your desired BDF or PCF font and place it in folder other than .fonts

2) Run mkfontdir on this directory

3) On your startup script add the following:

xset fp+ /home/$USER/myfonts &

xset fp rehash &

4) Reboot and run xfontsel again. NOTE: This method is a bit spotty even for me so you may need to hack your way out
5) You can avoid this mess and just install xft support.
For a multi-colored setup on your panel look into these patches:
ansistatuscolors
statuscolors

Tag names

You can change the 'workspaces' or tags by reffering to this section. By default you have it set from 1-9.

Special Window Rules

Some windows don't need to be tiled. Some windows need to be launched at a specific tag. Refer to this section.

    As you can see Gimp here is marked as a floating window. Modify the isfloating value. Firefox is also set to launch to the 9th workspace or tag (start from 1 move 8 spaces to the right ). You can also add your own rules, to any window you'd like following the same format. The tricky part is finding the 'window class' value. This can be found by running xprop | grep "CLASS" and selecting the desired window. Take the value with the first Capitalized letter. In general, gedit's class name would be Gedit, but for good practice it's better to be safe and run xprop.

Keybindings

You can edit your key commands in this section.

Define your command in the /* commands */ section. And set the appropriate key short cut in the Keys section.

Other

I hoped you learned a thing or two. You are on your way to become a guru. You can add extra functionality by visting suckless patches for DWM or if you know C, you can make your own!

Check out:



Comments