如何在多显示器环境下使用Compton
首先通过系统包管理器安装Compton(以常见系统为例):
sudo apt update && sudo apt install comptonsudo yum install comptonsudo dnf install compton多显示器的物理排列需通过xrandr命令预先设置,Compton会根据此配置适配窗口合成。
运行xrandr --query查看显示器名称(如HDMI-1、DP-1、eDP-1)。
以扩展屏为例(三显示器依次向右排列),命令如下:
xrandr --output HDMI-1 --auto --right-of eDP-1 # HDMI-1放在笔记本屏右侧
xrandr --output DP-1 --auto --right-of HDMI-1 # DP-1放在HDMI-1右侧
若需复制屏(所有显示器显示相同内容),可将--right-of替换为--same-as eDP-1。
Compton的主配置文件通常位于~/.config/compton.conf(若不存在则手动创建)。
基础多显示器配置需包含以下关键参数:
backend "glx" # 推荐使用OpenGL后端(性能更优)
glx-no-stencil true # 禁用模板缓冲,提升性能
glx-copy-from-front true # 允许从前缓冲复制,减少渲染延迟
xrandr-args "" # 留空表示自动适配xrandr配置
注意:避免开启alpha-mode(透明度模式),多显示器下可能导致视觉异常。
若需针对特定显示器调整(如缩放、旋转),可在配置文件中添加screen区块(以双屏为例):
screen0 {
output = "HDMI-1"; # 显示器名称(需与xrandr一致)
position = "left"; # 位置关系
transform = "normal"; # 不旋转
scale = 1.0; # 无缩放
}
screen1 {
output = "DP-1";
position = "right";
transform = "normal";
scale = 1.0;
}
此配置可解决部分显示器分辨率不匹配的问题。
为提升性能并避免特效干扰,可排除特定应用(如浏览器、桌面)的阴影或透明效果:
shadow-exclude = [
".*", # 默认排除所有窗口
"[class='Firefox']", # 排除Firefox
"[title='.*下载.*']" # 排除标题含“下载”的窗口
];
opacity-rule = [
"class_g 'Desktop' A", # 桌面图标保持不透明
"class_g 'Gnome-terminal' A" # 终端窗口不透明
];
调整后可减少GPU负载,尤其适合老旧设备。
配置完成后,通过以下命令启动Compton(需指定配置文件路径):
compton -c ~/.config/compton.conf
若配置正确,多显示器窗口合成效果将立即生效。
为避免每次登录手动启动,可创建systemd服务:
sudo nano /etc/systemd/system/compton.service
写入以下内容(路径需与配置文件一致):
[Unit]
Description=Compton Compositor
After=display-manager.service # 确保在显示管理器之后启动
[Service]
ExecStart=/usr/bin/compton -c ~/.config/compton.conf
Restart=on-failure # 失败时自动重启
[Install]
WantedBy=multi-user.target # 多用户模式下启动
保存后启用并启动服务:
sudo systemctl enable compton.service # 开机自启
sudo systemctl start compton.service # 立即启动
通过systemctl status compton.service可查看运行状态。
glx-sync-to-vblank true(开启垂直同步)或降低refresh-rate(刷新率)。backend改为xrender(软件渲染,性能要求低但效果略差),或关闭shadow(阴影特效)。xrandr-args是否正确,或重新运行xrandr确认显示器连接状态。通过以上步骤,Compton可在多显示器环境下实现流畅的窗口合成与视觉效果,同时支持个性化配置以满足不同需求。