Compton 在 Ubuntu 中的使用教程

一 安装与准备
sudo apt update && sudo apt install comptonecho $XDG_SESSION_TYPE 应输出 x11。二 快速上手
mkdir -p ~/.config && nano ~/.config/compton.confbackend = "glx"vsync = trueshadow = trueshadow-opacity = 0.3fade = truefade-delta = 30compton --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=ApplicationExec=compton --config ~/.config/compton.conf -bHidden=falseNoDisplay=falseX-GNOME-Autostart-enabled=trueName=Comptonmkdir -p ~/.config/systemd/user/ && nano ~/.config/systemd/user/compton.service[Unit]Description=Compton Window ComposerAfter=graphical-session.target[Service]Type=simpleExecStart=/usr/bin/compton --config %h/.config/compton.conf -bRestart=alwaysRestartSec=5[Install]WantedBy=default.targetsystemctl --user daemon-reloadsystemctl --user enable --now compton.servicesudo nano /etc/systemd/system/compton.service[Unit]Description=Compton Window ComposerAfter=display-manager.service[Service]Type=simpleExecStart=/usr/bin/compton --config /etc/xdg/compton.conf -bRestart=always[Install]WantedBy=multi-user.targetsudo systemctl daemon-reloadsudo 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 = trueshadow = trueshadow-opacity = 0.3fade = truefade-delta = 30ignore_root = true[blur]method = gaussiansize = 10deviation = 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)