Disable Unplugged Displays (xrandr)
Solution 1:
You can put all your configuration in just one command, like:
xrandr --output VGA1 --off --output HDMI1 --off --output LVDS1 --left-of HDMI1 --auto
and that should make the work, also since is a hard to write command (to long) you can create a script that test for the currently attached screens and make the desired setup. (you can added to a key shortcut)
if [ -z `xrandr --query | grep "HDMI1 connected"` ]
then
xrandr --output DP2 --off --output DP1 --off --output HDMI2 --off \
--output HDMI1 --off \
--output LVDS1 --mode 1366x768 --pos 0x0 --rotate normal \
--output VGA1 --off
else
xrandr --output DP2 --off --output DP1 --off --output HDMI2 --off \
--output HDMI1 --mode 1920x1080 --pos 0x0 --rotate normal --primary \
--output LVDS1 --off --output VGA1 --off
fi
it's not a fancy script but may work for you.
Solution 2:
I know this is a super old thread but I wanted to share how I solved the problem, using your information about turning monitors on and off and then disconnecting them. I used a program called autorandr and basically just set up my display with two monitors, then autorandr --save docked
. Then I used that xrandr --output VGA --off
, then unplugged my monitor, followed by autorandr --save mobile
. Autorandr automatically will switch between different modes depending on what you have plugged in or unplugged. Hopefully that helps anyone else who stumbles upon this! Also this is like my first real answer so let me know if I can change anything to be more clear.
Solution 3:
There doesn't appear to be an event generated when a screen is unplugged unfortunately. having a script poll xrandr is quite heavy but you could look into /sys/class/drm/*/status and poll those files then take the required xrandr action when the status changes from 'connected' to something else (or disappears entirely).