如何在 Mac OS X 上绘制桌面? [英] How do I draw the desktop on 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
(如果您不在计算机附近,这会显示您通常会看到桌面背景的屏幕保护程序.)
(If you’re not near your computer, this displays the screensaver where you would normally see your desktop background.)
我知道如何制作没有边框的窗口(通过继承 NSWindow 并覆盖 initWithContentRect:styleMask:backing:defer: 将窗口样式设置为 NSBorderlessWindowMask)并且没有阴影(setHasShadow:NO.)
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 将我的窗口放在其他窗口下方(参见 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.
推荐答案
您应该创建一个 NSWindow
的子类,并将级别设置为 (kCGDesktopWindowLevel - 1)
.这将使您的窗口位于图标下方.您还应该确保您的窗口不会成为关键或主窗口,并且通过不动来正确处理 Exposé/Spaces.
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屋!