feat: add i3-style session-specific autostart support and documentation

This commit is contained in:
Luxferre committed 2026-11-26 11:55:17 +02:00
1 parent f73040a0be
commit 8d6236a63f
13 files changed
+1156 -8

No files matched your search

+74
View File
@@ -0,0 +1,74 @@
# ANODE session autostart
ANODE supports i3-style session-specific autostart directives paired with per-profile overrides, `autostart.d/` drop-ins, and `ANODE`-filtered XDG `.desktop` entries.
## Startup lifecycle
- `anode-session` exports `XDG_CURRENT_DESKTOP=ANODE`, `XDG_SESSION_DESKTOP=anode`, `DESKTOP_SESSION=anode`, and `ANODE_SESSION_PROFILE` when `--profile NAME` or `--profile=NAME` is passed.
- On first session launch, `anode-session` creates `~/.config/anode/autostart.d/` and copies `PREFIX/share/anode/autostart` (falling back to `data/autostart` in source checkouts) to `~/.config/anode/autostart` if absent.
- Once `dwm` advertises `_NET_SUPPORTING_WM_CHECK` on the root window (polled with `xprop` for up to 2 s, falling back to `sleep 1`), `anode-session` launches `anode-autostart start` in the background.
- Pressing `Mod4 + Shift + r` (`reloadxres` with `arg->i = 1`) or sending `SIGHUP` to `dwm` (live `execvp` restart carrying `ANODE_DWM_RESTARTED=1`) triggers `anode-autostart reload`, re-running only `exec_always` entries. Background theme/DPI reloads via `SIGUSR1` or `XA_RESOURCE_MANAGER` pass `NULL` and do not re-trigger `anode-autostart reload`.
## Declarative directives
Declarative rules live in `~/.config/anode/autostart` (or the file passed via `--config FILE`). Blank lines and lines starting with `#` are ignored, and `--no-startup-id` is accepted for i3 compatibility.
| Directive | Behavior |
|---|---|
| `exec [--no-startup-id] <command>` | Run `<command>` once during `anode-autostart start` |
| `exec_once [--no-startup-id] <command>` | Run `<command>` during `start` only when no process matching its executable basename is already running (checked via POSIX `ps`) |
| `exec_always [--no-startup-id] <command>` | Run `<command>` during `start` and re-run on `anode-autostart reload` (`Mod4 + Shift + r` or `SIGHUP` restart) |
| `include <path>` | Load directives from another file (absolute path, `~/...`, or relative to the current file; duplicate/cyclic includes are skipped, and nesting deeper than 8 levels fails `check`) |
## Session profiles
Passing `--profile NAME` or `--profile=NAME` to `anode-session` or `anode-autostart` (or exporting `ANODE_SESSION_PROFILE=NAME`) loads `~/.config/anode/autostart.<profile>` (or `PREFIX/share/anode/autostart.<profile>` if no user file exists) immediately after the base `autostart` file:
```sh
# ~/.xinitrc
exec /usr/local/bin/anode-session --profile work
```
## Drop-ins & XDG autostart
During `start` (never during `reload`), `anode-autostart` also evaluates drop-in scripts/desktop files and XDG autostart directories:
- **Drop-in directories**: `$XDG_CONFIG_HOME/anode/autostart.d/` followed by `$ANODE_PREFIX/share/anode/autostart.d/`. Earlier basenames shadow later ones; regular executable files are executed directly, and `*.desktop` files follow desktop-entry filtering.
- **XDG autostart directories**: `$XDG_CONFIG_HOME/autostart/*.desktop` followed by each directory in `$XDG_CONFIG_DIRS` (default `/etc/xdg/autostart/*.desktop`). Earlier basenames shadow later ones, so placing a `.desktop` file with `Hidden=true` in `~/.config/autostart/` masks the corresponding system entry.
- **Desktop-entry filtering**: Honors `Hidden=true`, case-insensitive `OnlyShowIn` / `NotShowIn` matching against `$XDG_CURRENT_DESKTOP`, `TryExec` binary lookup, `Terminal=true` execution via `st -e <command>`, and stripping of `%f`/`%F`/`%u`/`%U`/`%d`/`%D`/`%n`/`%N`/`%i`/`%c`/`%k`/`%v`/`%m` field codes (`%%` is unescaped to `%`).
- **Disabling XDG autostart**: Pass `--no-xdg` or set `ANODE_XDG_AUTOSTART=0` to skip XDG `.desktop` discovery while keeping declarative configs and `autostart.d/` drop-ins active.
## Command-line usage
Syntax: `anode-autostart [start|reload|list|check] [OPTIONS]`
| Argument / flag | Behavior |
|---|---|
| `start` | Default subcommand; run `exec`, `exec_once`, `exec_always`, `autostart.d/`, and XDG entries |
| `reload` | Run only `exec_always` directives (invoked by `dwm` on `Mod4 + Shift + r` and `SIGHUP` restart) |
| `list` | Print resolved commands and drop-ins without executing them |
| `check` | Validate declarative configs and `include` chains (exits `0` on valid, non-zero on error) |
| `--config FILE` / `--config=FILE` | Use `FILE` instead of `~/.config/anode/autostart` |
| `--profile NAME` / `--profile=NAME` | Load profile overrides from `autostart.NAME` |
| `--no-xdg` | Skip `$XDG_CONFIG_HOME/autostart` and `$XDG_CONFIG_DIRS/autostart` entries |
| `--dry-run` | Print `[exec]`, `[exec_once]`, `[exec_always]`, `[script]`, and `[desktop]` actions without launching |
```sh
anode-autostart check
anode-autostart list --profile work
anode-autostart reload --dry-run
```
## Example configuration
```sh
# ~/.config/anode/autostart
include ~/.config/anode/local.conf
exec_always --no-startup-id xset r rate 260 35
exec_always --no-startup-id sh -c '[ -r ~/.wallpaper ] && feh --bg-fill ~/.wallpaper'
exec_once --no-startup-id nm-applet
exec_once --no-startup-id picom
exec notify-send "ANODE" "Session ready"
```