マルチディスプレイ

提供: ArchWiki
2018年2月7日 (水) 00:18時点におけるKusakata.bot (トーク | 投稿記録)による版 (文字列「http://i3wm.org/」を「https://i3wm.org/」に置換)
ナビゲーションに移動 検索に移動

関連記事

マルチヘッド, マルチスクリーン, マルチディスプレイ, マルチモニターは複数のディスプレイデバイスをコンピューターに接続して使用することを言います。この記事ではマルチディスプレイを設定する方法の説明や、設定例を示します。

ノート: 混乱を避けるために、この記事で使用する単語の意味を明確にします:
  • モニターは LCD パネルのような物理的な表示デバイスを示します。
  • スクリーンは X-Window の画面を示します (つまりモニターディスプレイに接続されます)。
  • ディスプレイはデスクトップの各部位を示すのに同時に使われるスクリーンの集合を示します (ディスプレイの中のスクリーンでウィンドウをドラッグすることができます)。

歴史的背景

全てとはいわなくてもほとんどの Unix/Linux コンピュータでは GUI を提供するために X Window System を基盤のグラフィカルインターフェイスとして使っています。X は1984年に MIT で開発されました。開発は35年間も続いており、その間に新しい機能や概念が追加され、ちょっとした化物と言われるようにまでなっています。長い開発の歴史の中で、タイムシェアリングシステムによって Xterminal に個別のビューを提供する単一の X というのが最も一般的な設定だったということを覚えておきましょう。近年になって、デスクトップやノートパソコンに単一のスクリーンを提供する X が標準となったのです。

ノート: There is still a rare configuration often called Zaphod display, which allows multiple users of a single computer to each have an independent set of display, mouse, and keyboard, as though they were using separate computers, but at a lower per-seat cost.

以上のことが意味するのは、同じことをするのに多数の方法が存在して、同じ目的を達成するのに少しづつ方法が変わってくるということです。X の最近のバージョンでは、設定にはほとんど触れずともよかったり、もしくは全く設定が不要な場合もあります。ここ数年では X が自分で設定を行ってしまうようになっています。設定は少なければ少ないほど良いという経験則が存在しますが、これはすなわち、何も設定しないのが一番良いわけです。

スクリーンの分割

X でマルチモニタを設定する最古の方法であり、数十年間も使われています。物理モニターのそれぞれに X スクリーンを割り当てるので、マウスをそれぞれのスクリーンで動かすことができ、各スクリーンは多かれ少なかれ独立します。

通常 X ディスプレイには DISPLAY 環境変数によって :0 のように ID が一つだけ指定されていますが、この設定では、各スクリーンごとに別々の値を $DISPLAY に指定します。一番目のスクリーンは :0.0 、二番目のスクリーンは :0.1 と続きます。

この設定を使用する場合、ウィンドウを別のスクリーンに移動させることはできません。ただし GIMP や Emacs などマルチスクリーンをサポートしている(ごく少数の)特別なプログラムは別です。ほとんどのプログラムでは、別のスクリーンにプログラムを表示するには DISPLAY 環境変数を変更する必要が出て来ます:

# Launch a terminal on the second screen
$ DISPLAY=:0.1 urxvt &

また、各スクリーン上のターミナルからプログラムを起動した場合、プログラムは DISPLAY の値を引き継いで、ターミナルと同じスクリーン上に表示されます。ただし、アプリケーションを別のスクリーンに移動しようと思った時は、一度アプリケーションを閉じてから、別のスクリーンからもう一度アプリケーションを開くことになります。

この方法を使用する利点としては、スクリーン上にポップアップウィンドウが表示されたときに、別のスクリーンで作業中のマウスのフォーカスが盗られないということが挙げられます。それぞれのスクリーンは完全に独立して存在します。

Xinerama

Xinerama は X のマルチスクリーンを実現する古い手段です。Xinerama は全てのモニターを単一のスクリーン (:0) にまとめるため、スクリーンを通り越してウィンドウをドラッグすることができます。

Xinerama は 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

You will need to create a Device section for each monitor, i.e. a dual head video card will have two Device sections. The following example shows how to configure two video cards each providing two outputs, for a total of four monitors.

/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

TwinView

TwinView はビデオカードに接続された2つのモニターを1つのスクリーンとして表示させる nVidia の拡張です。TwinView は Xinerama 拡張を内包しており、2つのモニターが接続されていることをアプリケーションは知ることができますが、TwinView は Xinerama と両立して使うことができません。ただしモニターを2つだけしか使っておらず、また、どちらのモニターも同一の nVidia カードに接続している場合、TwinView と Xinerama に違いはほとんどありません (この場合 TwinView の方が少しだけ高いパフォーマンスが得られるというのが唯一の違いです)。

2つ以上のモニターを接続したり、他のビデオカードにモニターを接続する場合、TwinView ではなく Xinerama を使用する必要があります。2012年4月現在、TwinView ではモニターの向きを合わせる必要があります。片方をランドスケープモードにして、もう片方をポートレートモードにすることは出来ません。

昔は、nVidia のカードで OpenGL のアクセラレーションを使いながら別のスクリーンにウィンドウをドラッグするには TwinView を使うしか方法がありませんでした。最新バージョンの nVidia のクローズドソースドライバーでは Xinerama を使用している場合でも OpenGL のアクセラレーションを得ることができるようになっています。

設定例は NVIDIA#TwinView を見て下さい。

RandR

RandR (Rotate and Resize) はクライアントが動的にスクリーンを変更 (例: リサイズ、回転、反転) できるようにする、X Window System の拡張です。ほとんどの場合、RandR は旧 Xinerama のセットアップを完全に置き換えることができます。RandR が Xinerama よりも優れている理由については この説明 を見て下さい。

RandR は xrandr ツールを使って現在のセッションに限って設定を行ったり、xorg.conf ファイルで永続的に設定することができます。

ノート: There are multiple ways to configure the same thing, you might have to experiment a little before you find the best configuration.

xrandr を使って設定

ノート: xrandr に関する基本的な情報は xrandr のページを読んでください。

相対的にスクリーンを配列したり (--right-of, --left-of, --above, --below オプションを使用)、絶対座標を使って配置することができます (--pos オプションを使用。絶対座標を使う場合はモニターの解像度を知る必要があります)。詳しくは man xrandr を見て下さい。よく使われる設定については以下で説明します。

HDMI1 の左側に適切な解像度で VGA1 を表示

$ xrandr --output VGA1 --auto --output HDMI1 --auto --right-of VGA1

--right-of はスクリーン (HDMI1) を指定したスクリーン (VGA1) の右に配置します。

HDMI1 の右側に指定した解像度で VGA1 を表示

$ 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) の左に配置します。

xorg.conf を使って設定

xrandr を使用する方法と似ており、各スクリーンごとに Monitor セクションを記述します。Identifier には、xrandr -q によって確認できる値と同じ値を使用します (--output VGA1 ではなく Identifier "VGA1" を用います)。

例: 相対座標を用いるデュアルヘッド設定

/etc/X11/xorg.conf
Section "Monitor"
    Identifier  "VGA1"
    Option      "Primary" "true"
EndSection

Section "Monitor"
    Identifier  "HDMI1"
    Option      "LeftOf" "VGA1"
EndSection

例: 絶対座標を用いるデュアルヘッド設定

/etc/X11/xorg.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    |
+---------------------++------------+

アプリケーションのサポート

このセクションでは個別のアプリケーションに関してのヒントを記述しています。

  • mplayer: -xineramascreen 1 を使えば動画をセカンドスクリーンで再生できます。~/.mplayer/configxineramascreen=1 を追加することで永続的に設定できます。
  • Xonotic: 複数の画面にまたがって再生するときに左右を変えられないとき、~/.xonotic/data/config.cfgvid_stick_mouse を 1 に設定してください。

ウィンドウマネージャ

このセクションではウィンドウマネージャのマルチモニター対応状況を載せています。

  • Awesome - 動作します。
  • FVWM - 動作します。Xinerama をサポートしており、Single Logical Screen のようなマルチスクリーンディスプレイが使えます。
  • i3 - 動作します。
  • KDE - 動作します。
  • MATE - 動作します。
  • Qtile - 動作します。
  • Spectrwm - 動作します (スクリーンには別々のワークスペースが割り当てられ、キーボードやマウスで切り替えることができます) - 2015年3月現在
  • Xmonad - 動作します (スクリーンには別々のワークスペースが割り当てられ、キーボードやマウスで切り替えることができます) - 2014年4月現在

ディスプレイマネージャ

  • GDM: gdm は gnome のディスプレイ設定が適用されないため、ログイン画面が適切なモニターに表示されないことがあります。対象方法は こちら にあります。ユーザーのモニター設定を gdm の設定にコピーするだけです。
  • KDM: 動作します。

ディスプレイマネージャがマルチディスプレイに対応していない場合、startx~/.xinitrc を使うという方法もあります。

フルスクリーンゲーム

多くのゲームはフルスクリーンで実行したときにウィンドウを (0,0) に表示します。(0,0) にある左のディスプレイでゲームを遊びたくない場合、フルスクリーンのゲームを別のスクリーンに移動することは不可能です。

A workaround for this is to create a separate X11 configuration (a new layout) just for playing games, which may have less (or only one) screen configured. You can then launch games using this separate layout, while normal desktop work uses the original multihead configuration.

To create a new layout, copy /etc/X11/xorg.d/90-serverlayout.conf and call it 91-serverlayout-gaming.conf. It is important to use a number larger than 90, as the one with the lowest number will become the default used when you first load X.

Adjust this new configuration file to your preferred gaming configuration. Here is an example (based on the example Xinerama configuration above) with only one screen defined, noting that the screen specifics (such as resolution) are defined in other files and are unchanged from and shared with the normal configuration:

/etc/X11/xorg.conf.d/91-serverlayout-gaming.conf
# New screen layout only using a single screen called "Primary"
Section "ServerLayout"
    Identifier   "Gaming"
    Screen       0 "Primary" Absolute 0 0
EndSection
ヒント: While it's easiest to just reuse the existing screen definitions, you can of course define new ones if you wish to have a different set of screen resolutions available.

この新しいレイアウトを使用するには、startx スクリプトを使ってゲームを起動します:

# Launch Xonotic on a new X11 display using the "Gaming" layout
startx /usr/bin/xonotic-glx -fullscreen -- :1 -layout Gaming

ノート:

  • 実行するコマンドはフルパスで指定してください。上記の場合 /usr/bin/xonotic-glx です。
  • The :1 must refer to an empty unused display. The first display you are likely using for your desktop is :0, so :1 will be fine for most people. But should you want to launch a second game at the same time, you would have to change this to :2.
  • Just as you can switch between text consoles with Alt+Ctrl+F1 and back to X with Alt+Ctrl+F7, the new display will sit on Alt+Ctrl+F8. So you can switch back to your desktop with Alt+Ctrl+F7 and back to the game with Alt+Ctrl+F8. This is because you are running an independent X desktop, so if you switch out of the game with Alt+Tab or equivalent there will be an empty desktop with no window manager running.

参照