Skip to content

Instantly share code, notes, and snippets.

@nobrowser
Created December 3, 2015 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobrowser/6398835a8f8a9b34f3fc to your computer and use it in GitHub Desktop.
Save nobrowser/6398835a8f8a9b34f3fc to your computer and use it in GitHub Desktop.
Change X virtual desktop by parking mouse on the edge
#! /bin/sh -Cefu
. /usr/local/bin/fortify.sh
# test0, xwinpos
. /usr/local/bin/mashlib.sh
margin=10
timeout=2
sleepwait=0.1
flipwait=0.4
while getopts :m:t:s:f: opt ; do
case $opt in
(m)
margin=$OPTARG
;;
(t)
timeout=$OPTARG
;;
(s)
sleepwait=$OPTARG
;;
(f)
flipwait=$OPTARG
;;
('?')
echo 'usage: deskflip [-m MARGIN] [-t TIMEOUT] [-s SLEEPWAIT] [-f FLIPWAIT]' >&2
exit 2
;;
esac
done
test_move_timeout()
{
status=$( echo "( $now - $last_move_time ) > $timeout" | bc -l)
test0 $status
}
test_flip_timeout()
{
status=$( echo "( $now - $last_margin_time ) > $flipwait" | bc -l)
test0 $status
}
xwinpos -root
rmargin=$(( w - margin ))
now=$( sleepenh 0 || true )
num_desks=$( xdotool get_num_desktops )
last_desk=$(( num_desks - 1 ))
last_move_time=$now
last_margin_time=$now
X=0
Y=0
while true ; do
then_X=$X
then_Y=$Y
eval $( xdotool getmouselocation --shell )
if test0 $X == $then_X '&&' $Y == $then_Y ; then
if test_move_timeout ; then
break
fi
else
last_move_time=$now
fi
if test0 $X '<' $margin '||' $X '>' $rmargin ; then
if test_flip_timeout ; then
this_desktop=$( xdotool get_desktop )
if test0 $X '<' $margin '&&' $this_desktop '>' 0 ; then
xdotool set_desktop $(( this_desktop - 1 ))
last_margin_time=$now
elif test0 $X '>' $rmargin '&&' $this_desktop '<' $last_desk ; then
xdotool set_desktop $(( this_desktop + 1 ))
last_margin_time=$now
fi
fi
else
last_margin_time=$now
fi
now=$( sleepenh $now $sleepwait || true )
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment