Skip to content

fix(window): recover persisted position after display changes - #356

Merged
forketyfork merged 2 commits into
mainfrom
fix/window-position-recovery
Aug 15, 2026
Merged

fix(window): recover persisted position after display changes#356
forketyfork merged 2 commits into
mainfrom
fix/window-position-recovery

Conversation

@forketyfork

Copy link
Copy Markdown
Owner

Issue

Architect persists the window's last position. If that position belongs to a disconnected display, the next launch can place the window outside the visible desktop.

Solution

Validate the persisted position after SDL initializes and query the primary display bounds. Reuse the saved position only when at least 32 pixels of the window remain reachable; otherwise leave placement to SDL's normal default behavior. The geometry is covered by unit tests, including negative display origins.

Context

This is the independent window-placement behavior salvaged from PR #87. The event-loop portion of that PR is superseded by the wakeable idle wait in PR #286 and the coalesced PTY wakeups in PR #337.

Test plan

  • Launch with a persisted position on an attached external display, disconnect that display, and verify Architect opens at the platform's default visible position.
  • Reconnect the display and verify a valid persisted position is still restored.

Issue: A persisted window position can refer to a disconnected display and leave Architect outside the visible desktop on the next launch.\n\nSolution: Validate the saved position after SDL initializes against the primary display bounds, preserving it only when a 32-pixel strip remains reachable. Otherwise let SDL choose its normal default placement, with focused geometry tests covering standard and negative-origin displays.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves startup window placement robustness by validating a persisted window position against the primary display bounds after SDL initializes, so disconnecting/reshuffling monitors doesn’t strand the window off-screen.

Changes:

  • Add geometry validation for restored window positions with a 32px “reachable” margin threshold.
  • Add unit tests covering visibility checks, including displays with negative origins.
  • Ensure the new tests are executed by registering platform/sdl.zig in the root test import list, and document the behavior in README/architecture docs.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/platform/sdl.zig Adds position validation helpers and unit tests; applies restored position only when usable.
src/main.zig Registers platform/sdl.zig in the root test block so its tests run.
src/c.zig Re-exports SDL display APIs needed for bounds validation.
README.md Documents fallback to default placement when saved position is unusable.
docs/ARCHITECTURE.md Notes the validated-restore behavior and the 32px reachability rule.
Suppressed comments (1)

src/platform/sdl.zig:61

  • restoredWindowPosition falls back to returning the persisted position when SDL_GetPrimaryDisplay() or SDL_GetDisplayBounds() fails. That bypasses the visibility validation and can still restore an off-screen window, contradicting the goal of recovering after display changes. Prefer returning null on display query failures so SDL's default placement is used (safe recovery behavior).
    const primary = c.SDL_GetPrimaryDisplay();
    if (primary == 0) return desired;

    var display_bounds: c.SDL_Rect = undefined;
    if (!c.SDL_GetDisplayBounds(primary, &display_bounds)) return desired;

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/platform/sdl.zig
Comment on lines +41 to +45
) bool {
const min_x = display_bounds.x - window_w + window_visibility_margin;
const max_x = display_bounds.x + display_bounds.w - window_visibility_margin;
const min_y = display_bounds.y - window_h + window_visibility_margin;
const max_y = display_bounds.y + display_bounds.h - window_visibility_margin;
@forketyfork
forketyfork merged commit 79c7c79 into main Aug 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants