Skip to content

RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process

docs: add a source map for agents and update the split-file notes

Claude0fb09979a386
diff --git a/AGENTS.md b/AGENTS.md
index a5b960a..126b471 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -1,7 +1,8 @@
# Notes for agents working on RediWM
Details that are easy to get wrong; read the section for what you touch.
-Tests: `TESTING.md`. Area notes are in an `AGENTS.md` beside the code; read
+Tests: `TESTING.md`. Where code lives: [source map](docs/agent-notes/map.md).
+Area notes are in an `AGENTS.md` beside the code; read
the one for the directory you work in: `src/files`, `src/editor`,
`src/desktop`, `src/input`, `src/control_center`, `src/ui`, `src/session`,
`src/dm`, `src/accounts_helper`, `src/printing`, `scripts`.
@@ -13,6 +14,12 @@ the one for the directory you work in: `src/files`, `src/editor`,
* Tool use is costly: no tight polling (wait 15–30 s between checks of long
operations), batch checks, don't re-read unchanged files.
* Add tests only when really needed or asked; prefer extending existing ones.
+* Keep files small enough to read whole. When a file you touch grows past
+ ~800 lines or a function past ~150, split it by concern (below), moving
+ code verbatim. Tests go in a `*_tests.zig` beside the code once they
+ outgrow a screen. Exempt: generated or table files (`ui/fold_data.zig`,
+ `ipc/commands.zig`) and the C rendering core, whose static state splitting
+ would have to share across translation units.
* Before finishing: build Debug and `-Doptimize=ReleaseSafe`, run
`zig build test` and the integration tests for what you touched. Some
suites fail on HEAD: compare with a `git worktree` of HEAD before calling a
@@ -20,16 +27,30 @@ the one for the directory you work in: `src/files`, `src/editor`,
## Split files
-Large types are spread over sibling files by concern. `Toplevel.zig` (`toplevel/`),
+Large types are spread over sibling files by concern. A TitleCase host keeps
+its methods in a lowercase directory: `Toplevel.zig` (`toplevel/`),
`Input.zig` (`input/`), `Taskbar.zig` (`taskbar/`), `Server.zig` (`server/`),
-`Output.zig` (`output/`), `files/app.zig`, `pdf/app.zig` and `desktop/app.zig`
-(`app_*.zig` beside them) keep the fields, `init`/`deinit` and one
+`Output.zig` (`output/`), `World.zig` (`world/`), `Dock.zig` (`dock/`),
+`Keyboard.zig` (`keyboard/`). Other hosts keep them beside them under a
+prefix: `files/app.zig`, `pdf/app.zig`, `desktop/app.zig`, `images/app.zig`,
+`editor/app.zig` (`app_*.zig`); `files/Client.zig` and the `Client` in
+`editor/main.zig` and `pdf/main.zig` (`client_*.zig`);
+`control_center/ControlCenter.zig` (`tree`, `keys`, `relayout`, `paint.zig`);
+`start_menu/StartMenu.zig` (`menu_*.zig`); `session/lock.zig`, `power.zig`
+(`lock_*`, `power_*.zig`); `systemd.zig` (`systemd/`); `network/manager.zig`,
+`dbus/connection.zig`, `ipc/wait.zig`, `ui/input.zig` (`<name>_*.zig`).
+Hosts keep the fields, `init`/`deinit` and one
`pub const name = group.name;` alias per method, so `self.name()` is unchanged;
the bodies are free functions taking the struct pointer. A new method goes in
its group file plus an alias line. `ipc/protocol_*.zig`, `ipc/handlers_*.zig`,
-`config/loader_*.zig`, `control_center/sections/appearance_*.zig` and
-`msg/msg_*.zig`, `ui/paint_*.zig` and `ui/anim_*.zig` re-export their public
-declarations from the original file.
+`config/loader_*.zig`, `control_center/sections/appearance_*.zig`,
+`printers_*.zig` and `msg/msg_*.zig`, `ui/paint_*.zig`, `ui/text_*.zig`,
+`ui/theme_*.zig`, `ui/anim_*.zig`, `chrome_paint.zig` re-export their public
+declarations from the original file. `handleRequest`/`handleAction` dispatch
+groups of tags to `handlers_*.zig`, each a `switch` with `else => unreachable`.
+`build.zig` keeps the options and shared modules; programs, data, session
+binaries and test steps are in `build/` and run in the order `build()` calls
+them.
Tests that used to sit in the big file are in a `*tests.zig` file reached by a
`test { _ = @import(...); }` block: a file nothing imports contributes no tests.
State (`var`) stays in the file that uses it; an alias would copy it.
diff --git a/docs/agent-notes/dock.md b/docs/agent-notes/dock.md
index 710a22b..3a23306 100644
--- a/docs/agent-notes/dock.md
+++ b/docs/agent-notes/dock.md
@@ -1,10 +1,11 @@
# Dock implementation notes
-Read when changing `src/Dock.zig`, `src/dock_drag.zig`, or their output,
+Read when changing `src/Dock.zig` (its methods are in `src/dock/`: reveal,
+items, paint, pointer, pins), `src/dock_drag.zig`, or their output,
taskbar, OSD and input integration. General rules remain in
[AGENTS.md](../../AGENTS.md); integration coverage is in `tests/dock.py`.
-* **The dock repaints cells, not itself** (`Dock.zig`). It keeps its last
+* **The dock repaints cells, not itself** (`dock/paint.zig`). It keeps its last
raster and, when only some items' looks changed (hover zoom, pills), clears
and repaints just their `itemCell`s (each item at the largest hover zoom, across
the dock's thickness) under a clip, publishing that damage alone. Dock-wide
@@ -54,7 +55,7 @@ taskbar, OSD and input integration. General rules remain in
ones: a press arms, motion past a threshold starts, and starting rebuilds the
menu so its release is no click. A pinned icon acts on release (`Dock.clickPin`)
so a drag can start from it. Closing the menu or Escape (`cancelDrag`; for a
- dock icon `Keyboard.zig` takes it ahead of every shell panel, for a menu app
+ dock icon `keyboard/process.zig` takes it ahead of every shell panel, for a menu app
before the menu's own Escape) abandons it. A dock
holds resolved pins as copies (`pin_arena`); `config_index` maps a slot back
into `dock_pinned_apps`, which also lists apps no longer installed.
diff --git a/docs/agent-notes/map.md b/docs/agent-notes/map.md
new file mode 100644
index 0000000..51ea75c
--- /dev/null
+++ b/docs/agent-notes/map.md
@@ -0,0 +1,112 @@
+# Source map
+
+Where things live, to find code without reading whole directories. Rules are
+in the root [AGENTS.md](../../AGENTS.md) and the `AGENTS.md` beside the code;
+tests are in [TESTING.md](../../TESTING.md).
+
+## Finding a function
+
+A type split across files keeps its fields, `init`/`deinit` and one alias
+line per method (`pub const paint = dock_paint.paint;`). When `self.paint()`
+leads to such a line, the body is in the file that alias names, imported a few
+lines above it. Group files are `host_*.zig` beside the host (`files/app_*.zig`)
+or a lowercase directory named after a TitleCase host (`Dock.zig` → `dock/`).
+`rg 'fn name\('` finds any body directly.
+
+## Programs
+
+| Binary | Root | Code |
+|---|---|---|
+| `rediwm` | `src/main.zig` | the compositor; everything below unless listed |
+| `rediwm-msg` | `src/msg/main.zig` | `msg_parse` (arguments), `msg_request` (request line), `msg_reply` (output) |
+| `rediwm-files` | `src/files_main.zig` | `files/`: `App` in `app.zig` + `app_*.zig`, its window in `Client.zig` + `client_*.zig`; `files/terminal/` (PTY drawer, `rediwm-files-terminal`, `files-bash.so`), `files/torrent/helper.cpp` (`rediwm-transfers`) |
+| `rediwm-images` | `src/images_main.zig` | `images/` (`app.zig` + `app_*.zig`) |
+| `rediwm-editor` | `src/editor_main.zig` | `editor/` (`app.zig` + `app_*.zig`, window in `main.zig` + `client_*.zig`) |
+| `rediwm-pdf` | `src/pdf_main.zig` | `pdf/` (sandboxed; window in `main.zig` + `client_*.zig`) |
+| `rediwm-monitor` | `src/system_monitor_main.zig` | `system_monitor/` |
+| `rediwm-calculator` | `src/calculator_main.zig` | `calculator/` |
+| `rediwm-share-picker` | `src/share_picker_main.zig` | `share_picker/` |
+| `rediwm-session` | `src/session_main.zig` | login supervisor (`session/supervisor.zig`, `publication.zig`) |
+| `rediwm-dm` | `src/dm/main.zig` | display manager, runs as root (`dm/AGENTS.md`) |
+| `rediwm-accounts-helper` | `src/accounts_helper/main.zig` | root account helper (`accounts_helper/AGENTS.md`) |
+| `rediwm-theme` | `src/theme_main.zig` | theme archive helper (`theme_helper/`) |
+
+`build.zig` holds the options, the shared modules, the compositor and
+`rediwm-msg`; `build/` the rest: `apps.zig` (the programs above), `data.zig`
+(installed data), `session.zig`, `tests.zig` (every `test*` step),
+`protocols.zig` (generated Wayland bindings), `support.zig` (helpers) and
+`context.zig` (what they share).
+
+## Shared modules
+
+No compositor imports (`build.zig` enforces the direction): `ui` (`src/ui/`:
+widgets, layout, text, theme, animation), `config` (`src/config/`: parsing and
+saving `config.toml`), `dbus`, `i18n`, `memory` and `protocol`
+(`src/ipc/protocol.zig`, the IPC wire format shared with `rediwm-msg`).
+
+## Compositor
+
+| Host | Methods | What |
+|---|---|---|
+| `Server.zig` | `server/` | startup and teardown, outputs, frames, wakeups, wallpaper |
+| `World.zig` | `world/` | window list, focus, the camera, zoom, pan and pinch |
+| `Toplevel.zig` | `toplevel/` | a window; `xdg.zig`, `xwayland_surface.zig` adapt the protocols |
+| `Output.zig` | `output/` | one monitor: frames, layout, modes, panels, wallpaper |
+| `Input.zig` | `input/` | seat, pointer, gestures, drags (`input/AGENTS.md`) |
+| `Keyboard.zig` | `keyboard/` | `process.zig`: the key pipeline (lock, switcher, panels, bindings, clients); `shell.zig`: keys for compositor panels |
+| `Taskbar.zig` | `taskbar/` | the taskbar; value types in `taskbar/types.zig` |
+| `Dock.zig` | `dock/` | the dock ([dock notes](dock.md)) |
+
+Also in `src/`: `Shell.zig` (xdg-shell and decorations), `Popup.zig`,
+`LayerSurface.zig`, `Xwayland.zig` (+ `xwayland_*.zig`), `Switcher.zig`
+(Alt+Tab), `workspaces.zig`, `snap.zig`, `auto_tiling.zig`, `window_tabs.zig`.
+
+**Rendering** (read [rendering details](rendering.md) first): own scene nodes
+`node.zig`/`node.c`/`node_surface.c`; `projection.zig`/`.c` (geometry and
+damage); `scene_output.zig`/`.c`, `scene_pass.c`, `scene_damage.c`,
+`scene_outputs.zig`/`.c` (the output pass); `glass.zig`/`.c`; `chrome.zig`
+(+ `chrome_paint.zig`, `chrome_tabs.zig`) for window frames; `panel_buffer`,
+`panel_paint` and `panel_present.zig` for compositor-drawn panels;
+`camera.zig`, `geometry.zig`, `color.zig`.
+
+## Compositor-drawn UI
+
+* **Start menu** (`start_menu/`): `panel.zig` re-exports `StartMenu`
+ (`StartMenu.zig` + `menu_*.zig`); the app catalog is `applications.zig`
+ with `desktop_file.zig` and `scan.zig`; `launch.zig`, `search.zig`.
+* **Settings** (`control_center/`, `AGENTS.md` there): the window is
+ `ControlCenter.zig` (+ `tree`, `keys`, `relayout`, `paint.zig`); `panel.zig`
+ has shared helpers; one `sections/*.zig` per page, the big ones split into
+ `appearance_*.zig` and `printers_*.zig`.
+* **Session** (`session/`, `AGENTS.md` there): `lock.zig` (+ `lock_account`,
+ `lock_events`, `lock_input`, `lock_view.zig`), `greeter.zig`, `idle.zig`,
+ `power.zig` (+ `power_*.zig`, logind), portals (`settings_portal.zig`,
+ `file_chooser.zig`), services.
+* The desktop icons (`desktop/`), `power_menu.zig`, `osd.zig`,
+ `calendar.zig`, `battery_popup.zig`, `network/popup.zig`, `mini_map.zig`,
+ `notifications/`, `tray.zig`, `polkit/` (authentication agent).
+
+## Services and system clients
+
+* **IPC** (`ipc/`): `server.zig` (socket and admission), `protocol*.zig`
+ (wire format), `handlers.zig` (checks and dispatch) with
+ `handlers_state`/`inspect` (queries) and `handlers_input`/`windows`/`frames`
+ (actions), `wait.zig` (+ `wait_conditions.zig`, `wait_replies.zig`),
+ `commands.zig` (the command table). The IPC is also the test harness.
+* **D-Bus** (`dbus/`): `connection.zig` (+ `connection_calls.zig`,
+ `connection_io.zig`), `wire.zig`.
+* `network/manager.zig` (+ `manager_*.zig`, NetworkManager), `bluetooth.zig`,
+ `audio/`, `printing/` (CUPS, `AGENTS.md` there), `systemd.zig`
+ (+ `systemd/`), `brightness.zig`, `power_profiles.zig`.
+* **Configuration**: `config/` reads and writes it (`loader.zig` +
+ `loader_parse`/`fields`/`edit`/`compare.zig`); `config_runtime/` applies it
+ to a running compositor.
+
+## Tests
+
+`zig build test` builds one test binary per root: `src/ui_tests.zig` (the
+compositor's code), `ipc_tests.zig`, `files_tests.zig`, `editor_tests.zig`,
+`images_tests.zig`, `pdf_tests.zig` and the shared modules. Other
+`*_tests.zig` files sit beside their code and are reached through
+`test { _ = @import(...); }` blocks; C fixtures are `src/*_test.c`;
+integration suites are `tests/*.py`.
diff --git a/src/control_center/AGENTS.md b/src/control_center/AGENTS.md
index 07d431f..3f0f1c9 100644
--- a/src/control_center/AGENTS.md
+++ b/src/control_center/AGENTS.md
@@ -1,6 +1,9 @@
# Settings (`ControlCenter`)
Settings is an ordinary window with a compositor-drawn body (`Backend.shell`).
+`ControlCenter.zig` holds its state and lifecycle; `tree.zig`, `keys.zig`,
+`relayout.zig` and `paint.zig` its methods; `panel.zig` the shared widget
+helpers (and `panel.ControlCenter`); `sections/` one file per page.
* The body paints into `scene_tree` at `render_scale` and presents with
`presentOwned`.
@@ -31,7 +34,7 @@ Settings is an ordinary window with a compositor-drawn body (`Backend.shell`).
`control_center.py` emits no such floods; a pass-through proxy that decodes bus
messages shows the real traffic without root (`BecomeMonitor` and
`Debug.Stats` need it).
-* Saving a theme slider rebuilds the page on release: `panel.rebuildTree`
+* Saving a theme slider rebuilds the page on release: `ControlCenter.rebuildTree` (`relayout.zig`)
carries named sliders' state across (`src/ui/AGENTS.md`, "Sliders").
* A rebuild of Appearance costs milliseconds (preset, wallpaper and icon-theme
scans) plus a full repaint: background wakes refresh only pages that show
diff --git a/src/files/AGENTS.md b/src/files/AGENTS.md
index b88c4bf..5258e6c 100644
--- a/src/files/AGENTS.md
+++ b/src/files/AGENTS.md
@@ -16,8 +16,13 @@ are free functions taking `self: *App` in `app_*.zig`, grouped by concern:
`app_git_sidebar`, `app_scroll`, `app_opening`, `app_pointer`,
`app_keyboard`, `app_menu`, `app_paint`, `app_items`. Shared enums and
records are in `app_model.zig`, drawing helpers in `app_draw.zig`, tests in
-`app_tests.zig`. A new method goes in its group file plus an alias line in
-`App`; a file that calls a sibling's non-method helper imports it directly.
+`app_tests.zig` (with `app_*_tests.zig` by area). A new method goes in its
+group file plus an alias line in `App`; a file that calls a sibling's
+non-method helper imports it directly.
+
+The window is `Client.zig` (Wayland globals, seat, buffers), re-exported by
+`main.zig`, with its handlers in `client_window`, `client_input`,
+`client_dnd`, `client_clipboard` and `client_render.zig`.
## Terminal drawer