Skip to content

macOS: order a dropped window out before closing it - #4728

Draft
crmne wants to merge 1 commit into
rust-windowing:masterfrom
crmne:macos-close-orderout-before-close
Draft

crmne wants to merge 1 commit into
rust-windowing:masterfrom
crmne:macos-close-orderout-before-close

Conversation

@crmne

@crmne crmne commented Oct 2, 2026

Copy link
Copy Markdown

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.

The stack runs from NSTouchBarFinderSetNeedsUpdateOnMain_block_invoke_2 through NSDisplayCycleFlush and CA::Transaction::commit to a run loop observer inside -[NSApplication run]. An application that catches the exception keeps running, but the Core Animation transaction is cut short, so the closed window stays on screen and looks frozen. This was reported against an Intel MacBookPro16,1 on macOS 26 by an app that keeps running in the tray after its window closes (crmne/zapfast#260).

Before closing, Window::drop now:

  • makes the window's first responder nil, so the view leaves the responder chain while it still exists and the Touch Bar observation is torn down in order;
  • orders the window out;
  • flushes the current CATransaction (looked up at runtime, so no new dependency), so the window leaves the screen before anything later in the display cycle can interrupt it.

Then it calls close() as before. Each of these steps is harmless on Macs without a Touch Bar.

Tested: built on macOS (arm64, no Touch Bar), where windows that are created and dropped while the event loop keeps running leave the screen at once and the loop exits cleanly. Draft until it is confirmed on Touch Bar hardware.

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

crmne added a commit to crmne/fastframe that referenced this pull request Oct 2, 2026
The forks section now lists every patch the egui and winit forks carry,
with its fork commit and its upstream pull request (or that it needs one),
under the rule that a patch stays in the fork until an egui or winit
release includes it.

The recommended revisions move to crmne/egui ba6790fe and crmne/winit
ed7caa90, which add the accessibility focus fix (emilk/egui#8621), an
OpenGL compatibility-profile fallback (#8655), the window size restored at
any zoom (#8656) and a dropped macOS window ordered out before it closes
(rust-windowing/winit#4728). An app that worked around the zoom shrink
drops its workaround with them. The block builds in a scratch app on
fastframe v0.2.3 with one egui and one winit, both from the forks.
crmne added a commit to crmne/zapfast that referenced this pull request Oct 3, 2026
The shared forks now carry four fixes every app on them wanted:

- winit orders a dropped macOS window out before closing it. On Touch Bar
  Macs AppKit threw while tearing the window down, and the closed window
  stayed on screen, looking frozen (#260, rust-windowing/winit#4728).
- egui moves the accessibility focus to the root when the focused widget
  has no node yet, which crashed renaming a group on Windows (#313,
  emilk/egui#8621).
- eframe falls back to a compatibility-profile OpenGL context, so drivers
  without OpenGL 3.3 or ES through WGL can still start the app (#349,
  emilk/egui#8655).
- eframe saves the zoom factor with the window size, so a window no longer
  shrinks each time it reopens at a zoom other than 100% (#293,
  emilk/egui#8656). ZapFast's own window_builder hook for that is removed:
  with the fixed eframe it would scale the size twice.
intellq pushed a commit to intellq/zapfast that referenced this pull request Oct 3, 2026
The shared forks now carry four fixes every app on them wanted:

- winit orders a dropped macOS window out before closing it. On Touch Bar
  Macs AppKit threw while tearing the window down, and the closed window
  stayed on screen, looking frozen (crmne#260, rust-windowing/winit#4728).
- egui moves the accessibility focus to the root when the focused widget
  has no node yet, which crashed renaming a group on Windows (crmne#313,
  emilk/egui#8621).
- eframe falls back to a compatibility-profile OpenGL context, so drivers
  without OpenGL 3.3 or ES through WGL can still start the app (crmne#349,
  emilk/egui#8655).
- eframe saves the zoom factor with the window size, so a window no longer
  shrinks each time it reopens at a zoom other than 100% (crmne#293,
  emilk/egui#8656). ZapFast's own window_builder hook for that is removed:
  with the fixed eframe it would scale the size twice.

(cherry picked from commit 4b0f79b)

Fork: vendor/winit recebe o diff fb8b24c..ed7caa9 do crmne/winit, mantendo
o patch de posição do arrasto; fica o size_within_monitor do fork.
On Macs with a Touch Bar, closing a window made AppKit throw 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 keeps running, but the Core Animation transaction
is cut short and the closed window stays on screen.

Resign the first responder while the view still exists, order the
window out and flush the Core Animation transaction before closing.
@crmne
crmne force-pushed the macos-close-orderout-before-close branch from 340c46f to 0ccb76d Compare October 14, 2026 21:16
@crmne

crmne commented Oct 14, 2026

Copy link
Copy Markdown
Author

Rebased onto master to resolve the changelog conflict. The 0.30 backport is #4764.

caue-r pushed a commit to caue-r/zapfast that referenced this pull request Nov 8, 2026
The shared forks now carry four fixes every app on them wanted:

- winit orders a dropped macOS window out before closing it. On Touch Bar
  Macs AppKit threw while tearing the window down, and the closed window
  stayed on screen, looking frozen (crmne#260, rust-windowing/winit#4728).
- egui moves the accessibility focus to the root when the focused widget
  has no node yet, which crashed renaming a group on Windows (crmne#313,
  emilk/egui#8621).
- eframe falls back to a compatibility-profile OpenGL context, so drivers
  without OpenGL 3.3 or ES through WGL can still start the app (crmne#349,
  emilk/egui#8655).
- eframe saves the zoom factor with the window size, so a window no longer
  shrinks each time it reopens at a zoom other than 100% (crmne#293,
  emilk/egui#8656). ZapFast's own window_builder hook for that is removed:
  with the fixed eframe it would scale the size twice.
aleliras added a commit to aleliras/zapfast that referenced this pull request Nov 23, 2026
The shared forks now carry four fixes every app on them wanted:

- winit orders a dropped macOS window out before closing it. On Touch Bar
  Macs AppKit threw while tearing the window down, and the closed window
  stayed on screen, looking frozen (crmne#260, rust-windowing/winit#4728).
- egui moves the accessibility focus to the root when the focused widget
  has no node yet, which crashed renaming a group on Windows (crmne#313,
  emilk/egui#8621).
- eframe falls back to a compatibility-profile OpenGL context, so drivers
  without OpenGL 3.3 or ES through WGL can still start the app (crmne#349,
  emilk/egui#8655).
- eframe saves the zoom factor with the window size, so a window no longer
  shrinks each time it reopens at a zoom other than 100% (crmne#293,
  emilk/egui#8656). ZapFast's own window_builder hook for that is removed:
  with the fixed eframe it would scale the size twice.

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