From 6c4039aebbe7ec25f47cb4623e44b96373e9e6e5 Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Sat, 7 Nov 2026 09:20:22 -0600 Subject: 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) --- rigel/.config/sway/fibonacci | 100 ++++++++++++++ rigel/.config/sway/machines/rigel.conf | 72 ++++++++++ rigel/.config/sway/ppd-switch.sh | 162 ++++++++++++++++++++++ rigel/.config/sway/session-daemons.sh | 175 ++++++++++++++++++++++++ rigel/.config/sway/veila-session-start.sh | 13 ++ rigel/AGENTS.md | 41 ++++++ sway/.config/sway/conf.d/floating_windows | 1 + sway/.config/sway/config | 214 ++++++++++++++++++++++++++++++ sway/.config/sway/machines/README.md | 14 ++ sway/AGENTS.md | 33 +++++ 10 files changed, 825 insertions(+) create mode 100755 rigel/.config/sway/fibonacci create mode 100644 rigel/.config/sway/machines/rigel.conf create mode 100755 rigel/.config/sway/ppd-switch.sh create mode 100755 rigel/.config/sway/session-daemons.sh create mode 100755 rigel/.config/sway/veila-session-start.sh create mode 100644 rigel/AGENTS.md create mode 100644 sway/.config/sway/conf.d/floating_windows create mode 100644 sway/.config/sway/config create mode 100644 sway/.config/sway/machines/README.md create mode 100644 sway/AGENTS.md 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 ` 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...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 + 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 /`, reshape + `machines/.conf` for its hardware, and give it the same + script/AGENTS treatment. diff --git a/sway/.config/sway/conf.d/floating_windows b/sway/.config/sway/conf.d/floating_windows new file mode 100644 index 0000000..ae9b0b4 --- /dev/null +++ b/sway/.config/sway/conf.d/floating_windows @@ -0,0 +1 @@ +for_window [app_id="org.pulseaudio.pavucontrol"] floating enable diff --git a/sway/.config/sway/config b/sway/.config/sway/config new file mode 100644 index 0000000..3a15494 --- /dev/null +++ b/sway/.config/sway/config @@ -0,0 +1,214 @@ +# ============================================================================= +# Sway configuration (shared across machines) +# doom-one palette · Terminess (Terminus) Nerd Font +# $mod = Alt (Mod1) · vim-style hjkl motions · fibonacci/dwindle tiling +# hot reload: Alt+Shift+R +# Per-machine hardware/stack/power lives in ~/.config/sway/machines/*.conf +# (included LAST, so machine files win). That file shapes hardware only — +# NEVER styling. See AGENTS.md in the dotfiles repo for the split doctrine. +# ============================================================================= + +### Variables +set $mod Mod1 +set $left h +set $down j +set $up k +set $right l +set $term foot +set $menu fuzzel --lines=10 + +### Doom One palette +set $bg #282c34 +set $bg_alt #21242b +set $fg #bbc2cf +set $base3 #3f444a +set $base5 #5b6268 +set $red #ff6c6b +set $orange #da8548 +set $green #98be65 +set $yellow #ecbe7b +set $blue #51afef +set $magenta #c678dd +set $violet #a9a1e1 +set $cyan #46d9ff + +### Appearance +font pango:Terminess Nerd Font 11 + +# border background text indicator child border +client.focused $blue $bg $fg $blue $blue +client.focused_inactive $base3 $bg $base5 $base3 $base3 +client.unfocused $base3 $bg $base5 $base3 $base3 +client.urgent $red $bg $fg $red $red +client.placeholder $bg $bg $fg $bg $bg +client.background $bg + +### Windows +# retro WM chrome: titlebars on (default_border normal = border + title with +# the window's name in the pixel font, centered), square corners everywhere +default_border normal +default_floating_border normal +title_align center +titlebar_padding 4 + +# 5px margin around the screen, 2px between windows +gaps inner 2 +gaps outer 5 + +### Output +# doom-one wallpaper as the universal fallback. Per-output scale/background +# rules belong to each machine: ~/.config/sway/machines/.conf +# (specific `output ` rules beat this `output *` fallback). +output * bg ~/Pictures/wallpaper.jpg fill + +### Key bindings +# Basics +bindsym $mod+Return exec $term +bindsym $mod+d exec $menu +bindsym $mod+Shift+q kill +bindsym $mod+f fullscreen +bindsym $mod+Shift+space floating toggle +bindsym $mod+space focus mode_toggle +floating_modifier $mod normal + +# Focus — vim motions +bindsym $mod+$left focus left +bindsym $mod+$down focus down +bindsym $mod+$up focus up +bindsym $mod+$right focus right +bindsym $mod+Left focus left +bindsym $mod+Down focus down +bindsym $mod+Up focus up +bindsym $mod+Right focus right + +# Alt+Tab — cycle every window of the current workspace, wrapping +# ("tiling" = whole-tree traversal; plain "focus next" only cycles the two +# children of the nearest split container, which dead-ends in fibonacci +# layouts). Floating windows (e.g. pavucontrol) are skipped. +bindsym $mod+Tab focus next tiling +bindsym $mod+Shift+Tab focus prev tiling + +# Move focused window — vim motions +bindsym $mod+Shift+$left move left +bindsym $mod+Shift+$down move down +bindsym $mod+Shift+$up move up +bindsym $mod+Shift+$right move right +bindsym $mod+Shift+Left move left +bindsym $mod+Shift+Down move down +bindsym $mod+Shift+Up move up +bindsym $mod+Shift+Right move right + +# Fibonacci/dwindle tiling: each new tiled window splits opposite to its parent. +# The parent-relative toggle repeats indefinitely; floating and manual tabbed / +# stacked layouts are left alone by fibonacci.py. +default_orientation vertical +bindsym $mod+b splith +bindsym $mod+v splitv +bindsym $mod+s layout stacking +bindsym $mod+w layout tabbed +bindsym $mod+e layout toggle split + +# Switch to workspace +bindsym $mod+1 workspace number 1 +bindsym $mod+2 workspace number 2 +bindsym $mod+3 workspace number 3 +bindsym $mod+4 workspace number 4 +bindsym $mod+5 workspace number 5 +bindsym $mod+6 workspace number 6 +bindsym $mod+7 workspace number 7 +bindsym $mod+8 workspace number 8 +bindsym $mod+9 workspace number 9 +bindsym $mod+0 workspace number 10 + +# Move focused container to workspace +bindsym $mod+Shift+1 move container to workspace number 1 +bindsym $mod+Shift+2 move container to workspace number 2 +bindsym $mod+Shift+3 move container to workspace number 3 +bindsym $mod+Shift+4 move container to workspace number 4 +bindsym $mod+Shift+5 move container to workspace number 5 +bindsym $mod+Shift+6 move container to workspace number 6 +bindsym $mod+Shift+7 move container to workspace number 7 +bindsym $mod+Shift+8 move container to workspace number 8 +bindsym $mod+Shift+9 move container to workspace number 9 +bindsym $mod+Shift+0 move container to workspace number 10 + +# Scratchpad +bindsym $mod+Shift+minus move scratchpad +bindsym $mod+minus scratchpad show + +# Resize mode (vim motions) +mode "resize" { + bindsym $left resize shrink width 10px + bindsym $down resize grow height 10px + bindsym $up resize shrink height 10px + bindsym $right resize grow width 10px + bindsym Left resize shrink width 10px + bindsym Down resize grow height 10px + bindsym Up resize shrink height 10px + bindsym Right resize grow width 10px + bindsym Return mode "default" + bindsym Escape mode "default" +} +bindsym $mod+r mode "resize" + +# Hot reload: sway config + waybar (the supervisor brings it back, so a +# module crash also resurrects the bar) + mako +bindsym $mod+Shift+r exec "swaymsg reload; pkill -x waybar; makoctl reload" +# (Alt+Shift+C also reloads the sway config, sway default) +bindsym $mod+Shift+c reload + +# Exit sway +bindsym $mod+Shift+e exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -B 'Yes, exit sway' 'swaymsg exit' + +### Lock and idle +# These land in machine overlays — the lock program (veila on rigel), the +# battery/AC timeout table, and whether a gamepad watcher runs are all +# machine facts. rigel binds $mod+Escape and starts swayidle from +# ~/.config/sway/machines/rigel.conf. + +# Screenshots (to clipboard) +bindsym Print exec grim - | wl-copy +bindsym $mod+Print exec slurp | grim -g - - | wl-copy +# macOS-style: fullscreen / click-and-drag selection +bindsym --locked Ctrl+Shift+3 exec grim - | wl-copy +bindsym --locked Ctrl+Shift+4 exec slurp | grim -g - - | wl-copy + +# Volume +bindsym --locked XF86AudioMute exec pactl set-sink-mute \@DEFAULT_SINK@ toggle +bindsym --locked XF86AudioLowerVolume exec pactl set-sink-volume \@DEFAULT_SINK@ -5% +bindsym --locked XF86AudioRaiseVolume exec pactl set-sink-volume \@DEFAULT_SINK@ +5% +bindsym --locked XF86AudioMicMute exec pactl set-source-mute \@DEFAULT_SOURCE@ toggle + +# Media +bindsym --locked XF86AudioPlay exec playerctl play-pause +bindsym --locked XF86AudioPause exec playerctl play-pause +bindsym --locked XF86AudioPrev exec playerctl previous +bindsym --locked XF86AudioNext exec playerctl next +bindsym --locked XF86AudioStop exec playerctl stop + +# Brightness +bindsym --locked XF86MonBrightnessDown exec brightnessctl set 5%- +bindsym --locked XF86MonBrightnessUp exec brightnessctl set 5%+ + +# Power profile switching is machine-scoped (laptop concern): rigel binds +# Ctrl+Alt+Shift+1/2/3 in ~/.config/sway/machines/rigel.conf. + +# Quality of life +focus_follows_mouse no +seat * xcursor_theme Adwaita 24 + +for_window [app_id="org.pulseaudio.pavucontrol"] floating enable + +# LibreWolf prefers client-side decorations (CSD). Sway honors its preference +# when the window is floated, dropping the sway titlebar and leaving the +# floating window bare (LibreWolf draws no decorations of its own here). +# Forcing server-side decorations gives float-and-tile the same sway titlebar. +for_window [app_id="librewolf"] border normal + +# system-managed config (distro) +include /etc/sway/conf.d/* + +# Machine overlays LAST: they may override anything above (specific +# `output ` rules beat `output *`; later bindsym definitions win). +# Hardware shape, session stack, power behavior only — never styling. +include ~/.config/sway/machines/*.conf diff --git a/sway/.config/sway/machines/README.md b/sway/.config/sway/machines/README.md new file mode 100644 index 0000000..266cedf --- /dev/null +++ b/sway/.config/sway/machines/README.md @@ -0,0 +1,14 @@ +# machines/ + +One `.conf` per sway machine, loaded LAST by the shared +`~/.config/sway/config` via `include ~/.config/sway/machines/*.conf`. + +Machine files may override anything from the shared config: specific +`output ` rules beat the shared `output *` fallback, and later +definitions win on bindsym conflicts. + +They may contain ONLY hardware shape (outputs, input blocks), that +machine's session stack (autostart of its own scripts), lock/idle, and +power behavior — never styling, never the shared palette or key slots for +muscle memory. Each machine ships its own file via its own repo package +(see `rigel/.config/sway/machines/rigel.conf` for the pattern). diff --git a/sway/AGENTS.md b/sway/AGENTS.md new file mode 100644 index 0000000..bb5532e --- /dev/null +++ b/sway/AGENTS.md @@ -0,0 +1,33 @@ +# sway — Component Context + +Parent rules: `../AGENTS.md` (repo root). This package holds the SHARED +sway config for every sway-using machine. + +## The split doctrine + +- Tracked `config` = shared, machine-agnostic layer: doom-one palette + variables, fonts, borders/gaps/titlebars, window rules, ALL muscle-memory + key bindings (vim motions, workspaces, screenshots, volume/media/ + brightness, resize mode), behavioral QoL. NO exec lines, no machine + paths, no output names. +- Machine overlays: `~/.config/sway/machines/.conf`, included + LAST — they may override anything above and may ONLY contain hardware + shape (outputs, input blocks), that machine's session stack (autostart + of its own scripts), lock/idle, and power behavior. NEVER styling. In + this repo the pattern is delivered by per-machine packages (currently + `../rigel`); see `machines/README.md` for the contract. +- Sway precedence facts the split relies on: specific `output ` + rules beat `output *`; later bindsym definitions win; `include` is + re-evaluated on every `swaymsg reload`. + +## Include depth constraint + +Sway's include is one level deep: `machines/*.conf` files are included +directly by the main config and must NOT themselves contain `include`. + +## Session scripts + +Referenced autostart scripts are per-machine repo content (rigel package +ships its supervisor/fibonacci/ppd/veila helpers). The shared config +contains no exec lines, so a bare `stow sway` on a new machine yields a +working, safe desktop before that machine's overlay lands. -- cgit v1.3