2

By default when an external display is connected it appears as extended to the right.

In Displays settings this can be changed and also one can be closed, etc.

enter image description here

Can displays settings be cycled with a keyboard shortcut between extended, left, right, mirror?

2
sudo apt install disper

More details on various arguments, here.

The command to cycle between clone, extended, internal and external displays should be like this:

disper --cycle-stages='-e : -c : -S : -s' --cycle

In that case, it would extend to the right. To cycle between the same options but extend to the left:

disper --direction=left --cycle-stages='-e : -c : -S : -s' --cycle

The command can be then associated to a short-key like the Super-P/Display key.

Restart may be needed to see changes.

Disper will detect displays and use the maximal resolutions by default. If no external display is connected, nothing will happen when the short-key is touched.


While it works fine with a shortcut, the disper command doesn't work with a launcher in Loki: trying to create a dock launcher to cycle displays in this way freezes completely the desktop and I have to log out in console (Ctrl-Alt-f1) and use killall -u <username>.

I don't know how to cycle displays with a launcher but, in order to get as close to that as possible, one could add all the needed commands as desktop actions within a single launcher.

To get the separate commands for the different display settings that need to be cycled, xrandr can be used (without the need for disper).

Do xrandr -q to see the name of the displays. Let's say that we get LVDS1 for internal and VGA1 for external display. Then, a launcher could be created:

gedit ~/.local.share/applications/cycle-displays.desktop

With:

[Desktop Entry]
Name=Cycle displays
Exec=xrandr --output VGA1 --off --output LVDS1 --auto 
Icon=unity-display-panel
Terminal=false
Type=Application
StartupNotify=true
Categories=GNOME;GTK;Settings;HardwareSettings;X-Unity-Settings-Panel;

Actions=extended1;extended2;external;internal

[Desktop Action extended1]
Icon=extended-internal
Name=Extend to left ~ primary internal
Exec=xrandr --output VGA1 --auto --left-of LVDS1 --output LVDS1 --auto --primary 

[Desktop Action extended2]
Icon=extended-external
Name=Extend to left ~ primary external
Exec=xrandr --output VGA1 --auto --left-of LVDS1 --primary --output LVDS1 --auto  

[Desktop Action external]
Icon=LCD
Name=External display only
Exec=xrandr --output VGA1 --auto --output LVDS1 --off 

[Desktop Action internal]
Icon=laptop
Name=Internal display only
Exec=xrandr --output VGA1 --off --output LVDS1 --auto

After adding some icons to ~/.local/share/icons, drag&drop the launcher onto Plank and, right-clicking on it:

enter image description here

Each command is set under a [Desktop Action] (all are listed after Actions=). As an Exec= line is mandatory under [Desktop Entry], in this example it runs the same as "Internal display only". So, just left click the launcher for that.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy