Small utility to enable/disable mouse/touchpad from X11 key shortcut
authorMatthew Mondor <mmondor@pulsar-zone.net>
Sat, 22 Aug 2015 16:51:49 +0000 (16:51 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Sat, 22 Aug 2015 16:51:49 +0000 (16:51 +0000)
mmsoftware/util/mouse-toggle.sh [new file with mode: 0755]

diff --git a/mmsoftware/util/mouse-toggle.sh b/mmsoftware/util/mouse-toggle.sh
new file mode 100755 (executable)
index 0000000..3187565
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+XINPUT=/usr/X11R7/bin/xinput
+AWK=/usr/bin/awk
+GREP=/usr/bin/grep
+
+DEV='Mouse0'
+
+id()
+{
+       $XINPUT list | $GREP $DEV | $AWK '{print $2}' | \
+               $AWK -F '=' '{print $2}' 
+}
+
+state_get()
+{
+       $XINPUT list-props $(id) | $GREP 'Device Enabled' | $AWK '{print $4}'
+}
+
+state_set()
+{
+       $XINPUT set-prop $(id) "Device Enabled" $1
+}
+
+toggle()
+{
+       v=$1
+
+       if [ $v -eq 0 ]; then
+               echo 1
+       else
+               echo 0
+       fi
+}
+
+state_set $(toggle $(state_get))