bspwm
bspwm 是一個平鋪窗口管理器,每一個窗口被表達為滿二叉樹的葉子。bspwm支持多顯示器,可通過messages進行配置和控制。bspwm部分支持EWMH。
安裝[編輯 | 編輯原始碼]
安裝 bspwm包 或 bspwm-gitAUR (開發版本)。
啟動[編輯 | 編輯原始碼]
使用 xinit 來啟動 bspwm
。
配置[編輯 | 編輯原始碼]
示例配置文件位於 /usr/share/doc/bspwm/examples/
。
複製或安裝 bspwmrc
和 sxhkdrc
分別到 ~/.config/bspwm/
和 ~/.config/sxhkd/
。
文件 bspwmrc
必須是可執行的,因為默認示例是一個shell腳本,此腳本隨後通過 bspc
命令配置bspwm。
$ install -Dm755 /usr/share/doc/bspwm/examples/bspwmrc ~/.config/bspwm/bspwmrc $ install -Dm644 /usr/share/doc/bspwm/examples/sxhkdrc ~/.config/sxhkd/sxhkdrc
這兩個文件會分別被用來設置窗口管理器和按鍵綁定。
查看 bspwm(1) 和 sxhkd(1) 手冊獲取詳細信息。
設置多顯示器[編輯 | 編輯原始碼]
以下示例配置將會配置10個桌面在單獨的顯示器上:
bspc monitor -d I II III IV V VI VII VIII IX X
如果使用多顯示器,則需要為每一個顯示器配置:
bspc monitor DVI-I-1 -d I II III IV bspc monitor DVI-I-2 -d V VI VII bspc monitor DP-1 -d VIII IX X
使用 xrandr -q
或 bspc query -M --names
命令來查看顯示器編號。
在上面的示例中,桌面的總數保持在10個,在 sxhkdrc 中,這樣每一個桌面仍然可以使用 super + {1-9,0}
來定位。
規則(rules)[編輯 | 編輯原始碼]
有兩種方法來設置窗口規則 (截至 cd97a32)
第一種是通過使用內置的 rule 命令,如示例 bspwmrc 所示:
bspc rule -a Gimp desktop=^8 follow=on state=floating bspc rule -a Chromium desktop=^2 bspc rule -a mplayer2 state=floating bspc rule -a Kupfer.py focus=on bspc rule -a Screenkey manage=off
第二種是使用外部的 rule 命令。雖然更加複雜,但是這允許你去構造更複雜的桌面規則。參考 these examples 獲取示例 rule 命令。
如果某個特定的窗口似乎沒有按照你的規則運行,請檢查程序的類名。可以通過運行 xprop | grep WM_CLASS
來確保你在使用正確的字符串,這需要 xorg-xprop包 軟件包。
面板(Panels)[編輯 | 編輯原始碼]
使用lemonbar[編輯 | 編輯原始碼]
在lemonbar的Github頁面提供了一個 lemonbar-gitAUR 的示例面板。你也可從 lemonbar 的維基頁面得到了些許啟發。面板將通過 bspwmrc 中的 panel &
啟動。檢查在 bspwm包 軟件包中的 optdepends,以獲取可能需要的依賴。
為了在你的狀態欄(status bar)中顯示系統信息,你可以使用各種系統調用(system calls)。示例將會展示給你如何編輯你的 panel
來使音量狀態顯示在你的狀態欄中:
panel_volume() { volStatus=$(amixer get Master | tail -n 1 | cut -d '[' -f 4 | sed 's/].*//g') volLevel=$(amixer get Master | tail -n 1 | cut -d '[' -f 2 | sed 's/%.*//g') # is alsa muted or not muted? if [ "$volStatus" == "on" ] then echo "%{Fyellowgreen} $volLevel %{F-}" else # If it is muted, make the font red echo "%{Findianred} $volLevel %{F-}" fi }
之後,我們必須確保它已被調用並且重定向至 $PANEL_FIFO
:
while true; do echo "S" "$(panel_volume) $(panel_clock)" > "$PANEL_FIFO" sleep 1s done &
使用yabar[編輯 | 編輯原始碼]
使用lemonbar示例面板需要你配置你的環境(.profile),並確保面板腳本在你的路徑上。yabarAUR 是更易配置的面板,只有一個配置文件。
使用polybar[編輯 | 編輯原始碼]
通過在你的配置文件中添加 polybar example &
來使用 Polybar,其中的 example
就是狀態欄的名稱。
暫存器/便箋(Scratchpad)[編輯 | 編輯原始碼]
使用pid[編輯 | 編輯原始碼]
你可以使用 bspwm 的窗口標籤來模仿下拉式終端(例如 i3wm 的便箋功能)。將下面的內容附加到 bspwm 的配置文件末尾(適用於你自己的終端):
bspc rule -a scratchpad sticky=on state=floating hidden=on # check scratchpad already running [ "$(ps -x | grep -c 'scratchpad')" -eq "1" ] && st -c scratchpad -e ~/bin/scratch &
sticky
標籤可確保窗口總是出現在當前的桌面上。
~/bin/scratch
是:
#!/usr/bin/sh # only add floating scratchpad window node id to /tmp/scratchid bspc query -N -n .floating | xargs -i sh -c 'bspc query --node {} -T | grep -q scratchpad && echo {} > /tmp/scratchid' exec $SHELL
切換 Scratchpad 的熱鍵應該綁定到:
id=$(cat /tmp/scratchid);\ bspc node $id --flag hidden;bspc node -f $id
使用類名(class name)[編輯 | 編輯原始碼]
在此示例中我們將使用帶有自定義類名的 termite 作為我們的下拉式終端。當然其類名沒有必要必須是 termite。
首先在你的路徑中創建一個有如下內容的文件並確保其可執行。在此示例中我們命其名為 scratchpad.sh
:
#!/usr/bin/bash if [ -z $1 ]; then echo "Usage: $0 <name of hidden scratchpad window>" exit 1 fi pids=$(xdotool search --class ${1}) for pid in $pids; do echo "Toggle $pid" bspc node $pid --flag hidden -f done
隨後添加這個到你的 bspwm 配置中。
... bspc rule -a dropdown sticky=on state=floating hidden=on termite --class dropdown -e "zsh -i" & ...
為了切換窗口,一個在 sxhkd 中的自定義規則是必不可少的。給定自定義類名作為參數。
super + u scratchpad.sh dropdown
其他[編輯 | 編輯原始碼]
對於無需預定義規則就可使用任何窗口類型的Scratchpad,參閱:[1]
有關支持更多開箱即用的終端,並具有用於執行諸如選擇性啟動tmuxinator / tmux會話,即時將任何窗口變成便箋本以及自動調整便箋本大小以適合當前顯示器的標誌的更複雜的便箋本腳本,參閱 tdrop-gitAUR 。
不同設備的顯示器配置[編輯 | 編輯原始碼]
因為 bspwmrc
是一個shell腳本,這允許你做類似如下的操作:
#! /bin/sh if [[ $(hostname) == 'myhost' ]]; then bspc monitor eDP1 -d I II III IV V VI VII VIII IX X elif [[ $(hostname) == 'otherhost' ]]; then bspc monitor VGA-0 -d I II III IV V bspc monitor VGA-1 -d VI VII VIII IX X elif [[ $(hostname) == 'yetanotherhost' ]]; then bspc monitor DVI-I-3 -d VI VII VIII IX X bspc monitor DVI-I-2 -d I II III IV V fi
設置某一桌面的所有窗口均為浮動模式[編輯 | 編輯原始碼]
下面的示例會將 3 號桌面的所有窗口均設置為浮動窗口。當使用 GIMP 或其他多窗口的應用程式時非常有用。
把這個腳本放到你的 $PATH
的某個位置並從 .xinitrc
或類似的(最後帶有 &
)調用:
#!/bin/bash # change the desktop number here FLOATING_DESKTOP_ID=$(bspc query -D -d '^3') bspc subscribe node_add | while read -a msg ; do desk_id=${msg[2]} wid=${msg[4]} [ "$FLOATING_DESKTOP_ID" = "$desk_id" ] && bspc node "$wid" -t floating done
(源)
鍵盤[編輯 | 編輯原始碼]
bspwm 不會處理任何鍵盤輸入而是提供 bspc 程序作為接口。
你必須為快捷鍵設置一個守護程序例如 sxhkd包 (開發版本:sxhkd-gitAUR)
故障排除[編輯 | 編輯原始碼]
屏幕空白,按鍵綁定不可用[編輯 | 編輯原始碼]
- 確保 sxhkd包 已被安裝。
- 確保 sxhkd 正在運行。
- 確保
~/.config/bspwm/bspwmrc
為可執行文件。
鼠標指針主題沒有應用到桌面[編輯 | 編輯原始碼]
參閱 Cursor themes#Change X shaped default cursor
窗口大於實際運行的應用程式[編輯 | 編輯原始碼]
若你正在使用GTK3應用程式並且經常用於對話窗口,那麼這種情況就會發生。修複方法是創建或添加以下內容到GTK3主題文件(~/.config/gtk-3.0/gtk.css
)。
.window-frame, .window-frame:backdrop { box-shadow: 0 0 0 black; border-style: none; margin: 0; border-radius: 0; } .titlebar { border-radius: 0; }
(源: Bspwm forum thread)
Java程序的問題[編輯 | 編輯原始碼]
如果你有例如Java程序窗口無法調整大小,或菜單在點擊後立即關閉的問題,參閱Java#Gray window, applications not resizing with WM, menus immediately closing。
此外,一些基於Java的應用程式顯示不出任何窗口內容(例如 Intellij的IDE)。一個解決辦法是安裝 wmname包 軟件包並且添加以下內容到你的 ~/.config/bspwm/bspwmrc
:
wmname LG3D
fish shell的按鍵綁定問題[編輯 | 編輯原始碼]
如果你正在使用 fish ,你會發現你不能切換桌面。這是因為 bspc 的 ^ 字符與 fish 不兼容。你可通過明確告訴 sxhkd 使用 bash 執行命令來解決問題。
$ set -U SXHKD_SHELL /usr/bin/bash
或者,將 ^ 字符在你的 sxhkdrc 中用反斜線(\)轉義。
使用fish shell的性能問題[編輯 | 編輯原始碼]
sxhkd 使用 SHELL 環境變量中的 shell 來執行命令。由於配置文件很大或配置不當,fish 的加載時間可能很長,因此所有 sxhkd 命令的執行時間可能比其他的shell都長。為了在不改變你的默認 shell 情況下修復這個問題,你可以明確地告訴 sxhkd 使用 bash 或其他更快的 shell 來執行命令 (比如sh):
$ set -U SXHKD_SHELL sh
啟動時報 "Could not grab key 43 with modfield 68" 錯誤[編輯 | 編輯原始碼]
要麼你嘗試綁定同一個鍵兩次,要麼你啟動了兩次 sxhkd ,檢查 bspwmrc 和 ~/.profile
或 ~/.bash_profile
,查看是否在啟動 sxhkd 時有多餘的命令。
火狐瀏覽器(Firefox)菜單在右鍵單擊時自動選擇第一選項[編輯 | 編輯原始碼]
添加以下內容到 userChrome.css
Firefox配置文件:
#contentAreaContextMenu{ margin: 5px 0 0 5px }
文件應位於 ~/.mozilla/firefox/something.default/chrome/
(如果沒有,就創建一個)。在Firefox中,你必須到 about:config
頁面開啟 toolkit.legacyUserProfileCustomizations.stylesheets
選項;否則,Firefox會忽略 userChrome.css 文件。
參照[編輯 | 編輯原始碼]
- Mailing List: bspwm at librelist.com.
#bspwm
- IRC channel at irc.libera.chat- https://bbs.archlinux.org/viewtopic.php?id=149444 - Arch BBS thread
- https://github.com/baskerville/bspwm - GitHub project
- https://github.com/windelicato/dotfiles/wiki/bspwm-for-dummies - earsplit's "bspwm for dummies"