Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a laptop with two video outputs that I use when I am home (HDMI1,VGA1). To enable them, I do this:

xrandr --output HDMI1 --right-of LVDS1 --auto
xrandr --output LVDS1 --off
xrandr --output VGA1 --right-of HDMI1 --auto

When I want to go to work, I take my laptop but first run the following:

xrandr --output VGA1 --off
xrandr --output LVDS1 --left-of HDMI1 --auto
xrandr --output HDMI1 --off

And then this leaves my laptop display active just like it should.

The problem I am encountering is that sometimes I don't remember to disable the two screens before taking my computer to work. When I arrive, I try various combinations of --output and --off but I cannot get my screen re-enabled.

This is the output I get running xrandr with nothing displayed:

Screen 0: minimum 320 x 200, current 3840 x 1080, maximum 8192 x 8192
LVDS1 connected (normal left inverted right x axis y axis)
   1366x768       60.0 +
   1024x768       60.0··
   800x600        60.3     56.2··
   640x480        59.9··
VGA1 disconnected 1920x1080+1920+0 (normal left inverted right x axis y axis) 0mm x 0mm
HDMI1 disconnected 1920x1080+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
DP1 disconnected (normal left inverted right x axis y axis)
  1920x1080 (0x4c)  148.5MHz
        h: width  1920 start 2008 end 2052 total 2200 skew    0 clock   67.5KHz
        v: height 1080 start 1084 end 1089 total 1125           clock   60.0Hz

Almost every command I've tried returns:

xrandr: Configure crtc 2 failed
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  140 (RANDR)
  Minor opcode of failed request:  21 (RRSetCrtcConfig)
  Serial number of failed request:  40
  Current serial number in output stream:  40

It's like the two monitors aren't giving up their CRTC and since my hardware only supports 2, it's locked in until I plug those monitors in and disable them.

share|improve this question

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"` ]
    xrandr --output DP2 --off --output DP1 --off --output HDMI2 --off \
        --output HDMI1 --off \
        --output LVDS1 --mode 1366x768 --pos 0x0 --rotate normal \
        --output VGA1 --off
    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

it's not a fancy script but may work for you.

share|improve this answer

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).

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .