It uses xrandr to do all the smart stuff which most pups have installed by default. You will need to use xrandr version 1.5 or later as it uses the --listmonitors switch to identify your monitors. Some earlier versions did not have this switch.
Version 1.0 of swapmon has two comboboxes. Select the monitors for left and right then press the swap button. If you don't know the names of your monitors, don't worry, just reverse the selection until you get what you want. Nothing will happen if you select the same monitor for left and right. It will only work if you select two different monitors. The comboboxes are blank when first run and pressing the swap button will do nothing.
When you click on the swap button, three actions take place.
1. It swaps your monitors,
2. It places a script in /root/Startup so the changes are persistent, and
3. It makes the script executable.
As this is a script that will probably only be run at setup I haven't provided a .desktop file. If you place it in one of bins, say /usr/bin, /usr/local/bin or /usr/sbin, it will run from a terminal when you type swapmon or just click on the script.
There are two other ways I have considered to swap monitors.
1. Make a script with a single toggle button. Each time the button is pressed the monitors are swapped back and forth with no other input required.
2. An even simpler method might be to have a script than swaps the monitors without any input from the user other than running the script. Still thinking about how to do this.
Code: Select all
#!/bin/sh
# swapmon ver 1.0
# Written by smokey01
# 01 September 2016
# It requires xrandr 1.5 or later
[ -z $GTKDIALOG ] && GTKDIALOG=gtkdialog
# This creates a list of your connected monitors
xrandr --listmonitors | awk '{print $NF}' | tail -n +2 > /tmp/list
# This generates a combobox list of monitors
MONITORS="<item>$monitor</item>"
for I in $(cat /tmp/list) ; do MONITORS=`echo "$MONITORS<item>$I</item>"`; done
# This is the function that swaps the monitors and saves the results in /root/Startup/setmonitors
SWAP () {
xrandr --output $MONITOR0 --auto --output $MONITOR1 --auto --right-of $MONITOR0
echo xrandr --output $MONITOR0 --auto --output $MONITOR1 --auto --right-of $MONITOR0 > /root/Startup/setmonitors
chmod 755 /root/Startup/setmonitors
}
export -f SWAP
MAIN_DIALOG='
<window icon-name="gtk-preferences" title="Swap Monitors" width-request="215">
<vbox>
<hbox>
<combobox width-request="100" tooltip-text="Select Left Monitor">
<variable>MONITOR0</variable>
'$MONITORS'
</combobox>
<combobox width-request="100" tooltip-text="Select Right Monitor">
<variable>MONITOR1</variable>
'$MONITORS'
</combobox>
</hbox>
<hbox>
<button>
<input file stock="gtk-quit"></input>
<label>Quit</label>
</button>
<button>
<input file stock="gtk-network"></input>
<label>Swap</label>
<action>SWAP</action>
</button>
</hbox>
</vbox>
</window>
'
export MAIN_DIALOG
case $1 in
-d | --dump) echo "$MAIN_DIALOG" ;;
*) $GTKDIALOG --program=MAIN_DIALOG ;;
esac
Cheers