Difference between revisions of "Herbstluftwm"

From ArchWiki
Jump to: navigation, search
(See also)
Line 152: Line 152:
* '''Screenshots and configuration files:''' [https://bbs.archlinux.org/viewtopic.php?id=133557 on ArchLinux Forum], [http://dotshare.it/category/wms/herbstluft/ on DotShare.it]
* '''Screenshots and configuration files:''' [https://bbs.archlinux.org/viewtopic.php?id=133557 on ArchLinux Forum], [http://dotshare.it/category/wms/herbstluft/ on DotShare.it]
* {{ic|#herbstluftwm}} - IRC channel at the irc.freenode.net
* {{ic|#herbstluftwm}} - IRC channel at the irc.freenode.net
* [https://github.com/ypnos/hlwm Git repository of a hlwm user] with autostart written in Perl and a few custom scripts
* [https://github.com/ypnos/hlwm User git repository #1] with autostart written in Perl and a few custom scripts
* [https://github.com/ylixir/hlwm-config User git repository #2] with autostart and panel written in Python

Revision as of 11:46, 20 November 2014

Herbstluftwm is a manual tiling window manager for X11 using Xlib and Glib.


Herbstluftwm can be installed with the package herbstluftwm or the AUR package herbstluftwm-git.

First steps

Read carefully herbstluftwm and herbstclient man pages in your favorite terminal emulator or online (herbstluftwm, herbstclient). Take your time to read through the whole documentation, they contain a lot of information from an explanation of the binary tree in which the layout is kept to config file options and possible values.


Copy /etc/xdg/herbstluftwm/autostart file to $HOME/.config/herbstluftwm/autostart. You can edit that file for your needs. Make sure the autostart file is executable, else you'll probably end up without keybindings!

The configuration of herbstluftwm is updated on-the-fly by issuing herbstclient reload (See Commands section), or having a keybinding for the reload command. Autostart is called on each reload, therefore within autostart you typically unmap all existing configuration first.

Multi-Monitor Support

Herbstluftwm supports multiple monitors as a virtual concept; monitors in herbstluftwm do not have to match the real monitor configuration as reported by xrandr. It brings a lot of flexibility and gives the user more control over his/her monitor-arrangement. You can use herbstclient detect_monitors to automatically adapt to the physical setup. Otherwise, see the manpage on how to add, remove, resize and move monitors.


Herbstclient is a very powerful tool, as it provides you with full control over your window manager from the command line.

There is a tab-completion for the parameters for herbstclient. Try herbstclient list_commands to show all parameters.

Right now there's no error message if you use wrong parameters on a command, but only a non-zero return value. If you don't show the return value of a command anyway (e.g. in your $SHELL-prompt), you might want to echo $? to find the return value of the last command.

Scripts and Hooks

The main way to control herbstluftwm is though commands to herbstclient. Since herbstclient can be called from any script, you have great flexibility in controlling herbstluftwm this way. Furthermore, you can listen to window management events and react to them accordingly.

Script to switch to the next empty tag

The following ruby script allows you to switch to the (next or previous) (full or empty) tag. Call it with the arguments (+1 or -1) and (full or empty). For example, if you save the script to herbst-move.rb, then

ruby herbst-move.rb +1 full

will move you to the next full tag. I use the following key bindings.

hc keybind $Mod-Left  spawn ruby /home/carl/Ruby/herbst-move.rb -1 empty
hc keybind $Mod-Right spawn ruby /home/carl/herbst-move.rb +1 empty
hc keybind $Mod-Up spawn ruby /home/carl/Ruby/herbst-move.rb -1 full
hc keybind $Mod-Down spawn ruby /home/carl/Ruby/herbst-move.rb +1 full

And here is the script.


incr, type = ARGV

d = incr.to_i
if type == 'full'
  ch = '.'
  ch = ':'

array = `herbstclient tag_status 0`.scan(/[:\.\#][^\t]*/)
len = array.length
orig = array.find_index{|e| e[0] == '#'}

i = (orig+d) % len
  array[i][0] == ch
  i = (i+d) % len

if i != orig
  system "herbstclient use_index #{i}"

Script to cycle though paddings (or other settings)

Here is a ruby script to cycle through a set of paddings, although you can modify it to cycle though any collection of settings. The script knows the previous layout by looking for the presence of two dummy files in /tmp.


file1 = "/tmp/herbst-padding-1"
file2 = "/tmp/herbst-padding-2"

pad1 = 'pad 0 0 0 0 0'
pad2 = 'pad 0 0 20 0 200'
pad3 = 'pad 0 0 0 0 150'

files = [file1, file2].map{|f| File.exist? File.expand_path(f)}

if files == [false, false]  # 0 files
  system "herbstclient #{pad2}"
  system "touch #{file1}"
elsif files == [true, false]  # 1 file
  system "herbstclient #{pad1}"
  system "touch #{file2}"
else           # 2 files
  system "herbstclient #{pad3}"
  system "rm #{file1} #{file2}"

Script to change decoration per-tag

The following Perl script demonstrates how to use hooks to react to window management events. It can be called in autostart (with backgrounding).

# This script watches for tag changes and gives visual feedback

## Configuration (fill with your tag names)
my %colors = (
	main => '#DD0000',
	devel => '#13B8E0',
	write => '#96E013',
	admin => '#C713E0'

## Apply tag color
# Right now we change the active window's border color to the tag's color.
sub redecorate
	my ($foo, $activity) = @_;
	system("herbstclient", "set", "window_border_active_color",

## main routine
use v5.20;

# set up a pipe for reading hooks
open HOOKS, "herbstclient -i '(tag_changed|reload)'|"
	or die "can't fork: $!";
# process incoming messages
while (<HOOKS>) {
	for ($_) {
		redecorate(split(/\t/)) when /^tag_changed/;
		last OUTER when /^reload/; # quit on reload
close HOOKS or die "unfinished love story: $! $?"; # happens on hlwm crash

See also