Compton 在 Ubuntu 中的使用教程
一 安装与准备
sudo apt update && sudo apt install comptonecho $XDG_SESSION_TYPE 应输出 x11。二 快速上手
mkdir -p ~/.config && nano ~/.config/compton.confbackend = "glx"
vsync = true
shadow = true
shadow-opacity = 0.3
fade = true
fade-delta = 30
compton --config ~/.config/compton.confcompton --config ~/.config/compton.conf -bkillall compton && compton --config ~/.config/compton.conf -b三 开机自启动
gnome-session-properties),添加命令:compton --config ~/.config/compton.conf -b~/.config/autostart/compton.desktop[Desktop Entry]
Type=Application
Exec=compton --config ~/.config/compton.conf -b
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=Compton
mkdir -p ~/.config/systemd/user/ && nano ~/.config/systemd/user/compton.service[Unit]
Description=Compton Window Composer
After=graphical-session.target
[Service]
Type=simple
ExecStart=/usr/bin/compton --config %h/.config/compton.conf -b
Restart=always
RestartSec=5
[Install]
WantedBy=default.target
systemctl --user daemon-reload
systemctl --user enable --now compton.service
sudo nano /etc/systemd/system/compton.service[Unit]
Description=Compton Window Composer
After=display-manager.service
[Service]
Type=simple
ExecStart=/usr/bin/compton --config /etc/xdg/compton.conf -b
Restart=always
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now compton.service
四 常用配置与示例
~/.config/compton.conf 或 /etc/xdg/compton.conf[blur]、[opacity-rule])backend:渲染后端,常用 glx(OpenGL,性能更好)或 xrender(兼容性更好)vsync:垂直同步,true/falseshadow:窗口阴影,true/falseshadow-opacity:阴影不透明度(如 0.3)fade / fade-delta:窗口切换淡入淡出与步进(如 30 ms)opacity / alpha:窗口透明度(0.0–1.0)ignore_root:忽略根窗口透明度(部分桌面环境需要设为 true)backend = "glx"
vsync = true
shadow = true
shadow-opacity = 0.3
fade = true
fade-delta = 30
ignore_root = true
[blur]
method = gaussian
size = 10
deviation = 5.0
[opacity-rule]
90:class_g 'Firefox'
95:name 'Terminal'
100:class_g 'Xephyr'
compton --config ~/.config/compton.conf --backend glx --vsync true --shadow-radius 5五 常见问题与优化
backend = "glx";如遇到撕裂,开启 vsync = true;若显卡驱动较旧或出现异常,可尝试 xrender。shadow-exclude = ["class_g 'Firefox'"]killall compton && compton --config ~/.config/compton.conf -bcpulimit -l 50 -p $(pgrep compton)