Existing NSWindow Show Notifications Don't Work
People in Slack asked me why I didn’t use another mechanism to get notified when NSWindow
s are shown. Here’s what I was suggested and what I found:
-
NSWindow.didChangeScreenNotification
:
Does not fire for all windows showing for the first time, and if it fires, if firest only once. Closing and re-showing the window will not trigger the notification again. -
NSWindow.didBecomeKeyNotification
:
That works, unless the window is not becoming key but opens “just so” or behind another window. Which some panels do sometimes. It’s not a problem that they show up behind other windows at times. I think it’s supposed to be the way it is in certain situations. It just makes the event unreliable for my purpose.
Same for the related NSWindowDelegate
calls you can receive, namely windowDidBecomeMain(_:)
and windowDidBecomeKey(_:)
.
The dance involving NSApplicationDelegate.applicationDidUpdate(_:)
an applicationWillUpdate(_:)
is still the most resilient option I know. I’m open to suggestions, though!