Switchscreen
Switchscreen is a utility to switch monitors. As of v0.1.1 it doesn’t really work properly because of my sloppy window focus setting, but I’ve added some modifications I found in another modified version. Now you can switch between several monitors and yet keep the mouse and keyboard focus working.
Background
Most window managers don’t have proper multihead window handling. WindowMaker does, with a hotkey and everything, but it’s from fucking 2005. When I actually switched to Linux in ~2003 WindowMaker was still modern…
I’ve recently switched to XFCE and since it doesn’t care about multihead setups (I have three monitors) I’ve had to come up with a solution.
The switchscreen utility
Switchscreen is a utility to switch monitors. As of v0.1.1 it doesn’t really work properly because of my sloppy window focus setting, but I’ve added some modifications I found in another modified version. Now you can switch between several monitors and yet keep the mouse and keyboard focus working.
My modified version of switchscreen
Download switchscreen-0.1.2.tar
Basically, I’ve added some options in the toggleScreen.sh script and a utility called fakemousemove.
toggleScreen.sh
#!/bin/bash
# Start of user settings.
# -----------------------
HIDECURSOR=1 # 1 to hide it. See below.
# Where to move the cursors for the displays that you're not using.
# Move the cursor wherever you want.
# Values are 0-based, therefore the maximum values are max-1.
# For example, the first one is for a 30" monitor that can do 2560x1600, then the max becomes 2560-1,1600-1
hideCursor=("2559,1599" "1919,1199" "1279,1023")
# In order for XFCE (among others) to properly grab focus using sloppy mouse focus, the mouse has to be "moved".
# The following two lines set the mouse to x0, y0 - which is where I have my panel.
# Then the mouse is then moved back to where it was: the window itself. Xfce sees this "movement" and the window is raised and what not.
SLOPPY_FOCUS_X=0 # Set to -1 for no sloppy focus fixing.
SLOPPY_FOCUS_Y=0
# Where did you put switchscreen & co?
DIRECTORY=/home/edward/scripts/switchscreen ### CHANGEME!!! ###
# End of user settings.
# ---------------------
STOREFILE=${DIRECTORY}/.toogleScreen
CMD_SWITCHSCREEN=${DIRECTORY}/switchscreen
CMD_FAKEMOUSEMOVE=${DIRECTORY}/fakemousemove
CURRENT="`$CMD_SWITCHSCREEN -P`"
CURSCR=`echo "$CURRENT" | gawk '{ print $2 }'`
CURPOS=`echo "$CURRENT" | gawk '{ print $4 }'`
echo $CURPOS > $STOREFILE.$CURSCR
# Calculate new monitor.
## CHANGEME!!! ##
# If you have two monitors, remove the '2' part (monitorCount+1).
# If you want some fancy schmany 0 -> 2 -> 1, instead of 0 -> 1 -> 2, change this.
case "$CURSCR" in
'0')
NEWSCR=1
;;
'1')
NEWSCR=2
;;
'2')
NEWSCR=0
;;
esac
NEWPOS="`cat $STOREFILE.$NEWSCR 2>/dev/null`"
if [ "$NEWPOS" ]; then
POSOPT="-c $NEWPOS"
else
POSOPT=""
fi
if [ "$HIDECURSOR" = "1" ]; then
$CMD_SWITCHSCREEN -c ${hideCursor[$CURSCR]} # Hide the cursor for this screen
fi
$CMD_SWITCHSCREEN -q $POSOPT $NEWSCR # Go to the new screen.
if [ "$SLOPPY_FOCUS_X" != "-1" ]; then
$CMD_FAKEMOUSEMOVE -c $SLOPPY_FOCUS_X,$SLOPPY_FOCUS_Y $NEWSCR # First, move the mouse to where the panel is (ie: out of the window).
$CMD_FAKEMOUSEMOVE $POSOPT $NEWSCR # And now move it back in. Sloppy focus will now have focused on the window again.
fi
Skip unimportant screens
Personally, I’ve modified the case to simplify irc:ing. Screen 0 is my main monitor, screen 1 is a misc monitor and screen 2 is irc/centerim. Since I don’t want to have to page past screen 1 when I want to quickly reply to something on IRC the script now checks when I last switched monitors.
If I switched a while ago (more than 1 second) then I’m probably just going to reply to something.
If I switched recently then I actually want to go to screen 1.
'0')
LASTSTORE=$STOREFILE.2
TIME_LAST=`date -r $LASTSTORE +%s`
let TIME_SINCE_LAST=`date +%s`-$TIME_LAST
if [ "$TIME_SINCE_LAST" -gt "1" ]; then
NEWSCR=2
else
NEWSCR=1
fi
;;
How to use it
- Unzip
- Look in toggleScreen.sh and look for the text “CHANGEME” (there are at least two). You might want to change the hideCursor() array.
- Make a keyboard shortcut in XFCE to the script. I’ve used ctrl-tab.

Leave a Reply