diff options
-rwxr-xr-x | sample_configuration/kb-lock.sh | 22 | ||||
-rwxr-xr-x | sample_configuration/kb-unlock.sh | 19 |
2 files changed, 36 insertions, 5 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 diff --git a/sample_configuration/kb-unlock.sh b/sample_configuration/kb-unlock.sh index c123414..5f19c62 100755 --- a/sample_configuration/kb-unlock.sh +++ b/sample_configuration/kb-unlock.sh @@ -1,12 +1,25 @@ #!/bin/bash -# use xinput to get all keyboards and pointers (mouse) -keyboards=$(xinput --list | grep -E "slave.*(keyboard|pointer)" | cut -f2 | cut -d'=' -f2) +TMP="${XDG_RUNTIME_DIR:-"/run/user/$UID"}/pvslock" +for i in 10 20 40 80 160 320 0; do + if unlink "$TMP/done"; then + keyboards=$( cat "$TMP/locked" ) + break + fi + [ -d "$TMP" ] || exit 0 + usleep ${i}000 +done +if [ "$i" = 0 ]; then + echo "locked, raced" + exit 0 +fi for id in $keyboards; do echo "enabling device #$id" - xinput --set-prop $id "Device Enabled" 1 & + xinput enable "$id" & done wait +rm -rf -- "$TMP" +exit 0 |