Created
May 24, 2014 20:21
-
-
Save bkanuka/b7b4ca94deb237b1e3f6 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env bash | |
TRACKPOINT_NAME="DualPoint Stick" | |
TRACKPAD_NAME="AlpsPS/2 ALPS GlidePoint" | |
POLL_INTERVAL=1.0s | |
point_xid=$(xinput --list --id-only "$TRACKPOINT_NAME") | |
pad_xid=$(xinput --list --id-only "$TRACKPAD_NAME") | |
is_enabled() { | |
en=$(xinput --list-props "$1" | grep -i Enabled | awk '{print $4}') | |
if [ $en = '1' ] | |
then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
in_use() { | |
node=$(xinput --list-props "$1" | grep -i "Device Node" | awk '{print $4}') | |
node="${node%\"}" | |
node="${node#\"}" | |
timeout $POLL_INTERVAL xxd -p -l 1 $node > /dev/null | |
if [ $? == 0 ] | |
then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
trap "exit" INT | |
while true; do | |
if in_use $point_xid; then | |
# TrackPoint is in use | |
if is_enabled $pad_xid; then | |
# TrackPad is Enabled | |
xinput --disable $pad_xid | |
fi | |
sleep $POLL_INTERVAL | |
else | |
# TrackPoint is not in use | |
if ! is_enabled $pad_xid; then | |
# TrackPad is not enabled | |
xinput --enable $pad_xid | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment