Skip to main content

Module window_state

Module window_state 

Source
Expand description

Windowed geometry persistence ([window] remember_state). Per-app window-state persistence.

Opt-in via [window] remember_state = true in lumen.toml. Stores (position, size, maximized) at <state_dir>/<app-id>/window-state.toml between runs (state_dir follows the XDG / macOS / Windows conventions: $XDG_STATE_HOME -> ~/.local/state on Linux, ~/Library/Application Support on macOS, %LOCALAPPDATA% on Windows).

Save happens on LoopExiting so a normal window close persists, and a SIGTERM / crash doesn’t (acceptable - apps usually want a clean state if they crashed). Save also runs whenever Resized or a future Moved event fires so kill-9 still keeps the most-recent committed state.

Structs§

WindowState
On-disk shape. Logical pixels for size so HiDPI machines don’t see the app come back at half-size; position is in physical pixels (winit’s outer_position units).

Functions§

load
Load the persisted state for app_id, returning a fresh default when the file doesn’t exist or fails to parse (corrupted state shouldn’t brick the app - just discard).
save
Save state for app_id. Best-effort: creates parent directories on the fly; logs to stderr on failure and returns.
state_path
Resolve the path Lumen uses to persist a given app’s window state. Returns None when no per-user state dir is available (CI containers, sandboxed runs without $HOME); callers should treat that as “remember_state silently no-ops”.