How to modify the default setting adopted by xrandr when connecting an external monitor

displaydisplay-settingsmonitorsmulti-monitorxrandr

I am confronted with a problem when connecting the external monitor while the computer is open.

At that point it seems that xrandr adopts one of the combinations that do not work.

As a workaround to the other larger problem, I want to be able to modify the default display settings that xrandr has upon connecting the external monitor while the computer is running. (So that I may put a setting that avoids the problem: either by a combination of resolutions that works, or by starting just one of the monitors).

If I connect the external monitor before starting the system, xrandr selects mirror display at a certain rather low resolution that works.


Update:

xrandr
Screen 0: minimum 320 x 200, current 1360 x 768, maximum 4096 x 4096
VGA-0 connected 1360x768+0+0 (normal left inverted right x axis y axis) 580mm x 320mm
   1360x768       60.0*+
   1280x720       60.0  
   1024x768       60.0  
   800x600        60.3  
   640x480        60.0  
DVI-0 disconnected (normal left inverted right x axis y axis)
LVDS connected (normal left inverted right x axis y axis)
   1680x1050      60.1 +
   1400x1050      60.0  
   1280x1024      59.9  
   1440x900       59.9  
   1280x960       59.9  
   1280x854       59.9  
   1280x800       59.8  
   1280x720       59.9  
   1152x768       59.8  
   1024x768       59.9  
   800x600        59.9  
   848x480        59.7  
   720x480        59.7  
   640x480        59.4  
S-video disconnected (normal left inverted right x axis y axis)

When I connect the external desktop I want to use it at its best resolution (which, considering my other problem, excludes the use of the internal monitor). I can set from GUI the resolution for dual monitor. But upon connecting the cable for the external monitor, I want the internal to go off and the external to have 1360×768 – just like they were when I ran the xrandr command above.

Best Answer

I don't know exactly how to write a default setting for xrandr when you connect an external monitor, but you can easily write a custom script and then associate it to a shortcut key, such as meta + P.

Example

> nano  /usr/bin/custom-xrandr
#!/bin/bash
xrandr --output VGA1 --off --output HDMI1 --auto

> chmod u+x /usr/bin/custom-xrandr

Then associate some shortcut to /usr/bin/custom-xrandr and every time you connect an external monitor just press that keys.

This should achieve exactly what you want.

Related Question