How do I draw the desktop on Mac OS X?

限于喜欢 提交于 2019-11-28 17:19:56

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:

  1. Call [window setLevel:kCGDesktopWindowLevel] to float below other application windows.
  2. Call [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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!