多顯示器

出自 Arch Linux 中文维基

多頭(Multi-head)多屏(multi-screen)多顯(multi-display)多監視器(multi-monitor)是指同一台計算機上連接了多個顯示設備的配置場景。本文提供多種多頭的配置方式,並給出若干設置實例。

注意: 為避免混淆,下列名詞在本文中有各自專屬的含義:
  • 監視器(Monitor):物理顯示設備,如液晶平板顯示器。
  • 屏幕(Screen):窗口屏幕,是已經連接到一個顯示區(display)監視器(monitor)
  • 顯示區(Display): 一組屏幕(screens),各自同時展示同一桌面的某一部分。用戶可以在同一個顯示區(display)的所有屏幕(screens)之間拖動窗口。

歷史背景[編輯 | 編輯原始碼]

大多數(甚至是全部)提供圖形用戶界面的Unix/Linux電腦都使用X窗口系統作為底層圖形界面。X窗口系統1984年在麻省理工學院被開發出來。歷經35年的開發、調校與新功能、新理念的加入,它的強大得到了公認。應該記得,在開發它的那個時代,常見的配置是一個運行著的X為一個分時系統中的X終端(Xterminal)們提供各自獨立的視圖。如今的標準情形是X為一台台式機或筆記本提供單一一塊屏幕。

注意: 現在仍然有一種罕見的配置,經常被稱作Zaphod display。它允許單台電腦的多個用戶每人擁有獨立的一組顯示、滑鼠和鍵盤,就好像每個人使用的電腦是分開的一樣,但每個人的平均成本更低。

以上這些都意味著,要實現同一件事或者滿足同一目標,互相之間略有差異的許多件事,有著很多方法。在現代的X版本中,有時候只需要很少量的配置或者不需要配置。最近幾年的趨勢是X是「自配置」(self configuring)的。當然最好的經驗法則是配置越少越好,也就是「只配置出問題的地方」。

獨立屏幕[編輯 | 編輯原始碼]

這是為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值從而出現在啟動它的那塊屏幕。但是在屏幕之間移動程序需要關閉它,然後在另一塊屏幕上重新打開。

這種工作方式確實有其優點,比如如果你在一塊屏幕上工作,另一塊屏幕上彈出的窗口不會搶走焦點——每塊屏幕都是相當獨立的。

RandR[編輯 | 編輯原始碼]

RandRRotate and Resize,旋轉與縮放)是一個X窗口系統擴展,允許客戶端動態調整(即縮放、旋轉、翻轉)屏幕。多數情況下,它可以完全替代舊的Xinerama配置。這篇文章說明了為什麼RandR優於Xinerama。

RandR可以通過xrandr工具為當前會話配置,或者通過xorg.conf文件進行持久設置。

注意: 同一配置有多種方法實現,可能需要進行一些實驗才能找到最佳配置。

用 arandr 配置[編輯 | 編輯原始碼]

arandr 能夠圖形化地排列監視器、改變解析度並保存腳本以存儲設置。默認狀態下點擊「另存為」(Save As)會把腳本保存到 ~/.screenlayout/,之後你就可以把這些文件加入到你的 ~/.profile。有時候登錄之後過早運行 arandr 腳本會引起問題。

編輯 ~/.profile

$ sleep 3
$ /home/<user>/.screenlayout/myLayout.sh

用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

例:使用相對坐標以及自定義解析度的雙屏配置[編輯 | 編輯原始碼]

可以通過運行$ xrandr -q命令查詢到各個監視器的ID。應當在Device中按照Monitor-<ID>的格式指明監視器的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    |
+---------------------++------------+

TwinView[編輯 | 編輯原始碼]

TwinView是nVidia的擴展,可以讓系統把一塊顯卡上連接的兩台監視器看做單塊屏幕。TwinView提供Xinerama擴展,這樣應用程式會知道連接了兩台監視器,因此它與Xinerama不兼容。不過如果你有兩台連接到同一塊nVidia顯卡的監視器,TwinView和Xinerama幾乎沒有差別(儘管這種情況下TwinView可能會提供稍好一些的性能。)

對於兩台以上監視器或者監視器接在不同顯卡上的情況,需要使用Xinerama而不是TwinView。同樣,截至2012年4月,兩台監視器的方向必須相同,不能一台水平顯示,另一台垂直顯示。

以前,要想在能夠在屏幕之間拖動窗口的同時獲得nVidia顯卡的OpenGL加速,TwinView是唯一的辦法。不過現在新版本的nVidia閉源驅動即使在使用Xinerama的情況下也能夠提供OpenGL加速。

配置示例見NVIDIA#TwinView

Xinerama[編輯 | 編輯原始碼]

Xinerama是實現真正多屏X的舊方式。Xinerama將所有監視器組合為單塊屏幕(:0),從而可以做到在屏幕之間拖動窗口。

Xinerama通過自定義的X配置文件進行配置。也有一款叫WideGuy的圖形化工具可以使得切換Xinerama更容易。注意,要使用WideGuy,你仍然需要包含一個ServerLayout節的Xorg配置。

以下是一些例子:

這是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

參見[編輯 | 編輯原始碼]