CentOS下Compton的常用使用技巧
在CentOS上,通过包管理器安装Compton(需root权限):
sudo yum install -y compton # CentOS 7及以下
sudo dnf install -y compton # CentOS 8及以上
Compton的主配置文件位于~/.config/compton.conf(若不存在可手动创建)。修改配置文件前,建议备份原文件:
mkdir -p ~/.config
cp /etc/compton.conf ~/.config/compton.conf # 若系统有默认配置
nano ~/.config/compton.conf # 使用文本编辑器修改
glx(支持GPU加速,提升性能),避免xrender(CPU密集型,适合低性能设备):backend = "glx"
shadow = false # 完全禁用
# 或针对性排除(如Firefox窗口)
shadow-exclude = [".*Firefox.*", ".*panel.*"]
opacity-rule为特定窗口设置透明度(数值0-1,1为不透明):opacity-rule = [
"90:class_g 'Firefox'", # Firefox窗口透明度90%
"100:class_g 'Xephyr'" # Xephyr窗口完全不透明
]
vsync减少画面撕裂(适合游戏或视频播放):vsync = true
background-blur提升视觉效果(需GPU支持):[blur]
method = gaussian # 模糊算法(可选:gaussian/box)
size = 10 # 模糊半径
deviation = 5.0 # 模糊强度
background-blur = true
cpulimit限制Compton的CPU占用(如限制为50%):cpulimit -l 50 -p $(pgrep compton) # 替换为Compton的实际进程ID
glx后端(见上文)。fade = false # 禁用淡入淡出
screen-edge-blur = false # 禁用屏幕边缘模糊
compton -b -c ~/.config/compton.conf # -b表示后台运行,-c指定配置文件
sudo nano /etc/systemd/system/compton.service
添加以下内容(根据桌面环境调整After字段,如i3则改为After=i3.service):[Unit]
Description=Compton Window Composer
After=display-manager.service
[Service]
ExecStart=/usr/bin/compton -b -c ~/.config/compton.conf
Restart=on-failure
[Install]
WantedBy=multi-user.target
保存后启用并启动服务:sudo systemctl daemon-reload
sudo systemctl enable compton
sudo systemctl start compton
~/.cache/compton/compton.log,通过以下命令查看实时日志:tail -f ~/.cache/compton/compton.log
pkill compton && compton -b -c ~/.config/compton.conf
nvidia-smi命令验证),驱动问题可能导致Compton无法正常工作。xrandr-args适配(需提前用xrandr命令确认显示器名称):xrandr-args = "--output HDMI-1 --auto --right-of eDP-1" # 示例:HDMI-1显示器放在eDP-1右侧
compton --toggle-shadow)。以上技巧覆盖了Compton在CentOS上的安装、配置、优化及故障排查,可根据实际硬件配置和桌面环境调整参数,平衡视觉效果与系统性能。