diff --git a/README.md b/README.md index f21d617..f6f1dfd 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ ANODE is a lightweight, keyboard-first, cross-Unix X11 desktop environment for * - `anode-media-key`: Multimedia key dispatcher for volume, mic mute, brightness, MPRIS/MPD/mpv media playback, screenshots, airplane toggle, suspend, and virtual keyboard toggling. - `anode-vkbd`: Optional EWMH dock multi-layer touch virtual keyboard (`QWERTY`, `Shift`, `Sym`, `Nav`) injecting XTest keystrokes without stealing focus. - **Zero-poll event daemons**: - - `anode-statusd`: `poll()` + self-pipe + XKB layout group/keymap events + Linux `NETLINK_ROUTE` / BSD `PF_ROUTE` link watcher + minute-aligned timer. + - `anode-statusd`: `poll()` + self-pipe + XKB group/keymap events (text-only lowercase layout indicator left of datetime) + Linux `NETLINK_ROUTE` / BSD `PF_ROUTE` link watcher + minute-aligned timer. - `anode-touchd`: XI2 multitouch edge-swipe gesture recognizer. - `anode-powerd`: Idle dim / lock / suspend policy daemon (`XScreenSaverQueryInfo` when available). - **gtkTtk 0.9 port**: @@ -46,14 +46,19 @@ make PREFIX=/opt/anode CC=clang WITH_GTKTTK=1 make DESTDIR=/tmp/stage PREFIX=/usr/local install ``` -Start ANODE from `.xinitrc` (`exec /usr/local/bin/anode-session`) or via a display manager selecting the installed `ANODE` XSession (`PREFIX/share/xsessions/anode.desktop`). Passing `--profile NAME` (or setting `ANODE_SESSION_PROFILE`) selects a session profile for autostart. To live-replace an already running X11 window manager or session without logging out, run `anode-replace` (pass `--keep-panels` to retain third-party panels/daemons). +Start ANODE from `.xinitrc` (`exec /usr/local/bin/anode-session`) or via a display manager selecting the installed `ANODE` XSession (`PREFIX/share/xsessions/anode.desktop`). Passing `--profile NAME` (or setting `ANODE_SESSION_PROFILE`) selects a session profile for autostart. + +## Live session replacement & desktop identity + +Run `anode-replace` inside any active X11 session to replace the running window manager or desktop environment live without logging out or closing open windows (pass `--keep-panels` to retain third-party panels and daemons). `anode-replace` and `anode-session` scrub conflicting DE variables, export `XDG_CURRENT_DESKTOP=ANODE`, and `dwm` advertises `_NET_WM_NAME = "ANODE WM"` so system tools such as `fastfetch` report `Desktop Environment: ANODE` and `Window Manager: ANODE WM (X11)` instead of `dwm`. See [docs/SESSION.md](docs/SESSION.md) for full replacement, identity, and XKB status indicator details. ## Session autostart -`anode-session` invokes `anode-autostart start` once DWM advertises `_NET_SUPPORTING_WM_CHECK`, seeding `~/.config/anode/autostart` from `PREFIX/share/anode/autostart` on first launch. Supported directives follow i3 conventions (`exec`, `exec_once`, `exec_always`, `--no-startup-id`, `include`), alongside per-profile files (`~/.config/anode/autostart.`), drop-in scripts or `.desktop` entries in `~/.config/anode/autostart.d/`, and `ANODE`-filtered XDG autostart entries. Pressing `Mod4 + Shift + r` or sending `SIGHUP` to DWM reloads `.Xresources`/theme/DPI and triggers `anode-autostart reload` (re-running `exec_always` entries). See [docs/AUTOSTART.md](docs/AUTOSTART.md) for full directive, profile, and XDG precedence details. +`anode-session` invokes `anode-autostart start` once DWM advertises `ANODE WM` via `_NET_SUPPORTING_WM_CHECK`, seeding `~/.config/anode/autostart` from `PREFIX/share/anode/autostart` on first launch. Supported directives follow i3 conventions (`exec`, `exec_once`, `exec_always`, `--no-startup-id`, `include`), alongside per-profile files (`~/.config/anode/autostart.`), drop-in scripts or `.desktop` entries in `~/.config/anode/autostart.d/`, and `ANODE`-filtered XDG autostart entries. Pressing `Mod4 + Shift + r` or sending `SIGHUP` to DWM reloads `.Xresources`/theme/DPI and triggers `anode-autostart reload` (re-running `exec_always` entries). See [docs/AUTOSTART.md](docs/AUTOSTART.md) for full directive, profile, and XDG precedence details. ## Documentation & tests +- [Session management & status bar](docs/SESSION.md) - [Session autostart](docs/AUTOSTART.md) - [Architecture](docs/ARCHITECTURE.md) - [Keybindings](docs/KEYBINDINGS.md) diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index ed4e4aa..505c4f9 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -33,3 +33,9 @@ In `src/dwm/dwm.c`: 1. `anode-session` exports `XDG_CURRENT_DESKTOP=ANODE`, `XDG_SESSION_DESKTOP=anode`, `DESKTOP_SESSION=anode`, and optional `ANODE_SESSION_PROFILE`, seeds `~/.config/anode/autostart` and `~/.config/anode/autostart.d/`, and starts a background waiter polling `_NET_SUPPORTING_WM_CHECK` before invoking `anode-autostart start`. 2. `anode-autostart` evaluates declarative files (`autostart` + optional `autostart.` + `include` graph via POSIX `awk`), then on `start` evaluates `autostart.d/` drop-ins and `ANODE`-filtered XDG `.desktop` entries with user-over-system basename masking. 3. `src/dwm/dwm.c` triggers `anode-autostart reload` (running only `exec_always`) from interactive `reloadxres` (`Mod4 + Shift + r`, `arg->i = 1`) and post-`SIGHUP` `execvp` restart (`ANODE_DWM_RESTARTED=1`), while `SIGUSR1` and `XA_RESOURCE_MANAGER` pass `NULL` so live theme/DPI reloads never cause autostart loops. + +## Live replacement, desktop identity & XKB status + +1. **ICCCM `WM_S` takeover & fallback**: `src/dwm/dwm.c` (`acquirewm`, `--replace`) claims `WM_S` on `wmcheckwin`, broadcasts `MANAGER`, exits cleanly on `SelectionClear`, and waits up to 5 s for `prev_owner` destruction and `SubstructureRedirectMask`. `scripts/anode-replace` pairs this with a 1.5 s UID-checked `_NET_WM_PID` `SIGTERM` fallback for non-ICCCM WMs. +2. **EWMH/XDG desktop identity**: `dwm` publishes `_NET_WM_NAME = "ANODE WM"`, `XA_WM_NAME = "ANODE WM"`, and `_NET_WM_PID`, while `anode-session` and `anode-replace` clear stale foreign DE variables, export `XDG_CURRENT_DESKTOP=ANODE`, and update DBus/systemd user activation environments so system tools such as `fastfetch` report `Desktop Environment: ANODE` and `Window Manager: ANODE WM (X11)`. +3. **Zero-poll XKB layout indicator**: `src/daemons/anode-statusd.c` selects `XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbNamesNotifyMask` and `XkbGroupStateMask`-filtered `XkbStateNotify` events on the X11 fd, resolving lowercase layout codes via `src/common/anode_xkb_parse.h` (live XKB symbols -> `_XKB_RULES_NAMES` -> group names) to place `` directly left of the datetime. diff --git a/docs/AUTOSTART.md b/docs/AUTOSTART.md index 83c6575..d9baa78 100644 --- a/docs/AUTOSTART.md +++ b/docs/AUTOSTART.md @@ -4,9 +4,9 @@ ANODE supports i3-style session-specific autostart directives paired with per-pr ## 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. +- `anode-session` scrubs stale third-party DE environment variables, exports `XDG_CURRENT_DESKTOP=ANODE`, `XDG_SESSION_DESKTOP=anode`, `DESKTOP_SESSION=anode`, `XDG_SESSION_TYPE=x11`, and `ANODE_SESSION_PROFILE` when `--profile NAME` or `--profile=NAME` is passed, and supports `--replace` and `--no-autostart`. - 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. +- Unless `--no-autostart` is passed, once `dwm` advertises `_NET_SUPPORTING_WM_CHECK` whose `_NET_WM_NAME` contains `ANODE` (polled with `xprop` for up to 5 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 diff --git a/docs/SESSION.md b/docs/SESSION.md new file mode 100644 index 0000000..beee0cd --- /dev/null +++ b/docs/SESSION.md @@ -0,0 +1,42 @@ +# ANODE session management & status bar + +## Starting or live-replacing an X11 session + +- **Fresh X11 startup**: Launch ANODE from `~/.xinitrc` (`exec /usr/local/bin/anode-session [--profile NAME]`) or select the installed `ANODE` session (`PREFIX/share/xsessions/anode.desktop`) in a display manager. `anode-session` also accepts `--replace` and `--no-autostart` and forwards `--replace` to `dwm --replace`. +- **Live replacement (`anode-replace`)**: Replace an active X11 window manager or desktop session without logging out or closing open X11 windows: + +```sh +anode-replace --dry-run +anode-replace +anode-replace --profile work --keep-panels +``` + +| Flag | Behavior | +|---|---| +| `--profile NAME` / `--profile=NAME` | Pass session autostart profile `NAME` (`ANODE_SESSION_PROFILE`) to `anode-session` | +| `--keep-panels` | Keep existing third-party panels, notification daemons, and settings daemons running | +| `--foreground` | Exec `anode-session --replace` in the foreground instead of detaching | +| `--no-autostart` | Skip `anode-autostart start` during replacement | +| `--dry-run` | Print the detected WM (`_NET_SUPPORTING_WM_CHECK` window and PID), cleanup mode, and command without replacing | +| `-h`, `--help` | Print command usage and exit | + +- **Two-stage WM handoff**: + 1. **ICCCM 2.0 `WM_S` takeover**: `dwm` claims `WM_S` on its check window and handles `SelectionClear` by cleanly unwinding (`restart_dwm = 0; running = 0;`). When invoked with `--replace`, `dwm` acquires `WM_S`, broadcasts a root `MANAGER` `ClientMessage`, and polls `ConnectionNumber(dpy)` for up to 5 s until the previous owner destroys its selection window and releases `SubstructureRedirectMask`. + 2. **Non-ICCCM fallback**: Before launching `anode-session --replace`, `anode-replace` records `_NET_WM_PID` from `_NET_SUPPORTING_WM_CHECK`. If the previous window manager still holds `_NET_SUPPORTING_WM_CHECK` after 1.5 s and its PID belongs to the current UID (checked via POSIX `ps`), `anode-replace` sends `SIGTERM` so `dwm --replace` can take over `SubstructureRedirectMask`. +- **Process cleanup & detached readiness**: `anode-replace` terminates duplicate UID-owned ANODE daemons (`anode-statusd`, `anode-powerd`, `anode-touchd`, `anode-vkbd`) and, unless `--keep-panels` is given, stops conflicting third-party panels, notification daemons, and settings daemons (`xfce4-panel`, `mate-panel`, `lxpanel`, `tint2`, `polybar`, `lemonbar`, `fbpanel`, `plank`, `wingpanel`, `dunst`, `xfce4-notifyd`, `xsettingsd`, `xfsettingsd`). By default it launches `anode-session --replace` immune to `SIGHUP` and waits up to 5 s for `ANODE WM` to advertise itself on `_NET_SUPPORTING_WM_CHECK`. + +## Desktop environment & window manager identity + +- **EWMH & ICCCM properties**: `dwm` sets `_NET_WM_NAME = "ANODE WM"`, `XA_WM_NAME = "ANODE WM"`, `_NET_SUPPORTING_WM_CHECK`, and `_NET_WM_PID` on `wmcheckwin`, and sets `{"anode-wm", "ANODE"}` as the `XClassHint` on status bar windows. +- **Clean session environment**: Both `anode-session` and `anode-replace` unset stale third-party DE variables (`KDE_FULL_SESSION`, `KDE_SESSION_VERSION`, `KDE_SESSION_UID`, `GNOME_DESKTOP_SESSION_ID`, `MATE_DESKTOP_SESSION_ID`, `CINNAMON_VERSION`, `XFCE_SESSION`, `LXQT_SESSION_CONFIG`, `TDE_FULL_SESSION`, `HYPRLAND_INSTANCE_SIGNATURE`, `SWAYSOCK`, `I3SOCK`, `BSPWM_SOCKET`, `WINDOWMAKER`, `E_START`, `GDMSESSION`), export `XDG_CURRENT_DESKTOP=ANODE`, `XDG_SESSION_DESKTOP=anode`, `DESKTOP_SESSION=anode`, and `XDG_SESSION_TYPE=x11`, and sync DBus/systemd user activation environments when available (unless `ANODE_NO_DBUS=1`). +- **System info reporting**: Tools such as `fastfetch` report `Desktop Environment: ANODE` and `Window Manager: ANODE WM (X11)` instead of `dwm`. Terminals that were already open before running `anode-replace` keep their earlier shell environment until a new terminal is launched or `export XDG_CURRENT_DESKTOP=ANODE` is run. + +## Status bar & XKB layout indicator + +- **Format**: `anode-statusd` publishes `VOL | | | | YYYY-MM-DD HH:MM` (plus `VOL MUTE` when muted) to the X11 root `WM_NAME`. The `VOL` segment is omitted when no audio backend is detected, and `` is omitted cleanly if XKB is unavailable. +- **Text-only layout indicator**: `` is a plain lowercase ASCII layout code (for example `us`, `de`, `ru`, `ua`, `latam`, `jp`) positioned immediately to the left of the datetime with no prefix labels, icons, or graphics. +- **Zero-poll event model**: After `XkbQueryExtension()`, `anode-statusd` subscribes to `XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbNamesNotifyMask` (`XkbSelectEvents`) and `XkbStateNotify` filtered solely to `XkbGroupStateMask` (`XkbSelectEventDetails`) so regular keystrokes and modifier presses never wake the `poll()` loop. +- **Layout code resolution (`src/common/anode_xkb_parse.h`)**: + 1. Parse the live XKB symbols name (`XkbSymbolsNameMask`), handling `setxkbmap` and `xkbcomp` keymaps while stripping `:N` group selectors, `(variant)` suffixes, vendor prefixes (such as `nec_vndr/jp` -> `jp`), and non-layout components (`pc`, `evdev`, `inet`, `group`, `level3`, etc.). + 2. Fall back to the root `_XKB_RULES_NAMES` layouts CSV when the symbols string cannot be matched. + 3. Fall back to the first two lowercase ASCII letters of the active XKB group name (`XkbGroupNamesMask`). diff --git a/src/dwm/dwm.1 b/src/dwm/dwm.1 index 86f497b..3145b57 100644 --- a/src/dwm/dwm.1 +++ b/src/dwm/dwm.1 @@ -4,6 +4,7 @@ dwm \- dynamic window manager .SH SYNOPSIS .B dwm .RB [ \-v ] +.RB [ \-\-replace ] .SH DESCRIPTION dwm is a dynamic window manager for X. It manages windows in tiled, monocle and floating layouts. Either layout can be applied dynamically, optimising the @@ -37,6 +38,11 @@ dwm draws a small border around windows to indicate the focus state. .TP .B \-v prints version information to standard output, then exits. +.TP +.B \-\-replace +replaces a running X11 window manager via ICCCM +.B WM_S +selection handoff. .SH USAGE .SS Status bar .TP