https://wiki.archlinux.org/api.php?action=feedcontributions&user=Riateche&feedformat=atomArchWiki - User contributions [en]2024-03-29T00:31:41ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Dwm&diff=214448Dwm2012-07-24T12:05:47Z<p>Riateche: /* Disable focus follows mouse behaviour */ add warning</p>
<hr />
<div>[[Category:Dynamic WMs]]<br />
[[es:Dwm]]<br />
[[fr:DWM]]<br />
[[ru:Dwm]]<br />
[[zh-CN:Dwm]]<br />
{{Article summary start|Summary}}<br />
{{Article summary text|Information on installing and configuring dwm}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|dmenu}}<br />
{{Article summary wiki|wmii}}<br />
{{Article summary end}}<br />
{{DISPLAYTITLE:dwm}}<br />
[http://dwm.suckless.org/ dwm] is a dynamic window manager for [[X]]. It manages windows in tiled, stacked, and full-screen layouts, as well as many others with the help of optional patches. Layouts can be applied dynamically, optimizing the environment for the application in use and the task performed. dwm is extremely lightweight and fast, written in C and with a stated design goal of remaining under 2000 source lines of code. It provides multi-head support for xrandr and Xinerama.<br />
<br />
==Installing==<br />
These instructions will install dwm using [[makepkg]] along with the Arch Build System, or [[ABS]] for short. This will allow reconfiguring it at a later time without complications. If only interested in installing dwm for a test drive, simply install the binary package from the repositories instead:<br />
# pacman -S dwm<br />
<br />
{{note|By omitting compiling dwm from source a great deal of customizability is lost, since dwm's entire configuration is performed by editing its source code. Taking this in mind, the rest of the article assumes that dwm has been compiled from source as explained in the entirety of this section.}}<br />
<br />
You will probably also want to consider installing [[dmenu]], a fast and lightweight dynamic menu for X:<br />
# pacman -S dmenu<br />
<br />
===Requirements===<br />
Basic programming tools present in {{Pkg|base-devel}} are needed in order to compile dwm and build a package for it, and the {{Pkg|abs}} package is also a requisite for fetching the necessary build scripts:<br />
# pacman -S base-devel abs<br />
<br />
===Download build scripts with ABS===<br />
Once the required packages are installed, use ABS to update and then copy the dwm build scripts from the ABS tree to a temporary directory. For example:<br />
# abs community/dwm<br />
$ cp -r /var/abs/community/dwm ~/dwm<br />
<br />
===Build and install package===<br />
Use {{Ic|cd}} to switch to the directory containing the build scripts (the example above used {{ic|~/dwm}}). Then run:<br />
$ makepkg -i<br />
<br />
This will compile dwm, build an Arch Linux package containing the resulting files, and install the package file all in one step. If problems are encountered, review the output for specific information. <br />
<br />
{{Tip|If this directory ({{ic|~/dwm}}) is saved, it can subsequently be used for making changes to the default configuration.}}<br />
<br />
==Configuring==<br />
dwm, as mentioned before, is exclusively configured at compile-time via some of its source files, namely {{ic|config.h}} and {{ic|config.mk}}. While the initial configuration provides a good set of defaults, it is reasonable to expect eventual customization.<br />
<br />
===Method 1: ABS rebuild (recommended)===<br />
Modifying dwm is quite simple using this route.<br />
<br />
====Customizing config.h====<br />
Browse to the dwm source code directory saved during the [[#Installing|installation process]]; {{ic|~/dwm}} in the example. The {{ic|config.h}} found within this directory is where the general dwm preferences are stored. Most settings within the file should be self-explanatory. For detailed information on these settings, see the [http://dwm.suckless.org/ dwm website].<br />
<br />
{{note|Be sure to make a backup copy of config.h before modifying it, just in case something goes wrong.}}<br />
<br />
Once changes have been made, pipe the new md5sums into the [[PKGBUILD]]:<br />
$ makepkg -g >> PKGBUILD<br />
This will eliminate a checksum mismatch between the official config.h and the new revised copy.<br />
<br />
Now, compile and reinstall:<br />
$ makepkg -efi<br />
<br />
Assuming the configuration changes were valid, this command will compile dwm, build and reinstall the resulting package. If problems were encountered, review the output for specific information.<br />
<br />
Finally, restart dwm in order to apply the changes.<br />
<br />
====Notes====<br />
From now on, instead of updating the md5sums for every {{ic|config.h}} revision, which are known to become frequent, one may erase the md5sums array and build dwm with the {{Ic|--skipinteg}} option:<br />
$ makepkg -efi --skipinteg<br />
<br />
And after adding a few lines to dwm's start-up script, it is possible to [[#Restart dwm without logging out or closing programs|restart dwm without logging out or closing programs]].<br />
<br />
===Method 2: Mercurial (advanced)===<br />
dwm is maintained upstream within a [http://www.selenic.com/mercurial/wiki/ Mercurial] version control system at [http://hg.suckless.org/dwm suckless.org]. Those already familiar with Mercurial may find it more convenient to maintain configurations and patches within this system. A [http://dwm.suckless.org/customisation/patch_queue detailed tutorial] on this method is available at the dwm website.<br />
<br />
Before building dwm from the Mercurial sources, be sure to alter config.mk accordingly, because failure to do so may result in X crashes. Here are the values that need changing:<br />
<br />
Modify {{Ic|PREFIX}}:<br />
PREFIX = /usr<br />
The X11 include folder:<br />
X11INC = /usr/include/X11<br />
And the the X11 lib directory:<br />
X11LIB = /usr/lib/X11<br />
<br />
==Starting dwm==<br />
To start dwm with {{Ic|startx}} or the [[SLIM]] login manager, simply append the following to {{ic|~/.xinitrc}}: <br />
exec dwm<br />
<br />
For [[GDM]], add it to {{ic|~/.Xclients}} instead, and select "Run XClient Script" from the Sessions menu.<br />
<br />
===Starting a customized dwm from a display manager===<br />
<br />
The default /usr/share/xsessions/dwm.desktop does not allow for a customized start like can be done in .xinitrc.<br />
A solution to this problem is to make a start script, for example /usr/bin/dwm-personalized and make an alternative xsession .desktop file (/usr/share/xsessions/dwm-personalized.desktop).<br />
<br />
Example of /usr/share/xsessions/dwm-personalized<br />
<pre>[Desktop Entry]<br />
Encoding=UTF-8<br />
Name=Dwm-personalized<br />
Comment=Dynamic window manager<br />
Exec=dwm-personalized<br />
Icon=dwm<br />
Type=XSession<br />
</pre><br />
<br />
Example of /usr/bin/dwm-personalized<br />
<br />
<pre>#!/bin/zsh<br />
<br />
#Set swedish keyboard map<br />
setxkbmap se<br />
<br />
#Set chrome as default browser<br />
if [ -n "$DISPLAY" ]; then<br />
BROWSER=google-chrome<br />
fi<br />
<br />
#Set status bar & start DWM<br />
conky | while read -r; do xsetroot -name "$REPLY"; done &<br />
exec dwm<br />
</pre><br />
<br />
===Using dbus with dwm===<br />
<br />
If you want to use xfce4-power-manager with dbus/polkit for example to hibernate, you can start dwm the following way from .xinitrc to enable dbus properly (as dwm does not provide its own autostart-mechanism which would allow for launching applications after starting only dwm with dbus-support):<br />
<br />
<pre>exec ck-launch-session bash -c "xfce4-power-manager & dwm"</pre><br />
<br />
An even better way would be to put all apps into their own file, e.g. ~/bin/startdwm, and then calling that file from .xinitrc:<br />
<br />
<pre>exec ck-launch-session dbus-launch --sh-syntax --exit-with-session ~/bin/startdwm</pre><br />
<br />
The applications then will all have polkit/dbus-assigned rights. An example for such a startdwm-file could be:<br />
<br />
<pre>#!/bin/bash<br />
#this file is called by .xinitrc to start some nice apps for dwm<br />
<br />
xrdb -merge ~/.Xresources &<br />
<br />
xfce4-power-manager &<br />
<br />
sh ~/.fehbg &<br />
<br />
while true; do<br />
xsetroot -name "$(date +"%a %d.%m/%H:%M:%S") $(df -h|grep root|awk '{print $4}')"<br />
sleep 1<br />
done &<br />
<br />
while true; do<br />
dwm || exit<br />
done<br />
</pre><br />
<br />
Note: the "dwm || exit" allows you to exit dwm more intuitively by calling "$ killall dwm" instead of having to remember the script name and typing "$ killall startdwm". You can still restart dwm simply by hitting ALT+SHIFT+Q as long as you have that while-loop.<br />
<br />
==Statusbar configuration==<br />
dwm uses the root window's name to display information in its statusbar, which can be changed with {{Ic|xsetroot -name}}.<br />
<br />
===Basic statusbar===<br />
This example prints the date in [http://en.wikipedia.org/wiki/ISO_8601 ISO 8601] format. Add it to files {{ic|~/.xinitrc}} or {{ic|~/.Xclients}} or see this page's discussion for more details about the GDM-3 case :<br />
<pre><br />
while true; do<br />
xsetroot -name "$( date +"%F %R" )"<br />
sleep 1m # Update time every minute<br />
done &<br />
exec dwm<br />
</pre><br />
<br />
Here is an example intended for laptops that depends on the {{Pkg|acpi}} package for showing battery information:<br />
<pre><br />
while true ; do<br />
xsetroot -name "$(acpi -b | awk 'sub(/,/,"") {print $3, $4}')"<br />
sleep 1m<br />
done &<br />
exec dwm<br />
</pre><br />
<br />
The script displays the amount of battery remaining besides its charging status by using the awk command to trim away the unneeded text from acpi, and tr to remove the commas.<br />
<br />
An alternative to the above is to selectively show the battery status depending on the current charging state:<br />
<pre><br />
while true; do<br />
batt=$(LC_ALL=C acpi -b)<br />
<br />
case $batt in<br />
*Discharging*)<br />
batt="${batt#* * * }"<br />
batt="${batt%%, *} "<br />
;;<br />
*)<br />
batt=""<br />
;;<br />
esac<br />
<br />
xsetroot -name "$batt$(date +%R)"<br />
<br />
sleep 60<br />
done &<br />
<br />
exec dwm<br />
</pre><br />
<br />
Finally, make sure there is only one instance of dwm in {{ic|~/.xinitrc}} or {{ic|~/.Xclients}}, so combining everything together should resemble this:<br />
~/.setbg<br />
autocutsel &<br />
termirssi &<br />
urxvt &<br />
<br />
while true; do<br />
xsetroot -name "$(date +"%F %R")"<br />
sleep 1m # Update time every minute<br />
done &<br />
'''exec dwm'''<br />
<br />
Here is another example that displays also the alsa volume and the battery state. The latter only when the system is off-line.<br />
<br />
#set statusbar<br />
while true<br />
do<br />
if acpi -a | grep off-line > /dev/null; then<br />
xsetroot -name "Bat. $(awk 'sub(/,/,"") {print $3, $4}' <(acpi -b)) \<br />
| Vol. $(awk '/dB/ { gsub(/[\[\]]/,""); print $5}' <(amixer get Master)) \<br />
| $(date +"%a, %b %d %R")"<br />
else<br />
xsetroot -name "Vol. $(awk '/dB/ { gsub(/[\[\]]/,""); print $5}' <(amixer get Master)) \<br />
| $(date +"%a, %b %d %R")"<br />
fi<br />
sleep 1s <br />
done &<br />
<br />
===Conky statusbar===<br />
[[Conky]] can be printed to the statusbar with {{Ic|xsetroot -name}}:<br />
conky | while read -r; do xsetroot -name "$REPLY"; done &<br />
exec dwm<br />
<br />
To do this, conky needs to be told to output text to the console only. The following is a sample conkyrc for a dual core CPU, displaying several stats:<br />
<pre><br />
out_to_console yes<br />
out_to_x no<br />
background no<br />
update_interval 2<br />
total_run_times 0<br />
use_spacer none<br />
<br />
TEXT<br />
$mpd_smart :: ${cpu cpu1}% / ${cpu cpu2}% ${loadavg 1} ${loadavg 2 3} :: ${acpitemp}c :: $memperc% ($mem) :: ${downspeed eth0}K/s ${upspeed eth0}K/s :: ${time %a %b %d %I:%M%P}<br />
</pre><br />
<br />
==Basic usage==<br />
===Using dmenu===<br />
Dmenu is a useful addon to dwm. Rather than a standard list-style menu, it acts as a sort of autocomplete to typing in the names of binaries. It is more advanced than many program launchers and integrates well within dwm.<br />
<br />
To start it, press {{Keypress|Mod1}} + {{Keypress|P}} ({{Keypress|Mod1}} should be the {{Keypress|Alt}} key by default). This can, of course, be changed if you so desire. Then, simply type in the first few characters of the binary you wish to run until you see it along the top bar. Then, simply use your left and right arrow keys to navigate to it and press enter.<br />
<br />
For more information, see [[dmenu]].<br />
<br />
===Controlling windows===<br />
====Moving a window to another tag====<br />
Moving a window from one tag to another is very simple. To do so, simply bring the window into focus by hovering over it with your cursor, then press {{Keypress|Shift}} + {{Keypress|Mod1}} + {{Keypress|x}}, where 'x' is the number of the tag to which you want to move the window. [Mod1] is, by default, the {{Keypress|Alt}} key.<br />
====Closing a window====<br />
To cleanly close a window using dwm, simply press {{Keypress|Shift}} + {{Keypress|Mod1}} + {{Keypress|C}}.<br />
<br />
====Window layouts====<br />
By default, dwm will operate in tiled mode. This can be observed by new windows on the same tag growing smaller and smaller as new windows are opened. The windows will, together, take up the entire screen (except for the menu bar) at all times. There are, however, two other modes: floating and monocle. Floating mode should be familiar to users of non-tiling window managers; it allows users to rearrange windows as they please. Monocle mode will keep a single window visible at all times.<br />
<br />
To switch to floating mode, simply press {{Keypress|Mod1}} + {{Keypress|F}}. {{Keypress|Mod1}} is, by default, the {{Keypress|Alt}} key. To check if you are in floating mode, you should see something like this next to the numbered tags in the top right corner of the screen: X>.<br />
<br />
To switch to monocole mode, press {{Keypress|Mod1}} + {{Keypress|M}}. To check if you are in monocle mode, you can see an M in square brackets (if no windows are open on that tag) or a number in square brackets (which corresponds with the number of windows open on that tag). Thus, a tag with no windows open would display this: [M], and a tag with 'n' windows open would display this: [n].<br />
<br />
To return to tiled mode, press {{Keypress|Mod1}} + {{Keypress|T}}. You will see a symbol which looks like this: []= .<br />
<br />
===Exiting dwm===<br />
To cleanly exit dwm, press {{Keypress|Shift}} + {{Keypress|Mod1}} + {{Keypress|Q}}.<br />
<br />
Source: [http://dwm.suckless.org/tutorial dwm tutorial].<br />
<br />
==Extended usage==<br />
<br />
===Patches & additional tiling modes===<br />
The official website has a number of [http://dwm.suckless.org/patches/ patches] that can add extra functionality to dwm. Users can easily customize dwm by applying the modifications they like. The [http://dwm.suckless.org/patches/bottom_stack Bottom Stack] patch provides an additional tiling mode that splits the screen horizontally, as opposed to the default vertically oriented tiling mode. Similarly, bstack horizontal splits the tiles horizontally. <br />
<br />
The [http://dwm.suckless.org/patches/gapless_grid gaplessgrid patch] allows windows to be tiled like a grid.<br />
<br />
====Enable one layout per tag====<br />
The default behaviour of dwm is to apply the currently selected layout for all tags.To have different layouts for different tags use the [http://dwm.suckless.org/patches/pertag pertag] patch.<br />
<br />
===Fixing gaps around terminal windows===<br />
If there are empty gaps of desktop space outside terminal windows, it is likely due to the terminal's font size. Either adjust the size until finding the ideal scale that closes the gap, or toggle {{Ic|resizehints}} to ''False'' in {{ic|config.h}}:<br />
static Bool resizehints = False; /* False means respect size hints in tiled resizals */<br />
<br />
This will cause dwm to ignore resize requests from all client windows, not just terminals. The downside to this workaround is that some terminals may suffer redraw anomalies, such as ghost lines and premature line wraps, among others.<br />
<br />
====Urxvt====<br />
{{Out of date|layoutgaps.patch has been applied upstream in December 2011 and is no longer part of {{AUR|rxvt-unicode-patched}}. Solution below does not work for dwm-6.0 and rxvt-unicode-9.15. }}<br />
Another choice for [[urxvt]] users is applying the [[urxvt#Fix maximized window gaps|hints patch]] and regressing to dwm's original behaviour:<br />
static Bool resizehints = '''True''';<br />
<br />
===Restart dwm without logging out or closing programs===<br />
For restarting dwm without logging out or closing applications, change or add a startup script so that it loads dwm in a ''while'' loop, like this:<br />
<pre><br />
while true; do<br />
# Log stderror to a file <br />
dwm 2> ~/.dwm.log<br />
# No error logging<br />
#dwm >/dev/null 2>&1<br />
done<br />
</pre><br />
<br />
dwm can now be restarted without destroying other X windows by pressing the usual Mod-Shift-Q combination.<br />
<br />
It is a good idea to place the above startup script into a separate file, {{ic|~/bin/startdwm}} for instance, and execute it through {{ic|~/.xinitrc}}. From this point on, when desiring to actually end the X session simply execute {{Ic|killall startdwm}}, or bind it to a convenient key.<br />
<br />
===Make the right Alt key work as if it were Mod4 (Windows Key)===<br />
When using Mod4 (aka Super/Windows Key) as the {{Ic|MODKEY}}, it may be equally convenient to have the right Alt key (Alt_R) act as Mod4. This will allow performing otherwise awkward keystrokes one-handed, such as zooming with Alt_R+Enter. <br />
<br />
First, find out which keycode is assigned to Alt_R:<br />
xmodmap -pke | grep Alt_R<br />
<br />
Then simply add the following to the startup script (e.g. {{ic|~/.xinitrc}}), changing the keycode ''113'' if necessary to the result gathered by the previous {{Ic|xmodmap}} command:<br />
xmodmap -e "keycode 113 = Super_L" # reassign Alt_R to Super_L<br />
xmodmap -e "remove mod1 = Super_L" # make sure X keeps it out of the mod1 group<br />
<br />
Now, any functions that are triggered by a Super_L (Windows) key press will also be triggered by an Alt_R key press.<br />
===Disable focus follows mouse behaviour===<br />
To disable focus follows mouse behaviour comment out the following line in definiton of struct handler in dwm.c <br />
<pre>[EnterNotify] = enternotify, </pre><br />
Note that this change can cause some difficulties. After it the first click on inactive window will only bring the focus on it. To interact with window contents (buttons, fields etc) you need to click again. Also if you have several monitors you can notice that keyboard focus doesn't switch to another monitor activated by clicking.<br />
<br />
===Adding custom keybinds/shortcuts===<br />
Two entries are needed in {{ic|config.h}} to create custom keybinds. One under the "/* commands /*" section, and another under the "static Key keys[] = {" section.<br />
<br />
static const char *<keybindname>[] = { "<command>", "<flags>", "<arguments>", NULL };<br />
<br />
<keybindname> can be anything... <command> <-flags> and <arguments> can be anything but they have to be individually enclosed in "",<br />
<br />
{ MODKEY, XK_<key>, spawn, {.v = <keybindname> } },<br />
<br />
...would bind Mod+<key> to the command defined previously.<br />
<br />
{ MODKEY|ShiftMask, XK_<key>, spawn, {.v = <keybindname> } },<br />
<br />
...would bind Mod+Shift+<key> Use ControlMask for Ctrl key.<br />
<br />
Single keys such as Fn or multimedia keys have to be bound with the hex codes obtainable from the program "xev"<br />
<br />
{ 0, 0xff00, spawn, {.v = <keybindname> } },<br />
<br />
...would bind foo key 0xff00 to <keybindname><br />
<br />
===Fixing misbehaving Java applications===<br />
<br />
As of JRE 6u20, Java applications misbehave in dwm because it is not a known window manager to Java. This causes menus to close when the mouse is released, and other little issues. First, install wmname from the [community] repository:<br />
# pacman -S wmname<br />
<br />
Now all you have to do is use wmname to set a WM name that Java recognizes:<br />
$ wmname LG3D<br />
<br />
This is not permanent, so you may want to add this command to your .xinitrc.<br />
<br />
It is also possible to change enable {{ic|1=export _JAVA_AWT_WM_NONREPARENTING=1}} in {{ic|/etc/profile.d/jre.sh}}<br />
<br />
==See also==<br />
* [http://dwm.suckless.org/ dwm's official website]<br />
* [[dmenu]] - Simple application launcher from the developers of dwm<br />
* The [http://bbs.archlinux.org/viewtopic.php?id=57549/ dwm thread] on the forums<br />
* [http://bbs.archlinux.org/viewtopic.php?id=92895/ Hacking dwm thread]<br />
* Check out the forums' [http://bbs.archlinux.org/viewtopic.php?id=57768/ wallpaper thread] for a selection of dwm wallpapers<br />
*[https://bbs.archlinux.org/viewtopic.php?id=74599 Show off your dwm configuration forum thread]<br />
* [http://www.xsnake.net/howto/dwm/dwm-eng.php HowTo by Snake]<br />
* [http://0x80.org/blog/?p=72 Moved to dwm]</div>Riateche