<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>EdwardH &#187; bash</title>
	<atom:link href="http://edwardh.se/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://edwardh.se</link>
	<description>Reviews and such</description>
	<lastBuildDate>Tue, 19 Oct 2010 16:53:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Switchscreen</title>
		<link>http://edwardh.se/2010/02/06/switchscreen/</link>
		<comments>http://edwardh.se/2010/02/06/switchscreen/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 23:43:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://edwardh.se/?p=45</guid>
		<description><![CDATA[Switchscreen is a utility to switch monitors. As of v0.1.1 it doesn&#8217;t really work properly because of my sloppy window focus setting, but I&#8217;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&#8217;t have [...]]]></description>
			<content:encoded><![CDATA[<p>Switchscreen is a   utility to switch monitors. As of v0.1.1 it doesn&#8217;t really work   properly because of my sloppy window focus setting, but I&#8217;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.<span id="more-45"></span></p>
<h2>Background</h2>
<p>Most window managers don&#8217;t have proper multihead window handling.  WindowMaker does, with a hotkey and everything, but it&#8217;s from fucking  2005. When I actually switched to Linux in ~2003 WindowMaker was still  modern&#8230;</p>
<p>I&#8217;ve recently switched to XFCE and since it doesn&#8217;t care about  multihead setups (I have three monitors) I&#8217;ve had to come up with a  solution.</p>
<h2>The switchscreen utility</h2>
<p><a href="http://users.tkk.fi/spniskan/switchscreen/">Switchscreen is a  utility to switch monitors</a>. As of v0.1.1 it doesn&#8217;t really work  properly because of my sloppy window focus setting, but I&#8217;ve added some  modifications I found in <a href="http://unlogical.net/files/scripts/switchscreen-0.4.tar.gz">another  modified version</a>. Now you can switch between several monitors and  yet keep the mouse and keyboard focus working.</p>
<h2>My modified version of switchscreen</h2>
<p><a href="http://edwardh.se/wp-content/uploads/2010/02/switchscreen-0.1.2.tar.gz">Download switchscreen-0.1.2.tar</a></p>
<p>Basically, I&#8217;ve added some options in the <strong>toggleScreen.sh</strong> script and a utility called <strong>fakemousemove</strong>.</p>
<h3>toggleScreen.sh</h3>
<pre>#!/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 &amp; 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 &gt; $STOREFILE.$CURSCR

# Calculate new monitor.

## CHANGEME!!! ##

# If you have two monitors, remove the '2' part (monitorCount+1).
# If you want some fancy schmany 0 -&gt; 2 -&gt; 1, instead of 0 -&gt; 1 -&gt; 2, change this.
case "$CURSCR" in
'0')
    NEWSCR=1
;;
'1')
    NEWSCR=2
;;
'2')
    NEWSCR=0
;;
esac

NEWPOS="`cat $STOREFILE.$NEWSCR 2&gt;/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
</pre>
<h3>Skip unimportant screens</h3>
<p>Personally, I&#8217;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&#8217;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.</p>
<p>If I switched a while ago (more than 1 second) then I&#8217;m probably just  going to reply to something.</p>
<p>If I switched recently then I actually want to go to screen 1.</p>
<pre>'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
;;</pre>
<h2>How to use it</h2>
<ol>
<li>Unzip</li>
<li>Look in <strong>toggleScreen.sh</strong> and look for the text  &#8220;CHANGEME&#8221; (there are at least two). You might want to change the  hideCursor() array.</li>
<li>Make a keyboard shortcut in XFCE to the script. I&#8217;ve used <strong>ctrl-tab</strong>.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://edwardh.se/2010/02/06/switchscreen/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

