主机窗口透明时应用CIFilter背景过滤器

Ben*_*hen 5 macos cocoa core-animation

我想在网格和列表模式中复制dock Stacks的背景.背景是半透明的黑色,具有模糊效果:

网格模式中的停靠堆栈示例http://www.thecustommac.com/wp-content/uploads/2009/09/stack-highlight.jpg

问题是[CALayer backgroundFilters]仅适用于窗口中的内容,过滤器不适用于其他窗口中的内容.这是我的代码:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification 
{
    //make window transparent
    self.window.backgroundColor = [NSColor clearColor];
    [self.window setOpaque:NO];
    [self.window setHasShadow:NO];
    [self.window setStyleMask:NSBorderlessWindowMask];


    //make the content view layer hosting
    CALayer *rootLayer = [CALayer layer];
    [[self.window contentView] setLayer:rootLayer];
    [[self.window contentView] setWantsLayer:YES];


    //blur the background contents - NOT WORKING!
    [rootLayer setBackgroundColor:CGColorCreateGenericGray(0.0, .716)];

    CIFilter *blurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
    [blurFilter setDefaults];
    [rootLayer setBackgroundFilters:[NSArray arrayWithObject: blurFilter]];
}
Run Code Online (Sandbox Code Playgroud)

我想不出怎样才能达到这个效果.(我已经看过显示服务,看看是否有任何有用的功能,但我看不到任何功能.)

有任何想法吗?

sbo*_*oth 9

这里有私有API.以下是Rob Keniger的示例代码:

在10.5中,您可以使用私有函数'CGSAddWindowFilter'将任何核心图像过滤器添加到窗口.

typedef void * CGSConnectionID;

extern OSStatus CGSNewConnection(const void **attr, CGSConnectionID *id);

- (void)enableBlurForWindow:(NSWindow *)window
{

CGSConnectionID _myConnection;
uint32_t __compositingFilter;

int __compositingType = 1; // Apply filter to contents underneath the window, then draw window normally on top

/* Make a new connection to CoreGraphics, alternatively you could use the main connection*/

CGSNewConnection(NULL , &_myConnection);

/* The following creates a new CoreImage filter, then sets its options with a dictionary of values*/

CGSNewCIFilterByName (_myConnection, (CFStringRef)@"CIGaussianBlur", &__compositingFilter);
NSDictionary *optionsDict = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:3.0] forKey:@"inputRadius"];
CGSSetCIFilterValuesFromDictionary(_myConnection, __compositingFilter, (CFDictionaryRef)optionsDict);

/* Now just switch on the filter for the window */

CGSAddWindowFilter(_myConnection, [window windowNumber], __compositingFilter, __compositingType );
}
Run Code Online (Sandbox Code Playgroud)