// ─────────────────────────────────────────────────────────────────────────────
// modules/autostart.kdl — Programs launched when niri starts
//
// PURPOSE: Lists every daemon, applet, and background service required for a
//          complete CyberQueer desktop session.  niri's spawn-at-startup
//          launches each command once; there is no restart logic, so crashed
//          daemons stay dead until the compositor is restarted.
//
// NOTE: Arguments are passed via execvp (not a shell).  Anything needing shell
//       features (tilde expansion, pipes, globs) must use `bash -c "..."`.
// ─────────────────────────────────────────────────────────────────────────────

// monitorhandler.sh — sets the wallpaper (swaybg) and launches eww bar.
// WHY first: wallpaper and status bar should appear as early as possible so
// the desktop looks ready before the user interacts with it.
spawn-at-startup "bash" "-c" "~/.config/scripts/monitorhandler.sh"

// vicinae — application launcher daemon that keeps a hot process/app cache.
// "vicinae server" starts the background index so that Mod+R (toggle) is
// near-instantaneous rather than waiting for a cold startup scan.
spawn-at-startup "bash" "-c" "vicinae server"

// bluetooth-applet.sh — thin wrapper around blueman-applet.
// WHY a wrapper script: allows environment setup or guard conditions before
// the applet is spawned (e.g. waiting for bluetoothd to be ready).
spawn-at-startup "bash" "-c" "~/.config/scripts/bluetooth-applet.sh"

// ulwatchdog.sh — keeps ulauncher alive (polls every 5 s and restarts it).
// WHY: ulauncher serves as a secondary launcher; the watchdog ensures it is
// always available so the first Mod+R after a crash doesn't silently fail.
spawn-at-startup "bash" "-c" "~/.config/scripts/ulwatchdog.sh"

// udiskie — automounter for removable media (USB drives, SD cards, etc.).
//   -t        → show a system-tray icon for manual mount/unmount actions
//   -m nested → display a nested submenu in the tray (cleaner than flat list)
//   -n        → suppress desktop notifications (dunst handles those instead)
spawn-at-startup "udiskie" "-t" "-m" "nested" "-n"

// xfce-polkit — PolicyKit authentication agent (privilege escalation dialog).
// WHY: without a running polkit agent, GUI applications that request root
// privileges (e.g. gparted, package managers) will silently fail or crash.
// xfce-polkit is lightweight and works on any Wayland session.
spawn-at-startup "xfce-polkit"

// gammastep — Wayland colour-temperature daemon (like redshift).
// -O 4500: apply a fixed 4500 K warm-white colour temperature at startup.
// WHY fixed value: avoids needing a GPS/location service.  4500 K is a
// comfortable default for mixed day/evening use.  binds.kdl provides
// shortcuts (Mod+Ctrl+X/W/A/Q/S) to change temperature on the fly.
spawn-at-startup "bash" "-c" "gammastep -O 4500"

// nm-applet — NetworkManager system-tray icon.
// WHY: provides quick access to Wi-Fi, VPN, and wired network management
// without keeping a full settings panel open.
spawn-at-startup "nm-applet"

// dunst — notification daemon (implements the freedesktop.org spec).
// WHY: lightweight alternative to mako/swaync; integrates tightly with
// dunstctl for the scripted close-all binding in binds.kdl (Mod+Ctrl+C).
spawn-at-startup "dunst"

// swayidle — idle-based screen locker and suspend manager.
// Flags and timeouts:
//   -w                              → wait for each command to finish before
//                                     acknowledging the idle state (prevents races)
//   timeout 300 'swaylock -f'       → lock screen after 5 minutes idle
//   timeout 600 'systemctl suspend' → suspend system after 10 minutes idle
//   before-sleep 'swaylock -f'      → lock before every suspend/hibernate,
//                                     including lid-close events
// WHY swaylock -f: the -f (fork) flag lets swaylock daemonise itself so
// swayidle doesn't block waiting for it to exit.
spawn-at-startup "bash" "-c" "swayidle -w timeout 300 'swaylock -f' timeout 600 'systemctl suspend' before-sleep 'swaylock -f'"

// presence-detect.sh — webcam-based automatic idle inhibitor.
// WHY: detects when the user is physically at the desk (via camera) and holds
// the idle inhibitor active so the screen doesn't lock unnecessarily.
// Complements the manual caffeine.sh toggle (Mod+Shift+C).
spawn-at-startup "bash" "-c" "~/.config/scripts/presence-detect.sh"

// blueman-applet — Bluetooth tray icon with device management UI.
// WHY separate from nm-applet: blueman exposes pairing, profile switching,
// and per-device settings that NetworkManager's Bluetooth support omits.
spawn-at-startup "blueman-applet"
