Dwm
From Gentoo Linux Wiki
DWM is a dynamic window manager for X. It manages windows in tiled and floating layouts. Either layout can be applied dynamically, optimizing the environment for the application in use and the task performed.
Contents |
[edit] About DWM
"In contrast to ion, larswm, and wmii, dwm is much smaller, faster and simpler with < 2000 SLOC (Standard Lines of Code)." -- DWM's Home Page.
This window manager gives you only what you need for a desktop with the features to navigate it, and nothing more!
- I spend most of my time in a shell (URxvt with GNU Screen), so I rarely ever see my desktop along with all the other bloated window manager's features.
- If I need a file manager, I'll use Thunar (or, for a more lightweight alternative, pcmanfm) with it's Volume Management feature for automatically mounting removable media.
- I've realized over the years, once I have modify or edited my settings, they usually remain the same for years.
Because of all this, DWM's static settings along with no desktop icons & menus omits a lot of resource hungry code!
The original author of this Gentoo Wiki appears to have been using dwm-5.4. Then I came along, after installing & using dwm-5.6.1, and edited this Wiki for grammar usage along with adding my own insight. Enjoy and feel free to modify/correct as needed! ;-)
[edit] Installation
There are two methods of installing DWM. The regular method is using Gentoo's Portage. The second method is by manually getting the source code. The benefit for the second method is you're getting your hands on the most up-to-date code prior to it's entry into the Portage packaging system.
[edit] Regular Install using Portage Emerge
Being such a small program DWM does not come with a lot of USE flags either. Due to the nature of DWM, it's recommended to enable the "savedconfig" USE Flag.
- xinerama: Allows for dual monitors.
- savedconfig: Restores your config from /etc/portage/savedconfig $/$.
For installing DWM via Portage, you can simply run:
[edit] Install from Source Code
You can get the source code two different ways:
- Directly from the main mirror.
- Via mercurial.
You can manage updates for DWM using Mercurial:
Check if you have permission to write in /usr/local and compile the source:
To customize dwm, just rewrite config.mk and config.h.
[edit] Optional DMenu Package
DWM also has a simple program launching utility called DMenu (and is also used by some other window managers). Like DWM itself, DMemu honors the "savedconfig", placing its config file in /etc/portage/savedconfig/x11-misc/.
[edit] Configure
[edit] The Configuration File (dwm.h)
DWM does not have any configuration files. Instead all configuration of DWM must be done through source code. This means, in order to change the window manager, one must first understand C and then recompile the package from source. This may pose as a problem to many users.
Fortunately, Gentoo provides an easy way to accomplish this. The DWM C header file, which serves as the user configuration file, is saved to /etc/portage/savedconfig/x11-wm/. This feature is activated with the USE Flag "savedconfig". After editing this config file, the next time you emerge DWM, this file will be used in place of the default header file (thereby incorporating your customizations). The USE flag also prevents the emerge process from overwriting your saved configuration, which will be used each time you emerge DWM. While this may seem tedious, DWM is so tiny (<= 2000 lines of code), it only takes seconds to emerge.
The file is laid out such that non-programmers can manage to make common customizations without any problems (colors, key bindings, etc.). With a little C programming skill one can make more substantial customizations. The source code of the application itself is readable and lends itself to patching. Patches created by other users are available on the application's home page and other places on the web.
To edit the DWM configuration file, if you have enabled the savedconfig USE Flag:
If you want auto syntax hilighting, it has been recommended to create a symlink to this file:
[edit] Settings File (dwm.rc)
The default xsession file provided by the Gentoo Ebuild (/etc/X11/Sessions/dwm) provides for a default status box that displays system load and the date/time or whatever shell code the user creates at ~/.dwm/dwmrc. The present mechanism (as of dwm-5.4, dwm-5.6) for sending text to a status box in the window manager's bar is to use 'xsetroot', as illustrated by the default xsession mentioned above. With a few lines of shell code, one can use this mechanism to send arbitrary text to the status bar (for example, your CPU temperature, the current track on your music player, number of unread emails, etc.)
[edit] Usage
The easy way to run dwm is modify your ~/.xinitrc, for example like this:
exec dwm
and run it with startx.
I (not the original author of this Wiki) have tried using Display Managers, but I fell-out of favor using them after realizing they were more bloated than this Window Manager. I even tried Slim. You can spend time configuring your favored Display Manager, but most users of DWM will strongly prefer to start from tty console. The Tips Section below gives some additional ideas.
[edit] Using DWM
[edit] Moving & Resizing Windows
You can move and resize windows, pressing the ALT (aka META) key + left (or right) mouse buttons.
[edit] Viewing Virtual Desktops
To view the other desktops, either use a mouse click on the number of the desktop or use ALT (aka META) key + (number). You can toggle between the current desktop & previous using ALT (aka META) + TAB keys.
Most key sequences are easily found within the DWM manfile.
#define MODKEY Mod4Mask /* Use Windows Key */
To assign a second Meta key allowing a typer to have a Meta key on both sides of the keyboard, you can mimmick or copy this key activity to another key on the keyboard. The Microsoft Menu key (or context menu key) on Microsoft keyboards is directly opposite of the Microsoft Windows key. You'll need the x11-apps/xmodmap package for this. (For reference, the two key's values are: "showkey 125/127" and "xev 133/135" respectively - on my MS NEK4000 keyboard.)
# Top of $HOME/.xinitrc file is a good place for this. # This reassigns MS NEK4000 right Menu key to simulate DWM Mod4Key as well. xmodmap -e "keycode 135 = Super_L" # reassign MS Menu Keypress to Super_L xmodmap -e "remove mod1 = Super_L" # make sure X keeps it out of the mod1 groupNow, a user should have a non-conflicting and easily accessible Meta key on both sides of the keyboard!
[edit] Using DMenu
DMenu is pretty simple to use. ALT (aka META) + p key sequence enables the menu. The default location is at the top of the screen and can be configured to use the bottom of the screen. Simply type the name of the program. It basically emulates command line shell syntax using "tab completion". Press ESC to escape the menu.
[edit] Tips
[edit] Simple .dwmrc
The .dwmrc file is treated like a regular sh script file.
xsetroot -name "`date`" xsetroot -solid black
[edit] Custom Status Bar 1
If you don't like the current status bar of dwm, it is possible to customize it. For example, this is my personal ~/.xinitrc:
#!/bin/sh
eval "$(gpg-agent --daemon)"
urxvtd -q -o -f && urxvtc &
amixer -q set Headphone mute &
feh --bg-scale docs/multimedia/images/wallpapers/006.jpg &
#display -window root repo/dwm/dwm.png
#xsetroot -solid black
sleep 3 && firefox &
wifi(){
STATUS="X`/sbin/iwgetid`"
if test "$STATUS" != "X" ; then
ESSID="`/sbin/iwgetid |awk -F ":" '{print $2}'|sed -e 's/"//g'`"
LINK="`awk '/wlan0:/ {print $3}' /proc/net/wireless |sed -e 's/\.//g'`"
echo " $ESSID:$LINK"
fi
}
batt(){
FULL=`cat /sys/class/power_supply/BAT0/charge_full`
PRESENT=`cat /sys/class/power_supply/BAT0/present`
CHARGE=`cat /sys/class/power_supply/BAT0/charge_now`
STATUS=`cat /sys/class/power_supply/BAT0/status`
if test "$PRESENT" != "0" ; then
CHARGE=$((${CHARGE}*100/${FULL}))
case $STATUS in
Full)
SIGN="=";;
Charging)
SIGN="+";;
Discharging)
SIGN="-";;
esac
echo " ${CHARGE}${SIGN}"
else
echo " AC"
fi
}
volume(){
STATUS="`amixer get Headphone |awk '/Front\ Left:/ {print $4}'`"
if test "$STATUS" != "[on]" ; then
echo " Mute"
else
echo " `/usr/bin/amixer get PCM |awk '/Front\ Left:/ {print $5}' | sed -e 's/\[//g'|sed -e 's/%\]//g'`v"
fi
}
cmusstats(){
if test "X`pgrep cmus`" != "X" ; then
TIME="`cmus-remote -Q |awk '/duration/ {print $2}'`"
CURR="`cmus-remote -Q |awk '/position/ {print $2}'`"
ARTIST="`cmus-remote -Q |sed -ne '/artist/s/tag artist //pg'`"
TITLE="`cmus-remote -Q |sed -ne '/title/s/tag title //pg'`"
echo "$TITLE ($ARTIST) $CURR/$TIME"
fi
}
while true; do
xsetroot -name "`cmusstats``wifi``volume``batt` `date '+%a %Y%m%d %H:%M'`"
sleep 1
done &
exec dwmand run it with startx.
[edit] Status Bar with Date/Time and DWM Restart Feature
This is a more simple & basic status bar only displaying the date, including time (without seconds) updated every 55 seconds. This will also auto start a simple terminal. A neat feature of this script, if you update the DWM package, you can simply restart it with the META + SHIFT + q key sequence and it will reload without closing all of your other applications!
(I have commented out my custom urxvt+screen.sh script to display some of the other possibilities.)
#exec /home/roger/bin/urxvt-screen.sh &
exec /usr/bin/urxvt &
while true
do
while true
do
while true
do
xsetroot -name "$(date +"%a, %b %d %Y | %H:%M")"
sleep 55s
done &
/usr/bin/dwm
done
done
[edit] Automatically Start DWM on Login
If you prefer to start X on login, you can add the "startx" command to the bottom of your .bash_profile file. Users who log into this box using Telnet or OpenSSH, should be prevent from within the .bash_profile from executing these specific commands.
# .bash_profile
# Read Bash settings file (Get private aliases & functions)
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# Start X if not a Telnet/SSH Session.
# (... X then reads .xinitrc to start DWM)
if [ -n $SSH_CONNECTION ]; then
exec startx
fi
