I want to draw the desktop on Mac OS X (Snow Leopard). Specifically, I want to achieve the same effect as running:
/System/Library/Frameworks/ScreenSaver.framework/Resources/
ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background
(If you’re not near your computer, this displays the screensaver where you would normally see your desktop background.)
I know how to make a window without a border (by subclassing NSWindow and overriding initWithContentRect:styleMask:backing:defer: to set the window style to NSBorderlessWindowMask) and without a shadow (setHasShadow:NO.)
I know that I can call setLevel:kCGDesktopWindowLevel or kCGDesktopIconWindowLevel to put my window below other windows (see question 418791.) However this isn’t exactly what I want, because a window at this level is still on top of the desktop icons. I want to be on top of the desktop background, but below the icons.
My view is opaque. If there is a technique that clobbers the desktop background, that is OK.
You should create a subclass of NSWindow
and set the level to (kCGDesktopWindowLevel - 1)
. This will get your window below the icons. You should also ensure that your window doesn't become key or main and that it handles Exposé/Spaces properly by not moving.
- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
{
self = [super initWithContentRect:contentRect styleMask:windowStyle backing:bufferingType defer:deferCreation];
if(self)
{
[self setLevel:kCGDesktopWindowLevel - 1];
[self setCollectionBehavior:
(NSWindowCollectionBehaviorCanJoinAllSpaces |
NSWindowCollectionBehaviorStationary |
NSWindowCollectionBehaviorIgnoresCycle)];
}
return self;
}
- (BOOL)canBecomeMainWindow
{
return false;
}
- (BOOL)canBecomeKeyWindow
{
return false;
}
To display above the desktop but below the desktop icons, you need to do two things:
[window setLevel:kCGDesktopWindowLevel]
to float below other application windows.[window orderBack:self]
to layer behind the window that draws the desktop icons.Something during app launching brings the application to the front, so you should call orderBack: in your application delegate’s applicationDidFinishLaunching: method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With