Skip to content

Instantly share code, notes, and snippets.

@Serjip
Last active June 12, 2024 12:53
Show Gist options
  • Save Serjip/c24853dc06e613ab9574 to your computer and use it in GitHub Desktop.
Save Serjip/c24853dc06e613ab9574 to your computer and use it in GitHub Desktop.
//Original http://cocoasnippets.io/cocoa/ui/nswindow/coregraphics/2014/02/27/translucent-nswindow-with-blurred-background.html
// one more solution http://stackoverflow.com/questions/11174918/how-to-get-window-with-semi-transparent-blurred-background
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 colorWithCalibratedWhite:1.0 alpha:0.5];
CGSConnection connection = CGSDefaultConnectionForThread();
CGSSetWindowBackgroundBlurRadius(connection, [window windowNumber], 20);
}
@TheMrugraj
Copy link

Dont use this solution. My App rejected due to use of this API.

"The use of non-public APIs can lead to a poor user experience should these APIs change in the future, and is therefore not permitted. The app includes : CGSSetWindowBackgroundBlurRadius from the framework '/System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics'."

@sackboy19
Copy link

I was having linking issues in ObjC++, so to help anyone in the future, make sure you have -framework CoreGraphics and if ur in ObjC++ declare the functions as extern "C"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment