一、安装Compton
sudo yum update -y
sudo yum groupinstall -y "Development Tools" # 仅源码安装需要
sudo yum install -y cmake git libX11-devel libXext-devel libXrender-devel libXi-devel libXrandr-devel libXinerama-devel libXcursor-devel libXcomposite-devel libxdamage-devel # 依赖包
sudo yum install epel-release -y):sudo yum install compton -y # CentOS 7及以下
sudo dnf install compton -y # CentOS 8及以上
git clone https://github.com/compton/compton.git
cd compton
mkdir build && cd build
cmake .. && make -j$(nproc) && sudo make install
二、配置Compton
~/.config/compton.conf,若不存在则创建:mkdir -p ~/.config
nano ~/.config/compton.conf # 或使用vim/vi
glx(需GPU支持)或xrender(兼容性好):backend = "glx" # 或 "xrender"
shadow = true
shadow-radius = 12
shadow-offset-x = -15
shadow-offset-y = -15
shadow-color = "rgba(0, 0, 0, 0.5)"
shadow-exclude = ["name = 'Notification'", "class_g = 'Conky'", "class_g = 'Cairo-clock'"]
inactive-opacity = 0.8 # 非活动窗口透明度
active-opacity = 1.0 # 活动窗口透明度
frame-opacity = 0.7 # 窗口边框透明度
opacity-rule = [
"90:class_g = 'Firefox'", # Firefox透明度90%
"80:class_g = 'URxvt'", # 终端透明度80%
"100:class_g = 'Alacritty'" # Alacritty(终端)不透明
]
glx-no-stencil = true
glx-no-rebind-pixmap = true
xrender-sync-fence = true
unredir-if-possible = true # 忽略全屏窗口的合成(如视频播放)
fading = true
fade-delta = 5
fade-in-step = 0.03
fade-out-step = 0.03
pkill compton && compton -b # 后台启动Compton
三、设置开机自启动
sudo nano /etc/systemd/system/compton.service
your_username为实际用户名):[Unit]
Description=Compton Window Compositor
After=display-manager.service
[Service]
ExecStart=/usr/bin/compton -b --config ~/.config/compton.conf
Restart=on-failure
User=your_username
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable compton.service
sudo systemctl start compton.service
四、验证与调试
systemctl status compton.service
compton --config ~/.config/compton.conf --verbose 2>&1 | tee compton.log
vsync参数为opengl-swc或drm;glx-no-stencil、paint-on-overlay;shadow-exclude或opacity-rule中添加应用排除规则。