Reputation: 215
I'm writing an application that is looking to draw a basic NSWindow on top of the Desktop icons (Mac OSX 10.7 Lion).
NSWindow *systemInfoWindow = [[NSWindow alloc] initWithContentRect:frame
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO];
systemInfoWindow.delegate = self;
[systemInfoWindow setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces];
[systemInfoWindow setBackgroundColor:backgroundColorSpace];
[systemInfoWindow makeKeyAndOrderFront:NSApp];
[systemInfoWindow setLevel:kCGDesktopIconWindowLevel];
This part of code works quite well and the NSWindow gets draw on top of the icons. But if I switch between two spaces my NSWindow stay behind the icons.
/* === Update === */ I think i have problems with my window Level. For better understanding I have uploaded two Screenshots. Space 1 - window stays like I want on top of the Icons http://dl.dropbox.com/u/1503795/Space1.png
Space 2 - the window is behind the Desktop icons. They should also stay on top http://dl.dropbox.com/u/1503795/Space2.png
A further problem I found. If I activated the App and stay on the first Space and everything looks good like on my first Screenshot. If I select the Files on the Desktop the window also jumps to the back: Sorry, can`t post a nother Screenshot
I hope my problem is a bit more understandably.
I dont`t know how to fix this. Has anybody an idea? Thanks!
Upvotes: 3
Views: 1236
Reputation: 46028
You probably need to register for the space change notification:
NSNotificationCenter* nc = [[NSWorkspace sharedWorkspace] notificationCenter];
[nc addObserver:self
selector:@selector(activeSpaceDidChange:)
name:NSWorkspaceActiveSpaceDidChangeNotification
object:nil];
You can then respond to the notification and update your window:
- (void) activeSpaceDidChange:(NSNotification*)aNotification
{
[[self window] orderFront:self];
}
Upvotes: 1