1. 安装Compton
在CentOS上,首先需要通过包管理器安装Compton。对于CentOS 7及以上版本(使用yum
或dnf
),执行以下命令:
# CentOS 7(使用yum)
sudo yum install epel-release -y # 确保epel仓库已启用
sudo yum install compton -y
# CentOS 8及以上(使用dnf)
sudo dnf install compton -y
安装完成后,Compton即可用于提升桌面显示效果。
2. 创建/编辑Compton配置文件
Compton的配置文件通常位于用户主目录的.config
文件夹下(~/.config/compton.conf
)。若文件不存在,可通过以下命令创建:
mkdir -p ~/.config
touch ~/.config/compton.conf
使用文本编辑器(如nano
)打开配置文件,添加以下基础配置以提升显示效果:
# 设置渲染后端(glx支持GPU加速,性能优于xrender)
backend "glx"
# 启用窗口阴影(增强立体感,可根据需求排除特定窗口)
shadow true
shadow-exclude [".*", "[class='GtkWindow']", "[title='.*Firefox.*']", "[class='Plasma-desktop']"]
# 启用背景模糊(提升视觉层次感,对性能有一定消耗)
bg_blur true
blur-strength 5 # 模糊强度(1-10,数值越大越模糊)
# 启用淡入淡出效果(窗口切换时更平滑)
fade-in-out true
fade-delta 10 # 淡入淡出速度(数值越小越快)
# 启用垂直同步(减少画面撕裂,需显卡支持)
vsync true
# 忽略OpenGL加速问题(若出现图形异常,可开启)
ignore_glx_glitz true
以上配置兼顾了视觉效果与性能平衡,可根据实际需求调整参数(如关闭bg_blur
提升性能)。
3. 启动Compton并设置开机自启
配置完成后,通过以下命令启动Compton(指定配置文件路径):
compton -c ~/.config/compton.conf
若希望Compton随系统启动自动运行,需创建systemd服务文件:
sudo nano /etc/systemd/system/compton.service
添加以下内容(确保路径与配置文件一致):
[Unit]
Description=Compton Compositor
After=display-manager.service
[Service]
ExecStart=/usr/bin/compton -c ~/.config/compton.conf
Restart=on-failure
[Install]
WantedBy=multi-user.target
保存后,执行以下命令启用并启动服务:
sudo systemctl daemon-reload
sudo systemctl enable compton.service
sudo systemctl start compton.service
通过systemctl status compton.service
可检查服务状态,确认Compton是否正常运行。
4. 性能优化建议
glx
(需显卡支持OpenGL),其性能远优于xrender
,尤其适合多显示器或高分辨率场景。bg_blur
(背景模糊)或shadow
(阴影),显著降低Compton的资源占用。vsync
设置为true
以减少撕裂;若出现卡顿,可尝试设置为false
。cpulimit
工具限制Compton的CPU占用(如cpulimit -l 50 -p $(pgrep compton)
),避免影响系统整体性能。注意事项
glxinfo | grep "OpenGL renderer"
检查),否则Compton的GPU加速功能无法生效。ignore_root
(忽略根窗口透明度)或ignore
(忽略特定窗口)参数。killall compton && compton -c ~/.config/compton.conf
)以应用更改。