22

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.

3 Answers3

14

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.

Agomezl
  • 430
5

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.

1

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

Cwissy
  • 321