How to get a window with a translucent blurry background

I would like to get a window with a translucent blurry background, just like what Terminal can do. Watch this video for about 30 seconds to see what I mean: http://www.youtube.com/watch?v=zo8KPRY6-Mk

See the image here: http://osxdaily.com/wp-content/uploads/2011/04/mac-os-x-lion-terminal.jpg

I work for an hour and cannot work anything. I believe that I need to somehow create a base animation layer and add a background filter, but so far I have not been successful ... I just see the gray background of my window. Here is the code that I still have:

the code:

// Get the content view -- everything but the titlebar. NSView *theView = [[self window] contentView]; [theView setAlphaValue:0.5]; // Create core animation layer, with filter CALayer *backgroundLayer = [CALayer layer]; [theView setWantsLayer:YES]; [theView setLayer:backgroundLayer]; CIFilter *blurFilter = [CIFilter filterWithName:@"CIGaussianBlur"]; [blurFilter setDefaults]; [theView layer].backgroundFilters = [NSArray arrayWithObject:blurFilter]; [[theView layer] setBackgroundFilters:[NSArray arrayWithObject:blurFilter]]; 

Any tips or examples to do what I'm trying to do? Thanks!

+7
source share
3 answers

no need for layers and filters, NSWindow can do it by itself

 [mywindow setOpaque:NO]; [mywindow setBackgroundColor: [NSColor colorWithCalibratedHue:0.0 saturation:0.0 brightness:0.2 alpha:0.5]]; 

please do not use this as it will be an alpha title bar (send it here just in case you need others)

 [mywindow setOpaque:NO]; [mywindow setBackgroundColor: [NSColor blackColor]]; [mywindow setAlphaValue:0.5]; 

enter image description here

+3
source

For transparency, use the Jiulong Zhao suggestion.

For blurry background use this

Call NSWindow:

 [self enableBlurForWindow:self]; 

Function:

 -(void)enableBlurForWindow:(NSWindow *)window { //!!!! Uses private API - copied from http://blog.steventroughtonsmith.com/2008/03/using-core-image-filters-onunder.html CGSConnection thisConnection; uint32_t compositingFilter; int compositingType = 1; // Under the window /* Make a new connection to CoreGraphics */ CGSNewConnection(NULL, &thisConnection); /* Create a CoreImage filter and set it up */ CGSNewCIFilterByName(thisConnection, (CFStringRef)@"CIGaussianBlur", &compositingFilter); NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:2.0] forKey:@"inputRadius"]; CGSSetCIFilterValuesFromDictionary(thisConnection, compositingFilter, (__bridge CFDictionaryRef)options); /* Now apply the filter to the window */ CGSAddWindowFilter(thisConnection, [window windowNumber], compositingFilter, compositingType); } 

NB: it uses a private API

+3
source

For those who read this in 2017 and using Swift 4 and wanting to change your BG Alpha , you can add the following to your custom NSWindow class:

 self.backgroundColor = NSColor.black self.backgroundColor = NSColor.init(calibratedHue: 0, saturation: 0, brightness: 0, alpha: 0.2) 

ps I do not need the blur effect, and when I do this, I will update the answer

0
source

All Articles