跳转至内容

Multihead

来自 ArchWiki

多头 (Multi-head)多屏 (multi-screen)多显示 (multi-display)多显示器 (multi-monitor) 指的是将多个显示设备连接到一台计算机上的设置。本文提供了几种多头设置方法的通用描述,并给出了一些配置示例。

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

历史背景

X Window System (X, X11) 是大多数提供图形用户界面 (GUI) 的 Unix/Linux 计算机的底层界面。它于 1984 年在 MIT 开发。经过约 35 年的开发、优化、新功能和理念迭代,它被公认为一个相当复杂的系统。在早期开发阶段,常见的配置是运行一个单一的 X,为分时系统 (time-sharing system) 上的 Xterminals 提供独立的视图。如今,X 通常在桌面或笔记本电脑上提供单个屏幕。

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

简而言之,使用 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 是一个 shell 脚本,用于使用 xrandr 快速管理双显示器显示。

独立屏幕 (Separate screens)

本文章或章节需要扩充。

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

这是使用 X 配置多个显示器的原始方法,已经存在了数十年。每个物理显示器都被分配为一个 X 屏幕,虽然您可以在它们之间移动鼠标,但它们在很大程度上是独立的。

通常 X display 有一个单一的标识符,如 :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

您需要为每个 显示器 (monitor) 创建一个 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

参见

© . This site is unofficial and not affiliated with Arch Linux.

Content is available under GNU Free Documentation License 1.3 or later unless otherwise noted.