Dual monitor problem

Michal Srb msrb at suse.com
Mon Apr 9 07:50:53 UTC 2018


On sobota 7. dubna 2018 23:13:48 CEST Leslie Katz wrote:
> I have a laptop that I usually connect to an external monitor. I use
> Ubuntu 16.04 and Gnome 3.18.5. When I do connect to the external
> monitor, I like to turn the laptop screen off. I can do that by going to
> System Settings, Screen Display, selecting the built-in display and then
> clicking "off". I'd like to automate the process. I found a script that
> claimed to do that at startup. It's as follows:
> 
> #!/bin/bash
> 
> sleep 15
> 
> EXTERNAL_OUTPUT="DP1"
> INTERNAL_OUTPUT="eDP1"
> 
> xrandr |grep $EXTERNAL_OUTPUT | grep " connected "
> if [ $? -eq 0 ]; then
>      xrandr --output $INTERNAL_OUTPUT --off --output $EXTERNAL_OUTPUT
> --auto
> else
>      xrandr --output $INTERNAL_OUTPUT --auto --output $EXTERNAL_OUTPUT --off
> fi
> 
> I made the script a startup application.
> 
> It works as advertised when the external monitor is connected. However,
> when the external monitor is not connected, I first see my desktop on
> the laptop screen as I would like it. Then, when the script wakes up and
> runs, the bottom panel on my desktop suddenly jumps to the top of the
> screen and comes to rest immediately below the top panel. I can't find
> any reports of this happening to anyone else.
> 
> If anyone could explain to me why the script is causing this behavior
> and tell me how to correct it, I'd be very grateful.

If there is no external output the script reconfigures the internal output and 
disables the external output. I can't explain why the desktop environment 
reacts to it the way it does, but maybe you could just drop the whole else 
branch so nothing happens if there is no external output.

So it would look somehow like this:

...

xrandr |grep $EXTERNAL_OUTPUT | grep " connected "
if [ $? -eq 0 ]; then
     xrandr --output $INTERNAL_OUTPUT --off --output $EXTERNAL_OUTPUT --auto
fi

...

Michal Srb


More information about the xorg mailing list