diff options
author | Simon Rettberg | 2024-07-09 11:46:49 +0200 |
---|---|---|
committer | Simon Rettberg | 2024-07-09 11:46:49 +0200 |
commit | 417de1d7b7a7ce6c2b2bfef2083deaf9c377f0db (patch) | |
tree | 0cbe677a808e6145e7ef6a7070665400ec134bb9 /sample_configuration | |
parent | [*] Better error handling and messaging (diff) | |
download | pvs2-417de1d7b7a7ce6c2b2bfef2083deaf9c377f0db.tar.gz pvs2-417de1d7b7a7ce6c2b2bfef2083deaf9c377f0db.tar.xz pvs2-417de1d7b7a7ce6c2b2bfef2083deaf9c377f0db.zip |
Revent versions of xinput change the output format of the list option
for disabled devices, which broke kb-unlock.sh
Fix this, and hopefully make scripts more robust, by remembering which
devices where locked by kb-lock, and then unlock those same devices in
kb-unlock.
While at it, there's now also some basic protection against concurrent
calls to those scripts.
Diffstat (limited to 'sample_configuration')
-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 |