mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-27 23:37:05 -05:00
feat: Give macOS window a Liquid Glass look when the background is set to transparent
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
#if defined(OS_MACOS)
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
|
||||
#include <CoreFoundation/CFBundle.h>
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
@@ -70,6 +73,49 @@
|
||||
cocoaWindow.titlebarAppearsTransparent = YES;
|
||||
cocoaWindow.styleMask |= NSWindowStyleMaskFullSizeContentView;
|
||||
|
||||
// Setup liquid glass background effect
|
||||
{
|
||||
NSView* glfwContentView = [cocoaWindow contentView];
|
||||
|
||||
NSOpenGLContext* context = [NSOpenGLContext currentContext];
|
||||
if (!context) {
|
||||
glfwMakeContextCurrent(window);
|
||||
context = [NSOpenGLContext currentContext];
|
||||
}
|
||||
|
||||
GLint opaque = 0;
|
||||
[context setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity];
|
||||
[context update];
|
||||
|
||||
NSView* containerView = [[NSView alloc] initWithFrame:[glfwContentView frame]];
|
||||
containerView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
||||
[containerView setWantsLayer:YES];
|
||||
|
||||
Class glassEffectClass = NSClassFromString(@"NSGlassEffectView");
|
||||
NSView* effectView = nil;
|
||||
if (glassEffectClass) {
|
||||
// Use the new liquid glass effect
|
||||
effectView = [[glassEffectClass alloc] initWithFrame:[containerView bounds]];
|
||||
} else {
|
||||
// Fall back to NSVisualEffectView for older systems
|
||||
NSVisualEffectView* visualEffectView = [[NSVisualEffectView alloc] initWithFrame:[containerView bounds]];
|
||||
visualEffectView.material = NSVisualEffectMaterialHUDWindow;
|
||||
visualEffectView.blendingMode = NSVisualEffectBlendingModeBehindWindow;
|
||||
visualEffectView.state = NSVisualEffectStateActive;
|
||||
effectView = visualEffectView;
|
||||
}
|
||||
|
||||
effectView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
||||
|
||||
[containerView addSubview:effectView];
|
||||
|
||||
[glfwContentView removeFromSuperview];
|
||||
glfwContentView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
||||
[containerView addSubview:glfwContentView];
|
||||
|
||||
[cocoaWindow setContentView:containerView];
|
||||
}
|
||||
|
||||
[cocoaWindow setOpaque:NO];
|
||||
[cocoaWindow setHasShadow:YES];
|
||||
[cocoaWindow setBackgroundColor:[NSColor colorWithWhite: 0 alpha: 0.001f]];
|
||||
@@ -407,4 +453,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user