在 Ubuntu 上使用 Compton 提升桌面体验
一 安装与快速启用
- 在 Ubuntu 上安装 Compton:
- sudo apt-get update
- sudo apt-get install compton
- 生成默认配置并启动:
- mkdir -p ~/.config && cp /etc/xdg/compton.conf ~/.config/compton.conf 2>/dev/null || nano ~/.config/compton.conf
- 重新加载:killall compton && compton --config ~/.config/compton.conf &
- 验证运行状态:pgrep -x compton,有输出即表示已在运行。
二 核心配置与性能优化
- 建议将配置文件 ~/.config/compton.conf 中的关键项按如下思路调整(示例为常用稳妥值):
- 渲染后端:backend = glx(若出现异常,可回退为 xrender)
- 垂直同步:vsync = true(减少撕裂;若出现卡顿或输入延迟,可尝试 false)
- 阴影:shadow = false(提升性能;需要美观可设为 true)
- 透明度:不使用全局 opacity 规则(避免额外合成开销),仅对特定窗口按需设置
- 背景模糊:bg_blur = false(性能优先时关闭;需要观感可开启)
- 应用与热重载:killall compton && compton --config ~/.config/compton.conf &
- 说明:Compton 通过合成窗口减少撕裂、提供阴影/透明度等效果;关闭高开销特效(如阴影、模糊)可显著降低 CPU/GPU 占用,backend 选择对性能影响最大。
三 开机自启与系统集成
- 会话级自启(推荐,适用于大多数桌面环境)
- 在“启动应用程序”中添加命令:compton --config ~/.config/compton.conf
- Systemd 用户级服务(可选,适合最小化环境或 i3/Sway 等)
- 创建文件:~/.config/systemd/user/compton.service
- 内容:
- [Unit]
- Description=Compton Window Composer
- After=graphical-session.target
- [Service]
- ExecStart=/usr/bin/compton --config %h/.config/compton.conf
- Restart=on-failure
- [Install]
- WantedBy=graphical-session.target
- 启用:
- systemctl --user daemon-reload
- systemctl --user enable --now compton.service
- 注意:若使用桌面自带的合成器(如部分 GNOME/KDE 会话),需先关闭其内置合成以避免冲突。
四 常见问题与进阶建议
- 画面撕裂或卡顿
- 优先开启 vsync(vsync = true);若仍不适,尝试切换 backend(glx/xrender)并关闭阴影/模糊;确保显卡驱动正确安装并启用 OpenGL 加速。
- 资源占用偏高
- 关闭不必要的特效(shadow、bg_blur、全局 opacity),减少窗口规则匹配数量;必要时用 cpulimit 限制进程:cpulimit -l 50 -p $(pgrep -x compton)。
- 兼容性与故障排查
- 出现异常时,先回退 backend 到 xrender,再逐项开启特效定位问题;使用 compton --config ~/.config/compton.conf -f 前台运行观察日志输出。