Ubuntu – xrandr extend display settings

displayhdmimultiple-monitorsxrandr

I have an old laptop Lenovo E330, running Xubunu 16.04

I have connected 2 external displays to it, one with VGA, and other with HDMI cable.

I'm trying to write a simple command to extend my desktop to two external displays, the lid will stay closed, so i will run only 2 display simultaneously.

    Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 8192 x 8192
LVDS-1 connected primary 1366x768+0+0 (normal left inverted right x axis y axis) 293mm x 165mm
   1366x768      60.03*+
   1360x768      59.80    59.96  
   1024x768      60.04    60.00  
   960x720       60.00  
   928x696       60.05  
   896x672       60.01  
   960x600       60.00  
   960x540       59.99  
   800x600       60.00    60.32    56.25  
   840x525       60.01    59.88  
   800x512       60.17  
   700x525       59.98  
   640x512       60.02  
   720x450       59.89  
   640x480       60.00    59.94  
   680x384       59.80    59.96  
   576x432       60.06  
   512x384       60.00  
   400x300       60.32    56.34  
   320x240       60.05  
VGA-1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 477mm x 268mm
   1920x1080     60.00*+
   1680x1050     59.95  
   1280x1024     75.02    60.02  
   1440x900      74.98    59.89  
   1024x768      75.03    60.00  
   800x600       75.00    60.32  
   640x480       75.00    72.81    66.67    59.94  
   720x400       70.08  
HDMI-1 connected (normal left inverted right x axis y axis)
   1920x1080     60.00 +
   1680x1050     59.88  
   1280x1024     75.02    60.02  
   1440x900      74.98    59.90  
   1024x768      75.03    60.00  
   800x600       75.00    60.32  
   640x480       75.00    72.81    66.67    59.94  
   720x400       70.08  
DP-1 disconnected (normal left inverted right x axis y axis)

The command should be something simple like one of these.

xrandr --auto --output VGA-1 --mode 1920x1080 --right-of HDMI-1

or

xrandr --output LVDS-1 --off  
xrandr --output VGA-1 --mode 1920x1080
xrandr --output HDMI-1 --mode 1920x1080

How should the correct script look like ?

Is it possible to enable laptop screen after I disconnect the external displays? Because currently it stays of even when I disconnect the external displays and restart the system ;(

Best Answer

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.

Related Question