以下是Compton在CentOS中的典型使用案例,涵盖安装、配置及优化全流程:
安装Compton
使用DNF包管理器安装(CentOS 8+):
sudo dnf install compton
或通过源码编译安装(需安装依赖meson
、ninja
等):
git clone https://github.com/channable/compton.git
cd compton && mkdir build && cd build
meson .. && ninja -C build && sudo ninja -C build install
手动启动
创建配置文件~/.config/compton.conf
后,通过命令行启动:
compton --config ~/.config/compton.conf
性能优化配置
# 启用GLX后端以支持GPU加速
backend = "glx"
glx-no-stencil = true
glx-copy-from-front = true
vsync = true # 启用垂直同步减少画面撕裂
frame_rate = 30 # 限制帧率降低CPU占用
视觉效果配置
# 启用窗口阴影(排除特定窗口)
shadow = true
shadow-exclude = [
"class_g = 'Firefox'",
"class_g = 'KDE'",
]
shadow-color = "0x00000080" # 半透明黑色阴影
多显示器支持
配合xrandr
设置多显示器后,Compton自动适配,无需额外配置。可通过以下命令验证:
xrandr --query # 查看显示器状态
xrandr --output HDMI-1 --auto --right-of eDP-1 # 扩展显示器
创建Systemd服务
sudo nano /etc/systemd/system/compton.service
内容示例:
[Unit]
Description=Compton Window Compositor
After=graphical.target
[Service]
ExecStart=/usr/bin/compton --config ~/.config/compton.conf
Restart=always
[Install]
WantedBy=graphical.target
启用并启动服务:
sudo systemctl enable compton
sudo systemctl start compton
验证服务状态
sudo systemctl status compton
若显示active (running)
,则服务正常运行。
兼容性处理
--backend x11
切换后端。shadow = false
opacity = false
资源监控
使用top
或htop
命令查看Compton进程的CPU/内存占用,若过高可通过cpulimit
限制:
cpulimit -l 50 -p $(pgrep compton) # 限制CPU使用率≤50%
以上配置可根据实际硬件和需求调整,更多选项可参考Compton官方文档。