一、安装Compton
首先确保系统已安装Compton。以Debian/Ubuntu为例,使用以下命令安装:
sudo apt update && sudo apt install compton -y
CentOS/RHEL系统可使用:
sudo yum install compton # CentOS 7及以下
sudo dnf install compton # CentOS 8及以上
二、创建/编辑Compton配置文件
Compton的配置文件通常位于~/.config/compton.conf(若不存在则手动创建)。建议使用文本编辑器(如nano)修改:
mkdir -p ~/.config
nano ~/.config/compton.conf
三、配置多显示器支持
Compton会自动检测通过xrandr配置的多显示器布局,但需在配置文件中指定后端(Backend)以启用硬件加速。推荐使用glx后端(支持OpenGL加速):
backend "glx"
glx-no-stencil true # 禁用模板缓冲区,提升性能
glx-copy-from-front true # 允许从前缓冲区复制,减少渲染开销
glx-hardware true # 强制使用硬件加速
若需针对每个显示器单独设置(如分辨率、位置、缩放),可使用screen模块。例如,配置两个显示器(HDMI-1左、DP-1右):
screen0 {
output = "HDMI-1" # 显示器名称(通过`xrandr`查看)
position = "left" # 相对位置(left/right/top/bottom)
transform = "normal" # 旋转方式(normal/90/180/270)
scale = 1.0 # 缩放比例(1.0为原始大小)
}
screen1 {
output = "DP-1"
position = "right"
transform = "normal"
scale = 1.0
}
注:显示器名称可通过
xrandr --query命令获取(如HDMI-1 connected 1920x1080+0+0)。
四、优化多屏显示性能
shadow = false # 全局关闭阴影
# 或仅排除特定窗口(推荐)
shadow-exclude = [
"class_g 'gnome-terminal'",
"class_g 'firefox'",
"class_g 'kdecoration'" # KDE桌面装饰窗口
]
opacity功能:opacity = false
fps-limit = 60
vsync = true # 或使用"opengl-swc"(OpenGL交换控制)替代
确保backend设置为glx(而非xrender),并开启以下选项:
glx-no-stencil true
glx-copy-from-front true
glx-hardware true
五、启动Compton并设置开机自启动
配置完成后,通过以下命令启动Compton(指定配置文件路径):
compton -c ~/.config/compton.conf
创建Systemd服务文件以实现开机自动运行:
sudo nano /etc/systemd/system/compton.service
添加以下内容(替换your_username为实际用户名):
[Unit]
Description=Compton Window Composer
After=display-manager.service # 确保在显示管理器启动后运行
[Service]
ExecStart=/usr/bin/compton -c ~/.config/compton.conf
Restart=always # 崩溃后自动重启
User=your_username
[Install]
WantedBy=multi-user.target
启用并启动服务:
sudo systemctl daemon-reload
sudo systemctl enable compton
sudo systemctl start compton
六、验证配置
systemctl status compton,确认服务状态为active (running)。fps-limit、vsync或关闭阴影/透明度等特效。注意事项
xorg.conf中配置Composite选项(参考NVIDIA官方文档)。shadow-radius调整阴影大小、opacity-rule添加更多窗口例外)。~/.cache/compton.log)排查问题。