how to get window with semi-transparent blurred background

后端 未结 3 484
北海茫月
北海茫月 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: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

提交回复
热议问题