This belongs to Research Software Engineering on Linux series
Super+P shortcut key can bring up a menu to switch between mirror, single, multiple modes.
keep Super key (windows key) pressed on, while P key can be released, use arrow key to select the display mode.
If primary display has turned off, Super+P shortcut key can save you from running the command
gnome-control-center display to bring up setup GUI.
If you want to a script to auto detect external monitor and set up the screen extension at start up. here is an example
#!/bin/bash # this script will change default multiple monitor layout at startup # by Qingfeng Xia, UKAEA 2020 # tested on Ubuntu 18.04, but it should work for Xwindows of all Linux distro # see also https://wiki.archlinux.org/index.php/Xrandr#Configuration # config for your purpose, # xrandr will print current minotor settings: minitor names, resolutions, positions etc # --pos <xpos>x<ypos>, unit pixel, Y axis increase downward # two monitor must be set in one command line # xrandr --help to get all relative position # installation ## add `bash this_script` to user start up application, not system start up /etc/rc.local BUILTIN_MINOTOR='eDP-1' EXTERNAL_MINOTOR='HDMI-1' EXTERNAL_MINOTOR_STATUS=$(xrandr |grep "$EXTERNAL_MINOTOR") # only shift primary minotor position if external minotor is connected # because, xrandr will not detect cable connected but the minitor is turned off condition # substring finding by wildcard matching if [[ "$EXTERNAL_MINOTOR_STATUS" == *'disconnected'* ]]; then # use only single monitor xrandr --output $BUILTIN_MINOTOR --mode 1920x1080 --pos 0x0 --primary --auto --output $EXTERNAL_MINOTOR --off; else # default monitor join is left and right extension layout, here the command for vertical extension xrandr --output $BUILTIN_MINOTOR --mode 1920x1080 --pos 0x1080 --primary --auto --below $EXTERNAL_MINOTOR --output $EXTERNAL_MINOTOR --mode 1920x1080 --pos 0x0 --auto; fi # Super+P shortcut key, to bring up a menu to switch between mirror, single, multiple # keep Super key (windows key) pressed on, while P key can be released, using arrow key to select the display # if primary display has turned off, Super+P shortcut key # run the command `gnome-control-center display` for setup in GUI