Skip to content

Agent: redraw macOS windows after display wake or change - #1641

Open
AnthonyRonning wants to merge 1 commit into
masterfrom
fix/1640-stale-window
Open

AnthonyRonning wants to merge 1 commit into
masterfrom
fix/1640-stale-window

Conversation

@AnthonyRonning

@AnthonyRonning AnthonyRonning commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Mitigation for #1640: Maple Work's window can stop painting after a lid close, undock or display change, while input and app state keep working, until the app restarts.

Cause (likely, not reproduced)

The gpui update in #1571 brought Zed's move of macOS 14+ frame pacing to a CAMetalDisplayLink on the window's layer (zed-industries/zed#65472). gpui wakes that link only when a window first becomes dirty, so a link that has gone silent, or is missing, is never woken again. Zed has an open report with the same signature: zed-industries/zed#67004 (process idle, no frames, only a restart helps). We are leaving the real fix to Zed. This is a small app-side recovery until then.

Change

New macOS-only desktop/native_redraw.rs, installed at startup (a failure only logs a warning):

  • Observes NSWorkspaceScreensDidWakeNotification, NSWorkspaceDidWakeNotification and NSApplicationDidChangeScreenParametersNotification.
  • On each, marks every window dirty and calls setNeedsDisplay: on its view. gpui's displayLayer: then draws one frame synchronously and attaches a new display link. A second pass runs 1 s later, once displays settle; bursts share that pass.
  • If a window gpui reports visible gets no frame request within 2 s of a pass, it logs no frame request within 2s of a display change; the window may have stopped painting. If this recurs, the log shows whether the recovery ran and failed.

Cost: one extra synchronous frame per window per wake or display change.

Limits

Testing

  • just ci-lint and the pre-commit ci-test pass.
  • Debug build on macOS 27.2 (M5 Max), with a test-only dylib injected through DYLD_INSERT_LIBRARIES (not committed):
    • Posting the three notifications in-process: two immediate passes and one coalesced settle pass per burst, no warning.
    • Recovery: at 6 s the dylib permanently pauses every existing CAMetalDisplayLink (unpause ignored), as in the frozen window. After the notifications, each pass made gpui create a new link (Public Release #2, teeny fix for nav spacing #3), and no warning followed, so frame requests resumed.
    • Control: same, but with GPUIView displayLayer: also turned into a no-op. Both passes logged the warning, which confirms the link really was dead and the detection works.

🤖 Generated with Claude Code


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

Since the gpui update, macOS 14+ windows are paced by a CAMetalDisplayLink.
After a lid close, undock or sleep, a window can stop painting while input
and state keep working, until a restart (#1640, zed-industries/zed#67004).

On display wake, system wake and screen-parameter changes, ask each window's
view to redisplay: gpui then draws one frame synchronously and attaches a new
display link. A second pass runs once displays settle. If a visible window
still gets no frame request within 2 s, log a warning for diagnosis.

Co-Authored-By: Claude <noreply@anthropic.com>

This branch has not been deployed

No deployments
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