fix(window): recover persisted position after display changes - #356
Merged
Conversation
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.
There was a problem hiding this comment.
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.zigin 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
restoredWindowPositionfalls back to returning the persisted position whenSDL_GetPrimaryDisplay()orSDL_GetDisplayBounds()fails. That bypasses the visibility validation and can still restore an off-screen window, contradicting the goal of recovering after display changes. Prefer returningnullon 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 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; |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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