在 Linux 上写 Compton(或已演变为 picom) 脚本,通常用于开机自启、热重载配置、不同场景切换配置等。下面从基础脚本、自启脚本、管理脚本、示例配置一步步说明。
很多发行版已用 picom(compton 的 fork):
which compton
which picom
picom → 用 picomcompton → 用 compton下面以 picom 为例(compton 完全类似)
start-compton.sh#!/bin/bash
# 杀掉已有进程
pkill -x picom
# 启动 picom
picom --config ~/.config/picom/picom.conf -b
赋予执行权限:
chmod +x start-compton.sh
方便排查问题:
#!/bin/bash
pkill -x picom
picom \
--config ~/.config/picom/picom.conf \
--log-level info \
--log-file ~/.cache/picom.log \
-b
例如:
~/.config/picom/
├── picom.conf
├── perf.conf
└── blur.conf
compton-switch.sh#!/bin/bash
case "$1" in
blur)
pkill -x picom
picom --config ~/.config/picom/blur.conf -b
;;
perf)
pkill -x picom
picom --config ~/.config/picom/perf.conf -b
;;
*)
echo "Usage: $0 {blur|perf}"
;;
esac
使用:
./compton-switch.sh blur
./compton-switch.sh perf
在 ~/.config/i3/config 或 ~/.xinitrc:
exec ~/.local/bin/start-compton.sh
或:
picom --config ~/.config/picom/picom.conf -b
~/.config/systemd/user/picom.service
[Unit]
Description=picom compositor
After=graphical-session.target
[Service]
ExecStart=/usr/bin/picom --config %h/.config/picom/picom.conf
Restart=on-failure
[Install]
WantedBy=default.target
启用:
systemctl --user enable --now picom
picom 支持 SIGUSR1 重载:
pkill -USR1 picom
可写成脚本:
#!/bin/bash
pkill -USR1 picom
~/.config/picom/picom.conf
backend = "glx";
vsync = true;
shadow = true;
shadow-radius = 12;
shadow-opacity = 0.4;
blur:
{
method = "gaussian";
size = 10;
};
fading = true;
fade-in-step = 0.03;
fade-out-step = 0.03;
unredir-if-possible = true;
#!/bin/bash
pkill -x picom
picom --config ~/.config/picom/picom.conf --diagnostics
或直接前台运行看输出:
picom --config ~/.config/picom/picom.conf
Compton 脚本 = 杀进程 + 指定配置 + 后台运行
如果你愿意,可以告诉我:
我可以直接帮你写一份可用的完整脚本 + 配置。