For anyone interested, here's my workaround. Problem: NSWindow's setCollectionBehavior:NSWindowCollectionBehaviorMoveToActiveSpace doesn't work.
Fix: Subclass NSWindow, override makeKeyAndOrderFront: (and/or orderFront:, orderBack:, depending on your needs). - (void) makeKeyAndOrderFront:(id)sender { /* set the window to join all spaces */ [self setCollectionBehavior: NSWindowCollectionBehaviorCanJoinAllSpaces]; /* now bring it to the front, it will appear on the active space */ [super makeKeyAndOrderFront:self]; /* then reset the collection behavior to default, so the window won't "follow" when you switch spaces */ [self setCollectionBehavior:NSWindowCollectionBehaviorDefault]; } This is equivalent to the NSWindowCollectionBehaviorMoveToActiveSpace behavior and will cause the window to appear on the active space when ordered back programmatically. You will still have a problem if the user clicks your app's Dock icon, though. This will trigger a spaces switch if your window is currently displayed on some other space. You therefore need to add the following delegate methods to your app delegate: - (void)applicationWillBecomeActive:(NSNotification *)aNotification { /* called before the spaces switch occurs. we need to prevent the switch by making sure the window is ordered out, if currently visible on some other space */ if ( [mainWin isVisible] && ![mainWin isOnActiveSpace] ) { [mainWin orderOut:self]; } } - (BOOL) applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag { /* the app has now been activated on the current space, and all we need to do is bring our window subclass to the front */ [mainWin makeKeyAndOrderFront:self]; return YES; } The above is all that is required if you are targeting Snow Leopard only. If you want to support Leopard and earlier as well, you'll need to implement NSWindow's (10.6-only) "isOnActiveSpace" method manually in your window subclass. This is the tricky part. First, in your header file, you'll need to define some private Core Graphics stuff: /* Internal CG typedefs */ typedef int CGSConnection; typedef int CGSWindow; /* Internal CG functions */ extern CGSConnection _CGSDefaultConnection(void); extern OSStatus CGSGetWindowWorkspace(const CGSConnection cid, const int wid, int *workspace); extern OSStatus CGSGetWorkspace(const CGSConnection cid, int *workspace); Then, in your implementation file, add: -(BOOL)isOnActiveSpace { int windowWorkspace, currentWorkspace; CGSGetWindowWorkspace(_CGSDefaultConnection(), [self windowNumber], &windowWorkspace); CGSGetWorkspace(_CGSDefaultConnection(), ¤tWorkspace); return currentWorkspace == windowWorkspace ? YES : NO; } That's it! Hope someone finds this useful (and that Apple eventually solves the actual problem...) Fabian On Fri, Nov 20, 2009 at 8:25 PM, slasktrattena...@gmail.com <slasktrattena...@gmail.com> wrote: > Hum, no. I was wrong. [self setCollectionBehavior:1] means "can join > all spaces". Any ideas how to get > NSWindowCollectionBehaviorMoveToActiveSpace to work? > > Again, test app here demonstrates the problem: > > http://lists.apple.com/archives/cocoa-dev/2009/Oct/msg00647.html > > On Sun, Nov 15, 2009 at 8:12 PM, slasktrattena...@gmail.com > <slasktrattena...@gmail.com> wrote: >> This appears to be a bug. I found that whereas calling >> >> [self setCollectionBehavior:NSWindowCollectionBehaviorMoveToActiveSpace]; >> >> has no effect, >> >> [self setCollectionBehavior:1]; >> >> produces the desired behavior. I'll file a radar. >> >> /f >> >> On Sun, Nov 15, 2009 at 7:31 PM, slasktrattena...@gmail.com >> <slasktrattena...@gmail.com> wrote: >>> Hi all, >>> >>> Setting the collection behavior of my (standard) NSWindow to >>> NSWindowCollectionBehaviorMoveToActiveSpace has no effect whatsoever. >>> Someone else posted a simple test project a while back demonstrating >>> the problem: >>> >>> http://lists.apple.com/archives/cocoa-dev/2009/Oct/msg00647.html >>> >>> Any ideas? Thanks. >>> >>> /f >>> >> > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com