Files
anode/docs/SESSION.md
T

10 KiB

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 in a display manager. Pass XSESSIONSDIR=/usr/share/xsessions to make install (e.g. sudo make XSESSIONSDIR=/usr/share/xsessions install) when installing into /usr/local so LightDM, SDDM, and GDM discover anode.desktop. 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, or switch to a clean ANODE display-manager session on a new VT:
anode-replace --dry-run
anode-replace
anode-replace --switch-session
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
--force Proceed with in-place replacement even when the active WM is a direct session child of a display manager or xinit
--switch-session Switch via LightDM (dm-tool switch-to-user) to an anode XSession when no user session is active yet; if a LightDM session for the current user is already active (where dm-tool merely refocuses the current VT), schedule a one-shot ~/.xprofile handoff ($XDG_CACHE_HOME/anode/switch-once) and exit the current WM so LightDM starts ANODE cleanly and returns to the previous default session on logout
--dry-run Print the detected WM (_NET_SUPPORTING_WM_CHECK window, PID, parent process, and DM session-leader warning) without replacing
-h, --help Print command usage and exit
  • Display manager session-leader safety guard: When a standalone window manager (such as i3) was launched directly as the session child of a display manager (lightdm, sddm, gdm, xdm, lxdm, slim, ly, greetd, emptty) or xinit/startx, causing it to exit via ICCCM replacement makes the display manager terminate the X server and restart/log out the session. anode-replace resolves the active WM PID (via _NET_WM_PID or falling back to a UID-filtered ps lookup by _NET_WM_NAME when _NET_WM_PID is omitted), checks its parent process, and refuses destructive in-place replacement unless --force is given — recommending anode-replace --switch-session (after sudo make XSESSIONSDIR=/usr/share/xsessions install) or selecting ANODE at login instead.
  • ANODE session holder (exit 75): When dwm yields ownership to another WM via ICCCM SelectionClear, dwm exits with status 75. anode-session stops its old background daemons and remains alive monitoring _NET_SUPPORTING_WM_CHECK until the replacement WM exits cleanly (tolerating brief transient reloads across 2 s) so a display manager does not kill the X server during in-place handoff.
  • Two-stage WM handoff:
    1. ICCCM 2.0 WM_S<screen> takeover: dwm claims WM_S<screen> on its check window and handles SelectionClear by cleanly unwinding (replaced_by_other = 1; restart_dwm = 0; running = 0;). When invoked with --replace, dwm acquires WM_S<screen>, 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 (or UID-matched WM PID fallback) 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, i3bar, 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 <n%> | CPU <c%> | RAM <r%> | <bat/AC> | <xkb> | 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, CPU/RAM use cross-Unix kernel telemetry (/proc/stat + /proc/meminfo on Linux, sysctl on FreeBSD/OpenBSD/NetBSD), and <xkb> is omitted cleanly if XKB is unavailable.
  • Text-only layout indicator: <xkb> 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.
  • Event-driven status loop: 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 loop, pairing XKB/signal events with a <= 2000 ms poll() refresh cadence for CPU/RAM telemetry and minute-aligned clock ticks without busy-polling.
  • 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).

Application launcher & XDG integration

  • Normalized XDG & Flatpak search path (data/env.sh): anode-session sources data/env.sh, which normalizes and exports XDG_DATA_DIRS without duplicates while appending $XDG_DATA_HOME/flatpak/exports/share, /var/lib/flatpak/exports/share, and /var/lib/snapd/desktop when present.
  • Desktop entry discovery (scripts/anode-launcher): Recursively scans applications/ directories (regular .desktop files and symlinks), builds standard XDG Desktop File IDs (translating subdirectories to -) so earlier user entries and Hidden=true / NoDisplay=true entries mask lower-priority system entries cleanly, and accepts --list to inspect resolved entries (label<TAB>workdir<TAB>term<TAB>cmd).
  • Execution semantics: Enforces Type=Application, case-insensitive OnlyShowIn / NotShowIn matching against XDG_CURRENT_DESKTOP, TryExec executability/PATH checks, locale priority (LC_ALL/LC_MESSAGES/LANG) for Name and GenericName, Flatpak @@u %U @@ wrapper and %i/%c/%k/%% field-code handling, [Desktop Action ...] sub-entries, Path= working directory changes, Terminal=true execution via st -e, DBusActivatable=true activation via gdbus, and setsid background detachment.
  • Full-height dmenu layout: anode-launcher invokes dmenu -i -l 0; in src/dmenu/dmenu.c, passing -l 0 (or omitting -l) fills the active monitor height (mh = sh) with all fitting (sh - bh) / bh rows, whereas explicit -l N sizes the menu tightly to (N + 1) * bh.

Idle power policy & screen locking

  • Idle policy (src/daemons/anode-powerd.c & src/common/anode_power_policy.h): Defaults to 5 min dim (DIM_SEC=300, dimming to max(0.35, 45%) of current brightness and polling every 500 ms while dimmed for responsive wake), 10 min lock (LOCK_SEC=600), 30 min battery-only suspend (SUSPEND_SEC=1800, SUSPEND_ON_AC=0), and 5% critical-battery warning/suspend (CRIT_BATT_PCT=5), configurable in $XDG_CONFIG_HOME/anode/power.conf.
  • Brightness restoration & backlight access: Automatically restores saved brightness when waking from ANODE_PWR_DIMMED / ANODE_PWR_LOCKED / ANODE_PWR_SUSPENDED or on daemon exit. On Linux, anode_backlight_get() (src/common/anode_plat.c) verifies writable /sys/class/backlight/*/brightness (access(..., W_OK) == 0) before using sysfs, falling back to brightnessctl / xrandr when unprivileged.
  • Screen-lock authentication (src/daemons/anode-checkpw.c): Verifies against /etc/shadow / BSD getpwnam directly when permitted and falls back to the setuid PAM helper (/sbin/unix_chkpwd / /usr/sbin/unix_chkpwd / /usr/libexec/unix_chkpwd) when running non-root; make install applies chmod 4755 to anode-checkpw when invoked as root with an empty DESTDIR.