How to enable auto-screen update on monitor plug-in/out on Lubuntu (Also, how can this be achieved in Ubuntu)?

7,914

Solution 1

It is probably a Gnome or Unity feature which is absent from LXDE. You could probably write a udev rule to do this on monitor disconnect.

I have written a little script that will detect the monitors and extend accordingly:

#!/usr/bin/env bash

xrandr | grep VGA | grep -w connected >/dev/null
echo $?
if [[ "$?" -lt 1 ]]
then
    notify-send "Extending desktop to VGA screen"
    xrandr --output DP-3 --auto --output VGA-0 --auto --right-of DP-3 --primary
else
    xrandr | grep DP-2 | grep connected >/dev/null
    if [[ "$?" -gt 0 ]]
    then
    notify-send "Extending desktop to DisplayPort screen"
    xrandr --output DP-3 --auto --output DP-2 --auto --right-of DP-3 --primary
    else
    notify-send "No known screens found"
    fi

fi

You need to have xrandr installed but you almost certainly do. You will also need to change the monitor names accordingly (in my case I switch between an external VGA and and external Display Port display). Run xrandr with your external screen connected to getthe right name or update your question with the output of xrandr and I can help you with it.

I have mapped this script to be run with a keyboard shortcut and simply run it whenever I connect or disconnect a screen.

Solution 2

You can use autorandr to save both settings and let autorandr change the settings when you plug/unplug your screen. If it does not work automatically, use autorandr -c to force detection of the current setting.

Share:
7,914

Related videos on Youtube

Shwouchk
Author by

Shwouchk

Updated on September 18, 2022

Comments

  • Shwouchk
    Shwouchk over 1 year

    I have a laptop which I want to have connected to an external monitor 99% of the time. The other 1% I would use its screen. I want the laptop to be closed (usually) to save space, and to use external KB/mouse. The external monitor supports a higher resolution than the laptop screen, so I won't use screen duplication, and extended desktop is annoying when one of the monitors can't be viewed, so also out of the question.

    Is there a simple way to enable the external only configuration, but that would switch to the internal monitor when the external monitor is disconnected, like regular Ubuntu/Windows/etc provide?

    In addition/alternatively, What software does regular Ubuntu or other linux distros use to enable this?

  • Shwouchk
    Shwouchk over 10 years
    Thanks! I also found this github repository which I like better since there is no polling. I will accept your answer nevertheless, since it provides a solution!