Go to your command line and create a .sh file (this will end up in home, I personnaly put them in a subfolder):
gedit ~/swap_monitors.sh
Copy & paste the following batch script. Note the bash call at the beginning, not sh
#!/bin/bash
## script to toggle between monitor modes
currentmonitor=$(xrandr | awk '/\ connected/ && /[[:digit:]]x[[:digit:]].*+/{print $1}')
double=$'DisplayPort-0\nHDMI-A-0'
right=$'DisplayPort-0'
left=$'HDMI-A-0'
if [ "$currentmonitor" = "$double" ]; then
xrandr --output $left --auto --primary --output $right --off
elif [ "$currentmonitor" = "$right" ]; then
xrandr --output $left --auto --primary --output $right --auto --right-of $left
else
xrandr --output $left --auto --primary --output $right --auto --right-of $left
fi
exit 0
change the varibles double, right and left to the name of your monitors (check them with xrandr -q). Change the xrandr commands also if needed, e.g. perhaps you prefer primary on the right screen.
Note the elif conditions leads to the same command than after else so it is useless here. But I left it in case you want another behavior (e.g. circle between double>right>left>double>...)
Go to System Settings>keyboard panel (nautilus) and add the shortcut:
I personnaly added the shortcut Super+F4.