Skip to content

[0.30] macOS: order a dropped window out before closing it - #4764

Draft
crmne wants to merge 1 commit into
rust-windowing:v0.30.xfrom
crmne:macos-close-orderout-0.30
Draft

crmne wants to merge 1 commit into
rust-windowing:v0.30.xfrom
crmne:macos-close-orderout-0.30

Conversation

@crmne

@crmne crmne commented Oct 14, 2026

Copy link
Copy Markdown

Backport of #4728 to the 0.30 maintenance branch, where eframe/egui and many other applications still are.

On Macs with a Touch Bar, dropping a Window calls -[NSWindow close], and in the next display-cycle flush AppKit throws NSRangeException: Cannot remove an observer <_NSTouchBarFinderObservation> for the key path "nextResponder" from <WinitView> because it is not registered as an observer. An application that catches the exception keeps running, but the Core Animation transaction is cut short and the closed window stays on screen. Reported against an Intel MacBookPro16,1 on macOS 26 (crmne/zapfast#260).

Before closing, Window::drop now clears the window's first responder, orders the window out, and flushes the current CATransaction (looked up at runtime, no new dependency), then calls close() as before. Each step is harmless on Macs without a Touch Bar.

Checked with cargo clippy --target aarch64-apple-darwin --all-targets -D warnings; the master version was run on an arm64 Mac without a Touch Bar. Draft until it is confirmed on Touch Bar hardware. CI on v0.30.x fails before compiling (syn is ambiguous, see #4692).

  • Tested on all platforms changed
  • Added an entry to the changelog module
  • Updated documentation to reflect any user-facing changes (none needed)

Dropping a Window closed it straight away. On Touch Bar Macs AppKit then
threw an NSRangeException in the next display-cycle flush, from
-[_NSTouchBarFinderObservation invalidate], because the view it observed
for nextResponder had already been unregistered. An application that
catches the exception in its run loop kept going, but the Core Animation
transaction was cut short and the closed window stayed on screen.

Resign the first responder while the view still exists, order the window
out and flush the Core Animation transaction before closing, so the
window leaves the screen whatever the display cycle does afterwards.

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

Development

Successfully merging this pull request may close these issues.

1 participant