xrandr extend display settings

14,057

Solution 1

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.

Solution 2

I'm now using this. It works on Xubuntu with awesome-wm. These xrandr functions switch monitors and lets the wm move the tags which are like alt desktops; that are shown as folder tabs along the top edge. As in my case sometimes the window manager doesn't like being told to pack it up and move.

The idea is to restart the Window Manager before you move screens again. So each time you call xrandr make sure to restart the window manager.

I'm using my ZSH shell

put these lines in your .zshrc or it may work in bashrc as well but, I havn't tried that.

switch1() {
    xrandr --output VGA1 --mode 1920x1080 --primary --output HDMI-1 --mode 1920x1080 --left-of LVDS1 --output LVDS1 --mode 1280x800 --left-of VGA1;
    sleep 2;
    echo 'customization.orig.restart()' | awesome-client;
    xrandr --output VGA1 --mode 1920x1080 --output HDMI-1 --mode 1920x1080 --left-of LVDS1 --output LVDS1 --primary --mode 1280x800 --left-of VGA1;
    sleep 2;
    echo 'customization.orig.restart()' | awesome-client;
    xrandr --output VGA1 --off --output HDMI1 --off;
    echo 'customization.orig.restart()' | awesome-client;
    sleep 1;
}

switch2() {
    xrandr --output VGA1 --mode 1920x1080 --output HDMI-1 --mode 1920x1080 --left-of LVDS1 --output LVDS1 --primary --mode 1280x800 --left-of VGA1;
    sleep 2;
    echo 'customization.orig.restart()' | awesome-client;
    xrandr --output VGA1 --mode 1920x1080 --primary --output HDMI-1 --mode 1920x1080 --left-of LVDS1 --output LVDS1 --mode 1280x800 --left-of VGA1;
    sleep 2;
    echo 'customization.orig.restart()' | awesome-client;
    xrandr --output LVDS1 --off;
    echo 'customization.orig.restart()' | awesome-client;
    sleep 1;
}

Next explaining the customization.orig.restart() is just a special part I had. The AwesomeWM function awesome.restart() would work insteed for those not using a modified rc.lua configuration.

Just so you have it all I found this discussion about moving tags to new screen and used the named tag mover functions found here which can go anywhere in the rc.lua or include a custom.lua file for extra functions you might add. Make sure a custom.lua is included in the rc.lua file.

Share:
14,057

Related videos on Youtube

P75
Author by

P75

Updated on September 18, 2022

Comments

  • P75
    P75 over 1 year

    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 ;(