温馨提示×

centos系统中compton配置步骤

小樊
42
2025-12-23 15:11:42
栏目: 智能运维

CentOS 系统中 Compton 配置步骤

一 环境准备与安装

  • 确认会话类型:Compton 是 X11 的合成器,不适用于 Wayland。如使用 Wayland,请改用相应桌面合成方案(如 Mutter/KWin/Wayland 原生合成)。
  • 更新系统并安装:
    • CentOS 7:
      • 安装 EPEL(若未安装):sudo yum install -y epel-release
      • 安装 Compton:sudo yum install -y compton
    • CentOS Stream 8/9:
      • 安装 Compton:sudo dnf install -y compton
  • 验证安装:compton --version。

二 创建配置文件

  • 配置文件路径:优先使用用户级配置 ~/.config/compton.conf;也可使用系统级 /etc/xdg/compton.conf
  • 生成基础配置(示例为稳定可用的起步配置,可按需增删):
    • 创建目录与文件:mkdir -p ~/.config && nano ~/.config/compton.conf
    • 写入示例:
      # 渲染后端:优先 glx(需驱动支持);xrender 为备选
      backend = "glx"
      
      # 同步与帧率
      vsync = "true"
      fps = 60
      
      # 阴影
      shadow = true
      shadow-radius = 12
      shadow-offset-x = 0
      shadow-offset-y = 8
      shadow-exclude = [
        "name = 'Conky'",
        "class_g = 'Polybar'",
        "class_g = 'Trayer'"
      ]
      
      # 透明度与忽略规则
      opacity-rule = [
        "90:class_g 'Firefox'",
        "90:class_g 'Terminal'",
        "100:class_g 'Xephyr'"
      ]
      
      # 背景模糊(可选,性能开销较大)
      # bg_blur = true
      # screen_edge_blur = true
      
      # 其他稳定性项
      glx-no-stencil = true
      glx-copy-from-front = false
      
  • 说明:上述关键项包括 backend、vsync、shadow、opacity-rule 等,均为常见且通用的起点配置。

三 启动与自启动

  • 手动前台启动(便于调试):compton -c ~/.config/compton.conf
  • 手动后台启动:compton --daemon --config ~/.config/compton.conf(或使用 -b 参数)
  • 配置 systemd 用户服务(推荐,登录会话自动启动):
    1. 创建服务文件:nano ~/.config/systemd/user/compton.service
    2. 写入内容(注意替换用户名与配置路径):
      [Unit]
      Description=Compton Window Composer
      After=graphical-session.target
      
      [Service]
      Type=simple
      ExecStart=/usr/bin/compton -c /home/你的用户名/.config/compton.conf
      Restart=on-failure
      Environment=DISPLAY=:0
      
      [Install]
      WantedBy=default.target
      
    3. 启用并启动:
      • systemctl --user daemon-reload
      • systemctl --user enable --now compton.service
  • 若使用系统级服务(全系统启动即运行,较少用):创建 /etc/systemd/system/compton.service,在服务段设置 User=你的用户名 与正确 ExecStart,然后执行:
    • sudo systemctl daemon-reload
    • sudo systemctl enable --now compton.service
  • 验证:
    • 查看状态:systemctl --user status compton.service(或 systemctl status compton.service)
    • 查看日志:journalctl --user -u compton.service -b(或 journalctl -u compton.service -b)

四 多显示器与常见问题

  • 多显示器:先通过 xrandr --query 确认输出名,再用 xrandr 设置扩展/排列;Compton 会随 X11 自动处理多屏合成,无需额外配置。
  • 会话与权限:
    • X11 会话可用;若在 Wayland 会话中,Compton 不会生效。
    • 使用 systemd 用户服务时,确保会话支持用户级服务(登录图形会话后再启用)。
  • 性能与画面质量:
    • 优先使用 backend = “glx”,并确保显卡驱动正确安装;如遇撕裂可开启 vsync = “true”
    • 降低开销:关闭或精简 shadow、bg_blur、opacity 等特效;必要时将 backend 调整为 xrender 以提升兼容性。
  • 调试技巧:
    • 修改配置后先 killall compton 再启动,或使用 systemctl 重启服务。
    • 通过日志与终端输出定位问题,必要时更换 backend 或逐项关闭特效排查。

0