Merge remote-tracking branch 'origin/quattro' into unified-input-method-setup
This commit is contained in:
commit
b673d9e942
6 files changed
+152
-12
No files matched your search
@@ -13,11 +13,29 @@ TB_DEVICE=org.freedesktop.bolt1.Device
|
||||
TB_DOMAIN=org.freedesktop.bolt1.Domain
|
||||
TB_PATH=/org/freedesktop/bolt
|
||||
TB_SYSFS=/sys/bus/thunderbolt/devices
|
||||
# How often the daemon re-checks Bolt while there is no controller and no boot
|
||||
# protection: well inside the 20 s a published snapshot stays valid.
|
||||
TB_IDLE_RECHECK=10
|
||||
TB_TRUST_JQ='def trusted($state): $state.trusted[.Uid] == {Uid,Name,Vendor} and
|
||||
((.Secure | not) or (.Stored and (.Key | IN("have","new"))));'
|
||||
|
||||
tb_fail() { printf '%s\n' "$*" >&2; return 1; }
|
||||
|
||||
# Sleeps without forking on each tick: a pipe open for reading and writing
|
||||
# never reaches EOF, so a timed read on it returns only on timeout or a signal.
|
||||
tb_wait() {
|
||||
[[ -n ${TB_TICK:-} ]] || exec {TB_TICK}<> <(:)
|
||||
read -r -t "$1" -u "$TB_TICK" _ || true
|
||||
}
|
||||
|
||||
tb_controller_present() {
|
||||
local domain
|
||||
for domain in "$TB_SYSFS"/domain*; do
|
||||
[[ -e $domain ]] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
tb_json_write() {
|
||||
local target=$1 mode=${2:-600} temporary
|
||||
temporary=$(mktemp "${target%/*}/.thunderbolt.XXXXXX") || return 1
|
||||
@@ -287,11 +305,24 @@ tb_reconcile() {
|
||||
}
|
||||
|
||||
tb_daemon() {
|
||||
local snapshot error
|
||||
local snapshot error policy idle_policy='' idle_since=0
|
||||
install -d -m 755 "$TB_RUNTIME"
|
||||
cat /proc/sys/kernel/random/uuid > "$TB_RUNTIME/generation"
|
||||
chmod 644 "$TB_RUNTIME/generation"
|
||||
while [[ -f $TB_MARKER ]]; do
|
||||
policy=''
|
||||
[[ -r $TB_STATE ]] && IFS= read -r -d '' policy < "$TB_STATE" || true
|
||||
# With no controller, no device and no boot protection there is nothing to
|
||||
# restore or reapply, so Bolt is reconciled every TB_IDLE_RECHECK seconds
|
||||
# instead of every tick. A controller appearing, a policy change or a boot
|
||||
# recovery checkpoint brings back the full check at once.
|
||||
if [[ -n $idle_policy && $policy == "$idle_policy" && ! -e ${TB_STATE%/*}/boot-recovery.json ]] &&
|
||||
(( EPOCHSECONDS - idle_since >= 0 && EPOCHSECONDS - idle_since < TB_IDLE_RECHECK )) &&
|
||||
! tb_controller_present; then
|
||||
tb_wait 2
|
||||
continue
|
||||
fi
|
||||
idle_policy=''
|
||||
(
|
||||
flock -x 9
|
||||
if snapshot=$(tb_reconcile 2> "$TB_RUNTIME/error"); then
|
||||
@@ -303,7 +334,13 @@ tb_daemon() {
|
||||
tb_json_write "$TB_RUNTIME/snapshot.json" 644
|
||||
fi
|
||||
) 9> "$TB_LOCK"
|
||||
sleep 2
|
||||
snapshot=''
|
||||
[[ -r $TB_RUNTIME/snapshot.json ]] && IFS= read -r -d '' snapshot < "$TB_RUNTIME/snapshot.json" || true
|
||||
if [[ -n $policy ]] && jq -e '.available == true and .domains == [] and .devices == [] and
|
||||
.warnings == [] and .error == "" and .boot_protection == false' <<< "$snapshot" >/dev/null 2>&1; then
|
||||
idle_policy=$policy idle_since=$EPOCHSECONDS
|
||||
fi
|
||||
tb_wait 2
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
@@ -139,15 +139,28 @@ tb_scan() {
|
||||
}
|
||||
|
||||
tb_watch() {
|
||||
local watch snapshot warning warned='' failures=0
|
||||
local watch snapshot warning warned='' failures=0 text generation clean='' clean_generation='' clean_time=0
|
||||
tb_requests
|
||||
watch=$(cat /proc/sys/kernel/random/uuid)
|
||||
while true; do
|
||||
if [[ -f $TB_PENDING && ! -f $TB_MARKER ]]; then
|
||||
if [[ $warned != "pending" ]] && tb_setup_notice; then warned=pending; fi
|
||||
sleep 2
|
||||
clean=''
|
||||
tb_wait 2
|
||||
continue
|
||||
fi
|
||||
# The last scan's snapshot, unchanged, still fresh and from the same daemon,
|
||||
# with no device, warning or request in flight, has nothing to deliver.
|
||||
text='' generation=''
|
||||
[[ -r $TB_RUNTIME/snapshot.json ]] && IFS= read -r -d '' text < "$TB_RUNTIME/snapshot.json" || true
|
||||
[[ -r $TB_RUNTIME/generation ]] && IFS= read -r generation < "$TB_RUNTIME/generation" || true
|
||||
if [[ -n $clean && ${text%$'\n'} == "$clean" && $generation == "$clean_generation" ]] &&
|
||||
(( EPOCHSECONDS - clean_time >= 0 && EPOCHSECONDS - clean_time < 20 )) &&
|
||||
! compgen -G "$TB_REQUESTS/request-*.json" >/dev/null; then
|
||||
tb_wait 2
|
||||
continue
|
||||
fi
|
||||
clean=''
|
||||
if snapshot=$(tb_scan "$watch"); then
|
||||
failures=0
|
||||
warning=$(jq -c '[.generation,.warnings,.error]' <<< "$snapshot")
|
||||
@@ -157,6 +170,10 @@ tb_watch() {
|
||||
fi
|
||||
else
|
||||
warned=''
|
||||
if jq -e '.devices == []' <<< "$snapshot" >/dev/null; then
|
||||
IFS=' ' read -r clean_generation clean_time <<< "$(jq -r '"\(.generation) \(.time)"' <<< "$snapshot")"
|
||||
[[ $clean_time =~ ^[0-9]+$ ]] && clean=$snapshot
|
||||
fi
|
||||
fi
|
||||
else
|
||||
failures=$((failures + 1))
|
||||
@@ -164,7 +181,7 @@ tb_watch() {
|
||||
warned=unavailable
|
||||
fi
|
||||
fi
|
||||
sleep 2
|
||||
tb_wait 2
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ OMARCHY_KEYBOARD_LAYOUTS=$'English (US)|us
|
||||
English (UK)|uk
|
||||
English (US, Dvorak)|dvorak
|
||||
English (US, Colemak)|colemak
|
||||
Azerbaijani|azerty
|
||||
Belarusian|by
|
||||
Belgian|be-latin1
|
||||
Bulgarian|bg-cp1251
|
||||
|
||||
Reference in new issue
Block a user