0

How do you save a monitor configuration based on how many displays are available on a laptop?

I have a laptop that I often use with and without an external monitor. When I connect the monitor, Gnome-Shell automatically reconfigures to use the second display, but it always places the laptop's screen to the left. I have it physically located to the right, so I use the Displays dialog to move it. However, this is lost every time I unplug the display or suspend and resume the laptop.

This is similar to this question but I don't want to hard-code my Xorg/Xrandr setup to force dual displays because I often use the laptop without a monitor. I just want it to automatically place my laptop's screen to the right whenever I plug in the external monitor.

Edit: Output of xrandr with external monitor setup.

Screen 0: minimum 8 x 8, current 3200 x 1080, maximum 8192 x 8192
LVDS-0 connected primary 1280x800+1920+0 (normal left inverted right x axis y axis) 286mm x 179mm
   1280x800       60.2*+
DP-0 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 510mm x 290mm
   1920x1080      60.0*+
   1680x1050      60.0  
   1280x1024      75.0     60.0  
   1280x960       60.0  
   1152x864       75.0  
   1024x768       75.0     60.0  
   800x600        75.0     60.3     56.2  
   640x480        75.0     59.9  
DP-1 disconnected (normal left inverted right x axis y axis)
Cerin
  • 6,485

1 Answers1

3

The solution exists of two parts:

1. create a small script to arrange the screens

You should think of your combined screens as one combined virtual screen, as explained here.
To arrange two screens into the combined virtual screen, you need to arrange them from left to right. In your case:

to place the left screen on 0,0:

xrandr --output DP-0 --pos 0x0

to place the right screen (your build in screen):

xrandr --output LVDS-0 --pos 1920x0

When we put these two commands in a script:

#/bin/bash
xrandr --output DP-0 --pos 0x0
xrandr --output LVDS-0 --pos 1920x0
  • Copy the script into an empty file, save it as set_screen.sh
  • To use it (after the second screen is connected), run the command:

    /bin/bash /path/to/set_screen.sh
    

    or, if you make it executable:

    /path/to/set_screen.sh
    

Now you have two options, you can either:

  • add the script to a shortcut key: choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command to run the script,

or:

2. Run a script in the background to call the command

As described In the post: Run script when monitor is connected.
Replace in the section:

#--- set both commands (connect / disconnect) below
connect_command = "gedit"

"gedit" by the command to run the script that you created in step 1:

"/bin/bash /path/to/set_screen.sh"

If you add the script in the linked post to your startup applications, you will have your setup to fully automatically arrange your screens if the second monitor is connected.

Jacob Vlijm
  • 83,767