Linux Compton 配置中主题切换
核心思路 Compton 的“主题”本质上是不同的配置文件(如:~/.config/compton.conf、~/.config/compton-dark.conf、~/.config/compton-light.conf)。切换主题就是在这些配置之间替换,并让 Compton 重新加载。Compton 本身并不直接管理 GTK/图标等桌面主题,这类外观通常由 GTK 主题、图标主题等工具控制,可与 Compton 配置配合实现整体风格统一。
准备多个主题配置
backend = "glx"
vsync = "opengl-swc"
shadow = true
shadow-radius = 12
shadow-offset-x = -15
shadow-offset-y = -15
shadow-opacity = 0.5
blur-background = true
blur-kern = "3x3box"
inactive-opacity = 0.9
active-opacity = 1.0
backend = "glx"
vsync = "opengl-swc"
shadow = true
shadow-radius = 8
shadow-opacity = 0.4
blur-background = false
inactive-opacity = 0.95
active-opacity = 1.0
切换主题的方法
pkill compton
compton --config ~/.config/compton-dark.conf -b
sudo systemctl restart compton(前提是服务按单一配置启动)。export COMPTON_CONFIG=~/.config/compton-dark.conf
compton --config "$COMPTON_CONFIG" -b
[Unit]
Description=Compton Compositor
After=graphical-session.target
[Service]
ExecStart=/usr/bin/compton --config /home/你的用户名/.config/compton-dark.conf -b
Restart=always
[Install]
WantedBy=default.target
systemctl --user daemon-reload
systemctl --user enable --now compton.service
# 切换到亮色主题:更新服务文件中的 --config 路径后
systemctl --user restart compton.service
实用建议
#!/usr/bin/env bash
THEME="$1"
case "$THEME" in
dark)
CFG="$HOME/.config/compton-dark.conf"
;;
light)
CFG="$HOME/.config/compton-light.conf"
;;
*)
echo "Usage: $0 {dark|light}"
exit 1
;;
esac
pkill compton
compton --config "$CFG" -b
保存为 /usr/local/bin/switch-compton,赋予可执行权限后执行:switch-compton dark 或 switch-compton light。pkill compton && compton ... -b 重载,确认无误再写入自启动或 systemd。