diff options
Diffstat (limited to 'desktop/modules/status')
| -rw-r--r-- | desktop/modules/status/README.md | 24 | ||||
| -rw-r--r-- | desktop/modules/status/StatusPage.qml | 14 | ||||
| -rwxr-xr-x | desktop/modules/status/notify-sound | 10 | ||||
| -rwxr-xr-x | desktop/modules/status/statusctl | 27 | ||||
| -rwxr-xr-x | desktop/modules/status/test-notify-sound.sh | 15 | ||||
| -rwxr-xr-x | desktop/modules/status/test-statusctl.sh | 23 |
6 files changed, 93 insertions, 20 deletions
diff --git a/desktop/modules/status/README.md b/desktop/modules/status/README.md index ea069d6..15bb122 100644 --- a/desktop/modules/status/README.md +++ b/desktop/modules/status/README.md @@ -1,9 +1,10 @@ # status -Desktop modes as state: `dnd`, `presentation`, `nolock` and `quiet`, owned by -the `Status` singleton and stored as files under `$XDG_RUNTIME_DIR`. A fifth, -`status.gaming`, is written only by the shell's game detector; it is not a -mode `statusctl` exposes. +Desktop modes as state: `dnd`, `presentation`, `nolock`, `quiet` and `nolamp`, owned by +the `Status` singleton and stored as files under `$XDG_RUNTIME_DIR`. Two more, +`status.gaming`, written only by the shell's game detector, and `status.xbox`, +written only by deck-it while the Xbox runs a game, are not modes `statusctl` +exposes; either one turns presentation on. ## The files are the interface @@ -11,7 +12,9 @@ mode `statusctl` exposes. $XDG_RUNTIME_DIR/status.presentation $XDG_RUNTIME_DIR/status.nolock $XDG_RUNTIME_DIR/status.quiet + $XDG_RUNTIME_DIR/status.nolamp $XDG_RUNTIME_DIR/status.gaming + $XDG_RUNTIME_DIR/status.xbox Each holds `0` or `1`; a missing file means off. That directory is tmpfs, so a reboot resets every mode and there is no cleanup code. A shell restart does @@ -63,7 +66,7 @@ asks `statusctl quiet get` and plays nothing on a 1. `~/bin/notify-sound` is a symlink to the repo copy, like `statusctl`. notify-sound claude Claude Code's Notification hook - notify-sound <event> opencode-notifier's command hook + notify-sound <event> <session> opencode-notifier's command hook The opencode notifier runs its command for every event, `session_started` and `user_message` included, so an argument with no sound plays nothing; only @@ -71,6 +74,12 @@ The opencode notifier runs its command for every event, `session_started` and are off in `opencode-notifier.json`, and it rereads that file on every event, so neither change needs an opencode restart. +`nolamp` keeps the agent lamp (the sibling agent-lamp repo) dark. The shell +does nothing with it: agent-lamp's renderer reads the file each second and +restores the bulb while it is 1, keeping the agents' states for when it +turns off. `notify-sound` forwards the opencode notifier's two arguments +(`<event> <session>`) to `agent-lamp`, before the quiet check. + ## Game detection Presentation is set automatically while a game runs, so a fullscreen game does @@ -110,8 +119,9 @@ without touching the manual half, so a bar widget would otherwise read class with its own icon, and `toggle` is refused while it holds: the detector reasserts the file within its poll, so the write would not stick. `set` is still allowed, since the manual half is worth setting for when the game exits. -The watch therefore follows `status.gaming` as well as its own file, and emits -only on a real change so an unchanged rewrite draws nothing. +The watch therefore follows `status.gaming` and `status.xbox` as well as its +own file, and emits only on a real change so an unchanged rewrite draws +nothing. `status.xbox` counts as gaming in all of this. ## The checks diff --git a/desktop/modules/status/StatusPage.qml b/desktop/modules/status/StatusPage.qml index 4741bcc..5a00ded 100644 --- a/desktop/modules/status/StatusPage.qml +++ b/desktop/modules/status/StatusPage.qml @@ -61,6 +61,20 @@ Column { color: Qt.alpha(Theme.text, 0.08) } + StatusRow { + width: page.width + mode: "nolamp" + label: "No lamp" + description: "Keeps the agent lamp dark, for a film. Agents still notify on screen." + value: Status.nolamp + } + + Rectangle { + width: page.width + height: 1 + color: Qt.alpha(Theme.text, 0.08) + } + LockRow { width: page.width } diff --git a/desktop/modules/status/notify-sound b/desktop/modules/status/notify-sound index c028b3e..36efaaa 100755 --- a/desktop/modules/status/notify-sound +++ b/desktop/modules/status/notify-sound @@ -15,7 +15,7 @@ # silence both. Their popups do not come through here and are unaffected. # # notify-sound claude Claude Code's Notification hook -# notify-sound <opencode-notifier event> the notifier's command hook +# notify-sound <event> <session> the opencode notifier's command hook # # An argument with no sound plays nothing. That is deliberate: the opencode # notifier runs its command for every event, session_started and @@ -24,6 +24,14 @@ set -u here="$(dirname "$(readlink -f "$0")")" + +# opencode's notifier passes its event and session id: forward them to the +# agent lamp, before the quiet check, since quiet mutes sound and not light. +# Claude Code passes one argument and has hooks of its own for the lamp. +if [[ $# -eq 2 ]] && command -v agent-lamp >/dev/null; then + agent-lamp "$1" "$2" </dev/null >/dev/null 2>&1 & +fi + [[ "$("$here/statusctl" quiet get)" == "1" ]] && exit 0 dir="${NOTIFY_SOUND_DIR:-$HOME/Music/notify}" diff --git a/desktop/modules/status/statusctl b/desktop/modules/status/statusctl index 718ee39..69dc5a1 100755 --- a/desktop/modules/status/statusctl +++ b/desktop/modules/status/statusctl @@ -25,7 +25,7 @@ set -u -MODES="dnd presentation nolock quiet" +MODES="dnd presentation nolock quiet nolamp" DIR="${XDG_RUNTIME_DIR:-/tmp}" usage() { @@ -83,17 +83,22 @@ tooltip() { case "$1" in activated) printf '%s: on' "$mode" ;; deactivated) printf '%s: off' "$mode" ;; - gaming) printf '%s: on (auto: game or call)' "$mode" ;; + gaming) printf '%s: on (auto: game, call or Xbox)' "$mode" ;; esac } -# The shell's game detector owns status.gaming and presentation is the OR of -# the two, so the CLI has to read it to agree with the shell. It is not a mode -# in MODES: nothing here may write it, and only presentation is affected. +# The shell's game detector owns status.gaming, deck-it owns status.xbox (a +# game on the Xbox), and presentation is the OR of them and its own file, so +# the CLI has to read both to agree with the shell. Neither is a mode in +# MODES: nothing here may write them, and only presentation is affected. gaming_on() { - local v="" - [[ -e "$DIR/status.gaming" ]] && v="$(tr -d '[:space:]' < "$DIR/status.gaming" 2>/dev/null)" - [[ "$v" == "1" ]] + local f v + for f in status.gaming status.xbox; do + v="" + [[ -e "$DIR/$f" ]] && v="$(tr -d '[:space:]' < "$DIR/$f" 2>/dev/null)" + [[ "$v" == "1" ]] && return 0 + done + return 1 } # A missing file is the off state, not a distinct condition: read_mode already @@ -158,14 +163,14 @@ case "$action" in exec 3< <(inotifywait -q -m -e create,close_write,moved_to,delete --format '%f' "$DIR" 2>/dev/null) watcher=$! trap 'kill "$watcher" 2>/dev/null' EXIT TERM INT - # Presentation also follows status.gaming, so a game starting or - # ending redraws the widget. Emitting only on a real change keeps a + # Presentation also follows status.gaming and status.xbox, so a game + # starting or ending redraws the widget. Emitting only on a real change keeps a # write of an unchanged value from firing a duplicate line. last="$(state_now)" while read -r changed <&3; do case "$changed" in "status.$mode") ;; - status.gaming) [[ "$mode" == "presentation" ]] || continue ;; + status.gaming|status.xbox) [[ "$mode" == "presentation" ]] || continue ;; *) continue ;; esac now="$(state_now)" diff --git a/desktop/modules/status/test-notify-sound.sh b/desktop/modules/status/test-notify-sound.sh index 9571d4c..d70893f 100755 --- a/desktop/modules/status/test-notify-sound.sh +++ b/desktop/modules/status/test-notify-sound.sh @@ -13,7 +13,8 @@ # # The one runnable check for notify-sound. A fake paplay first on PATH # records what it was asked to play, and XDG_RUNTIME_DIR is a temporary -# directory, so no sound plays and the live quiet mode is untouched. +# directory, so no sound plays and the live quiet mode is untouched. A fake +# agent-lamp records its arguments, so the real lamp is never driven. # # Usage: ./test-notify-sound.sh (exit 0 = all passed) @@ -27,6 +28,8 @@ export NOTIFY_SOUND_DIR="/sounds" mkdir "$tmp/bin" printf '#!/bin/sh\nprintf "%%s\\n" "$1" >> "%s/played"\n' "$tmp" > "$tmp/bin/paplay" chmod +x "$tmp/bin/paplay" +printf '#!/bin/sh\nprintf "%%s %%s\\n" "$1" "$2" >> "%s/lamp"\n' "$tmp" > "$tmp/bin/agent-lamp" +chmod +x "$tmp/bin/agent-lamp" export PATH="$tmp/bin:$PATH" pass=0 @@ -64,5 +67,15 @@ check "quiet mutes permission" "" "$(play permission)" "$here/statusctl" quiet set 0 check "quiet off plays again" "/sounds/claude-attention.opus" "$(play claude)" +# Two arguments (opencode's event and session) are forwarded to agent-lamp, +# even in quiet mode; Claude's single argument never is. +rm -f "$tmp/lamp" +"$here/notify-sound" claude +"$here/notify-sound" permission ses1 +"$here/statusctl" quiet set 1 +"$here/notify-sound" complete ses2 +sleep 0.2 +check "lamp forward" "permission ses1|complete ses2" "$(paste -sd'|' "$tmp/lamp" 2>/dev/null)" + printf '\n%d passed, %d failed\n' "$pass" "$fail" [[ "$fail" -eq 0 ]] diff --git a/desktop/modules/status/test-statusctl.sh b/desktop/modules/status/test-statusctl.sh index 170101c..0c51968 100755 --- a/desktop/modules/status/test-statusctl.sh +++ b/desktop/modules/status/test-statusctl.sh @@ -149,11 +149,34 @@ kill "$watcher5" 2>/dev/null wait "$watcher5" 2>/dev/null check "first write, created by link, redraws" "1" "$(grep -c '"class": *"gaming"' "$out5")" +# deck-it writes status.xbox while the Xbox runs a game; it holds +# presentation on the same way, so the watch follows it too. +rm -f "$tmp/status.gaming" "$tmp/status.presentation" +out6="$tmp/watch6.out" +"$ctl" presentation watch > "$out6" 2>/dev/null & +watcher6=$! +sleep 0.3 +printf '1\n' > "$tmp/status.xbox.tmp" +mv -f "$tmp/status.xbox.tmp" "$tmp/status.xbox" +sleep 0.5 +kill "$watcher6" 2>/dev/null +wait "$watcher6" 2>/dev/null +check "xbox game redraws as gaming" "1" "$(grep -c '"class": *"gaming"' "$out6")" +"$ctl" presentation toggle 2>/dev/null +check "toggle refused while the xbox plays" "1" "$?" +rm -f "$tmp/status.xbox" + # quiet is a plain mode like dnd. "$ctl" quiet set 1 check "quiet set 1" "1" "$("$ctl" quiet get)" "$ctl" quiet toggle check "quiet toggle from 1" "0" "$("$ctl" quiet get)" +# nolamp keeps agent-lamp's bulb dark; a plain mode like quiet. +"$ctl" nolamp set 1 +check "nolamp set 1" "1" "$("$ctl" nolamp get)" +"$ctl" nolamp toggle +check "nolamp toggle from 1" "0" "$("$ctl" nolamp get)" + printf '\n%d passed, %d failed\n' "$pass" "$fail" [[ "$fail" -eq 0 ]] |
