CentOS Compton支持多显示器,但需通过正确配置实现。以下是具体步骤及注意事项:
Compton作为轻量级X11窗口合成器,默认支持多显示器,但需确保以下前提:
glx驱动);xrandr正确配置(如扩展屏、双屏显示模式)。在CentOS中,通过包管理器安装Compton(以CentOS 7/8为例):
# CentOS 7(使用yum)
sudo yum update -y && sudo yum install -y compton
# CentOS 8及以上(使用dnf)
sudo dnf update -y && sudo dnf install -y compton
Compton的主配置文件通常位于~/.config/compton.conf(若不存在则手动创建):
mkdir -p ~/.config && nano ~/.config/compton.conf
以下配置启用了glx后端(推荐,提升性能),并关闭了阴影、透明度等可能影响多显示器显示的特效:
backend = "glx"; # 使用glx渲染后端(支持硬件加速)
shadow-exclude = [ ".*", "[class='.*Firefox']", "[title='.*Firefox']" ]; # 排除Firefox等应用的阴影
alpha-mode = "none"; # 关闭窗口透明度
alpha-ignores = [ ".*", "[class='.*Firefox']", "[title='.*Firefox']" ]; # 忽略特定应用的透明度
glx-no-stencil = true; # 禁用模板缓冲,提升性能
glx-copy-from-front = true; # 允许从前缓冲复制,减少渲染延迟
shader-file = null; # 不使用自定义着色器
shader-frag = null; # 不使用自定义片段着色器
shader-vert = null; # 不使用自定义顶点着色器
xrandr-args = ""; # 不额外传递xrandr参数(由xrandr独立配置)
Compton依赖xrandr管理多显示器布局。通过以下命令查看当前显示器信息:
xrandr --query
假设输出显示有三个显示器:HDMI-1(外接屏)、DP-1(外接屏)、eDP-1(笔记本内置屏),可将它们配置为扩展模式(右侧依次排列):
xrandr --output HDMI-1 --auto --right-of eDP-1 # HDMI-1放在eDP-1右侧
xrandr --output DP-1 --auto --right-of HDMI-1 # DP-1放在HDMI-1右侧
注:
--auto表示自动适配分辨率,--right-of指定相对位置(也可用--left-of、--above、--below)。
通过配置文件启动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 /home/your_username/.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
若显示“active (running)”,则表示Compton已启动。backend(如改为xrender,但性能较差)或关闭glx-copy-from-front;xrandr-args或shadow-exclude/opacity-rule针对性调整。