Files
chandra/docs/reloading.md
Claude ff6f733810
CI / test (push) Canceled after 7m7s
chandra-ctl windows: how Chandra sees each window, and what the pointer is over
For "this window won't resize" reports (V's Gajim still not resizing on real hardware,
while a libadwaita window built like Gajim's resizes headless on both hosts): one line per
window with its frame kind (client-frame / chandra-frame), layout state (floating, tiled,
maximized, fullscreen), box, buffer, the client's shadow per side, min/max size and title,
then the pointer position and what it's over (a resize grip and which edge, a window, a
title bar, a tiling divider, the panel, the desktop).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hiu4r7mEXBdKY6cgv6
2026-11-26 04:39:45 +00:00

7.1 KiB

Picking up a new build in a running session

After just install the files under /usr/local are new, but the running session keeps what it loaded at startup. What can be swapped without logging out:

Part Reload without logout? How
Panel modules (/usr/local/share/chandra/modules/*.wasm) yes Applications → Reload, just reload / chandra-ctl reload, kill -USR1, or Settings → Panel (remove, add again)
The desktop module (desktop-modules.md) yes the same; chandra-ctl reload desktop for only it
compositor.wasm (shell, WM, portal backend) no restart the session
chandra-host (wasmhost) no restart the session
config/, themes, assets not checked restart the session to be sure

The control socket and the SIGUSR1 handler are part of the compositor and host, so a session started before they existed has neither. Log out and back in once after installing a build that has them; from then on module reloads need no logout. Don't send SIGUSR1 to a session older than that: without the handler the signal's default action ends the session.

Reloading panel modules

just install            # or: just modules, after `just install --link`
just reload                     # reload every panel module from disk
just reload clock-digital       # just one

just reload runs session/chandra-ctl reload; just install also installs it as /usr/local/bin/chandra-ctl:

chandra-ctl reload              # every loaded module
chandra-ctl reload NAME         # modules whose name (clock-digital), slot (w3) or path is NAME
chandra-ctl list                # loaded modules in panel order: slot, module, path
chandra-ctl ping                # is the compositor answering?
chandra-ctl shortcut overview   # run a keyboard shortcut by its id (see Settings > Shortcuts)
chandra-ctl windows             # each window's frame, layout state, box, shadow and size limits,
                                # then what the pointer is over (a resize grip, a window, ...)
chandra-ctl help

It prints one line per module and exits 0 when everything reloaded, 1 when the compositor reported an error (a module that failed to load, an unknown name), 2 when it could not reach a compositor:

$ chandra-ctl reload
reloaded w10 launcher
...
failed w8 my-widget: Can't load module: not a wasm file
error 1 of 9 failed to reload

What a reload does, for each module: load the .wasm again from the path it was loaded from (for an installed session, /usr/local/share/chandra/modules), apply its saved settings (:module-config in ~/.config/chandra/state.edn, the same values a login gives it), put the new instance in the old one's place in the panel, then drop the old instance. A module that fails to load is left loaded as it was, and the reply says why. The new instance gets a new slot id (w3 becomes w12) and starts fresh: an open popup closes. The module catalog is scanned again, so a module installed since login shows up under Settings → Panel → Add. A notice above the panel says what happened ("Reloaded 9 modules", or the error).

The reload goes through the same shell code as Settings → Panel (DesktopShell::reload_modules and replace_slot in compositor/shell/widgets.mbt), so a module that imports no new host capability needs nothing else. A module that needs a host interface the running host lacks fails to load and stays as it was: that needs a new session.

From the launcher

The Application Launcher's menu ends in a session row (Reload, Log out, Suspend, Restart, Power off). Reload does chandra-ctl reload from the desktop: the launcher calls session.reload (wit/capabilities.wit), which reaches the shell as the ReloadSession request, and DesktopShell::process_requests calls reload_modules(""). Same result and notice; windows and running apps are untouched, and it acts on the first click (Log out, Restart and Power off take a second one). Its own menu closes, and the launcher itself is reloaded with the rest.

SIGUSR1

Sending SIGUSR1 to the host process reloads every module, like chandra-ctl reload:

pkill -USR1 -x chandra-host

The result goes to the session log (the host's stderr) and the notice above the panel; there is nobody to answer. The handler is installed by the host at startup (sys.take-sigusr1, which the compositor polls every pass). The signal interrupts the idle loop's wait, so it is handled promptly.

The control socket

The compositor listens on $XDG_RUNTIME_DIR/chandra/<wayland socket name>.sock. The login session's Wayland socket is wayland-moon-0, so its control socket is /run/user/$UID/chandra/wayland-moon-0.sock. $XDG_RUNTIME_DIR is private to the user (mode 0700), so no other user can connect. Without XDG_RUNTIME_DIR there is no control socket (the log says so). When the path is already answered by another running compositor (a nested just run with the same socket name), the newcomer leaves it alone and has no control socket.

chandra-ctl finds the socket from --socket PATH, then $CHANDRA_CONTROL, then $WAYLAND_DISPLAY (inside the session), and otherwise takes the only socket in $XDG_RUNTIME_DIR/chandra (from a text console or ssh as the same user, with XDG_RUNTIME_DIR set). With several compositors running it lists them and asks for --socket.

The protocol is lines of text, so anything that can talk to a unix socket can drive it, for example echo reload | socat - UNIX-CONNECT:$XDG_RUNTIME_DIR/chandra/wayland-moon-0.sock. A client writes one command per line; each reply is zero or more lines of output and then one line starting with ok or error. Several commands may be sent on one connection.

Command Reply
ping ok pong
list <slot> <module> <path> per module, then ok <n> modules
reload [NAME] reloaded <new slot> <module> or failed <slot> <module>: <why> per module, then ok <n> reloaded or error ...
help the commands, then ok

The compositor handles the socket in its main loop (compositor/host/control.mbt, from ChandraCompositor::step), and the listening socket and its clients are among the fds the idle loop waits on, so an idle desktop still sleeps (about 0.4% CPU, unchanged) and wakes for a command. It is the same code on the MoonBit host and the native build.

Not reloadable

chandra-host and compositor.wasm are read once when chandra-session starts them. There is no reload request or file watcher for them. docs/ARCHITECTURE.md says so ("no hot reload on file change"), and the WM hot-swap in docs/compositor-design.md (replaying list<window-state> into a new WM component's sync-windows) is a design: nothing triggers it yet. Changes to the compositor, WM, portal backend or host need a new session: log out and back in.

Status

Tested headless on build/wasmhost (and on the Rust host, since removed) with the modules from build/components: ping, list, reload, reload NAME, a module replaced by a broken file (reported, old instance kept), SIGUSR1, and idle CPU before and after. Tests: compositor/host/control_test.mbt. Not yet run against an installed login session.