My VGA output (VGA-1 is configured to be at the right of my main screen (LVDS-1).

How can I configure my system for my VGA ouput to be above my main screen by default?


To put my VGA above, I use

xrandr --output VGA-1 --auto --above LVDS-1
  • You mean the issue is that it will not restore this whenever VGA-1 is disconnected and reconnected? – Jacob Vlijm Nov 14 '16 at 14:23
  • Everytime I branch the VGA, the new screen goes at the right of my main default computer screen. I want it to be automatically be above instead of on the right. Thank you – user618632 Nov 14 '16 at 14:32
  • Did it not work properly in 'System Settings'? – WinEunuuchs2Unix Nov 14 '16 at 16:00
  • @WinEunuuchs2Unix that should work, but not always does, due to miscommunication between grapics driver and screen. – Jacob Vlijm Nov 14 '16 at 16:09

The issue that the screen layout doesn't stick is most likely the result of a minor bug, however:

You have two options:

1. Run a background script to run your command automatically once the second screen is connected:

#!/usr/bin/env python3
import subprocess
import time

#--- set both commands (connect / disconnect) below
connect_command = "gedit"
disconnect_command = ""

# function to get the output of xrandr
def get(cmd): return subprocess.check_output(cmd).decode("utf-8")
# - to count the occurrenc of " connected "
def count_screens(xr): return xr.count(" connected ")
# - to run the connect / disconnect command(s)
def run_command(cmd): subprocess.Popen(cmd)

# first count
xr1 = count_screens(get(["xrandr"]))

while True:
    # second count
    xr2 = count_screens(get(["xrandr"]))
    # check if there is a change in the screen state
    if xr2 != xr1:
        if xr2 == 2:
            # command to run if connected (two screens)
            run_command(["xrandr", "--output", "VGA-1", "--auto", "--above", "LVDS-1"])
        elif xr2 == 1:
            # command to run if disconnected (one screen)
            # uncomment run_command(disconnect_command) to enable, then also comment out pass
            # run_command(disconnect_command)
    # set the second count as initial state for the next loop
    xr1 = xr2

The script is an outtake of this one.

To use it

  • Copy the script into an empty file, save it as setup_scr.py
  • Test-run it by the command:

    python3 /path/to/setup_scr.py
  • If all works as it should, add to Startup Applications: Dash > Startup Applications > Add. Add the command:

    /bin/bash -c "sleep 15 && python3 /path/to/setup_scr.py"

2. Simply add the command to a shortcut, press it after you connect the second screen:

Add shortut key: Choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:

python3 /path/to/setup_scr.py


  • The script covers both running commands on connect- and disconnecting a screen, I left it as it was, so you have extra options.
  • I couldn't test, since I don't have a second screen attached currently. It should work fine, but I am sensitive to blind spots and typos...
  • The script, as it is, assumes no errors will occur, which means the defined screen should be the only (external) screen you use. If that is not the case, we should build in either a conditional or a try/except. If so, please mention.

    In case of errors, please let me know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy