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?
PS:
To put my VGA above, I use
xrandr --output VGA-1 --auto --above LVDS-1
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?
PS:
To put my VGA above, I use
xrandr --output VGA-1 --auto --above LVDS-1
The issue that the screen layout doesn't stick is most likely the result of a minor bug, however:
You have two options:
#!/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:
time.sleep(5)
# 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
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.
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"
Add shortut key: Choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:
python3 /path/to/setup_scr.py
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.