From 427245a4eb13b855cc818a81712b1d18c61455a2 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Fri, 25 May 2018 17:01:14 -0400 Subject: bin/xinput-toggle: New script --- (limited to 'bin') 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 [ ...]\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 "${@}" -- cgit v0.9.1