Multihead

来自ArchWiki
(重定向自 DualScreen

多显示器多屏幕多显示器 代表连接到单台计算机的多个显示设备设置。本文提供几种多显示器设置方法的通用描述,并提供一些配置示例。

注意: 本文使用的术语非常具体,以避免混淆
  • 显示器 指的是物理显示设备,例如 LCD 面板。
  • 屏幕 指的是 X 窗口屏幕(即:连接到显示显示器)。
  • 显示 指的是同时使用并显示单个桌面不同部分的屏幕集合(您可以在单个显示中的所有屏幕之间拖动窗口)。

历史背景

X 窗口系统 (X, X11) 是大多数提供图形用户界面 (GUI) 的 Unix/Linux 计算机的底层图形用户界面。它于 1984 年在 MIT 开发。经过大约 35 年的开发、调整、新功能和想法,它通常被认为是有点复杂。在早期开发时期,常见的配置是单个运行的 X,它在分时系统上为 X 终端提供单独的视图。今天,X 通常在台式机或笔记本电脑上提供单个屏幕。

注意: 仍然有一种罕见的配置,通常称为Zaphod 显示,它允许多个单台计算机的用户各自拥有一组独立的显示器、鼠标和键盘,就像他们在使用单独的计算机一样,但每座成本更低。

简而言之,有许多方法可以使用 X 配置 GUI。当使用现代版本时,有时您甚至可以在有限或没有配置的情况下完成。在过去几年中,自夸的是 X 是自配置的。当然,一个好的经验法则是配置越少越好 - 也就是说,只配置默认配置错误的内容

RandR

RandRRotate and Resize)是 X 窗口系统 扩展,它允许客户端动态更改(例如,调整大小、旋转、反射)屏幕。在大多数情况下,它可以完全取代旧的 Xinerama 设置。请参阅解释,了解为什么 RandR 比 Xinerama 更好。

RandR 可以通过 xrandr 工具、arandr 为当前会话配置,也可以通过 xorg.conf 文件持久配置。

注意: 配置同一件事有多种方法,您可能需要稍微尝试一下才能找到最佳配置。

使用 xrandr 进行配置

注意: 本节假设您已阅读 xrandr 页面以获取有关 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-0auto 决定虚拟显示器的大小,将此设置为 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

示例:使用相对坐标和自定义分辨率的双显示器配置

每个显示器的 ID 可以通过运行 $ xrandr -q 命令找到,并且应在 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 配置保存为配置文件。
  • monsAURmons-gitAUR 是一个 shell 脚本,用于使用 xrandr 快速管理双显示器显示。

独立屏幕

这是使用 X 配置多显示器的原始方式,并且已经存在了几十年。每个物理显示器都被分配为一个 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 加速,同时能够在屏幕之间拖动窗口的唯一方法。但是,即使在使用 Xinerama 时,现代版本的 NVIDIA 闭源驱动程序也能够提供 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

上面部分中的每个屏幕都在单独的文件中定义,例如这个文件

/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

另请参阅