X.Org/Dual Monitors
Getting X working on multiple monitors used to be difficult, but now it's actually quite easy!
Contents |
[edit] Rely on Auto-Detection
Modern X11 / udev can detect multiple monitors quite well. Before trying any of the below, try connecting your second monitor and restart X without an xorg.conf to see what it achieves without guidance. You will only need to follow this article if that fails.
[edit] Additional Driver-specific Information
The following are links to additional information about specific cards and drivers beyond the information provided below. This information may be useful if the general instructions don't achieve what you are looking for.
[edit] Single, Multi-headed Graphics Card
These instructions set up a single X Screen spanning two physical displays. As such, we define only one Device and one Screen in xorg.conf. This should work for any driver which uses XRandR version 1.2. Modern versions of X.Org can auto-detect most setups, so it's usually best to omit options unless absolutely necessary.
[edit] Fixed Dual-Monitors
For desktop users and other setups where the monitor configuration does not change, we start the X Server with both monitors enabled. This example shows an nVidia card using the open-source nouveau driver, and two horizontally adjacent displays with a resolution of 1280x1024.
First, we calculate the total dimensions of the X Screen. This depends on the physical placement of the two monitors and their individual resolutions. In a side-by-side arrangement, the width of the X screen equals the combined widths of the two monitors (1280+1280=2560) while the height remains unchanged. If the monitors were placed one above the other, then the width would remain the same (1280) while their heights were combined (1024+1024=2048).
In this example, our X Screen has total dimensions of 2560x1024 pixels. This figure will be used in the Virtual field when defining the screen below. Notice also how we define Monitor0 as the primary display and Monitor<wiki>'<wiki> position in relation to it. Other valid position values include Left, Above, and Below.
Section "Monitor" Identifier "Monitor0" Option "Primary" "false" EndSection
Section "Monitor" Identifier "Monitor1" Option "Right" "Monitor0" Option "Primary" "False" EndSection
Section "Device" Identifier "Card" Driver "nouveau" EndSection
Section "Screen"
Identifier "Screen"
Device "Card"
Monitor "Monitor0"
DefaultDepth 24
SubSection "Display"
Modes "1280x1024"
Virtual 2560 1024
EndSubSection
EndSection
If X.Org does not position the displays correctly, there are a few options to help it along:
Section "Device" Identifier "Card0" Driver "nouveau" Option "Monitor-DVI-I" "Monitor0" Option "Monitor-DVI-II" "Monitor1" EndSection
This specifies that the physical out DVI-I be used as Monitor0 and so on. Xrandr can be used to identify output ports
[edit] Occasional Dual-Monitors
If the second monitor is not always present, as in a laptop with an occasionally-used external display, we do not define a second monitor explicitly in xorg.conf, but enable it using xrandr after starting an X session. This example uses a laptop with a 1280x800 built-in display and a radeon graphics card with a VGA port.
Assuming a working single-display setup, the only necessary change is an extra large Virtual value (since we don't necessarily know how big the X Screen will be).
Section "Screen"
Identifier "Screen0"
Device "Card0"
Monitor "Monitor0"
DefaultDepth 24
SubSection "Display"
Modes "1280x800"
Virtual 4096 4096
EndSubSection
EndSection
As always, changes to xorg.conf require restarting the X session.
After physically connecting the second screen, enable it using xrandr:
If it doesn't autoconfig to your satisfaction, identify and manually specify the screen and its position:
If you get errors, confirm that RandR is enabled:
[edit] Graphical RandR tools
Gnome users should use System -> Preferences -> Display.
KDE Users should use: K -> System -> Krandr
Other tools include:
- x11-misc/arandr -- Graphical Screen layout, orientation, resolution tool.
- lxde-base/lxrandr -- Basic. Allows changing resolution and enabling/disabling monitors
- x11-misc/grandr -- Buggy, but feature-rich
[edit] Multiple Graphics Cards
[edit] Prerequisites
If you are using two graphics cards it is quite quick and easy to make a new xorg.conf for your new cards. (Remember to back your current one up first!)
First, disable X from starting at boot by running:
[edit] Switching Primary Card
When you install both cards, you may find that your computer has chosen the wrong one as the primary card (the one that your bios information shows up on).
If you're using two different card interfaces, such as PCI and AGP, you may be able to switch their order in your BIOS. If not, you can always switch the cables!
- In AWARD BIOS (v4.51PG), menu: Integrated Peripherals -> Init Display First -> [PCI Slot / AGP]
- In AMIBIOS (v 08.00.08), menu: PCIPnP -> PCI Bus Scan Order -> [Ascent/Descent]
- In other BIOSs it's called: Bios First Boot -> [AGP/PCI]
[edit] ATI Crossfire
See the radeon or fglrx guide depending on your chosen driver.
[edit] Configuring X
In most cases, it is simplest to let X do as much auto-configuring as possible. To that end, use as bare-bones an xorg.conf as you can, such as the one below Change the graphics card drivers to suit your setup.
... Section "Monitor" Identifier "LeftMonitor" EndSection ... Section "Monitor" Identifier "RightMonitor" EndSection ... Section "Device" Identifier "LeftCard" Driver "nvidia" EndSection ... Section "Device" Identifier "RightCard" Driver "ati" EndSection ... Section "Screen" Identifier "LeftScreen" Device "LeftCard" Monitor "LeftMonitor" DefaultDepth 24 EndSection ... Section "Screen" Identifier "RightScreen" Device "RightCard" Monitor "RightMonitor" DefaultDepth 24 EndSection ...
[edit] Positioning X Screens
The layout can be specified using keywords or absolute pixel positions. In this example, "LeftScreen" is located at position 0,0 with "RightScreen" to its right.
... Section "ServerLayout" Identifier "My X Server" Screen 0 "LeftScreen" 0 0 Screen 1 "RightScreen" RightOf "LeftScreen" EndSection
The useable keywords are "RightOf <identifier>", "LeftOf <identifier>", "Above <identifier>", and "Below <identifier>". A special keyword is "Relative" - it is used to specify the position in pixels of a screen in relation to another screen. For instance:
... Section "ServerLayout" Identifier "My X Server" Screen 0 "LeftScreen" 0 0 Screen 1 "RightScreen" Relative "LeftScreen" 1024 40 EndSection ...
So, try starting the X server using your test configuration file again. Verify that the mouse can move from screen-to-screen in a relatively intuitive manner, and that your resolution and refresh rate is right. You can then copy your configuration file overtop of your old xorg.conf.
[edit] Using Multiple screens
With the way I have the X configuration set above, you are given two separate "screens". Using multiple screens in this way gives advantages mainly in terms of speed and hardware acceleration, and in allowing different colour depths on different screens. Another advantage is that your window manager effectively runs independently on each screen, so you can have different configurations on each, or many workspaces on each screen.
The main disadvantage is that you cannot move windows between two screens unless your program has a facility for doing this internally. As well, programs cannot overlap screens or stretch over all of them.
The DISPLAY environment variable on an X Server running multiple screens has the format ":0.0". The ":0" refers to the server number, and the following digit refers to the screens (counting from zero, of course).
To make an application run on a different screen than it would normally start on, run it as[edit] Moving focus between screens
Moving the mouse pointer between screens can be accomplished by dragging it over the edge of one onto the next. If you are interested in a tool to do this from the command-line, read the switchscreen article.
[edit] Controlling your window manager
The program x11-misc/wmctrl can be used manually or within scripts to change workspaces and windows on either screen. KDE in particular takes control over all available X screens. If you do not want this behaviour, read the KDE Dual Monitors guide
[edit] Xinerama
With Xinerama, both monitors are formed into one virtual screen. Apps can move over it, and windows can overlap. Some programs that use e.g. fullscreen may not work correctly unless they are recompiled with "xinerama" added to your USE flags.
If you want/need features that you don't get with multiple screens, you can have them by using Xinerama, but at the expense of speed and causing problems with some hardware accelerated apps.
To enable Xinerama, add the following new section to your X configuration file:
Section "ServerFlags" Option "Xinerama" "true" EndSection
Note that both monitors must run at the same color depth, or X may not start. If one of your graphics cards is limited in memory, you can either lower the resolution on it, or lower the color depth on both monitors.
Enabling xinerama support in an application allows it to know where monitor bounderies are. E.g. in metacity (the gnome window manager), it enables better placement of newly opened windows, and keeps windows on the screen better.
USE="$USE xinerama"
[edit] Troubleshooting
- /etc/init.d/xdm stop
- If Xdm won't start because it thinks it's already running, but you know it isn't, use the following command to reset its state: /etc/init.d/xdm zap
- control-alt-f7 switches to vt7 (virtual terminal), which is where X usually resides.
- control-alt-f1 (f1..f6) get to those virtual terminals
- control-alt-backspace will kill the current x session
- elinks if your x stops working, this web browser works pretty well
- You can specify a different config file to the default (/etc/X11/xorg.conf) using: startx -config <config_file>
- X can be a real pain about mice, it might not be starting because your mouse device isn't set correctly (usually /dev/input/mice)
- A second X sesssion can be started using the following command. Note that it will spawn on the next available vt (usually vt8): startx -- :1
If you have problems with windows spanning across your dual or triple monitors, or you seem to notice that your windows don't seem to "snap" to your screens, you probably haven't compiled your favorite window manager with the xinerama use flag. (if it supports it, that is). When you compile or recompile your window manager (eg. Gnome's Metacity) with the xinerama use flag, your windows will only maximize to one screen. This is a small, but important issue that people tend to overlook at first (including myself).
- If you have trouble reading text on your TV, try reducing the resolution using xrandr. x11-misc/arandr can be a useful frontend for this.
[edit] Mouse Trouble
See the Dual Monitors Mouse guide for information.