Make NSWindow show up on every workspace, even newly created ones after

By using NSWindowCollectionBehaviorCanJoinAllSpaces, I can make NSWindow show up on every already opened space, however, it won't show up on spaces that were added after app launch. How can I display NSWindow on spaces which were added after app launch? For example SideNotes app it can be shown on all spaces, on already opened ones before app launch and ones which were created after app launch.

Replies

1.Use NSPanel instead of NSWindow:

window = [[NSPanel alloc] initWithContentRect:CGRectMake(100, 100, 400, 300) styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskNonactivatingPanel backing:NSBackingStoreBuffered defer:NO];
  window.level = NSMainMenuWindowLevel;
  window.collectionBehavior = NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorFullScreenAuxiliary;

2.Watching NSWorkspaceActiveSpaceDidChangeNotification:

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(notifyChange) name:NSWorkspaceActiveSpaceDidChangeNotification object:nil];

- (void)notifyChange {
  [window makeKeyAndOrderFront:nil];
}