diff --git a/bin/omarchy-screensaver b/bin/omarchy-screensaver index acd3868364a8..4349e809129a 100755 --- a/bin/omarchy-screensaver +++ b/bin/omarchy-screensaver @@ -35,10 +35,14 @@ wait_for_terminal_resize() { wait_for_terminal_resize +effect_args=(--random-effect) +screensaver_effect=$(omarchy-screensaver-effect) +[[ -n $screensaver_effect ]] && effect_args=(--random-effect --include-effects "$screensaver_effect") + while true; do ttfx -i ~/.config/omarchy/branding/screensaver.txt \ --frame-rate 120 --canvas-width 0 --canvas-height 0 --reuse-canvas --anchor-canvas c --anchor-text c\ - --random-effect --no-eol --no-restore-cursor & + "${effect_args[@]}" --no-eol --no-restore-cursor & while pgrep -t "${tty#/dev/}" -x ttfx >/dev/null; do if read -n1 -t 1 || ! screensaver_in_focus; then diff --git a/bin/omarchy-screensaver-effect b/bin/omarchy-screensaver-effect new file mode 100755 index 000000000000..9e4bef093c75 --- /dev/null +++ b/bin/omarchy-screensaver-effect @@ -0,0 +1,21 @@ +#!/bin/bash + +# omarchy:summary=Resolve the configured ttfx effect for the screensaver, if any. +# omarchy:hidden=true + +config_file="$HOME/.config/omarchy/shell.json" +defaults_file="$OMARCHY_PATH/config/omarchy/shell.json" +source_file=$defaults_file +[[ -s $config_file ]] && source_file=$config_file + +effect=$(jq -er '.idle.screensaverEffect // empty' "$source_file" 2>/dev/null) || exit 0 +[[ -n $effect ]] || exit 0 + +# Every ttfx effect is also its own subcommand, so this doubles as validation: +# an effect name that isn't real fails --help instead of ttfx erroring later, +# inside the screensaver's restart loop, with no easy way to surface why. +if ttfx "$effect" --help >/dev/null 2>&1; then + printf '%s\n' "$effect" +else + omarchy-notification-send -g ⚠️ "Unknown screensaver effect \"$effect\" in shell.json, using random effects" +fi diff --git a/default/agents/skills/omarchy/plugins.md b/default/agents/skills/omarchy/plugins.md index 6e3ab0695ea5..aa8e06ca581d 100644 --- a/default/agents/skills/omarchy/plugins.md +++ b/default/agents/skills/omarchy/plugins.md @@ -50,3 +50,7 @@ automatically. If a change somehow fails to apply, force a reload with Set `idle.screensaver` and `idle.lock` in `~/.config/omarchy/shell.json`, in seconds since user idle began. Example: "lock after ten minutes" means setting `idle.lock` to `600`. + +Set `idle.screensaverEffect` to a `ttfx` effect name (e.g. `"matrix"`) to +pin the screensaver to that effect instead of a random one each cycle. An +unrecognized name falls back to random and notifies. diff --git a/docs/omarchy-shell.md b/docs/omarchy-shell.md index d62ff7436df9..a86ef8269eaa 100644 --- a/docs/omarchy-shell.md +++ b/docs/omarchy-shell.md @@ -161,6 +161,9 @@ Rules: First-party non-bar plugins are enabled unless listed in `disabledPlugins[]`. 6. `barWidget.allowMultiple: true` in the manifest permits multiple instances. 7. `idle.screensaver` and `idle.lock` are seconds since user idle began. + `idle.screensaverEffect` is optional and pins the screensaver to one + `ttfx` effect name instead of picking randomly each cycle; an + unrecognized name is ignored (falls back to random) and notifies. 8. `version: 1` is required. `config/omarchy/shell.json` describes the fresh-install state. When no diff --git a/manual/13-toggles-idle-screensaver.md b/manual/13-toggles-idle-screensaver.md index 2effdac1e690..30798e3a62f1 100644 --- a/manual/13-toggles-idle-screensaver.md +++ b/manual/13-toggles-idle-screensaver.md @@ -94,6 +94,20 @@ You can start it on demand from _System > Screensaver_ (`Super + Esc`), which fo The logo it draws is yours to change, under _Style > Screensaver_. Upload a png or svg and Omarchy converts it to ASCII. See [branding](41-branding.md). +Each run of the screensaver picks a random effect from `ttfx`, the terminal text-effects engine underneath it — beams, matrix-style digital rain, fireworks, and dozens more. To pin it to one effect instead, add `screensaverEffect` to the `idle` block in `~/.config/omarchy/shell.json`: + +```json +{ + "idle": { + "screensaver": 150, + "lock": 300, + "screensaverEffect": "matrix" + } +} +``` + +The name has to match one of `ttfx`'s effects (run `ttfx --help` for the full list); an unrecognized name falls back to the random rotation and sends a notification saying so. + ### The lock screen `Super + Ctrl + L` locks the machine. That runs the lock screen from the Omarchy shell, blanks the display, resets your keyboard layout to the first one so you're not typing your password in the wrong alphabet, and — if you have it running — locks 1Password on the way out. diff --git a/test/shell.d/screensaver-effect-test.sh b/test/shell.d/screensaver-effect-test.sh new file mode 100755 index 000000000000..f3af5655a4ed --- /dev/null +++ b/test/shell.d/screensaver-effect-test.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +require_command jq + +test_tmp=$(mktemp -d) +trap 'rm -rf "$test_tmp"' EXIT + +stub_bin="$test_tmp/bin" +mkdir -p "$stub_bin" + +# Only "matrix" is a real effect here; anything else fails --help the way an +# unrecognized ttfx subcommand would. +cat >"$stub_bin/ttfx" <<'STUB' +#!/bin/bash +[[ $1 == "matrix" && $2 == "--help" ]] +STUB +chmod +x "$stub_bin/ttfx" + +notify_log="$test_tmp/notify.log" +cat >"$stub_bin/omarchy-notification-send" <>"$notify_log" +STUB +chmod +x "$stub_bin/omarchy-notification-send" + +fake_home="$test_tmp/home" +fake_omarchy_path="$test_tmp/omarchy-path" +mkdir -p "$fake_home/.config/omarchy" "$fake_omarchy_path/config/omarchy" + +cat >"$fake_omarchy_path/config/omarchy/shell.json" <<'JSON' +{ + "version": 1, + "idle": { "screensaver": 150, "lock": 300 } +} +JSON + +resolve_effect() { + rm -f "$notify_log" + HOME="$fake_home" OMARCHY_PATH="$fake_omarchy_path" PATH="$stub_bin:$PATH" \ + "$ROOT/bin/omarchy-screensaver-effect" +} + +# No screensaverEffect configured anywhere: falls back to random, silently. +rm -f "$fake_home/.config/omarchy/shell.json" +[[ -z $(resolve_effect) ]] || fail "screensaver effect defaults to random when unset" +[[ ! -s $notify_log ]] || fail "screensaver effect stays quiet when unset" +pass "screensaver effect defaults to random when unset" + +# A recognized effect is resolved and printed as-is. +cat >"$fake_home/.config/omarchy/shell.json" <<'JSON' +{ + "version": 1, + "idle": { "screensaver": 150, "lock": 300, "screensaverEffect": "matrix" } +} +JSON +[[ $(resolve_effect) == "matrix" ]] || fail "screensaver effect resolves a configured effect" +[[ ! -s $notify_log ]] || fail "screensaver effect stays quiet for a valid effect" +pass "screensaver effect resolves a configured effect" + +# An unrecognized effect name falls back to random and notifies why. +cat >"$fake_home/.config/omarchy/shell.json" <<'JSON' +{ + "version": 1, + "idle": { "screensaver": 150, "lock": 300, "screensaverEffect": "not-a-real-effect" } +} +JSON +[[ -z $(resolve_effect) ]] || fail "screensaver effect falls back to random for an unknown effect" +grep -q "not-a-real-effect" "$notify_log" || fail "screensaver effect notifies about the unknown effect" +pass "screensaver effect falls back to random and notifies for an unknown effect"