1. 安装Compton
首先确保系统已安装Compton。若未安装,可通过包管理器安装(CentOS 7用yum,CentOS 8/Stream用dnf):
sudo yum install compton # CentOS 7
sudo dnf install compton # CentOS 8/Stream
2. 配置文件准备
Compton的配置文件通常位于~/.config/compton.conf(用户级)或/etc/compton.conf(系统级)。若文件不存在,用文本编辑器创建:
mkdir -p ~/.config
nano ~/.config/compton.conf
3. 关键参数优化(提升画面质量与性能)
backend = "glx"(OpenGL加速),替代老旧的xrender,显著提升渲染性能和画面流畅度。shadow = true;
shadow-exclude = [ "class_g = 'Compton'", "class_g = 'Polybar'", "class_g = 'KRunner'" ];
shadow-radius = 10; # 阴影半径(调整阴影扩散范围)
shadow-offset-x = 2; # 阴影偏移量(X轴)
shadow-offset-y = 2; # 阴影偏移量(Y轴)
shadow-opacity = 0.3; # 阴影透明度(0-1,值越小越淡)
blur-background = true;
blur-background-frame = true; # 模糊窗口框架
blur-background-fixed = false; # 动态模糊(跟随窗口移动)
blur-method = "kawase"; # 模糊算法(可选:kawase/gaussian,kawase性能更好)
blur-strength = 5; # 模糊强度(1-10,值越大越模糊)
vsync = true;
glx-vsync = true; # OpenGL垂直同步
fade = true;
fade-in-step = 0.03; # 淡入步长(0-1,值越小越慢)
fade-out-step = 0.03; # 淡出步长(0-1,值越小越慢)
fade-delta = 10; # 淡入淡出速度(毫秒)
4. 排除不必要窗口(减少资源消耗)
通过shadow-exclude和opacity-rule排除不需要特效的窗口(如桌面、面板、视频播放窗口),降低Compton的负载:
shadow-exclude = [
"class_g = 'Compton'",
"class_g = 'Polybar'",
"class_g = 'KRunner'",
"name = 'vlc'" # 排除VLC播放器(视频窗口无需阴影)
];
opacity-rule = [
"100:class_g = 'Polybar'", # 面板完全不透明
"100:class_g = 'KRunner'", # 跑马灯完全不透明
"90:name = 'Firefox'" # Firefox窗口透明度90%
];
5. 启动Compton并设置开机自启
compton --config ~/.config/compton.conf &
/etc/systemd/system/compton.service:[Unit]
Description=Compton Window Compositor
After=display-manager.service
[Service]
ExecStart=/usr/bin/compton --config ~/.config/compton.conf
Restart=on-failure
[Install]
WantedBy=multi-user.target
启用并启动服务:sudo systemctl daemon-reload
sudo systemctl enable compton
sudo systemctl start compton
6. 监控与调优
compton --verbose命令查看Compton的实时性能数据(如FPS、渲染时间),根据输出调整参数(如降低blur-strength或关闭fade)。killall compton && compton --config ~/.config/compton.conf &重启Compton,无需注销即可应用更改。通过以上步骤,可在CentOS系统上显著提升Compton的画面质量(如阴影、模糊、淡入淡出效果),同时通过优化参数保持系统性能稳定。需根据自身硬件配置(如显卡型号、内存大小)调整特效强度,避免过度消耗资源。