There are 2 basic approaches you can take. The first is to utilize randr which will allow you to create one large virtual display in which you can position your monitors. The second is to utilize xinerama which will allow you to have 2 separate X screens which will function as one large display. I will cover both here and you can decide which is more appropriate for your needs.
RandR - Resize and Rotate
You can dynamically enable dual head by using XRandR
xrandr --output foo --above bar
There is also a gui frontend for this called arandr which is in the 12.04 repos, but it would seem that you want a more static configuration.
It could be as simple as creating /etc/X11/xorg.conf.d/10-monitor.conf with the contents:
Section "Monitor"
Identifier "Monitor0"
EndSection
Section "Monitor"
Identifier "Monitor1"
Option "Above" "Monitor0"
EndSection
This method implies an randr setup. There are some notable drawbacks if using xrandr with monitors of different resolutions. Windows may be improperly placed, there may be black areas on one screen, etc..
When you run xrandr without command line options you can find out which Identifier you need to use in your 10-monitor.conf. Then restart Ubuntu to see if the settings are loaded.
Xinerama
To enable xinerama you need to modify
/etc/X11/xorg.conf:
Section "ServerFlags"
Option "Xinerama" "true"
EndSection
It might be as simple as that as X is pretty good about automagically configuring things based on hardware detection. But, if simply turning the xinerama extension on does not provide the functionality you desire, you may opt to fully configure X to use xinerama. There are a few ways to configure X. You could have multiple files in /etc/X11/xorg.conf.d/, some for your monitors, some for the devices, etc. I will cover having a single xorg.conf file that contains all the settings using a modified version of my current setup.
Section "ServerLayout"
Identifier "DualHead"
Screen 0 "Screen0" 0 0
Screen 1 "Screen1" Above "Screen0"
Option "Xinerama" "1" # You can specify xinerama here
EndSection
Section "Device"
Identifier "Device0" # A Device section for each monitor
Driver "nvidia" # Specify the driver to use
VendorName "NVIDIA Corporation"
BoardName "GeForce GT 430"
BusID "PCI:1:0:0" # Use lspci | grep VGA to find BusID
Screen 0 # Do note the screen number
EndSection
Section "Device"
Identifier "Device1"
Driver "nvidia"
VendorName "NVIDIA Corporation"
BoardName "GeForce GT 430"
BusID "PCI:1:0:0"
Screen 1 # Do note the screen number
EndSection
Section "Monitor"
Identifier "Monitor0"
VendorName "Unknown"
ModelName "Gateway HX2000"
HorizSync 31.0 - 83.0
VertRefresh 56.0 - 76.0
Option "DPMS"
EndSection
Section "Monitor"
Identifier "Monitor1"
VendorName "Unknown"
ModelName "DELL 1907FPV"
HorizSync 30.0 - 81.0
VertRefresh 56.0 - 76.0
Option "DPMS"
EndSection
Section "Screen"
Identifier "Screen0"
Device "Device0"
Monitor "Monitor0"
DefaultDepth 24
EndSection
Section "Screen"
Identifier "Screen1"
Device "Device1"
Monitor "Monitor1"
DefaultDepth 24
EndSection
Obviously you will need to modify this to suit your hardware, but the basic skeleton is there for you.
Do note that I have recently read that Intel might have issues with xinerama. You may find yourself needing to utilize your discrete graphics card.
You have to make two scrips to achieve your goal.
one to switch both external displays on and turn off your laptop display.
and the other to revert the change made by script one.
So create script1.sh
and make it executable with following contents.
#!/bin/bash
xrandr --output LVDS-1 --off
xrandr --output VGA-1 --mode 1920x1080 --auto
xrandr --output HDMI-1 --mode 1920x1080 --auto
and script2.sh
with following contents and make this too executable.
#!/bin/bash
xrandr --output VGA-1 --off
xrandr --output HDMI-1 --off
xrandr --output LVDS-1 --mode 1366x768 --auto
You can run the scipt1.sh
after connecting the external displays and you have to run the script2.sh
before removing the external displays.
Note that the above method will mirror your screen to two separate screens at the same time. And if you need a separate screen rather than mirroring, you can use either --left-of
or --right-of
option and provide device names accordingly.
And also you can check if your hardware supports three displays at the same time by turning on the laptop display along with the two monitors.
Best Answer
If you use NVIDIA drivers you must change your settings from there.I would recommend using
xrand
command to change your settings, you can make auto run script or a key combination to switch between settings usingxrand
command.Edit: To fix it set
IgnoreLid=true
in/etc/UPower/UPower.conf
file!