warbo-utilities: eca3051927fc3527480324d384da986b8bde2b98

     1: #!/usr/bin/env bash
     2: set -e
     3: 
     4: # Checks every few seconds whether we should fix the keyboard (layout, hotkeys,
     5: # etc.). This is needed when we plug peripherals in/out, and ideally would be
     6: # done from udev. Unfortunately that doesn't seem to work properly, so we use
     7: # udev to *request* that the keyboard be fixed, and rely on this script (running
     8: # inside X, e.g. from ~/.xsession) to actually honour those requests.
     9: 
    10: function readDefault {
    11:     [[ -f "$1" ]] || echo "$2" > "$1"
    12:     cat "$1"
    13: }
    14: 
    15: RANFILE="/tmp/keys-last-ran"
    16: 
    17: while true
    18: do
    19:     # Check for new requests, with a few seconds padding to debounce udev events
    20:     LASTRAN=$(readDefault "$RANFILE"            0)
    21:     LASTASK=$(readDefault "/tmp/keys-last-ask" 60)
    22:     if [[ "$(( LASTRAN + 3 ))" -lt "$LASTASK" ]]
    23:     then
    24:         # We've been asked to run but haven't done so yet. Update last-ran first
    25:         # to minimise race conditions, then again in case 'keys' took a while.
    26:         date '+%s' > "$RANFILE"
    27:         # Wait for keyboard to settle
    28:         sleep 3
    29:         keys
    30:         date '+%s' > "$RANFILE"
    31:     fi
    32:     sleep 1
    33: done

Generated by git2html.