3

Every time I turn on my laptop and plug in my external monitor via HDMI, I need to go to the display settings to adjust the default settings. On start-up, I get a duplicated screen instead of the extended screen that I want. I also get my external monitor on the right when I always put it on the left. How can I make it so that by default it stays extended and on the left? Yes, I always put "apply" and "keep this configuration", but it seems to reset on startup.

xrandr output with the monitor set up exactly how I want:

Screen 0: minimum 8 x 8, current 3520 x 1080, maximum 32767 x 32767
LVDS1 connected primary 1600x900+1920+180 (normal left inverted right x axis y axis) 382mm x 215mm
   1600x900      60.01*+  40.03  
   1440x900      59.89  
   1368x768      60.00  
   1360x768      59.80    59.96  
   1152x864      60.00  
   1280x720      60.00  
   1024x768      60.00  
   1024x576      60.00  
   960x540       60.00  
   800x600       60.32    56.25  
   864x486       60.00  
   800x450       60.00  
   640x480       59.94  
   720x405       60.00  
   640x360       60.00  
DP1 disconnected (normal left inverted right x axis y axis)
DP2 disconnected (normal left inverted right x axis y axis)
DP3 disconnected (normal left inverted right x axis y axis)
HDMI1 disconnected (normal left inverted right x axis y axis)
HDMI2 disconnected (normal left inverted right x axis y axis)
HDMI3 disconnected (normal left inverted right x axis y axis)
VGA1 disconnected (normal left inverted right x axis y axis)
VIRTUAL1 disconnected (normal left inverted right x axis y axis)
DP-1-4 disconnected
HDMI-1-4 disconnected
HDMI-1-5 connected 1920x1080+0+0 510mm x 287mm
   1920x1080     60.00*+  50.00    59.94  
   1920x1080i    60.00    50.00    59.94  
   1280x1024     75.02    60.02  
   1280x960      60.00  
   1280x800      59.91  
   1152x864      75.00  
   1280x720      60.00    50.00    59.94  
   1024x768      75.08    70.07    60.00  
   832x624       74.55  
   800x600       72.19    75.00    60.32    56.25  
   720x576       50.00  
   720x480       60.00    59.94  
   640x480       75.00    72.81    66.67    60.00    59.94  
   720x400       70.08  
  1024x768 (0x55) 65.000MHz -HSync -VSync
        h: width  1024 start 1048 end 1184 total 1344 skew    0 clock  48.36KHz
        v: height  768 start  771 end  777 total  806           clock  60.00Hz
  800x600 (0x59) 40.000MHz +HSync +VSync
        h: width   800 start  840 end  968 total 1056 skew    0 clock  37.88KHz
        v: height  600 start  601 end  605 total  628           clock  60.32Hz
  800x600 (0x5a) 36.000MHz +HSync +VSync
        h: width   800 start  824 end  896 total 1024 skew    0 clock  35.16KHz
        v: height  600 start  601 end  603 total  625           clock  56.25Hz
  640x480 (0x62) 25.175MHz -HSync -VSync
        h: width   640 start  656 end  752 total  800 skew    0 clock  31.47KHz
        v: height  480 start  490 end  492 total  525           clock  59.94Hz
Jacob Vlijm
  • 83,767
  • 1
    It's (kind of) a bug with some driver/screen combinations. Can be worked around. What is the output of xrandr with the screen setup as you want? please add it to your question. – Jacob Vlijm Jul 03 '16 at 17:23
  • @JacobVlijm added the output – whatwhatwhat Jul 03 '16 at 17:28
  • Hi whatwhatwhat, posted. It was done by heart, so please test all before applying :) – Jacob Vlijm Jul 03 '16 at 18:03
  • please mention if all is clear. – Jacob Vlijm Jul 03 '16 at 19:16
  • I have no explanation for that. The command shoud work. Is there any error? Will look at it tomorrow with a fresh mind. – Jacob Vlijm Jul 03 '16 at 20:05
  • @JacobVlijm sorry to bother you but the script is not working. I tested it numerous times. On startup, the screen seems to get it right but then the monitors go black and then it puts it into "mirrored" mode. I see the same screen on both sides. Any idea why this could be happening? – whatwhatwhat Aug 07 '16 at 01:56
  • @JacobVlijm so as a work around I figured out that after I let my laptop boot up (with the script still in place in the startup folder), if I simply go to terminal and runt he script from there it works and my screens are set up nicely. So the script works, just not on startup. Any ideas? – whatwhatwhat Aug 21 '16 at 18:05
  • Hi @whatwhatwhat, ah, the break will be too short, try /bin/bash -c "sleep 30 && python3 /path/to/set_screen.py". Let me know if it works, then I'd undelete the answer. Would appreciate it if you accept it if so. Not just for the points, but it makes clear it works then. – Jacob Vlijm Aug 21 '16 at 18:09
  • Should I try that in the terminal right now or restart my laptop first? – whatwhatwhat Aug 21 '16 at 18:14
  • Log out/in should do. – Jacob Vlijm Aug 21 '16 at 18:15
  • This didn't work. After logging back in, I ran this command in the terminal and after a while it did a few things: 1) narrowed the screen on the laptop to make it thinner than the physical screen. 2) moved the open applications to the external monitor 3) created sticky edges on the laptop screen on both sides so I couldn't move my mouse to the external monitor. – whatwhatwhat Aug 21 '16 at 18:37
  • However, just now after unplugging my external monitor and re-plugging it in, I tried the command xrandr --output HDMI-1-5 --pos 0x0 --output LVDS1 --pos 1920x180 and this worked. So the problem just seems to be in the script. – whatwhatwhat Aug 21 '16 at 18:38
  • Question: Did you try to increase the break? If the script breaks on running too early, it won't run afterwards. – Jacob Vlijm Aug 21 '16 at 18:52
  • I think maybe I was confused. After logging in I just typed that into the terminal. Should I have instead added that to the script? So that when it runs on startup it sleeps for a bit first? – whatwhatwhat Aug 21 '16 at 19:30
  • Simply add the following command to Startup Applications: /bin/bash -c "sleep 30 && python3 /path/to/set_screen.py", as explained in the last section of the answer. – Jacob Vlijm Aug 21 '16 at 19:35
  • Ok, I did that. I notice that the screen seems to flicker very slightly when it runs the script after 30 (I also tried 50) seconds. But it doesn't set it up correctly. The laptop screen is narrow with sticky edges on both sides and I cannot move the mouse to the external monitor. – whatwhatwhat Aug 21 '16 at 20:20

1 Answers1

1

Work around

Screen layouts that do not stick often happens when the graphics driver and the sreen somehow do not communicate in a sufficient way. However, that does not mean there is no solution.

The command to make your setup as you want it, is (if I made no mistake or typo):

xrandr --output HDMI-1-5 --pos 0x0 --output LVDS1 --pos 1920x180

WHy this is the command to do so is explained a.o. here.

How to use

You can use this command in two ways:

1. Manual version (shortcut)

Add it to a shortcut key to press once the second screen is connected: choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:

xrandr --output HDMI-1-5 --pos 0x0 --output LVDS1 --pos 1920x180

2. Automaic version

Run this command automatically if the second screen is connected:

  • Copy the script below into an empty file, save it as set_screen.py

    #!/usr/bin/env python3
    import subprocess
    import time
    
    def numscreens():
        scrdata = subprocess.check_output("xrandr").decode("utf-8").splitlines()
        return len([l for l in scrdata if " connected" in l])
    
    nscr1 = None
    
    while True:
        time.sleep(5)
        nscr2 = numscreens()
        if nscr2 != nscr1:
            if nscr2 == 2:
                subprocess.Popen(["xrandr", "--output", "HDMI-1-5", "--pos", "0x0",
                                  "--output", "LVDS1", "--pos", "1920x180"])
        nscr1 = nscr2
    
  • Test run the script by running it from a terminal:

    python3 /path/to/set_screen.py
    
  • If all works fine, add it to Startup Applications: Dash > Startup Applications > Add. Add the command:

    /bin/bash -c "sleep 30 && python3 /path/to/set_screen.py"
    
Jacob Vlijm
  • 83,767