summaryrefslogtreecommitdiffstats
path: root/bin/xinput-toggle
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2018-05-25 17:01:14 (EDT)
committer P. J. McDermott <pj@pehjota.net>2018-05-25 17:01:14 (EDT)
commit427245a4eb13b855cc818a81712b1d18c61455a2 (patch)
tree90f607ba1f75de90f965a63b4f6735671ae8792f /bin/xinput-toggle
parentab339beff6e3d3201948fbb656af48c56bcf0b9b (diff)
downloadfluxbox-427245a4eb13b855cc818a81712b1d18c61455a2.zip
fluxbox-427245a4eb13b855cc818a81712b1d18c61455a2.tar.gz
fluxbox-427245a4eb13b855cc818a81712b1d18c61455a2.tar.bz2
bin/xinput-toggle: New script
Diffstat (limited to 'bin/xinput-toggle')
-rwxr-xr-xbin/xinput-toggle64
1 files changed, 64 insertions, 0 deletions
diff --git a/bin/xinput-toggle b/bin/xinput-toggle
new file mode 100755
index 0000000..ff038e0
--- /dev/null
+++ b/bin/xinput-toggle
@@ -0,0 +1,64 @@
+#!/bin/sh
+#
+# xinput-toggle -- Toggle enabled state of input devices
+#
+# Copyright (C) 2018 Patrick "P. J." McDermott
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+set -eu
+
+toggle()
+{
+ local device="${1}"
+ shift 1
+ local state=
+
+ state=$(xinput --list-props "${device}" | \
+ sed -n 's/^\tDevice Enabled ([0-9]*):\t\([01]\)$/\1/p;')
+ xinput --set-prop "${device}" 'Device Enabled' $((${state} ^ 1))
+
+ return 0
+}
+
+usage()
+{
+ printf 'Usage: %s <device> [<device> ...]\n' "${0}"
+
+ return 0
+}
+
+main()
+{
+ local device=
+
+ if [ ${#} -lt 1 ]; then
+ usage 1>&2
+ return 1
+ fi
+
+ for device in "${@}"; do
+ toggle "${device}"
+ done
+
+ return 0
+}
+
+main "${@}"