Ubuntu 下使用 Compton 优化显示
一 基础准备与安装
sudo apt update && sudo apt install compton。echo $XDG_SESSION_TYPE(返回 x11 再继续)。ps -e | grep compton;如已运行,先停止旧进程再加载新配置。二 配置文件与关键参数
mkdir -p ~/.config && nano ~/.config/compton.conf。# 渲染与同步
backend = glx
vsync = true
# 特效开关(关掉最耗性能的项)
shadow = false
blur-background = false
opacity = false
# 刷新率与渲染质量(按显示器实际刷新率设置)
refresh-rate = 0 # 0 表示自动,若卡顿可固定为 60/120/144
# 排除不需要合成的窗口(示例:Dock、桌面)
shadow-exclude = [
"name = 'Plank'",
"class_g = 'Xfdesktop'"
]
focus-exclude = [
"class_g = 'Conky'"
]
# 日志与调试(排错时临时开启)
# log-level = debug
# log-file = /tmp/compton.log
vsync = false 并结合固定刷新率测试。三 启动与自启
compton --config ~/.config/compton.conf -f。killall compton && compton --config ~/.config/compton.conf &。/etc/systemd/system/compton.service[Unit]
Description=Compton Window Composer
After=xorg.service
[Service]
ExecStart=/usr/bin/compton --config /etc/compton.conf
Restart=on-failure
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload && sudo systemctl enable --now compton。killall compton && compton --config ~/.config/compton.conf & 或 sudo systemctl restart compton 使配置生效。四 性能调优与排错
$PID 的进程限制在 50%):cpulimit -l 50 -p $PID。log-level = debug 与 log-file 分析。五 场景化配置建议
backend = glx、vsync = true、shadow = false、blur-background = false、opacity = false、refresh-rate = 60/120(按显示器设置)。opacity = true,但继续使用 shadow = false,并将模糊范围控制在必要窗口;必要时只对特定应用启用透明度规则。shadow-exclude、focus-exclude 精确排除 Dock/桌面/常驻悬浮 窗口;对视频播放器或游戏窗口可单独设置规则以减少合成开销。