Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ Architect is a terminal multiplexer displaying 9 interactive sessions in a 3×3

## Runtime Flow

**main.zig** owns application lifetime, window sizing, PTY/session startup, configuration persistence, and the frame loop. Each frame it:
**main.zig** owns application lifetime, window sizing, PTY/session startup, configuration persistence, and the frame loop. Each iteration it:

1. Polls SDL events and scales coordinates to render space.
2. Builds a lightweight `UiHost` snapshot and lets `UiRoot` handle events first.
3. Runs remaining app logic (terminal input, resizing, keyboard shortcuts).
4. Runs `xev` loop iteration for async process exit detection.
5. Processes output from all sessions and drains async notifications.
1. Computes a wait deadline (0ms when work is pending, ~16ms during inertia, up to 500ms when idle) and blocks on `SDL_WaitEventTimeout`.
2. SDL events include user events posted by a dedicated IO thread (xev) whenever a PTY has data or a child exits.
3. Builds a lightweight `UiHost` snapshot and lets `UiRoot` handle events first.
4. Runs remaining app logic (terminal input, resizing, keyboard shortcuts).
5. Processes PTY output only for sessions marked “ready” by the IO thread, then flushes queued stdin.
6. Updates UI components and drains `UiAction` queue.
7. Advances animation state if transitioning.
8. Calls `renderer.render` for the scene, then `ui.render` for overlays, then presents.
9. Sleeps based on idle/active frame targets (~16ms active, ~50ms idle).
8. Calls `renderer.render` for the scene, then `ui.render` for overlays, then presents—only when something is dirty/animating.

The IO-facing work is isolated on a dedicated xev thread: it watches all PTY masters for readability and process exits, then posts SDL user events that wake the main loop. Access to the xev loop is serialized with a mutex when (re)registering watchers during spawns or restarts.

**renderer/render.zig** draws only the *scene*:
- Terminal cell content with HarfBuzz-shaped text runs
Expand Down
6 changes: 6 additions & 0 deletions src/c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pub const SDL_FillSurfaceRect = c_import.SDL_FillSurfaceRect;
pub const SDL_BlitSurface = c_import.SDL_BlitSurface;
pub const SDL_GetError = c_import.SDL_GetError;
pub const SDL_PollEvent = c_import.SDL_PollEvent;
pub const SDL_WaitEventTimeout = c_import.SDL_WaitEventTimeout;
pub const SDL_PushEvent = c_import.SDL_PushEvent;
pub const SDL_Delay = c_import.SDL_Delay;
pub const SDL_StartTextInput = c_import.SDL_StartTextInput;
pub const SDL_StopTextInput = c_import.SDL_StopTextInput;
Expand All @@ -79,6 +81,7 @@ pub const SDL_EVENT_MOUSE_MOTION = c_import.SDL_EVENT_MOUSE_MOTION;
pub const SDL_EVENT_MOUSE_WHEEL = c_import.SDL_EVENT_MOUSE_WHEEL;
pub const SDL_EVENT_WINDOW_RESIZED = c_import.SDL_EVENT_WINDOW_RESIZED;
pub const SDL_EVENT_WINDOW_MOVED = c_import.SDL_EVENT_WINDOW_MOVED;
pub const SDL_EVENT_USER = c_import.SDL_EVENT_USER;
pub const SDL_EVENT_DROP_BEGIN = c_import.SDL_EVENT_DROP_BEGIN;
pub const SDL_EVENT_DROP_FILE = c_import.SDL_EVENT_DROP_FILE;
pub const SDL_EVENT_DROP_TEXT = c_import.SDL_EVENT_DROP_TEXT;
Expand All @@ -96,6 +99,9 @@ pub const SDL_SCANCODE_END = c_import.SDL_SCANCODE_END;
pub const SDL_KMOD_MODE = c_import.SDL_KMOD_MODE;
pub const SDL_SCANCODE_AC_HOME = c_import.SDL_SCANCODE_AC_HOME;
pub const SDL_SCANCODE_AC_END = c_import.SDL_SCANCODE_AC_END;
pub const SDL_DisplayID = c_import.SDL_DisplayID;
pub const SDL_GetPrimaryDisplay = c_import.SDL_GetPrimaryDisplay;
pub const SDL_GetDisplayBounds = c_import.SDL_GetDisplayBounds;

pub const SDL_SetTextureScaleMode = c_import.SDL_SetTextureScaleMode;
pub const SDL_SCALEMODE_LINEAR = c_import.SDL_SCALEMODE_LINEAR;
Expand Down
Loading