如何在Mac OS X上绘制桌面? [英] How do I draw the desktop on Mac OS X?

查看:162
本文介绍了如何在Mac OS X上绘制桌面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Mac OS X(Snow Leopard)上绘制桌面。具体来说,我想实现与运行相同的效果:

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

(如果您不在附近

我知道如何创建一个没有边框的窗口(通过子类化NSWindow并覆盖initWithContentRect:

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.)

我知道我可以调用setLevel:kCGDesktopWindowLevel或者kCGDesktopIconWindowLevel()函数,可以设置窗口风格为NSBorderlessWindowMask将我的窗口放在其他窗口之下(请参阅 question 418791 )但是这不是我想要的,因为这个级别的窗口仍然在桌面图标的顶部。我想在桌面背景的顶部,但在图标下面。

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.

推荐答案

您应该创建一个<$ c $的子类c> NSWindow 并将级别设置为(kCGDesktopWindowLevel - 1)。这将使你的窗口下面的图标。

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;
}

这篇关于如何在Mac OS X上绘制桌面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆