CentOS配置Compton的主要方法
配置Compton的第一步是安装软件包。根据CentOS版本选择包管理器:
yum安装,命令为sudo yum install compton -y;dnf安装,命令为sudo dnf install compton -y。sudo yum update -y或sudo dnf update -y)以确保兼容性。Compton的配置文件通常位于用户主目录的.config文件夹下(~/.config/compton.conf)。若文件不存在,可通过以下命令创建:
mkdir -p ~/.config && touch ~/.config/compton.conf。
配置文件的核心参数包括:
backend = "glx"(推荐,支持GPU加速,提升性能)或backend = "xrender"(兼容性好,但性能较低);shadow = true(启用阴影)或shadow = false(禁用阴影,减少资源消耗);shadow-exclude = [".*Firefox.*", ".*notification.*"](排除特定窗口的阴影,如浏览器、通知栏);opacity = 0.8(窗口透明度,0为完全透明,1为不透明);unredir-if-possible = true(优化全屏应用时的透明度,提升性能);vsync = true(开启垂直同步,减少屏幕撕裂);frame-rate = 60(设置合成帧率,默认60帧,可根据硬件调整);glx-no-stencil = true(禁用模板缓冲区,减少内存占用)。compton --config ~/.config/compton.conf手动应用配置。配置完成后,可通过命令行手动启动Compton:
compton --config ~/.config/compton.conf &(&表示后台运行)。
若需临时调整参数(如关闭阴影),可直接在命令后添加选项:compton --config ~/.config/compton.conf --no-shadow &。
为避免每次登录都手动启动Compton,可创建systemd服务文件:
sudo nano /etc/systemd/system/compton.service;your-username为实际用户名):[Unit]
Description=Compton Window Composer
After=display-manager.service
[Service]
ExecStart=/usr/bin/compton --config /home/your-username/.config/compton.conf
Restart=always
User=your-username
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload && sudo systemctl enable compton.service && sudo systemctl start compton.service。根据硬件配置调整Compton参数,可显著提升性能:
shadow = false(禁用阴影)、opacity = false(禁用透明度);backend = "glx"(GPU加速)替代xrender;frame-rate = 30(从60帧降至30帧,减少CPU占用);frame-dropping = true(允许Compton丢弃部分帧,提升流畅度);cpulimit工具限制Compton的CPU占用率(如cpulimit -l 50 -p $(pgrep compton),将CPU使用率限制在50%)。