I'm searching for the "best" way of creating a fullscreen overlay under Mac OS X. I want to create a transparent or semi-transparent overlay, which cares about mouse events and shows other input/output elements.
This overlay should be above every other GUI items (like the CMD-Tab overlay).
Do you know how to do it effectively? At the moment I'm playing around with this kind of code:
int windowLevel = CGShieldingWindowLevel();
NSRect windowRect = [[NSScreen mainScreen] frame];
NSWindow *overlayWindow = [[NSWindow alloc] initWithContentRect:windowRect
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO
screen:[NSScreen mainScreen]];
[overlayWindow setReleasedWhenClosed:YES];
[overlayWindow setLevel:windowLevel];
[overlayWindow setBackgroundColor:[NSColor colorWithCalibratedRed:0.0
green:0.0
blue:0.0
alpha:0.5]];
[overlayWindow setAlphaValue:1.0];
[overlayWindow setOpaque:NO];
[overlayWindow setIgnoresMouseEvents:NO];
[overlayWindow makeKeyAndOrderFront:nil];
…and it works fine but I've got no options to initiate any kind of animations like slowly increasing the transparency (slowly dimming the screen) etc.
Although I'm not understanding how to put this window in the background, without releasing it and let it pop up time to time.
So is there a better or "standard" way to do it?
[NSScreen mainScreen]
isn't what you probably think it is: It's the screen with the active (main) window on it, which may be a secondary screen. If you want the screen that has the menu bar on it, that's[[NSScreen screens] objectAtIndex:0]
. (Everybody makes this mistake at least once.) – Peter Hosey