CentOS 上 Compton 高级配置指南
一 环境准备与安装
sudo yum install -y compton 或 sudo dnf install -y comptonmkdir -p ~/.config && nano ~/.config/compton.confcompton --config ~/.config/compton.conf --backend glx --vsync true --shadow false二 配置文件结构与核心参数
backend:渲染后端,优先 glx(性能与兼容性更好),必要时用 xrender。vsync:垂直同步,取值 true/false,用于减少撕裂;若出现卡顿可尝试切换。shadow:是否启用窗口阴影;在高刷新率或低性能设备上可关闭以提升性能。opacity / alpha:全局透明度(0.0–1.0),谨慎使用以免影响可读性与性能。ignore_root:是否忽略根窗口透明度,部分桌面环境需要设为 true。shadow-radius、shadow-offset-x、shadow-offset-y、shadow-opacity[blur] method = gaussian; size = 10; deviation = 5.0[opacity-rule] ["90:class_g 'Firefox'", "90:name 'Terminal'"]三 高级场景配置示例
backend = glxvsync = trueshadow = falseopacity = 1.0frame-rate = 60backend = glxvsync = trueshadow = trueshadow-radius = 5shadow-offset-x = 1shadow-offset-y = 1shadow-opacity = 0.3[blur] method = gaussian; size = 10; deviation = 5.0[opacity-rule] ["90:class_g 'Firefox'", "92:name 'Terminal'"]shadow-exclude = ["class_g = 'Firefox'"]~/.config/compton.conf 中,保存后重启 Compton 生效。四 自启动与系统集成
~/.xinitrc、~/.config/i3/config)中添加:
exec compton --config ~/.config/compton.confnano ~/.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=always[Install] WantedBy=default.targetsystemctl --user daemon-reloadsystemctl --user enable --now compton.servicesudo nano /etc/systemd/system/compton.service[Unit] Description=Compton Window Composer After=display-manager.service[Service] ExecStart=/usr/bin/compton --config /home/用户名/.config/compton.conf Restart=always[Install] WantedBy=multi-user.targetsudo systemctl daemon-reloadsudo systemctl enable --now compton.service五 性能调优与故障排查
cpulimit -l 50 -p $(pgrep compton)(谨慎使用,避免影响交互)。vsync 取值(true/false),并测试不同后端(glx/xrender)。shadow-exclude、[blur] 参数与受影响应用的 class/title。xrandr 输出正常,必要时在配置或启动脚本中显式设置输出参数。