diff options
Diffstat (limited to 'src/macos/Sources/AppDelegate.swift')
| -rw-r--r-- | src/macos/Sources/AppDelegate.swift | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/macos/Sources/AppDelegate.swift b/src/macos/Sources/AppDelegate.swift index 4e91e407..cbe9cdc9 100644 --- a/src/macos/Sources/AppDelegate.swift +++ b/src/macos/Sources/AppDelegate.swift @@ -81,8 +81,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, PardesViewDelegate { // The grid and the blur are SIBLINGS in a plain container, not parent // and child. A transparent theme has to show something through the // grid, and AppKit will not blur what is behind a window unless an - // NSVisualEffectView asks it to — but the backdrop is hidden for every - // theme that brings its own background, and hiding a superview hides + // NSVisualEffectView asks it to. The backdrop can be hidden independently + // when blur is disabled or the ground is opaque; hiding a superview hides // its subviews with it. Nested, an opaque theme drew a blank window. let container = NSView(frame: NSRect(origin: .zero, size: want)) container.autoresizesSubviews = true @@ -460,6 +460,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, PardesViewDelegate { /// theme whose background happened to equal the view's starting guess /// would otherwise leave the window in AppKit's default clothes forever. private var dressed = false + private var appliedBlur: UInt8 = 0 private func applyTheme() { // Both reads happen every pump, and neither may be short-circuited by @@ -468,15 +469,17 @@ final class AppDelegate: NSObject, NSApplicationDelegate, PardesViewDelegate { // tick would leave one of them unworn. let themeChanged = view.adoptThemeBG(pardes_theme_bg()) let opacityChanged = view.adoptWindowOpacity(pardes_window_opacity()) - guard themeChanged || opacityChanged || !dressed else { return } + let blur = pardes_window_blur() + let blurChanged = blur != appliedBlur + guard themeChanged || opacityChanged || blurChanged || !dressed else { return } + appliedBlur = blur + backdrop.alphaValue = CGFloat(blur) / 100 + backdrop.isHidden = blur == 0 || (view.themeBG != nil && view.backgroundAlpha >= 1) dressed = true - // A ground short of solid needs the same non-opaque window a - // background-less theme does — but not the blur behind it. The backdrop - // answers "this theme brings no background"; WindowOpacity says how - // much of the one it brings to paint, and what shows through the rest - // is the desktop, which is what asking for a translucent window means. + // Opacity paints the theme ground; blur controls the native material + // behind it. An opaque ground hides the backdrop without losing the + // requested strength, so lowering opacity restores the effect. if let rgb = view.themeBG { - backdrop.isHidden = true window.isOpaque = view.backgroundAlpha >= 1 window.backgroundColor = view.backgroundAlpha < 1 ? .clear : NSColor( srgbRed: CGFloat((rgb >> 16) & 0xFF) / 255, @@ -493,10 +496,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate, PardesViewDelegate { window.appearance = NSAppearance(named: luma > 0.5 ? .aqua : .darkAqua) } else { // Transparent: the window stops painting anything of its own and - // the blur takes over. isOpaque false is what lets the desktop + // the optional blur sits behind it. isOpaque false lets the desktop // reach the backdrop at all — a titled window is opaque by default // and would composite over it. - backdrop.isHidden = false window.isOpaque = false window.backgroundColor = .clear window.appearance = NSAppearance(named: .darkAqua) |
