dwm

From Gentoo Wiki
Jump to: navigation, search

Resources

dwm (shortened from dynamic window manager) is a dynamic window manager for X11.

  • dwm is only a single binary, and its source code is intended to never exceed 2000 SLOC.
  • dwm is customized through editing its source code

Introduction

dwm is a dynamic window manager for X. It manages windows in tiled, monocle and floating layouts. All of the layouts can be applied dynamically, optimizing the environment for the application in use and the task performed.

Window model

Launch a few terminals with Shift+Alt+Enter and dwm will tile the windows between the master and stack. A new terminal appears on the master window. Existing windows are pushed upon a stack to the right of the screen. Alt+Enter toggles windows between master and stack.

   +------+----------------------------------+--------+
   | tags | title                            | status +
   +------+---------------------+------------+--------+
   |                            |                     |
   |                            |                     |
   |                            |                     |
   |                            |                     |
   |          master            |        stack        |
   |                            |                     |
   |                            |                     |
   |                            |                     |
   |                            |                     |
   +----------------------------+---------------------+

Installation

USE flags

USE flags for x11-wm/dwm a dynamic window manager for X11

xinerama Add support for querying multi-monitor screen geometry through the Xinerama API

Users should consider enabling the savedconfig USE flag in order to save customized configuration file to /etc/portage/savedconfig/x11-wm/dwm-6.0.h for later editing.

root #euse --enable savedconfig

Users with multiple monitors should enable the xinerama USE flag regardless of whether or not Xinerama will be used.

root #euse --enable xinerama

Emerge

Install x11-wm/dwm:

root #emerge --ask x11-wm/dwm

Configuration

Starting

To start dwm use a display manager or the startx command.

Those choosing to go the startx route and want ConsoleKit support, setup ConsoleKit and create the following file:

FILE ~/.xinitrc
exec ck-launch-session dbus-launch --sh-syntax --exit-with-session dwm

Main dwm configuration file (dwm.h file)

As stated previously, the main dwm configuration file is the /etc/portage/savedconfig/x11-wm/dwm-6.0 file and after each change, dwm needs to be recompiled for any changes to take effect.

In order for the editor to use syntax highlighting feature for C code, create a symlink using a header filename.

root #ln -s /etc/portage/savedconfig/x11-wm/dwm-6.0 /etc/portage/savedconfig/x11-wm/dwm-6.0.h

(When already within a dwm session and just recompiled dwm, use the META+SHIFT+q key sequence for reloading the dwm binary currently executing within memory.)

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-6.0) 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, the CPU temperature, the current track on the music player, number of unread emails, etc.)

Additional features

dmenu

dmenu is a dynamic menu for X, originally designed for dwm.

root #emerge --ask x11-misc/dmenu

ALT (aka META) +p key sequence enables the menu.

dmenu's options can be customized during execution using the dwm.h file, such as displaying the menu at the bottom of the display.

FILE /etc/portage/savedconfig/x11-wm/dwm-6.0.h
static const char *dmenucmd[] = { "dmenu_run", "-b", "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL };

Conky

For displaying additional status information on dwm's menu bar, one can use Conky. Prefer installing with -X USE flag as only text information is piped through to the dwm instance. (USE flags for consideration are "-X hddtemp iostats wifi".)

root #emerge --ask app-admin/conky

An example .conkyrc file. Top file are Conky related options, while the TEXT section are printed results. The TEXT section is usually system specific and likely will need further editing to run properly.

FILE $HOME/.conkyrc
background no
format_human_readable yes
out_to_console yes
out_to_x no 
temperature_unit fahrenheit
total_run_times 0
update_interval 1
#use_spacer left
use_spacer none

TEXT
M ${memperc}%/${swapperc}% | \
/sda ${diskio sda} /sdb ${diskio sdb} \
/sdc ${diskio sdc} | \
${if_existing /proc/net/route ppp0}P0 U ${upspeed ppp0} D ${downspeed ppp0} |${endif}\
${if_existing /proc/net/route eth0}E0 U ${upspeed eth0} D ${downspeed eth0} |${endif}\
${if_existing /proc/net/route wlan0}W0 U ${upspeed eth0} D ${downspeed eth0}\
${wireless_ap wlan0} ${wireless_link_qual_perc wlan0} ${endif}\
CPU ${hwmon 1 temp 1}F \
/sda ${hddtemp /dev/sda}F \
/sdb ${hddtemp /dev/sdb}F \
     ${time %a, %b %d %Y  %H:%M (%z)}
Note
I started seeing two (double) Conky status lines within Xorg/DWM desktop recently and just realized "out_to_x no" is now needed. Recently, Conky started printing the status line, and then printing a line automatically to the root X window, and only updating the X window status line until the desktop was changed, then and only then would the dwm status line update. This option prevents this from happening.

Keys and key functions

Alt is the default META key

Moving a window manually

To move a window to another window tag manually, hold down the META (Alt) key and left click anywhere on the window. And then, while still holding down the META key, click again on the window tag want to move the window to.

Default Shortcuts

Those shotcuts are used by default in x11-wm/dwm.


Window management

  • Alt+2 - Display window tag number two
  • Alt/Meta+Shift+1-9 - Hover mouse over window and press keys. Puts window on tag number specified.
  • Alt/Meta+Shift+0 - Hover mouse over window and press keys. Puts window on all tags.


Utilities

  • Shift+Alt+Enter - Launch a terminal
  • Shift+Alt+c - Kills a window
  • Alt+p - dmenu
  • Alt+J or Alt+K - Move to another terminal.
  • Alt+Enter - Toggles Windows between stack and master.
  • Shift+Alt+q - Quit dwm

Changing layout

  • Alt+F - Change layout on floating.
  • Alt+T - Change layout on tiled.

Volume keys

Warning
"..." means to be include in x11-wm/dwm NOT to file end

Add following lines to the config file and re-emerge dwm:

FILE /etc/portage/savedconfig/x11-wm/dwm-6.0
#include <X11/XF86keysym.h>

...

/* commands */
static const char *upvol[] = { "amixer", "set", "Master", "2+", NULL };
static const char *downvol[] = { "amixer", "set", "Master", "2-", NULL };

// for muting/unmuting //
static const char *mute[] = { "amixer", "-q", "set", "Master", "toggle", NULL };

// for pulse compatible //
static const char *upvol[] = { "amixer", "-q", "sset", "Master", "1%+", NULL };
static const char *downvol[] = { "amixer", "-q", "sset", "Master", "1%-", NULL };
static const char *mute[] = { "amixer", "-q", "-D", "pulse", "sset", "Master", "toggle", NULL };

...

static Key keys[] = {
        /* modifier                     key        function        argument */
        { 0,              XF86XK_AudioRaiseVolume, spawn,          {.v = upvol } },
        { 0,              XF86XK_AudioLowerVolume, spawn,          {.v = downvol } },
        { 0,              XF86XK_AudioMute,        spawn,          {.v = mute } },

Customization

(Put user customization tricks & tips here.)

Patching

Gentoo has a specific way of patching dwm. If the patches are ready to be merged with dwm source, there is special function called eapply_user that can be called during the emerge process. This function allows user patches to be applied to the source. Move the necessary patches one of the two locations:

Patches in /etc/portage/patches/category/application

First create the a the following directory:

root #mkdir -p /etc/portage/patches/x11-wm/dwm

Copy the dwm patches to /etc/portage/pacthes/x11-wm/dwm/ and make sure each patch is prefixed with a number, like so: 01-name_of_patch.patch. Also the file needs to be named *.patch otherwise Portage will not apply it. For this example we will assume that patch is located in the user called larry's ~/ (home directory).

root #cp /home/larry/01-dwm.6.0-xft.patch /etc/portage/patches/x11-wm/dwm/

Now just install dwm, emerge will take care of applying patches

root #emerge --ask dwm

Patches in a custom repository

Copy x11-wm/dwm from /var/db/repos/gentoo/ to the custom repository, for more information how to create custom repository see the Custom repository article.

Next we need to place our patches in files directory.

root #cp /home/larry/01-dwm-6.0-xft.diff /usr/local/portage/x11-wm/dwm/files/

Open /usr/local/portage/x11-wm/dwm/dwm-6.1.ebuild or whatever location of custom repository and list them in the PATCHES variable array for automatic patching.

FILE /usr/local/portage/x11-wm/dwm-6.1.ebuild
PATCHES=( "${FILESDIR}/01-dwm-6.0-xft.diff"
          "${FILESDIR}/02-dwm-6.1-x11.diff"
 )

Fire up emerge and enjoy

root #emerge --ask dwm

Assigning applications to window tags

A user can have their favorite applications start on a different window tags, such as starting mplayer on window tag number five.

First, you need to know the "name" of the application recorded by Xorg so dwm can be aware of this window on startup. To find this, start your application (mplayer in this example) and then further execute a command called "xprop" (x11-apps/xprop). Click on the mplayer window and xprop will report Xorg's data on the mplayer window. Use the second window name identified on the "WM_CLASS(STRING)" line. Now we have the name of the window dwm needs to be self aware of. (Sometimes an application will have multiple windows of itself and will report one window without capital letters, while the second will have no capital letters! Wildcard char is allowed within window names and I currently have no idea how many regular expressions are recognized here.)

FILE /etc/portage/savedconfig/x11-wm/dwm-6.0.h
static const Rule rules[] ={
    { "MPlayer",    NULL,       NULL,   1 << 4,     True,        0 },
};

Troubleshooting

Upgrading to dwm-6.0

Upgrading from dwm-5.9 to dwm-6.0 incorporated many changes making your previous config.h a likely problem for compiling dwm-6.0. Likely problems displayed might be compiler error messages "[nowiki]'nmaster' undeclared[/nowiki]". To resolve, compile and install dwm-6.0 without using your custom config.h file and then find the default dwm-6.0 config.h file and diff against your old config.h file. (Or, uncompress the dwm-6.0 tarball to acquire the default dwm-6.0 config.h file.)

Remap META Key

If you have conflicts with the default dwm ALT key conflicting with your other console interface applications, you can use the ESC key while within your console application. The ESC key is an immediate usable fall back escape key. Another option, redefine the META key to use the keyboard "Windows Key" or other additional keys near the space bar.

FILE /etc/portage/savedconfig/x11-wm/dwm-6.0.h
#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 group

Now, a user should have a non-conflicting and easily accessible Meta key on both sides of the keyboard!

Fix Java application misbehaving

Java application are known to misbehave as java doesn't know which WM are we using. After all this result in GUI of specific java application to don't work properly. To solve this we need to install wmname tool and set it to LG3D.

root #emerge --ask wmname

and set it to

user $wmname LG3D

To make this setting permanent add this command to ~/.xinitrc.

It is also useful to export AWT_TOOLKIT if some java applications are using AWT, as noted below.

Blank (grey) windows of Java applications (such as netbeans)

Export this environment variable:

user $AWT_TOOLKIT=MToolkit; export AWT_TOOLKIT

Start the program:

user $netbeans-7.1
Note
All fixes are not permanent, so we need to include those fixes in out startup script, for example ~/.xinitrc

Background not redrawing

You might run into situations where the background doesn't properly redraw when the current view is switched. For example, some terminal emulators such as st don't draw the entirety of their allocated window space. In these cases, X root window must have a properly defined color. This can be done with the xsetroot command. For example:

user $xsetroot -solid black