一、安装Compton
在自定义配置前,需确保Compton已安装在CentOS系统上。可通过以下命令安装:
yum(CentOS 7及以下):sudo yum install compton -ydnf(CentOS 8及以上):sudo dnf install compton -y二、创建/编辑配置文件
Compton的配置文件通常位于~/.config/compton.conf(用户级,仅当前用户生效)或/etc/compton.conf(系统级,所有用户生效)。若文件不存在,可手动创建:
mkdir -p ~/.config nano ~/.config/compton.conf 或直接复制系统默认配置(若有)进行修改:
sudo cp /etc/compton.conf.default /etc/compton.conf sudo nano /etc/compton.conf 三、常见自定义配置选项
根据需求调整以下核心参数,优化视觉效果与性能:
glx(支持OpenGL加速,适合现代显卡)或xrender(兼容性好,适合老旧设备):backend = "glx";shadows = true启用阴影,shadow-exclude排除不需要阴影的窗口(如Firefox、终端):shadows = true;shadow-exclude = [".*", "class_g='Firefox'", "class_g='konsole'"];fade = true;glx-no-stencil禁用模板缓冲区,glx-copy-from-front从前台复制像素(避免不必要的渲染):glx-no-stencil = true;glx-copy-from-front = true;alpha-mode = "none"禁用全局透明度,alpha-ignores排除不需要透明的窗口(如视频播放器):alpha-mode = "none";alpha-ignores = [".*", "class_g='vlc'"];vsync = true开启(适合游戏/视频),false关闭(适合日常办公):vsync = true;四、应用配置
保存配置文件后,需重启Compton使更改生效:
pkill compton # 结束当前Compton进程 compton -c ~/.config/compton.conf & # 用新配置重启 或通过systemctl(若已创建服务):
sudo systemctl restart compton 五、设置开机自启动(可选)
若希望Compton随系统启动自动运行,可创建systemd服务文件:
sudo nano /etc/systemd/system/compton.service 添加以下内容(根据配置文件路径调整):
[Unit] Description=Compton Window Composer After=display-manager.service [Service] ExecStart=/usr/bin/compton -c ~/.config/compton.conf Restart=always [Install] WantedBy=multi-user.target 保存后,执行以下命令启用并启动服务:
sudo systemctl daemon-reload sudo systemctl enable compton sudo systemctl start compton 六、性能优化建议
shadows = false、alpha-mode = "none"),减少GPU负载;frame_rate限制帧率(如frame_rate = 30),降低CPU占用;vsync与高刷新率显示器(可能导致卡顿),根据显示器规格调整。