跳转至内容

Multihead

来自 ArchWiki
(从 DualScreen 重定向而来)

多头Multi-head)、多屏multi-screen)、多显示器multi-display)或多监视器multi-monitor)指连接到单台计算机的多个显示设备的设置。本文档提供了几种多头设置方法的通用描述,并包含一些配置示例。

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

历史背景

X Window System (X, X11) 是大多数提供图形用户界面 (GUI) 的 Unix/Linux 计算机的基础。它于 1984 年在麻省理工学院开发。经过大约 35 年的发展、调整、新功能和想法,普遍认为它已经有点像个庞然大物了。在早期开发阶段,常见的配置是运行一个 X 服务器,为 分时共享系统上的 X 终端提供独立的视图。如今,X 通常在台式机或笔记本电脑上提供一个屏幕。

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

简而言之,有许多方法可以使用 X 配置 GUI。在使用现代版本时,有时甚至可以做到有限甚至无需配置。近几年来,X 的宣传是它具有自我配置能力。当然,一个好的经验法则是,配置越少越好——也就是说,只配置默认设置有误的地方

RandR

RandR (Rotate and Resize) 是一个 X Window System 扩展,它允许客户端动态更改(例如,调整大小、旋转、镜像)屏幕。在大多数情况下,它可以完全取代旧的 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 是一个使用 xrandr 快速管理双显示器设置的 shell 脚本。

独立屏幕

本文章或章节需要扩充。

原因:没有关于如何设置 X 服务器以实现所述行为的信息。(在 Talk:Multihead 讨论)

这是配置多个显示器的原始方式,已经存在了几十年。每个物理显示器都被分配为一个 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

上面的部分的每个 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

参见