温馨提示×

深入了解centos compton配置

小樊
41
2025-12-27 12:14:36
栏目: 智能运维

CentOS 上 Compton 配置全指南

一 环境准备与安装

  • 确认会话为 X11(Compton 仅作用于 X11;若使用 Wayland,请改用 Picom 或切换会话)。
  • 安装 Compton:
    • CentOS 7:sudo yum install -y epel-release && sudo yum install -y compton
    • CentOS 8/9:sudo dnf install -y compton
  • 可选:安装图形化配置工具(部分发行版提供)sudo yum install -y compton-conf。
  • 验证安装:compton --version。

二 配置文件位置与生效方式

  • 配置文件路径:
    • 用户级:~/.config/compton.conf(不存在可创建)
    • 系统级:/etc/xdg/compton.conf/etc/compton.conf
  • 生效方式:
    • 前台调试:compton -c ~/.config/compton.conf
    • 后台常驻:compton -b -c ~/.config/compton.conf
  • 修改后重启:pkill compton && compton -b -c ~/.config/compton.conf。

三 核心配置要点与示例

  • 渲染与同步
    • backend:渲染后端,优先 “glx”(性能更好),兼容性差时改用 “xrender”
    • vsync:建议 true 减少撕裂;若用 xrender 可尝试 vsync = “xrender-sync-fence”
  • 阴影与淡入淡出
    • shadow:关闭可显著减负(shadow = false)。
    • shadow-exclude:排除不需要阴影的窗口,如通知、桌面组件。
    • fade:窗口切换动画,低配可关闭(fade = false)。
  • 透明度与模糊
    • inactive-opacity / active-opacity:非活动/活动窗口透明度(如 0.8 / 1.0)。
    • opacity-rule:按应用设定透明度(如终端更透明)。
    • blur-background / blur-method / blur-strength:背景模糊与强度(性能开销较大)。
  • 性能与资源
    • fps-limit:限制帧率(如 60)。
    • cache-size:缓存大小(MB,如 1024)。
    • 省略不必要效果(阴影、模糊、淡入淡出)是提升性能的最快手段。
  • 多显示器
    • 使用 xrandr-args 描述显示器拓扑,避免重复或错位的合成效果。
  • 示例配置(~/.config/compton.conf)
    backend = "glx"
    vsync = true
    shadow = false
    fading = false
    fps-limit = 60
    cache-size = 1024
    
    inactive-opacity = 0.85
    active-opacity = 1.0
    opacity-rule = [
      "90:class_g = 'Alacritty'",
      "80:class_g = 'Thunar'"
    ]
    
    ignore-root = true
    
    # 多显示器示例(请按 xrandr --query 输出调整)
    # xrandr-args = "--output HDMI-1 --auto --right-of eDP-1"
    
    # 如需背景模糊(性能敏感,谨慎开启)
    # blur-background = true
    # blur-method = "kawase"
    # blur-strength = 5
    
    上述关键项与取值适用于大多数 CentOS + X11 场景,可按硬件与偏好微调。

四 开机自启动与系统集成

  • Systemd 用户级服务(推荐,避免权限与图形会话问题)
    1. 创建服务文件:/etc/systemd/system/compton.service
    [Unit]
    Description=Compton Window Compositor
    After=graphical.target
    
    [Service]
    ExecStart=/usr/bin/compton -b -c /home/你的用户名/.config/compton.conf
    Restart=on-failure
    User=你的用户名
    Environment=DISPLAY=:0
    
    [Install]
    WantedBy=graphical.target
    
    1. 启用与启动
    • sudo systemctl daemon-reload
    • sudo systemctl enable --now compton.service
    • 验证:systemctl status compton.service
  • 桌面环境提示
    • 若使用 GNOME/KDE/Xfce,通常需先关闭其内置合成器,避免冲突。
    • 某些桌面在登录管理器(GDM/SDDM)阶段启动,After= 建议使用 graphical.targetdisplay-manager.service

五 调试与常见问题

  • 快速诊断
    • 进程检查:ps -e | grep compton
    • 前台运行查看日志:compton -c ~/.config/compton.conf --log-level debug --log-file /tmp/compton.log
    • 前台运行(最简):compton(终端输出实时日志,便于定位)。
  • 常见问题与对策
    • 黑屏/无效果:用最简配置逐项恢复(先仅保留 backend = “glx”),确认配置路径无误。
    • 画面撕裂:开启 vsync = true;xrender 下尝试 vsync = “xrender-sync-fence”
    • 高 CPU/GPU:关闭 shadow/blur/fade,降低 fps-limit,必要时改用 backend = “xrender”
    • 阴影异常:检查 shadow-exclude 是否误伤目标窗口。
    • 兼容性:较新发行版与驱动下,可考虑使用 Picom(Compton 的活跃分支)获取更好的兼容性与修复。

0