Herbstluftwm是一個使用 Xlib 的手動 X11 窗口管理器。
安裝
安裝 herbstluftwm包 包或 herbstluftwm-gitAUR (開發版本)。
啟動
從 TTY 啟動
用 xinit 啟動 herbstluftwm
。
作為桌面環境啟動
herbstluftwm包 包含可以啟動窗口管理器的 herbstluftwm.desktop
作為 Xsession。
從其他窗口管理器啟動
如果已經啟動了一個窗口管理器會話,可以用 herbstluftwm --replace
替換掉原窗口管理器。
第一步
閱讀 herbstluftwm(1) 和 herbstclient(1) 手冊頁,它們包含很多對配置選項和有效值的解釋。
配置
複製 /etc/xdg/herbstluftwm/autostart
到~/.config/herbstluftwm/autostart
。可以按需修改文件。 保證 autostart 文件可執行,否則鍵綁定極有可能失效!
Herbstluftwm 的配置可以用 herbstclient reload
即時更新 (見 #Commands)。每次 reload 配置時 Autostart 腳本都會被調用,所以它一般會先恢復所有配置到默認值。
多顯示器支持
Herbstluftwm 支持多個顯示器 as a virtual concept;Herbstluftwm 中,顯示器信息不必與 xrandr 報告的真實監視器配置相匹配。它帶來了很大的靈活性,讓用戶可以更好地控制顯示器的布置。可以使用 herbstclient detect_monitors
自動適應物理設置,或者通過手冊了解如何添加、移除、調整和移動顯示器。多監視器設置中的標記不為某個監視器 "擁有"。這意味著當一個監視器切換到另一個監視器中激活的標記時,兩個監視器將交換標記。
命令
Herbstclient 很強大,因為它能讓你通過命令行完全控制窗口管理器。
Herbstclient 的參數支持 Tab 補全。用 herbstclient list_commands
查看所有參數。
現在如果傳給 Herbstclient 的參數有誤,Herbstclient 不會列印錯誤信息,指揮以非零值退出。如果不通過其他方式顯示返回值(比如用$SHELL-prompt
),可能需要用 echo $?
列印返回值。
腳本和鉤子
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.
Herbstluftwm includes a number of example scripts: /usr/share/doc/herbstluftwm/examples/
or https://github.com/herbstluftwm/herbstluftwm/tree/master/scripts
Script to switch to the next empty tag
The following python 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.py, then
python3 herbst-move.py +1 full
will move you to the next full tag. I use the following key bindings.
hc keybind $Mod-Left spawn herbst-move.py -1 empty hc keybind $Mod-Right spawn herbst-move.py +1 empty hc keybind $Mod-Up spawn herbst-move.py -1 full hc keybind $Mod-Down spawn herbst-move.py +1 full
And here is the script.
#!/usr/bin/env python3 def run(*cmd): from subprocess import Popen, PIPE proc = Popen(cmd, shell=False, stderr=PIPE, stdout=PIPE) return proc.stdout.read() import sys tag_offset, mode = sys.argv[1:] tag_offset = int(tag_offset) if mode == 'full': ch = {'.'} elif mode == 'empty': ch = {':', '!'} else: raise Exception('Unknown type ' + mode) tag_list = run('herbstclient', 'tag_status', '0').strip().decode('ascii').split('\t') tag_curr = int(run('herbstclient', 'attr', 'tags.focus.index').strip()) tag_next = (tag_curr + tag_offset) % len(tag_list) while (tag_next != tag_curr) and (tag_list[tag_next][0] in ch): tag_next = (tag_next + tag_offset) % len(tag_list) if tag_next != tag_curr: run('herbstclient', 'use_index', str(tag_next))
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.
#!/usr/bin/ruby 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}" end
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).
#!/usr/bin/perl # 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", "$colors{$activity}"); } ## 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 OUTER: while (<HOOKS>) { chomp; 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
Troubleshooting
- After installing,
$mod+enter
keybind does not start a terminal: the herbstluftwm autostart configuration file uses the xterm terminal by default. Make sure xterm包 is installed or edit the autostart file to use a different terminal. - To log out of herbstluftwm, use the command
herbstclient quit
or the default keybind of$mod+shift-q
See also
- The herbstluftwm homepage
- Arch Linux BBS thread
-
/usr/share/doc/herbstluftwm/examples/
- various scripts -
/usr/share/doc/herbstluftwm/BUGS
- bugs - A herbstluftwm thread on the CrunchBang Forums
- Screenshots and configuration files: on Arch Linux Forum, on DotShare.it
-
#herbstluftwm
- IRC channel at irc.libera.chat - User git repository #1 with autostart written in Perl and a few custom scripts
- User git repository #2 with autostart and panel written in Python
- Github Discussions
- Herbstluftwm Subreddit