Title Bar Transparency Removes Blur

时间:2016-04-04 16:51:35

标签: cocoa blur nswindow titlebar

I have a subclassed NSWindow which uses the undocumented CGSSetWindowBackgroundBlurRadius method to blur a transparent background.

This is working fine however I also want to blur the title bar. In order to do this I can OR a NSFullSizeContentViewWindowMask mask to the existing style. This successfully changes the title bar to a transparent view but the blur effect is lost! Any ideas of how I can go about this?

#import "TransparentNSWindow.h"

@implementation TransparentNSWindow

typedef void * CGSConnection;
extern OSStatus CGSSetWindowBackgroundBlurRadius(CGSConnection connection, NSInteger   windowNumber, int radius);
extern CGSConnection CGSDefaultConnectionForThread();

- (void)enableBlurForWindow:(NSWindow *)window
{
    [window setOpaque:NO];
    window.backgroundColor = [NSColor colorWithCalibratedRed:255./255. green:255./255. blue:255./255. alpha:0.4];

    CGSConnection connection = CGSDefaultConnectionForThread();
    CGSSetWindowBackgroundBlurRadius(connection, [window windowNumber], 20);
}



- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag {
    NSUInteger currentStyle = [self styleMask];
    NSUInteger style = NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask;

    self = [super initWithContentRect:contentRect styleMask :style backing :NSBackingStoreBuffered defer:NO ];
    if (self)
    {
        [self setOpaque:NO];
        [self setHasShadow:NO];

        self.titlebarAppearsTransparent = true;
        self.titleVisibility = true;

        // Uncommenting this line results in a transparent title bar but no blur
        //self.styleMask |= NSFullSizeContentViewWindowMask;

        [self enableBlurForWindow:self];
    }
    return self;
}

@end

1 个答案:

答案 0 :(得分:0)

与Apple取得联系,显然无法做到这一点。