When switching Spaces, keep floating NSPanel on its original space

Viewed 50

My document-based app has floating panels attached to its main document windows. When using Spaces, switching between desktops causes the floating windows to follow. I'd like to keep them on the original space.

The behavior is obviously caused by level being NSFloatingWindowLevel, and not NSNormalWindowLevel, even if my collectionBehavior is set to 0. I try avoid this by setting window level to normal when document window resigns main:

- (void)windowDidResignMain:(NSNotification *)notification {
    for (NSPanel *panel in panels) {
        panel.level = NSNormalWindowLevel;
    }
}

However, for some reason, when the user switches spaces, the document does not automatically resign. At that point, macOS decides to throw all the panels on the next Space, and leaves them there, even when the original document window becomes main again.

I've tried catching NSWorkspaceActiveSpaceDidChangeNotification, but this happens too late, and the panels have already moved on the wrong space.

This can be fixed by using [window addChildWindow:...], but seriously harms the UI, as all the panels then move alongside main window.

Is there a way to make always-on-top windows stay on the same Space they were before? Or is there a window.level setting which would keep some windows on top of their parent window, but not on top of other stuff?

0 Answers
Related