Multihead
多头 (Multi-head)、多屏 (multi-screen)、多显示器 (multi-display) 或 多监视器 (multi-monitor) 指的是连接到一台计算机的多个显示设备的设置。本文档提供了几种多头设置方法的通用描述,并提供了一些配置示例。
- 显示器 (Monitor) 指的是物理显示设备,例如 LCD 面板。
- 屏幕 (Screen) 指的是一个 X 窗口屏幕(即:连接到显示器的显示器)。
- 显示 (Display) 指的是一组同时使用并显示单个桌面一部分的屏幕(您可以在单个显示的所有屏幕之间拖动窗口)。
历史背景
X Window System (X, X11) 是大多数提供图形用户界面的 Unix/Linux 计算机的基础图形用户界面 (GUI)。它于 1984 年在麻省理工学院开发。经过大约 35 年的开发、调整、新功能和想法,它普遍被认为有点庞大。在早期开发期间,常见的配置是一个正在运行的 X,它为 X 终端提供独立的视图,运行在一个分时系统中。如今,X 通常在一个桌面或笔记本电脑上提供一个屏幕。
简而言之,配置 GUI 的方法有很多种。在使用现代版本时,有时甚至可以不用或只需很少的配置。近几年来,X 的宣传是它能够自配置。当然,经验法则是配置越少越好——也就是说,只配置默认设置错误的部分。
RandR
RandR (Rotate and Resize) 是一个X Window System 扩展,允许客户端动态更改(例如:调整大小、旋转、镜像)屏幕。在大多数情况下,它可以完全取代旧的 Xinerama 设置。请参阅此处解释,了解为什么 RandR 比 Xinerama 更好。
RandR 可以通过 xrandr 工具、arandr 进行当前会话的配置,也可以通过 xorg.conf 文件进行持久化配置。
使用 xrandr 配置
您可以相对排列屏幕(使用 --right-of、--left-of、--above、--below 选项),或使用绝对坐标(使用 --pos 选项;请注意,在这种情况下,您通常需要知道显示器的分辨率)。有关详细信息,请参阅 xrandr(1)。下面介绍一些常用的设置。
VGA1 在 HDMI1 左侧,使用首选分辨率
$ xrandr --output VGA1 --auto --output HDMI1 --auto --right-of VGA1
--right-of 将前一个屏幕 (HDMI1) 放置在指定屏幕 (VGA1) 的右侧。
VGA1 在 HDMI1 右侧,使用固定分辨率
$ xrandr --output VGA1 --mode 1024x768 --pos 1920x0 --output HDMI1 --mode 1920x1080 --pos 0x0
或者
$ xrandr --output VGA1 --mode 1024x768 --output HDMI1 --mode 1920x1080 --left-of VGA1
--left-of 将前一个屏幕 (HDMI1) 放置在指定屏幕 (VGA1) 的左侧。
将屏幕合并为虚拟显示器
自 randr 版本 1.5 起,可以将显示器合并为一个虚拟显示器。这是 Xinerama 原有功能的更新版本,可与开源驱动程序配合使用,且无需重启 Xorg。一些桌面环境尚未支持此功能。Openbox 已测试并支持此功能。
通过执行 xrandr --listmonitors 获取显示器列表。
0: +*DisplayPort-4 1920/518x1200/324+1920+0 DisplayPort-4 1: +DisplayPort-3 1920/518x1200/324+0+0 DisplayPort-3 2: +HDMI-A-0 1920/518x1200/324+3840+0 HDMI-A-0
创建虚拟显示器 xrandr --setmonitor SomeName auto DisplayPort-4,DisplayPort-3,HDMI-A-0。auto 确定虚拟显示器的大小,将其设置为 auto 将自动创建正确的显示器数组大小。此命令中的显示器顺序无关紧要,显示器需要在执行此命令之前或之后正确重新排列。
更详细的解释请参阅此页面。
使用 xorg.conf 配置
这类似于使用 xrandr,每个屏幕都需要一个单独的 Monitor 部分。作为 Identifier,使用 xrandr -q 报告的相同值(即,使用 Identifier "VGA1" 而不是 --output VGA1)。
示例:使用相对坐标的双头配置
/etc/X11/xorg.conf.d/10-monitor.conf
Section "Monitor"
Identifier "VGA1"
Option "Primary" "true"
EndSection
Section "Monitor"
Identifier "HDMI1"
Option "LeftOf" "VGA1"
EndSection
示例:使用相对坐标和自定义分辨率的双头配置
可以通过运行 $ xrandr -q 命令找到每个显示器的 ID,并且应该在 Device 部分中将其定义为 Monitor-<ID>。
请参阅 Xrandr#添加未检测到的分辨率。
/etc/X11/xorg.conf.d/10-monitor.conf
Section "Monitor"
Identifier "DVI"
Modeline "1680x1050_60.00" 146.25 1680 1784 1960 2240 1050 1053 1059 1089 -hsync +vsync
Option "PreferredMode" "1680x1050_60.00"
Option "LeftOf" "DP"
Option "DPMS" "true"
EndSection
Section "Monitor"
Identifier "DP"
Modeline "1920x1080_60.00" 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync
Option "PreferredMode" "1920x1080_60.00"
Option "RightOf" "DVI"
Option "DPMS" "true"
EndSection
Section "Screen"
Identifier "Screen0"
Device "Radeon" # e.g. Radeon, Intel, nvidia
Monitor "DP"
DefaultDepth 24
SubSection "Display"
Depth 24
Virtual 3600 2130 # 1920 + 1680 (3600), 1080 + 1050 (2130)
EndSubSection
EndSection
/etc/X11/xorg.conf.d/20-radeon.conf
Section "Device" Identifier "Radeon" Driver "radeon" Option "Monitor-DVI-0" "DVI" # use DVI-0 as DVI Option "Monitor-DisplayPort-0" "DP" EndSection
示例:使用绝对坐标的双头配置
/etc/X11/xorg.conf.d/10-monitor.conf
Section "Monitor"
Identifier "VGA1"
Option "PreferredMode" "1024x768"
Option "Position" "1920 312"
EndSection
Section "Monitor"
Identifier "HDMI1"
Option "PreferredMode" "1920x1080"
Option "Position" "0 0"
EndSection
没有负坐标,设置的最左侧和最高可能的定位点是 0,0。
(0,0)-----------------+ | |(1920,312)---+ | 1920 x 1080 || | | HDMI1 || 1024 x 768 | | || VGA1 | +---------------------++------------+
动态显示配置
以下选项允许您自动检测何时连接了新的显示器,然后根据连接情况更改布局。这对于经常在需要不同设置的多个不同环境中工作的笔记本电脑用户很有用。
- autorandr 允许您根据连接的显示硬件将当前的 xrandr 配置保存为配置文件。
- monsAUR 或 mons-gitAUR 是一个使用 xrandr 快速管理双显示器配置的 shell 脚本。
独立屏幕
这是配置多个显示器的原始方法,已经存在了几十年。每个物理显示器被指定为一个 X 屏幕,虽然您可以在它们之间移动鼠标,但它们或多或少是独立的。
通常 X 显示器有一个标识符,例如 :0,在 DISPLAY 环境变量中设置;但在这种配置中,每个屏幕都有不同的 $DISPLAY 值。第一个屏幕是 :0.0,第二个是 :0.1,依此类推。
使用此配置,无法在屏幕之间移动窗口,除了少数特殊程序(如 GIMP 和 Emacs)具有多屏幕支持。对于大多数程序,您必须在启动时更改 DISPLAY 环境变量,才能使程序出现在另一个屏幕上。
# Launch a terminal on the second screen $ DISPLAY=:0.1 urxvt &
或者,如果您在每个屏幕上都有一个终端,启动程序将继承 DISPLAY 值并出现在启动它们的同一屏幕上。但是,在屏幕之间移动应用程序涉及关闭它并在另一个屏幕上重新打开它。
这样工作确实有某些优点。例如,如果正在一个屏幕上工作,弹出的窗口不会抢占您的焦点,因为每个屏幕都相当独立。
TwinView
TwinView 是 NVIDIA 的扩展,它使连接到显卡的两个显示器显示为一个屏幕。TwinView 提供 Xinerama 扩展,以便应用程序能够感知连接了两个显示器,因此它与 Xinerama 不兼容。但是,如果您只有两个显示器并且它们都连接到同一个 NVIDIA 卡,那么 TwinView 和 Xinerama 之间的区别很小(尽管在这种情况下 TwinView 可能提供略好的性能)。
如果您希望连接多于两个显示器或连接到其他显卡的显示器,则需要使用 Xinerama 而不是 TwinView。同样,截至 2012 年 4 月,两个显示器必须处于相同的方向——您不能一个设置为纵向模式,另一个设置为横向模式。
过去,TwinView 是在使用 NVIDIA 显卡并能够拖动窗口在屏幕之间移动的同时获得 OpenGL 加速的唯一方法。然而,NVIDIA 闭源驱动程序的新版本即使在使用 Xinerama 时也能提供 OpenGL 加速。
有关示例配置,请参阅 NVIDIA#TwinView。
Xinerama
Xinerama 是实现真正多头 X 的旧方法。Xinerama 将所有显示器合并为一个屏幕 (:0),从而可以拖动窗口在屏幕之间移动。
Xinerama 通过自定义 X 配置文件进行配置。还有一个名为 WideGuy 的 GUI 工具,可以更轻松地切换 Xinerama。请注意,要使用 WideGuy,您仍然需要一个具有 ServerLayout 部分的 Xorg 配置。
以下是一些 X 配置示例。
这是控制每个显示器相对于其他显示器位置的 ServerLayout 部分。
/etc/X11/xorg.conf.d/90-serverlayout.conf
Section "ServerLayout" Identifier "Main" Screen 0 "Primary" Screen 1 "DellPortraitLeft" RightOf "Primary" Screen 2 "Wacom" RightOf "DellPortraitLeft" Screen 3 "U2412" LeftOf "Primary" Option "Xinerama" "1" # enable XINERAMA extension. Default is disabled. EndSection
上面的 ServerLayout 部分中的每个 Screen 都定义在一个单独的文件中,例如这个文件:
/etc/X11/xorg.conf.d/30-screen-dell2001.conf
# Define the monitor's physical specs
Section "Monitor"
Identifier "Dell 2001FP"
VertRefresh 60
Option "dpms" "on"
# Modelines are probably unnecessary these days, but it does give you fine-grained control
# 1600x1200 @ 60.00 Hz (GTF) hsync: 74.52 kHz; pclk: 160.96 MHz
Modeline "1600x1200" 160.96 1600 1704 1880 2160 1200 1201 1204 1242 -HSync +Vsync
EndSection
# Define a screen that uses the above monitor. Note the Monitor value matches the above
# Identifier value and the Device value matches one of the video cards defined below
# (the card and connector this monitor is actually plugged in to.)
Section "Screen"
Identifier "DellPortraitLeft"
Device "GeForce 8600GTb"
Monitor "Dell 2001FP"
DefaultDepth 24
SubSection "Display"
Depth 24
Modes "1600x1200"
ViewPort 0 0
Virtual 1600 1200
EndSubsection
# This screen is in portrait mode
Option "Rotate" "left"
EndSection
您需要为每个**显示器**创建一个 Device 部分,即双头显卡将有两个 Device 部分。下面的示例展示了如何配置两块显卡,每块显卡提供两个输出,总共四个显示器。
/etc/X11/xorg.conf.d/20-nvidia.conf
# First head of first video card in the system Section "Device" Identifier "GeForce 8600GT" Driver "nvidia" # If you have multiple video cards, the BusID controls which one this definition refers # to. You can omit it if you only have one card. BusID "PCI:1:0:0" # Need to flag this as only referring to one output on the card Screen 0 # For nVidia devices, this controls which connector the monitor is connected to. Option "UseDisplayDevice" "DFP-0" # We want control! Option "DynamicTwinView" "FALSE" # Various performance and configuration options Option "AddARGBGLXVisuals" "true" Option "UseEDIDDpi" "false" Option "DPI" "96 x 96" Option "Coolbits" "1" EndSection # Second head of same video card (note different Identifier but same BusID.) We can omit # the UseDisplayDevice option this time as it will pick whichever one is remaining. Section "Device" Identifier "GeForce 8600GTb" Driver "nvidia" BusID "PCI:1:0:0" # This is the second output on this card Screen 1 # Same config options for all cards Option "AddARGBGLXVisuals" "true" Option "UseEDIDDpi" "false" Option "DPI" "96 x 96" Option "Coolbits" "1" Option "DynamicTwinView" "FALSE" EndSection # First head of second video card, note different BusID. Section "Device" Identifier "G210" Driver "nvidia" BusID "PCI:2:0:0" Screen 0 # Same config options for all cards Option "AddARGBGLXVisuals" "true" Option "UseEDIDDpi" "false" Option "DPI" "96 x 96" Option "Coolbits" "1" Option "DynamicTwinView" "FALSE" EndSection # Second head of second video card. Output connector is set here, which means the previous # Device will use the other connector, whatever it may be. Section "Device" Identifier "G210b" Driver "nvidia" BusID "PCI:2:0:0" Screen 1 Option "UseDisplayDevice" "DFP-1" # Same config options for all cards Option "AddARGBGLXVisuals" "true" Option "UseEDIDDpi" "false" Option "DPI" "96 x 96" Option "Coolbits" "1" Option "DynamicTwinView" "FALSE" EndSection