i3wm是Linux下的一款窗口管理器(Windowns Manager), 通常简称为i3。 本文档基于Archlinux(其它发行版大同小异), 简单介绍了i3的常用软件与配置。

安装

sudo pacman -S i3-wm polybar rofi feh picom
yay i3lock-fancy-rapid
序号软件功能
01i3-wmi3-wm本体
02polybar状态栏,i3-bar的替代者
03rofi启动菜单,dmenu的替代者
04feh设置桌面壁纸
05picom透明支持
06i3lock-fancy-rapid锁屏,i3lock的升级版,支持背景虚化

配置

配置polybar

  1. 生成polybar配置文件
mkdir ~/.config/polybar

cp /usr/share/doc/polybar/examples/config.ini ~/.config/polybar/config
# cp /etc/polybar/config.ini ~/.config/polybar/config
  1. 编辑polybar配置文件
vim ~/.config/polybar/config 
------------------------------------------
[bar/example]
...
radius = 0
border-size = 0pt
modules-left = xworkspaces xwindow
modules-right = memory cpu battery wlan eth date
tray-position = right
...

[module/battery]
type = internal/battery
full-at = 98
battery = BAT0
adapter = ADP1
label-charging = %{F#F0C674}充电中%{F-} %percentage%%
label-discharging = %{F#F0C674}放电中%{F-} %percentage%%
label-full = %{F#F0C674}满电量%{F-} %percentage%%
label-low = %{F#F0C674}低电量%{F-} %percentage%%

[network-base]
type = internal/network
interval = 5
format-connected = <label-connected>
format-disconnected = <label-disconnected>

[module/wlan]
inherit = network-base
interface-type = wireless
label-connected = %{F#F0C674}无线%{F-} %essid% %local_ip%
label-disconnected = %{F#F0C674}无线%{F#707880} 未连接

[module/eth]
inherit = network-base
interface-type = wired
label-connected = %{F#F0C674}有线%{F-} %local_ip%
label-disconnected = %{F#F0C674}有线%{F#707880} 未连接
...
------------------------------------------
  1. 新建polybar启动文件
vim ~/.config/polybar/launch.sh
killall -q polybar
while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done
polybar example
chmod +x launch.sh
  1. 启用polybar(参见配置i3
vim ~/.config/i3/config
exec --no-startup-id ~/.config/polybar/launch.sh

配置rofi

  1. 拷贝主题文件
mkdir ~/.config/rofi
cp -r /usr/share/rofi/themes ~/.config/rofi
  1. 预览主题
rofi-theme-selector
  1. 修改rofi配置
rofi -dump-config > ~/.config/rofi/config.rasi
vim ~/.config/rofi/config.rasi
------------------------------------------
configuration {
    ...
    modi: "window,run,ssh,drun";
    show-icons: true;
    ...
}
....
------------------------------------------
  1. 启用rofi(参见配置i3
vim ~/.config/i3/config
## 绑定rofi:drun
bindsym --release $mod+space exec --no-startup-id rofi -show drun -theme ~/.config/rofi/themes/arthur.rasi
## 绑定rofi:window
bindsym $mod+Tab exec --no-startup-id rofi -show window -theme ~/.config/rofi/themes/arthur.rasi # sidebar

配置关停脚本

详情请参考ArchLinux Wiki

vim ~/.config/i3/i3exit.sh
------------------------------------------
#!/bin/sh
lock() {
    i3lock-fancy-rapid 5 3
}

case "$1" in
    lock)
        lock
        ;;
    logout)
        i3-msg exit
        ;;
    suspend)
        lock && systemctl suspend
        ;;
    hibernate)
        lock && systemctl hibernate
        ;;
    reboot)
        systemctl reboot
        ;;
    shutdown)
        systemctl poweroff
        ;;
    *)
        echo "Usage: $0 {lock|logout|suspend|hibernate|reboot|shutdown}"
        exit 2
esac

exit 0

------------------------------------------
chmod +x ~/.config/i3/i3exit.sh

配置i3

vim ~/.config/i3/config
------------------------------------------
## 将mod设置为Alt键
set $mod Mod1

## 设置标题字体
font pango:monospace 10

# 关闭当前窗口(注释原有映射,与Mac保持一致)
#bindsym $mod+Shift+q kill
bindsym $mod+q kill

## 关闭底部常驻的i3bar(注释掉bar)
#bar {
#        status_command i3status
#}

## 设置窗口边框等等
new_window none
new_float normal
hide_edge_borders both
## 设置窗口间距
gaps inner 0
gaps outer 0

## 启动polybar
exec --no-startup-id ~/.config/polybar/launch.sh
## 设置背景图片
exec --no-startup-id feh --bg-fill ~/Pictures/156274745324.jpg
## 设置透明
exec --no-startup-id picom -b
## 启动中文输入法支持
exec --no-startup-id fcitx 
## Deepin系应用前置处理
exec --no-startup-id /usr/lib/gsd-xsettings &
## 将显示器DP2设置为主屏
exec --no-startup-id xrandr --output DP2 --primary

## 给应用程序添加默认启动到的窗口(使用xprop获取class)
assign [class="Xfce4-terminal"] 1
assign [class="firefox"] 2
assign [class="Chromium"] 2
assign [class="Chrome"] 2
assign [class="Microsoft-edge"] 2
assign [class="Code"] 3
assign [class="jetbrains"] 3
assign [class="RedisInsight"] 3
assign [class="Wireshark"] 3
assign [class="thunderbird"] 4
assign [class="dingtalk"] 4
assign [class="QQ"] 4
assign [class="Remmina"] 5
assign [class="VirtualBox"] 5
assign [class="Thunar"] 6
assign [class="Typora"] 6
assign [class="obsidian"] 6
assign [class="KeePassXC"] 6
assign [class="wpsoffice"] 6

## 启动对应窗口的常用应用
exec --no-startup-id xfce4-terminal
exec --no-startup-id firefox
exec --no-startup-id code
exec --no-startup-id thunderbird
exec --no-startup-id dingtalk
# exec --no-startup-id remmina
exec --no-startup-id virtualbox
exec --no-startup-id flameshot
exec --no-startup-id obsidian
exec --no-startup-id keepassxc

## 绑定rofi:drun
bindsym --release $mod+space exec --no-startup-id rofi -show drun -theme ~/.config/rofi/themes/custom-arthur.rasi # 在arthur.rasi的基础上将font的大小修改为14
## 绑定rofi:window
bindsym $mod+Tab exec --no-startup-id rofi -show window -theme ~/.config/rofi/themes/custom-arthur.rasi
## 绑定便签本:把当前窗口设为便笺本
bindsym $mod+Shift+minus move scratchpad
## 绑定便签本:呼出第一个便笺本
bindsym $mod+minus scratchpad show 
## 绑定锁屏功能
bindsym Mod4+l exec --no-startup-id ~/.config/i3/i3exit.sh lock
## 绑定截图
bindsym control+Mod1+a exec --no-startup-id flameshot gui

# 默认布局
workspace_layout tabbed
# 标题栏对齐方式
title_align center
------------------------------------------