AtlatestRepositorysigil-wm
1
#!/usr/bin/env bash2
# Sourced in an isolated stacking compositor with the optional protocols enabled.3
msg() { bash scripts/msg "$SIGIL_WM_REPL" "$1"; }4
msg '(define permission-handler (on-event! host (lambda (event) (when (= (event-kind event) 70) (reply-request! host (vector-ref (event-raw event) 1) #t)))))'5
mkfifo "$runtime_dir/virtual-control"6
exec {virtual_control}<> "$runtime_dir/virtual-control"7
build/input-driver < "$runtime_dir/virtual-control" > build/receipts/virtual-allowed.log 2>&1 &8
security_pid=$!9
wait_log build/receipts/virtual-allowed.log INPUT_DEVICE_READY10
printf 'key 39\n' >&"$virtual_control"11
wait_log "build/receipts/$manager-red.log" 'CLIENT_KEY=39,0'12
msg '(define admitted-devices (filter (lambda (device) (dict-ref device virtual?:)) (dict-ref (host-snapshot host) devices:)))'13
msg '(and (= (length admitted-devices) 2) (every (lambda (device) (and (string? (dict-ref device name:)) (not (dict-ref device libinput?:)))) admitted-devices))' | grep -q '(value #t)'14
msg '(define pointer-settings-result #f)'15
msg '(on-event! host (lambda (event) (when (eq? (event-type event) (quote pointer-configuration-result)) (set! pointer-settings-result (map (lambda (field) (event-ref event field)) (quote (tap-status: dwt-status: middle-emulation-status: natural-scroll-status:)))))))'16
msg '(configure-pointer! host (dict-ref (find (lambda (device) (= (dict-ref device device-type:) 1)) admitted-devices) id:) (dict tap: #t dwt: #t middle-emulation: #t natural-scroll: #t))'17
settings_ready=false18
for ((attempt=0; attempt<100; attempt++)); do19
if msg '(equal? pointer-settings-result (quote (1 1 1 1)))' | grep -q '(value #t)'; then settings_ready=true; break; fi20
sleep 0.0221
done22
$settings_ready23
printf 'absolute 160 180\npress 38\nbutton 273 1\n' >&"$virtual_control"24
wait_log "build/receipts/$manager-red.log" 'CLIENT_KEY=38,1'25
wait_log "build/receipts/$manager-red.log" 'CLIENT_BUTTON=273,1'26
kill "$security_pid"27
wait "$security_pid" 2>/dev/null || true28
security_pid=29
wait_log "build/receipts/$manager-red.log" 'CLIENT_KEY=38,0'30
wait_log "build/receipts/$manager-red.log" 'CLIENT_BUTTON=273,0'31
devices_retired=false32
for ((attempt=0; attempt<100; attempt++)); do33
if msg '(null? (filter (lambda (device) (dict-ref device virtual?:)) (dict-ref (host-snapshot host) devices:)))' | grep -q '(value #t)'; then devices_retired=true; break; fi34
sleep 0.0235
done36
$devices_retired37
echo 'DEVICE_LIFETIME=PASS copied origin metadata explicit unsupported settings held key/button releases retirement'38
msg '(begin (remove-handler! host permission-handler) (set! permission-handler (on-event! host (lambda (event) (when (= (event-kind event) 70) (reply-request! host (vector-ref (event-raw event) 1) #f))))))'39
build/input-driver < "$runtime_dir/virtual-control" > build/receipts/virtual-denied.log 2>&1 &40
security_pid=$!41
sleep 0.1542
printf 'key 40\n' >&"$virtual_control"43
for ((attempt=0; attempt<100; attempt++)); do44
kill -0 "$security_pid" 2>/dev/null || break45
sleep 0.0246
done47
if kill -0 "$security_pid" 2>/dev/null; then echo 'denied virtual client still active' >&2; exit 1; fi48
wait "$security_pid" 2>/dev/null || true49
security_pid=50
msg '(remove-handler! host permission-handler)'51
if grep -q 'CLIENT_KEY=40,' "build/receipts/$manager-red.log"; then exit 1; fi52
exec {virtual_control}>&-53
echo 'VIRTUAL_PERMISSIONS=PASS accepted and refused separately from emulation'55
msg '(define observed-lock-state 0)'56
msg '(on-event! host (lambda (event) (when (= (event-kind event) 61) (set! observed-lock-state (vector-ref (event-raw event) 1)))))'57
mkfifo "$runtime_dir/lock-control"58
exec {lock_control}<> "$runtime_dir/lock-control"59
build/lock-client draw < "$runtime_dir/lock-control" > build/receipts/lock.log 2>&1 &60
security_pid=$!61
wait_log build/receipts/lock.log '^LOCKED '62
msg '(= observed-lock-state 2)' | grep -q '(value #t)'63
msg '(emulate-key! host 1 112 #t)'64
msg '(capture-output! host (dict-ref (car (dict-ref (host-snapshot host) outputs:)) id:) "build/receipts/locked.ppm")'65
for ((attempt=0; attempt<100; attempt++)); do66
[[ ! -s build/receipts/locked.ppm ]] || break67
sleep 0.0268
done69
sleep 0.170
build/readback build/receipts/locked.ppm build/receipts/locked.png locked71
printf 'u\n' >&"$lock_control"72
wait_log build/receipts/lock.log LOCK_UNLOCK_CONFIRMED73
wait "$security_pid"74
security_pid=75
msg '(= observed-lock-state 0)' | grep -q '(value #t)'76
msg '(example-redraw! example)'77
if grep -q 'CLIENT_KEY=112,' "build/receipts/$manager-red.log"; then exit 1; fi78
exec {lock_control}>&-79
echo 'LOCK=PASS opaque isolation real presentation authenticated protocol unlock emulation refused'