温馨提示×

Ubuntu Compton与多显示器设置

小樊
34
2025-12-20 07:23:04
栏目: 智能运维

Ubuntu 下使用 Compton 配置多显示器

核心要点

  • ComptonX11 的窗口合成器,负责阴影、透明度、淡入淡出等视觉效果;它不直接管理显示器的连接、分辨率与相对位置,这些应由 xrandr 或桌面环境设置完成。多显示器场景下,先用 xrandr 正确布局,再启动 Compton 即可稳定工作。若使用 Wayland,Compton 不适用(Wayland 使用自身的合成机制)。

快速上手步骤

  1. 安装 Compton
    • 在基于 Debian/Ubuntu 的系统上:
      sudo apt update && sudo apt install compton
  2. 用 xrandr 配置多显示器
    • 查看输出名称:
      xrandr --query
    • 示例(扩展模式):
      xrandr --output HDMI-1 --auto --right-of eDP-1
      xrandr --output DP-1 --auto --right-of HDMI-1
  3. 创建基础配置文件
    • 建议路径:~/.config/compton.conf
    • 示例(启用 OpenGL 加速与帧率限制):
      backend = “glx”
      fps-limit = 60
      shadow-exclude = [ “class_g = ‘gnome-terminal’”, “class_g = ‘konsole’”, “class_g = ‘xterm’” ]
  4. 手动测试
    • compton -c ~/.config/compton.conf
  5. 设置开机自启动(用户级 systemd 服务)
    • 新建:~/.config/systemd/user/compton.service
      [Unit]
      Description=Compton Compositor
      After=graphical-session.target
      [Service]
      ExecStart=/usr/bin/compton -c %h/.config/compton.conf
      Restart=always
      [Install]
      WantedBy=graphical-session.target
    • 启用:
      systemctl --user daemon-reload
      systemctl --user enable --now compton.service
      以上流程涵盖安装、用 xrandr 完成多屏布局、创建 Compton 配置并测试与自启动,适用于 Ubuntu 等常见环境。

多显示器优化与常见问题

  • 性能与同步
    • 使用 backend = “glx” 获取更好的硬件加速;将 fps-limit 设为与显示器刷新率一致(如 60),必要时开启 glx-vsync 减少撕裂(若出现卡顿可先关闭测试)。
  • 阴影与特定应用
    • 多屏下阴影计算开销更高,建议对不需要阴影的应用进行排除,例如终端与部分工具类应用:
      shadow-exclude = [ “class_g = ‘gnome-terminal’”, “class_g = ‘konsole’”, “class_g = ‘xterm’” ]
  • 多 DPI 与缩放
    • Compton 不负责缩放;请在系统“设置 → 显示器”或 xrandr 中分别为各输出设置 scale/分辨率,然后再启动 Compton。
  • 故障排查
    • 先确认正在使用 Xorg(echo $XDG_SESSION_TYPE),再检查 Compton 是否运行(systemctl --user status compton),必要时用 compton --config ~/.config/compton.conf --log-level debug 查看日志并逐项回退最近改动。

0