Last active
August 29, 2015 14:10
-
-
Save hsharrison/47ff3c9b21d476aea45e to your computer and use it in GitHub Desktop.
croutonwheel modification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
# Copyright (c) 2014 The crouton Authors. All rights reserved. | |
# Use of this source code is governed by a BSD-style license that can be | |
# found in the LICENSE file. | |
. "`dirname "$0"`/../installer/functions" | |
# Default button numbers | |
u=4 | |
d=5 | |
l=6 | |
r=7 | |
# Do horizontal scrolling by default | |
x=1 | |
# Set the default scaling and constant values | |
xs='0.2' | |
xc='0.01' | |
ys='0.2' | |
yc='0.05' | |
# | |
USAGE="${0##*/} [-x] [-r] [-a #.#] [-b #.#] [-c #.#] [-d #.#] | |
Runs the mousewheel daemon. | |
Options: | |
-r Reverse the direction of scrolling. | |
-x Disable horizontal scrolling. | |
-a Sets the X scrolling scaling factor (default: $xs). | |
-b Sets the X scrolling constant additive (default: $xc). | |
-c Sets the Y scrolling scaling factor (default: $ys). | |
-d Sets the Y scrolling constant additive (default: $yc)." | |
# Process options | |
while getopts 'a:b:c:d:rx' opt; do | |
case "$opt" in | |
a) xs="$OPTARG";; | |
b) xc="$OPTARG";; | |
c) ys="$OPTARG";; | |
d) yc="$OPTARG";; | |
r) z=$u; u=$d; d=$z; z=$l; l=$r; r=$z;; | |
x) x='0';; | |
\?) echo "$USAGE" 1>&2; exit 1;; | |
esac | |
done | |
if [ $# -ge "$OPTIND" ]; then | |
echo "$USAGE" 1>&2 | |
exit 1; | |
fi | |
# Operate on the Chromium OS X11 server | |
eval "`host-x11`" | |
# Only let one instance *really* run at a time | |
mkdir -m 775 -p /tmp/crouton-lock | |
exec 3>/tmp/crouton-lock/wheel | |
flock 3 | |
# Monitor xinput2 events, reacting only to scroll events (axes 2 and 3). | |
# Accumulate the x and y scrolls, but reduce the acceleration so it doesn't go | |
# crazy. After a threshold, simulate the wheel presses using xte. | |
# Use xev to detect window changes and disable mouse wheel events when aura is | |
# focused. | |
# The goal of this system is to avoid having to launch any processes on a | |
# per-event basis, both to improve latency and performance. | |
{ | |
croutonxi2event & | |
xi="$!" | |
aura="`xwininfo -name 'aura_root_0' | grep 'Window id' | grep -oP '\dx\d+'`" | |
xev -id "$aura" | |
trap "kill $! $xi 2>/dev/null || true" INT TERM HUP 0 | |
wait | |
} | unbuffered_awk ' | |
# Test if x is a non-zero real number (i.e. not nan, inf, "", or 0) | |
function isnonzero(x) { | |
return (x != "") && (x != 0) && (x != "nan") && (x != "inf") | |
} | |
# Disable when aura is visible and enable when it is not | |
/^FocusIn/ { | |
w = 1 | |
x = 0 | |
y = 0 | |
} | |
/^FocusOut/ { | |
w = 0 | |
} | |
!w && /^EVENT type 17/ { | |
# Valuators start at $10; >=10 valuators implies a trackpad | |
if ($19 != "") { | |
dx = $14 | |
dy = $15 | |
tp = 1 | |
} else { | |
dx = $12 | |
dy = $13 | |
tp = 0 | |
} | |
if ('"$x"' && isnonzero(dx)) { | |
if (dx > 0) { | |
if (x < 0) x = 0 | |
x += tp ? log(dx) * '"$xs"' + '"$xc"' : 1 | |
} else { | |
if (x > 0) x = 0 | |
x -= tp ? log(-dx) * '"$xs"' + '"$xc"' : 1 | |
} | |
while (x >= 1) { | |
output("mouseclick '"$r"'") | |
x -= 1 | |
} | |
while (x <= -1) { | |
output("mouseclick '"$l"'") | |
x += 1 | |
} | |
} | |
if (isnonzero(dy)) { | |
if (dy > 0) { | |
if (y < 0) y = 0 | |
y += tp ? log(dy) * '"$ys"' + '"$yc"' : 1 | |
} else { | |
if (y > 0) y = 0 | |
y -= tp ? log(-dy) * '"$ys"' + '"$yc"' : 1 | |
} | |
while (y >= 1) { | |
output("mouseclick '"$u"'") | |
y -= 1 | |
} | |
while (y <= -1) { | |
output("mouseclick '"$d"'") | |
y += 1 | |
} | |
} | |
} | |
' | xte & | |
trap "pkill -P $$ 2>/dev/null || true" INT TERM HUP 0 | |
wait | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment