1. 安装Compton
首先通过包管理器安装Compton(以Debian/Ubuntu为例):
sudo apt update && sudo apt install compton
安装完成后,Compton会自动检测系统中的多显示器配置,但需通过配置文件进一步优化。
2. 创建/编辑Compton配置文件
Compton的主配置文件通常位于~/.config/compton.conf
(若不存在则手动创建)。使用文本编辑器(如nano
)打开:
mkdir -p ~/.config nano ~/.config/compton.conf
配置文件是优化多屏显示的核心,需调整以下关键参数:
3. 配置多显示器参数
Compton默认支持多显示器,但需通过xrandr-output
指定显示器连接关系(避免显示冲突)。例如,若有两个显示器HDMI-1
(外接)和eDP-1
(笔记本屏幕),且HDMI-1
在右侧,可添加:
xrandr-output HDMI-1 eDP-1;
通过xrandr --query
命令查看自身显示器名称(如HDMI-1
、DP-1
等),替换上述参数。
若需更精细的控制,可为每个显示器单独设置参数(如分辨率、刷新率、缩放比例):
screen0 { output = "HDMI-1"; # 显示器名称 position = "left"; # 相对位置(left/right/top/bottom) transform = "normal"; # 旋转方式(normal/90/180/270) scale = 1.0; # 缩放比例(适配高DPI屏幕) } screen1 { output = "eDP-1"; position = "right"; transform = "normal"; scale = 1.0; }
此配置可实现双屏扩展或拼接模式(需配合xrandr
的物理连接设置)。
4. 优化性能(避免多屏卡顿)
多屏显示对GPU资源消耗较大,需调整以下参数提升流畅度:
backend "glx"; # 使用OpenGL加速(优先于xrender) glx-no-stencil false; # 启用模板缓冲区(提升复杂窗口渲染) glx-copy-from-front true; # 允许从前缓冲区复制(减少渲染次数) glx-hardware true; # 强制使用GPU硬件加速 damage true; # 仅合成修改的区域(降低CPU负载) shadow false; # 禁用阴影(减少合成开销,若需阴影可保留但排除常用窗口) opacity false; # 禁用窗口透明(若需透明可保留但调整规则) vsync true; # 启用垂直同步(防止画面撕裂,若出现延迟可设为false) fps-limit 60; # 限制帧率为60FPS(平衡性能与流畅度)
注:若使用NVIDIA显卡,需确保驱动支持OpenGL,并安装nvidia-settings
工具调整Xorg配置。
5. 排除不需要特效的窗口
为常用窗口(如终端、浏览器、桌面)禁用阴影或透明,避免不必要的性能消耗:
shadow-exclude [ "class_g 'gnome-terminal'", "class_g 'firefox'", "class_g 'Desktop'", "class_g 'plasma-desktop'" ]; opacity-rule [ "class_g 'gnome-terminal' A", "class_g 'firefox' A", "class_g 'Desktop' A" ];
通过xprop
命令获取窗口的class
名称(如终端窗口输入xprop | grep class
),替换上述参数。
6. 启动Compton并设置开机自启动
compton -c ~/.config/compton.conf
若多屏显示正常且无卡顿,继续下一步。
创建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=on-failure User=你的用户名 [Install] WantedBy=multi-user.target
启用并启动服务:
sudo systemctl daemon-reload sudo systemctl enable compton.service sudo systemctl start compton.service
通过systemctl status compton.service
验证服务状态(显示“active (running)”即为成功)。
7. 验证与调整
systemctl status compton.service
cat ~/.cache/compton.log
fps-limit
、vsync
或shadow-exclude
规则)。