Ubuntu – Script display settings: xrandr

displaylenovomultiple-monitorsxrandrxubuntu

I would really like to be apply my display settings (currently managed with xrandr) on an automated basis after plugging in my display. I assumed this could be done with a Bash script, however I have not found a way to get a handle on display settings from the terminal.

After connecting an HDMI external monitor, I have to use the 'Display Settings' GUI to activate and configure the monitor. This would not be a big deal, except checking 'Use this output' doesn't always take the first time (the 'keep this configuration' dialog pops up, but the display remains inactive), I have to use the 'advanced' settings to rearrange the two displays, and this has to be done every time I wake the machine from sleep.

I wanted to look into scripting some of these settings with xrandr, but I can't get xrandr commands to work on the HDMI display.

$ xrandr --output HDMI1 --mode 1920x1080

..flashes the built in display and pops up the Display settings GUI (if 'Configure new displays when connected' is checked in the GUI, flashes output and does nothing if not).

xrandr -d :0 output HDMI1 --auto

does the same thing. I've also tried the 'arandr' GUI. Not sure what commands it runs, but they do the same thing also.

  • Xubuntu 15.04
  • xfce 4.12
  • Lenovo Yoga 13 intel i5
  • Intel HD Graphics 4000
  • Samsung 27" SyncMaster SA550 external display

xrandr output:

Screen 0: minimum 8 x 8, current 3520 x 1346, maximum 32767 x 32767
LVDS1 connected primary 1600x900+0+446 (normal left inverted right x axis y axis) 294mm x 166mm
   1600x900       60.1*+
   1440x900       59.9  
   1360x768       59.8     60.0  
   1152x864       60.0  
   1024x768       60.0  
   800x600        60.3     56.2  
   640x480        59.9  
DP1 disconnected (normal left inverted right x axis y axis)
HDMI1 connected 1920x1080+1600+0 (normal left inverted right x axis y axis) 509mm x 286mm
   1920x1080      60.0*+   50.0     59.9  
   1680x1050      59.9  
   1280x1024      60.0  
   1440x900       59.9  
   1280x800       59.9  
   1152x864       75.0  
   1280x720       60.0     50.0     59.9  
   1024x768       70.1     60.0  
   800x600        60.3     56.2  
   720x576        50.0  
   720x480        60.0     59.9  
   640x480        66.7     60.0     59.9  
   720x400        70.1  
VGA1 disconnected (normal left inverted right x axis y axis)
VIRTUAL1 disconnected (normal left inverted right x axis y axis)

Edit: xrandr output before adjusting with gui:

(Not sure if it's relevant, but if I plug in the display and don't configure immediately, the xfce4-display-settings guis/processes begin to pop up every few seconds endlessly. The power management 'Blank after x minutes' kicked in yesterday with a different hdmi display plugged in and there were about 50 'Displays' windows open when I resumed use.)

Screen 0: minimum 8 x 8, current 1600 x 900, maximum 32767 x 32767
LVDS1 connected primary 1600x900+0+0 (normal left inverted right x axis y axis) 294mm x 166mm
   1600x900       60.1*+
   1440x900       59.9  
   1360x768       59.8     60.0  
   1152x864       60.0  
   1024x768       60.0  
   800x600        60.3     56.2  
   640x480        59.9  
DP1 disconnected (normal left inverted right x axis y axis)
HDMI1 connected (normal left inverted right x axis y axis)
   1920x1080      60.0 +   50.0     59.9  
   1680x1050      59.9  
   1280x1024      60.0  
   1440x900       59.9  
   1280x800       59.9  
   1152x864       75.0  
   1280x720       60.0     50.0     59.9  
   1024x768       70.1     60.0  
   800x600        60.3     56.2  
   720x576        50.0  
   720x480        60.0     59.9  
   640x480        66.7     60.0     59.9  
   720x400        70.1  
VGA1 disconnected (normal left inverted right x axis y axis)
VIRTUAL1 disconnected (normal left inverted right x axis y axis)

Best Answer

After setting the screen via GUI

In the line (in the output of xrandr after you set the screen via GUI):

HDMI1 connected 1920x1080+1600+0 (normal left inverted right x axis y axis) 509mm x 286mm

the position of the second screen (HDMI1) is defined top-allined, at he the right of your main screen (LVDS1): 1920x1080+1600+0, as explained here.

Before setting the screen via GUI

The definition of the position of your right screen seems to be missing for some reason.

I am not sure what causes the behaviour, might be a minor incompatibility, but it should be fixed with the command:

xrandr --output HDMI1 --pos 1600x0

Which will position the second screen at the right of the main screen, top- allined.