diff options
Diffstat (limited to 'sample_configuration/kb-lock.sh')
-rwxr-xr-x | sample_configuration/kb-lock.sh | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/sample_configuration/kb-lock.sh b/sample_configuration/kb-lock.sh index 27db6da..64e3915 100755 --- a/sample_configuration/kb-lock.sh +++ b/sample_configuration/kb-lock.sh @@ -1,12 +1,30 @@ #!/bin/bash # use xinput to get all keyboards and pointers (mouse) -keyboards=$(xinput --list | grep -E "slave.*(keyboard|pointer)" | cut -f2 | cut -d'=' -f2) +keyboards=$( xinput list | grep -E "slave.*(keyboard|pointer)" | grep -oP '(?<=id=)\d+' ) +[ -z "$keyboards" ] && exit 0 + +# Make sure we're matching lock/unlock calls +TMP="${XDG_RUNTIME_DIR:-"/run/user/$UID"}/pvslock" +for i in 10 20 40 80 160 320 0; do + if mkdir "$TMP"; then + echo "$keyboards" > "$TMP/locked" && break + fi + usleep ${i}000 +done + +if [ "$i" = 0 ]; then + echo "locked, raced" + exit 0 +fi for id in $keyboards; do echo "disabling device #$id" - xinput --set-prop $id "Device Enabled" 0 & + xinput disable "$id" & done wait +touch "$TMP/done" + +exit 0 |