aboutsummaryrefslogtreecommitdiff
path: root/rigel
diff options
context:
space:
mode:
authorNick Moore <nicholasvmoore@gmail.com>2026-11-07 09:20:22 -0600
committerNick Moore <nicholasvmoore@gmail.com>2026-11-07 09:20:22 -0600
commit6c4039aebbe7ec25f47cb4623e44b96373e9e6e5 (patch)
tree6b29ac15408e586c41d6bc91561294709c87a962 /rigel
parent34abcb44caf7266ce40063daca05a2a06f1b26c7 (diff)
Track sway (shared + rigel machine overlay), replace fibonacci with dwm-dwindle listener
- sway package: shared config (styling, all muscle-memory binds, no exec lines) including ~/.config/sway/machines/*.conf overlays included LAST; floating_windows + machines/README contract; sway/AGENTS.md doctrine - rigel package: machine overlay (outputs, touchpad, session stack, power bindings) + session scripts now stow-managed; fibonacci.py replaced by a POSIX sh+jq dwindle listener (dwm dwindle geometry, --monitor subscription, mark+move re-home, flock singleton); machines/rigel.conf exec line updated to the new path - validated in a headless nested sway against a literal port of fibonacci.c: five- and seven-window trees plus refocus-before-spawn all match dwm's rects (modulo the bar offset)
Diffstat (limited to 'rigel')
-rwxr-xr-xrigel/.config/sway/fibonacci100
-rw-r--r--rigel/.config/sway/machines/rigel.conf72
-rwxr-xr-xrigel/.config/sway/ppd-switch.sh162
-rwxr-xr-xrigel/.config/sway/session-daemons.sh175
-rwxr-xr-xrigel/.config/sway/veila-session-start.sh13
-rw-r--r--rigel/AGENTS.md41
6 files changed, 563 insertions, 0 deletions
diff --git a/rigel/.config/sway/fibonacci b/rigel/.config/sway/fibonacci
new file mode 100755
index 0000000..20a42a8
--- /dev/null
+++ b/rigel/.config/sway/fibonacci
@@ -0,0 +1,100 @@
+#!/bin/sh
+# fibonacci — dwm's dwindle layout, for sway.
+#
+# Geometry = dwm's dwindle (dwm-fibonacci-6.2.diff): window 1 = left half,
+# 2 = top-right, 3 = bottom of 2 (right column keeps going down), 4 = top of
+# the following remainder, 5 = bottom of it... each new window shrinks toward
+# the bottom-right corner; "look to the bottom right" holds at every birth.
+#
+# Sway only guarantees a new window lands *next to the focused* window.
+# On each new tiled window this listener:
+# 1. finds the corner leaf (deepest last-child leaf = the previous window),
+# 2. re-homes the newborn beside it (`move container to mark`) when sway
+# gave birth beside an older pane instead — the corner already sits in
+# its open birth-cell, whose layout was set by the last toggle, so the
+# plain move inserts as the second child with the right direction,
+# 3. wraps the newborn in a singleton cell with the direction opposite its
+# housing (`split toggle`) so the NEXT window slides into that cell —
+# that is what makes the dwindle pattern self-perpetuating.
+#
+# Floating windows and tabbed/stacked containers are left alone entirely.
+# Cost: one jq spawn per window event, zero while idle. `--monitor` keeps
+# the subscription streaming (without it swaymsg exits after one event, and
+# births in the reconnect gap would be lost); the flock keeps sway reloads
+# from stacking duplicate listeners (singleton per sway socket).
+
+[ -n "$SWAYSOCK" ] || exit 1
+
+LOCK="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/fibonacci-$(basename "$SWAYSOCK").lock"
+exec 9>"$LOCK"
+flock -n 9 || exit 0
+
+JQ='
+def has($i): any(.. | objects; .id == $i);
+def leaf:
+ if . == null then null
+ elif (.nodes | length) == 0 then .id
+ elif (.nodes[-1].layout == "tabbed" or .nodes[-1].layout == "stacked") then null
+ else .nodes[-1] | leaf end;
+def housing($i): # immediate parent container node of node $i
+ ([(.. | objects | select(any(.nodes[]?; .id == $i)))] | last);
+def scan($w; $m): # $w inside a tabbed/stacked container?
+ . as $node
+ | if .id == $w then $m
+ elif (.nodes | length) == 0 then empty
+ else
+ ($m or .layout == "tabbed" or .layout == "stacked") as $m2
+ | .nodes[] | scan($w; $m2)
+ end;
+. as $r
+| ([$r | scan($w; false)] | any(. == true)) as $manual
+| (first(.. | objects | select(.type == "workspace" and has($w)))) as $ws
+| ([$ws.nodes[] | select(.id != $w)] | last | leaf) as $corner
+| if $ws == null or $manual then "skip"
+ else
+ (housing($w)) as $hnW
+ | if $corner == null then "none"
+ elif $corner == $w then "self"
+ else
+ (housing($corner)) as $hnC
+ | if $hnW == $hnC then "home"
+ else "away|\($corner)" end
+ end
+ end
+'
+
+on_new() {
+ # $1 = con id of the newborn window
+ tree=$(swaymsg --raw --type get_tree) || return
+ info=$(printf %s "$tree" | jq -r --argjson w "$1" "$JQ") || return
+ mode=${info%%|*}
+ corner=$(printf %s "$info" | cut -d'|' -f2)
+
+ case $mode in
+ skip|self|none) ;; # nothing to re-home
+ home) ;; # newborn already beside the
+ # corner; nothing to move
+ away) # alien housing: the corner
+ # already sits in its open
+ # birth-cell, so a plain
+ # mark-move inserts beside it
+ swaymsg --quiet "[con_id=$corner] mark fibonacci-corner"
+ swaymsg --quiet "[con_id=$1] move container to mark fibonacci-corner"
+ swaymsg --quiet "[con_id=$corner] unmark" ;;
+ esac
+ # wrap the newborn so the NEXT birth lands in this corner cell
+ [ "$mode" != skip ] && swaymsg --quiet "[con_id=$1] split toggle"
+}
+
+# Wrap the subscription in a self-healing loop: a missed sway reload or IPC
+# hiccup drops the stream; retry rather than dying.
+while :; do
+swaymsg --monitor --raw --type subscribe '["window"]' | while IFS= read -r event; do
+ # only leaf con births; wrapper containers also emit "new" events
+ kind=$(printf %s "$event" | jq -r '.change + "/" + (if (.container.nodes // []) | length == 0 then "leaf" else "wrap" end) + "/" + (.container.type // "?")')
+ case $kind in
+ new/leaf/con) on_new "$(printf %s "$event" | jq '.container.id')" ;;
+ esac
+done
+sleep 0.5
+done
diff --git a/rigel/.config/sway/machines/rigel.conf b/rigel/.config/sway/machines/rigel.conf
new file mode 100644
index 0000000..e653985
--- /dev/null
+++ b/rigel/.config/sway/machines/rigel.conf
@@ -0,0 +1,72 @@
+# =============================================================================
+# machines/rigel.conf — rigel machine overlay (Gentoo laptop)
+#
+# Included LAST by the shared sway config; values here win. This file may
+# only shape rigel's hardware, session stack, and power behavior — NEVER
+# styling. Stowed by the repo `rigel` package (stow --adopt -t ~ rigel),
+# whose session scripts (session-daemons.sh, fibonacci, ppd-switch.sh,
+# veila-session-start.sh) live alongside in ~/.config/sway/.
+# =============================================================================
+
+### Output — rigel hardware
+# laptop panel at 1.5x; external Philips 346B1C at native scale. Specific
+# `output <name>` rules beat the shared `output *` wallpaper fallback.
+output eDP-1 scale 1.5
+output "Philips Consumer Electronics Company PHL 346B1C 0x000039DC" scale 1
+
+### Touchpad — laptop anatomy, meaningless on a desktop
+input type:touchpad {
+ tap enabled
+ drag enabled
+ dwt enabled
+}
+
+### Autostart — rigel's session stack
+# pipewire + pipewire-pulse + wireplumber + mako + waybar under a per-session
+# supervisor instead of bare `exec`: on OpenRC, sway-`exec`ed daemons become
+# orphans of dead sessions (2026-10-27: three pipewire-pulse survivors kept
+# /run/user/$UID/pulse/native out of reach while this session's pipewire and
+# wireplumber were dead, and waybar aborted its whole bar on the failed
+# pa_context_connect() — the bar-every-moonlight-connect bug).
+exec_always /home/nicholas/.config/sway/session-daemons.sh
+# Alternate split direction for each new tiled window; the helper is
+# singleton-safe so Sway config reloads won't start duplicate listeners.
+# dwindle listener (shell + jq, was fibonacci.py)
+exec_always /home/nicholas/.config/sway/fibonacci
+# polkit authentication agent: without it, polkit has no way to prompt and
+# NetworkManager settings (nmtui/nmcli edits) fail with "Insufficient privileges".
+exec /usr/libexec/polkit-gnome-authentication-agent-1
+exec_always /home/nicholas/.config/sway/veila-session-start.sh
+
+### Lock and idle — veila lock, battery/AC timeouts, gamepad watch
+# Lock via Veila (Doom One theme and live battery include in ~/.config/veila);
+# ~/.config/swaylock/lock.sh remains the fallback.
+bindsym $mod+Escape exec /home/nicholas/.config/swayidle/lock.sh
+
+# Idle: screen off after 5 min on battery / 15 min on AC; suspend after
+# 15 min on battery / 60 min on AC. The event table (timeouts, resume,
+# before-sleep) lives in ~/.config/swayidle/config — the standard location
+# per swayidle(1) — see that file for the full rationale:
+# swayidle has no built-in AC/battery split, so the battery-only timeouts are
+# no-ops when plugged in (see idle-screen-off.sh / idle-suspend.sh) and the
+# always-timeouts fire on either power source. Lock runs before power-off and
+# before suspend, so waking/resuming requires auth. Also locks on suspend
+# (closing the lid makes elogind suspend this session).
+#
+# Controller gaming: swayidle only counts keyboard/touchpad/tablet events as
+# activity, so playing on a gamepad with a hand never off the pad still tripped
+# the 15-min timeout and locked the screen mid-game. gamepad-idle-watch.py
+# timestamps real stick/button input; idle-screen-off.sh / idle-suspend.sh read
+# it and skip locking/suspending while the pad is in use. Needs nicholas in the
+# 'input' group.
+exec_always /home/nicholas/.config/swayidle/gamepad-idle-restart.sh
+exec_always /home/nicholas/.config/swayidle/idle-start.sh
+
+### Power profile — laptop concern, machine-scoped by design
+# (see ~/.config/sway/ppd-switch.sh for the auto/manual zones): power-saver =
+# battery mode when armed into auto, performance = the manual zone that
+# ppd-switch.sh never touches. Setting balanced/power-saver by hand re-enters
+# auto, effective from the next plug/unplug transition.
+bindsym --locked Ctrl+Alt+Shift+1 exec powerprofilesctl set power-saver
+bindsym --locked Ctrl+Alt+Shift+2 exec powerprofilesctl set balanced
+bindsym --locked Ctrl+Alt+Shift+3 exec powerprofilesctl set performance
diff --git a/rigel/.config/sway/ppd-switch.sh b/rigel/.config/sway/ppd-switch.sh
new file mode 100755
index 0000000..4d2f496
--- /dev/null
+++ b/rigel/.config/sway/ppd-switch.sh
@@ -0,0 +1,162 @@
+#!/bin/bash
+# ppd-switch.sh — auto-switch the power-profiles-daemon profile on AC↔battery.
+#
+# power-profiles-daemon deliberately has no "switch profile on power source"
+# public policy (that's a session thing; DEs like GNOME/KDE do it). 0.30 adds
+# internal battery/AC awareness (BatteryAware) — feed events into drivers and
+# actions, e.g. intel_pstate switches *internally* — but nothing emits a
+# user-decidable balanced↔power-saver-on-ac rule. Sway has no DE policy
+# engine, so this script is the policy. Everything talks to the *system* bus
+# (ppd + UPower), which means no session env is required — the supervisor can
+# spawn it from a bare context.
+#
+# The equality gate means we never fight ppd's own native choices: if the
+# daemon already sits on the state-correct profile, apply_profile no-ops.
+#
+# Policy (agreed 2026-10-31):
+# auto zone {balanced, power-saver} — on every power transition it flips
+# to the state-correct profile: mains → balanced, battery →
+# power-saver (first message's mapping; the "balanced (AC)" win).
+# manual zone {performance} — never touched, on ANY transition. Sticks
+# until the user changes it themselves (sway keybinds:
+# Ctrl+Alt+Shift+3). Setting balanced/power-saver by hand
+# re-enters auto, effective from the next transition: the
+# check below re-reads ActiveProfile at every event, so the
+# zone it lands in governs what happens next — no daemon state
+# to track, the profile *is* the zone.
+#
+# Events: the battery's UPower PropertiesChanged signals. They also fire on
+# plain charge-level updates every ~30s; those are cheap no-ops thanks to the
+# equality check in apply(), so no debounce bookkeeping beyond one short
+# settle-sleep per event (the kernel isn't atomic about adapter/battery
+# reveals).
+#
+# Supervisor: part of the daemons=() array in session-daemons.sh — singleton
+# flock, crash-restart, session teardown, and stderr rolling into
+# session-daemons.log. Name must be ≤15 chars (it is), because the
+# supervisor resolves pids via /proc/*/comm which truncates at 15.
+
+set -u
+
+BUS="--system"
+PPI="org.freedesktop.UPower.PowerProfiles"
+PPIPATH="/org/freedesktop/UPower/PowerProfiles"
+# The only battery on this machine (checked: BAT0 absent, BAT1 present).
+BATTERY="/org/freedesktop/UPower/devices/battery_BAT1"
+
+msg() { echo "$(date '+%F %T') [ppd-switch.sh] $*"; }
+
+# --- D-Bus helpers — raw gdbus calls, no powerprofilesctl dependency -------
+# (ppd 0.30: no SetProfile method on the interface; ActiveProfile is a
+# readwrite property, Get/Set alongside every other property — verified by
+# introspection and by flipping profiles live before writing this.)
+
+profile_get() { # -> ActiveProfile on stdout
+ gdbus call $BUS --dest "$PPI" --object-path "$PPIPATH" \
+ --method org.freedesktop.DBus.Properties.Get "$PPI" ActiveProfile \
+ | sed -n "s/^.*<'\([a-z][a-z-]*\)'>.*$/\1/p" # <'balanced'> -> balanced
+}
+
+profile_set() { # $1 = profile; write is a variant "<'x'>"
+ gdbus call $BUS --dest "$PPI" --object-path "$PPIPATH" \
+ --method org.freedesktop.DBus.Properties.Set "$PPI" ActiveProfile \
+ "<'$1'>" >/dev/null || msg "set ActiveProfile='$1' FAILED"
+}
+
+# --- power state ------------------------------------------------------------
+
+# Any mains adapter online? Authored as a scan for type=Mains on purpose:
+# the AC is ACAD but there are also four USB-C PD ports (ucsi-source-psy-*),
+# and which one has the charger can vary by port.
+mains_online() {
+ local t online
+ for d in /sys/class/power_supply/*/; do
+ read -r t <"$d/type" 2>/dev/null || continue
+ [ "$t" = Mains ] || continue
+ read -r online <"$d/online" 2>/dev/null || continue
+ [ "$online" = 1 ] && return 0
+ done
+ return 1
+}
+
+desired_profile() { # state-correct auto profile
+ if mains_online; then echo balanced; else echo power-saver; fi
+}
+
+# --- the one decision -------------------------------------------------------
+
+apply_profile() {
+ local cur want
+ # Manual zone: performance is sticky across every transition. If it's set,
+ # decline entirely — including the startup one-shot.
+ cur=$(profile_get)
+ [ "$cur" = performance ] && return 0
+ want=$(desired_profile)
+ [ "$cur" = "$want" ] && return 0 # no-op: also absorbs the
+ # charge-update event noise
+ msg "transition -> '$want' (was '$cur')"
+ profile_set "$want"
+}
+
+# --- event loop ---------------------------------------------------------------
+
+# Teardown: the supervisors TERM-kills the whole leftover stack, and our
+# instance was setsid'd into its own process group (we are the group leader),
+# so every child — gdbus monitor, the settle sleeps — shares the group. kill
+# 0 takes them all out at once instead of leaving the monitor orphaned until
+# its next battery write hits a closed pipe (SIGPIPE, ~30s later). Guard: if
+# we are NOT the process-group leader (e.g. someone ran this interactively),
+# kill 0 would take the caller's terminal pgrp with it — skip the group kill
+# there and just exit.
+cleanup() {
+ # Clear the traps FIRST: leaving them active while kill 0 TERMs our own
+ # group means this very shell re-enters the trap from its own group kill,
+ # and the handler's exit 0 never wins the race (verified: unbounded trap
+ # replay). Cleared, the self-TERM lands on default disposition and drops
+ # the shell instantly — exactly probe2.sh's correct behaviour.
+ trap - EXIT HUP INT TERM
+ if [ "$(ps -o pgid= --no-headers -p $$ 2>/dev/null | tr -d '[:space:]')" = "$$" ]; then
+ kill 0 2>/dev/null
+ fi
+ exit 0
+}
+trap cleanup EXIT HUP INT TERM
+
+# Startup one-shot, zone-respecting: a performance pick from a previous
+# session therefore also survives a full session restart. Failures here (e.g.
+# ppd briefly not ready at login) are not fatal — the loop below converges on
+# the first battery signal, and profiles only need one read/write.
+apply_profile
+
+while :; do
+ # monitor only watches the battery device: its PropertiesChanged is the
+ # trigger for "power config may have changed". If the monitor dies (bus
+ # hiccup), the outer while restarts it; the supervisor's crash-restart
+ # covers the script as a whole.
+ # Coupling subtlety #1 — pipeline: `gdbus monitor | while read` seats the
+ # main shell in do_wait on the pipeline and never services pending traps.
+ # Subtlety #2 — read builtin: even with the reader as the main shell
+ # (process substitution), bash defers pending traps until the read
+ # *returns* (verified live: TERM was ignored for tens of seconds). The
+ # pattern that works is reader-in-subshell + main shell waiting via
+ # `wait $!`: wait-on-async runs deferred traps IMMEDIATELY, so the
+ # supervisor's TERM -> our trap -> kill 0 teardown actually executes.
+ # The reader owns no state; it is pure "event -> apply" code, so it needn't
+ # handle a TERM itself — the group kill in cleanup covers it.
+ reader() {
+ while read -r; do
+ apply_profile
+ sleep 0.3 # settle: hot-trailing signals are gated in apply()
+ done
+ }
+ reader < <(gdbus monitor $BUS --dest org.freedesktop.UPower --object-path "$BATTERY") &
+ wait $!
+ msg "monitor exited; restarting in 30s"
+ # sleep is a builtin run to completion, and bash defers pending traps
+ # until a builtin RETURNS (this file's history is one big proof of that) —
+ # so the 30s restart backoff sleeps in 1s slices: a pending TERM never
+ # waits longer than ~1s from here.
+ for _ in $(seq 30); do
+ sleep 1
+ done
+done
diff --git a/rigel/.config/sway/session-daemons.sh b/rigel/.config/sway/session-daemons.sh
new file mode 100755
index 0000000..c8300e1
--- /dev/null
+++ b/rigel/.config/sway/session-daemons.sh
@@ -0,0 +1,175 @@
+#!/bin/bash
+# session-daemons.sh — per-session supervisor for the daemons sway used to
+# bare-`exec` (pipewire, pipewire-pulse, wireplumber, mako, waybar).
+#
+# Why: OpenRC has no user service manager and sway does not kill `exec`ed
+# children when the session ends, so daemons pile up across dead sessions.
+# 2026-10-27: three pipewire-pulse survivors (14:39 / 21:06 / current) held
+# /run/user/$UID/pulse/native while this session's pipewire and wireplumber
+# were dead, so every PA client got "Connection refused" — and waybar's
+# pulseaudio module aborts the whole bar on pa_context_connect() failure,
+# which is how the bar kept dying the moment a Moonlight stream started.
+#
+# What this script does instead:
+# 1. singleton per session: flock; a reload re-runs `exec_always`, and the
+# stale instance just exits (see idle-start.sh for the same pattern);
+# 2. on first start, kills EVERY leftover instance of the watched daemons
+# (fresh session start = fresh stack; no orphans of our own either);
+# 3. starts the daemons in dependency order and restarts any that die
+# while the session lives — including waybar, which is exactly the
+# bar-resurrection behaviour we want (see the 2026-10-27 notes);
+# 4. daemon stderr/stdout is appended to $runtime/session-daemons.log, so
+# a crash comes with its last words and a timestamp;
+# 5. when the sway whose socket we captured exits, everything is torn
+# down — nothing survives into the next session.
+#
+# Session identity: $SWAYSOCK is `sway-ipc.<uid>.<pid>.sock`, same trick the
+# veilad session launcher uses. Processes from other sessions carry a stale
+# socket there in their environ; anything comm-matching without ours is a
+# leftover and gets killed.
+
+set -u
+shopt -s nullglob
+
+runtime="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
+log="$runtime/session-daemons.log"
+daemons=(pipewire pipewire-pulse wireplumber mako waybar ppd-switch.sh)
+
+note() { echo "$(date '+%F %T') [$SWAYSOCK supervisor $$] $*" >>"$log"; }
+
+# comm-matching pids (pgrep -x would also work; this avoids coalescing).
+pids_of() {
+ for p in /proc/[0-9]*; do
+ [ -r "$p/comm" ] || continue
+ [ "$(tr -d '\0' <"$p/comm" 2>/dev/null)" = "$1" ] && echo "${p##*/}"
+ done
+}
+
+# Procpg name check. NOTE: this pgrep has no -q and errors out if given it,
+# so never write `pgrep -qx` here — that made every check fail, and the
+# supervise loop spawned a fresh waybar every cycle (2026-10-27).
+running() { pgrep -x "$1" >/dev/null 2>&1; }
+
+# --- singleton ----------------------------------------------------------------
+# High fd: bash marks descriptors >=10 close-on-exec, so the daemons we spawn
+# do NOT inherit the lock. With fd 9 they did — and surviving children then
+# kept the lock forever, making every later supervisor exit silently
+# (2026-10-27: 32 stray wireplumbers held the lock and froze the takeover).
+lockfd=200
+exec {lockfd}>"$runtime/session-daemons.lock"
+if ! flock -n "$lockfd"; then
+ note "another supervisor already holds the lock; exiting without changes"
+ exit 0
+fi
+
+# --- session identity --------------------------------------------------------
+sock="${SWAYSOCK:-}"
+sway_pid=""
+case "$sock" in
+ */sway-ipc.*.sock)
+ t="${sock##*/sway-ipc.}" # "uid.pid.sock"
+ t="${t#*.}" # drop uid
+ sway_pid="${t%%.*}" # keep pid
+ ;;
+esac
+if [ -z "$sock" ] || [ ! -S "$sock" ] || [ -z "$sway_pid" ] || [ ! -d "/proc/$sway_pid" ]; then
+ echo "session-daemons.sh: no live sway session (SWAYSOCK='$sock'); refusing to start" >&2
+ exit 1
+fi
+
+note "taking over the session daemons (sway pid $sway_pid)"
+
+# --- first start: clear every leftover instance ------------------------------
+# Both dead-session orphans (stale/error SWAYSOCK) and this session's own
+# copies from before the takeover. Killing pipewire first releases the
+# socket paths so the fresh instances can bind without unlink fights.
+for d in "${daemons[@]}"; do
+ for pid in $(pids_of "$d"); do
+ note "stopping leftover $d (pid $pid)"
+ kill "$pid" 2>/dev/null
+ done
+done
+sleep 2
+for d in "${daemons[@]}"; do
+ for pid in $(pids_of "$d"); do
+ note "force-killing leftover $d (pid $pid)"
+ kill -9 "$pid" 2>/dev/null
+ done
+done
+# Stale socket files from dead instances; fresh processes recreate them.
+rm -f "$runtime/pipewire-0" "$runtime/pipewire-0-manager" "$runtime/pulse/native"
+
+wait_for_socket() { # $1 socket path, 5s budget
+ local i=0
+ while [ "$i" -lt 50 ]; do
+ [ -S "$1" ] && return 0
+ i=$((i + 1))
+ sleep 0.1
+ done
+ return 1
+}
+
+# --- start helpers ------------------------------------------------------------
+start_daemon() {
+ local d="$1" cmd="$d"
+ # Bare names go through PATH (all the system daemons). Entries that live
+ # in ~/.config/sway (ppd-switch.sh) are not on PATH, so resolve them to
+ # the full file here. Note running()/pids_of()/kill below always use the
+ # bare name, which is also the /proc comm — hence ppd-switch.sh must stay
+ # <=15 chars.
+ [ -x "$HOME/.config/sway/$d" ] && cmd="$HOME/.config/sway/$d"
+ if running "$d"; then
+ # Another path (e.g. the reload keybind) brought it back already.
+ note "$d came back from elsewhere; not spawning a second copy"
+ return 0
+ fi
+ note "starting $d"
+ setsid "$cmd" >>"$log" 2>&1 </dev/null &
+}
+
+# --- dependency-ordered start -------------------------------------------------
+# pipewire is the core; pipewire-pulse bridges PulseAudio clients onto it;
+# wireplumber is the policy manager riding on the core.
+start_daemon pipewire
+if wait_for_socket "$runtime/pipewire-0"; then
+ start_daemon pipewire-pulse
+ wait_for_socket "$runtime/pulse/native" || note "pipewire-pulse socket still missing after 5s"
+ start_daemon wireplumber
+else
+ note "pipewire-0 socket still missing after 5s; starting the rest anyway"
+ for d in pipewire-pulse wireplumber mako waybar; do start_daemon "$d"; done
+fi
+start_daemon mako
+start_daemon waybar
+
+# --- supervision loop ---------------------------------------------------------
+session_alive() {
+ [ -S "$sock" ] && [ -d "/proc/$sway_pid" ]
+}
+
+while :; do
+ if ! session_alive; then
+ note "sway (pid $sway_pid) is gone; tearing the session daemons down"
+ for d in "${daemons[@]}"; do
+ for pid in $(pids_of "$d"); do
+ kill "$pid" 2>/dev/null
+ done
+ done
+ sleep 2
+ for d in "${daemons[@]}"; do
+ for pid in $(pids_of "$d"); do
+ kill -9 "$pid" 2>/dev/null
+ done
+ done
+ note "session daemons stopped; exiting"
+ exit 0
+ fi
+
+ for d in "${daemons[@]}"; do
+ if ! running "$d"; then
+ note "*** $d died; restarting"
+ start_daemon "$d"
+ fi
+ done
+ sleep 2
+done
diff --git a/rigel/.config/sway/veila-session-start.sh b/rigel/.config/sway/veila-session-start.sh
new file mode 100755
index 0000000..ee14fb3
--- /dev/null
+++ b/rigel/.config/sway/veila-session-start.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+# Called by Sway (exec_always). Starts the battery text updater only.
+#
+# The Veila daemon itself is managed by the OpenRC service
+# /etc/init.d/veilad (with /usr/local/sbin/veilad-session-launch), which
+# waits for this session, injects its environment and replaces stale
+# daemons. The old nohup-in-Sway approach kept dead-session daemons around
+# and silently broke every lock (see 2026-10-22), so it is gone.
+
+watcher=/home/nicholas/.config/veila/battery-watch.sh
+
+"$watcher" --once
+"$watcher" >/dev/null 2>&1 </dev/null &
diff --git a/rigel/AGENTS.md b/rigel/AGENTS.md
new file mode 100644
index 0000000..a285661
--- /dev/null
+++ b/rigel/AGENTS.md
@@ -0,0 +1,41 @@
+# rigel — machine overlay package
+
+Parent rules: `../AGENTS.md` (repo root). Machine-level context for the
+laptop itself lives in the rigel workspace (`~/git/rigel/AGENTS.md`);
+this file describes THIS package's contents and the stow mechanics.
+
+Deploy: `stow --adopt -t ~ rigel` after `stow --adopt -t ~ sway` (the
+shared package must land first).
+
+## Contents
+
+- `.config/sway/machines/rigel.conf` — rigel's machine overlay: outputs,
+ touchpad, session-stack autostart, lock/idle, power-profile bindings.
+ Included LAST by the shared sway config.
+- `.config/sway/session-daemons.sh` — per-session supervisor (pipewire,
+ mako, waybar, ppd-switch) instead of bare sway `exec`: on OpenRC/elogind,
+ sway-exec'ed daemons become orphans of dead sessions. Idempotent across
+ reloads; restart-on-crash for some daemons.
+- `.config/sway/fibonacci` — dwm-dwindle listener (POSIX sh + jq, no
+ python runtime). Keeps every new tiled window in the bottom-right
+ corner: finds the corner leaf, re-homes off-focus births beside it via
+ mark+move, and wraps the newborn alternately (`split toggle`) so the
+ pattern self-perpetuates. `--monitor` on the sway subscribe is required
+ — without it swaymsg exits after one event and births in the reconnect
+ gap get lost. Floating and tabbed/stacked containers are left alone.
+ flock-singleton per sway socket, so reloads don't stack duplicates; the
+ exec path must stay `/home/nicholas/.config/sway/fibonacci` (no .py)
+ because the machine conf execs it by that absolute path.
+- `.config/sway/ppd-switch.sh` — auto-switches power-profiles-daemon on
+ AC/battery transitions; its /proc comm matches its filename, which is
+ why the supervisor manages it by that exact name.
+- `.config/sway/veila-session-start.sh` — veila session wiring.
+
+## Rules
+
+- `machines/rigel.conf` never receives styling; the shared sway `config`
+ never receives rigel paths, outputs, or exec lines. Move a line between
+ the two only with a comment explaining which fact made it machine-level.
+- New machine coming in? Copy this package as `<newmachine>/`, reshape
+ `machines/<newmachine>.conf` for its hardware, and give it the same
+ script/AGENTS treatment.