how to get window with semi-transparent blurred background

后端 未结 3 470
北海茫月
北海茫月 2021-02-09 06:30

I\'d like to get a window that has a semi-transparent blurred background, just like what the Terminal can do. See this video, about 30 sec in, to see what I mean: http://www.you

相关标签:
3条回答
  • 2021-02-09 07:16

    For those reading 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)
    

    p.s. I do not need the blur effect yet and when I do, I'll update the answer

    0 讨论(0)
  • 2021-02-09 07:21

    For the transparency use Jiulong Zhao's suggestion.

    For a blurred background use this

    The call on a NSWindow :

    [self enableBlurForWindow:self];
    

    The 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

    0 讨论(0)
  • 2021-02-09 07:23

    no need for layers and filters, NSWindow can do it 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 alpha your title bar also (post it here just in case others need)

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

    enter image description here

    0 讨论(0)
提交回复
热议问题