在 Ubuntu 上配置 Compton 实现平滑滚动
一 安装与准备
- 在终端执行以下命令安装 Compton:
- sudo apt update
- sudo apt install compton
- 确认正在使用 X11(Compton 主要面向 X11;若在 Wayland 会话中,请切换到 Xorg 会话再使用 Compton)。
- 验证图形驱动与 OpenGL 支持(需支持 OpenGL 才能启用相关加速):
- glxinfo | grep “OpenGL version”
二 配置 Compton 启用平滑滚动
- 创建或编辑配置文件:
- mkdir -p ~/.config
- nano ~/.config/compton.conf
- 写入以下示例配置(按需调整):
- backend = “glx” # 使用 GLX 后端以获得更好性能
- vsync = true # 开启垂直同步,减少撕裂
- enable-dri = true # 启用 DRI
- dri-drivers = [“glx”] # 指定 DRI 驱动
-
平滑滚动相关
- smooth-scrolling = true # 启用平滑滚动
- smooth-dnd = true # 启用拖拽时的平滑动画(可选)
- smooth-scrolling-distance = 10 # 滚动距离阈值(像素),可按需微调
- 保存并退出编辑器(nano 中按 Ctrl+X,然后 Y,回车)。
三 启动与开机自启动
- 手动启动以测试配置:
- compton --config ~/.config/compton.conf
- 设置开机自启动(会话级,推荐):
- 打开“启动应用程序”(Startup Applications),新增一项:
- 名称:Compton
- 命令:compton --config ~/.config/compton.conf
- 若需系统级自启(可选,非必须):
- 创建服务文件:sudo nano /etc/systemd/system/compton.service
- 写入示例内容:
- [Unit]
- Description=Compton Compositor
- After=display-manager.service
- [Service]
- ExecStart=/usr/bin/compton --config /home/你的用户名/.config/compton.conf
- Restart=on-failure
- [Install]
- WantedBy=multi-user.target
- 启用并启动:
- sudo systemctl daemon-reload
- sudo systemctl enable --now compton。
四 验证与常见问题排查
- 验证效果:
- 打开浏览器或文本编辑器,使用鼠标滚轮或触摸板滚动,观察是否呈现平滑过渡。
- 排查要点:
- 配置文件路径是否正确(应为 ~/.config/compton.conf)。
- 参数名是否拼写正确(例如使用 smooth-scrolling,而非 smooth_scrolling)。
- OpenGL 是否可用(运行 glxinfo | grep “OpenGL version” 检查)。
- 若未生效,先结束现有 Compton 进程后再启动,或改用日志方式定位问题:
- compton --log-file=/tmp/compton.log。