Skip to content

maple-agent: remember the main window position - #1270

Merged
AnthonyRonning merged 1 commit into
masterfrom
feat/agent-window-position
Oct 25, 2026
Merged

AnthonyRonning merged 1 commit into
masterfrom
feat/agent-window-position

Conversation

@AnthonyRonning

@AnthonyRonning AnthonyRonning commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Maple Work now reopens where it was last left on macOS. Before this change it saved only the window size and maximized state, and always opened centered.

Why position needs native code

  • The pinned GPUI (cc053a4a) can position a window only when it opens one. It has resize, but no move.
  • Settings live in the encrypted store, which opens after the main window is already showing.
  • A plaintext pre-store geometry file is ruled out by the store design ("no plaintext preferences").

Changes

  • Saved state: WindowState gains position { x, y, display }. The display is GPUI's persistent display UUID. Older saved state without a position still parses.
  • Recording: the position is captured on root render, which GPUI triggers on every move. The display UUID lookup reruns only when the display changes.
  • macOS restore: once the store opens, desktop/native_window.rs applies the saved size and position in one AppKit setFrame.
    • If the saved display is no longer connected, the window stays centered and is resized as before.
    • constrainFrameRect:toScreen: keeps the title bar on screen.
    • The frame change runs on the foreground executor, as GPUI's own resize does. Called synchronously inside window.update, AppKit's move and resize callbacks hit a borrowed window and GPUI logged RefCell already borrowed.
  • Linux and Windows: the startup window restores size only, unchanged. Moving it natively on Windows needs GPUI-private border offsets, and Wayland exposes no position.
  • Tray reopen: a window reopened from the tray (Linux/Windows) now opens at the saved position through GPUI's window_bounds + display_id.
  • Dependency: raw-window-handle is added as a direct macOS dependency to reach the NSWindow. It was already in the lockfile through GPUI.

Verification (macOS VM, isolated XDG profile)

  • Move and resize: moved and resized with cua-driver set_window_frame to (20, 60) 1000×700, chose Quit, relaunched. The window reopened at exactly (20, 60) 1000×700, and a screenshot showed the content laid out at the new size.
  • Move only: moved to (300, 120) without resizing, quit, relaunched. The window reopened at (300, 120).
  • Log: clean after the executor deferral. The first, synchronous version logged the RefCell error.
  • Checks: just clippy passes for all feature sets, the desktop/settings tests pass, and the pre-commit hook is green.

Not tested:

  • Linux and Windows, beyond compiling through CI.
  • A disconnected second display (the VM has one display).

Known limitation

On macOS the window still visibly moves from the centered default to its saved frame once the store opens, as the size restore already did. Removing that jump means opening the main window after the store is ready, which is store design decision #36 and a larger startup change.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Save the window origin and the display's UUID with the saved size. When
the store opens, macOS moves the window to that frame in one AppKit
change. If the display is gone, the window stays centered. The pinned
GPUI can only position a window when it opens one, and settings arrive
after the window is open. On Linux and Windows the startup window
therefore still restores size only. A window reopened from the tray
uses the saved position through GPUI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AnthonyRonning
AnthonyRonning merged commit 08b5890 into master Oct 25, 2026
40 checks passed
@AnthonyRonning
AnthonyRonning deleted the feat/agent-window-position branch October 25, 2026 06:34
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.

1 participant