From 49ec30899ef5a9324e4a778fed17432171123eac Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 23 Dec 2025 15:56:45 +0100 Subject: [PATCH] feat: Give macOS window a Liquid Glass look when the background is set to transparent --- lib/libimhex/source/helpers/utils_macos.m | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/lib/libimhex/source/helpers/utils_macos.m b/lib/libimhex/source/helpers/utils_macos.m index 56ee0dbde..c5e284969 100644 --- a/lib/libimhex/source/helpers/utils_macos.m +++ b/lib/libimhex/source/helpers/utils_macos.m @@ -1,5 +1,8 @@ #if defined(OS_MACOS) + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" + #include #include #include @@ -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