diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-09-04 11:11:37 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-09-04 11:11:37 +0200 |
| commit | bb5daa2e90623691a5259700b9d388d2d21f46d3 (patch) | |
| tree | f5629e81bedc6cdd35ee9a79628997c5e14ffa7c /Liquid Glass Bezel/BackgroundView.swift | |
| parent | 3dfeb86c5c3b72acc59919c7a198fcf76a54c35c (diff) | |
Rename to Liquid Glass Bezel, add preferences
Diffstat (limited to 'Liquid Glass Bezel/BackgroundView.swift')
| -rw-r--r-- | Liquid Glass Bezel/BackgroundView.swift | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/Liquid Glass Bezel/BackgroundView.swift b/Liquid Glass Bezel/BackgroundView.swift new file mode 100644 index 0000000..e5f4c86 --- /dev/null +++ b/Liquid Glass Bezel/BackgroundView.swift @@ -0,0 +1,88 @@ +import Foundation +import Cocoa + + +class BackgroundView: QSBezelBackgroundView { + + private var glassView: NSGlassEffectView? + + override func awakeFromNib() { + super.awakeFromNib() + configureParentView() + setupGlassEffect() + } + + override init(frame frameRect: NSRect) { + super.init(frame: frameRect) + configureParentView() + setupGlassEffect() + } + + required init?(coder: NSCoder) { + super.init(coder: coder) + configureParentView() + setupGlassEffect() + } + + private func configureParentView() { + // Make the parent background much more transparent so glass effect shows through + setColor(NSColor.clear) // Try completely transparent first + setIsGlass(NSNumber(value: false)) // Disable the parent's glass rendering + + // Alternative: if clear doesn't work, try a very transparent background + // setColor(NSColor.black.withAlphaComponent(0.1)) + } + + private func setupGlassEffect() { + let glassView = NSGlassEffectView(frame: bounds) + glassView.autoresizingMask = [.width, .height] + glassView.cornerRadius = 12.0 + glassView.style = .clear + + // Create a content view for the glass effect + let contentView = NSView(frame: glassView.bounds) + contentView.autoresizingMask = [.width, .height] + glassView.contentView = contentView + + // Add subtle tint based on appearance + updateGlassTint() + + // Insert the glass view at the bottom of the view hierarchy + addSubview(glassView, positioned: .below, relativeTo: nil) + self.glassView = glassView + } + + private func updateGlassTint() { + guard let glassView = glassView else { return } + + let darkMode = effectiveAppearance.name == .darkAqua + if darkMode { + // Very subtle tint for dark mode to maintain translucency + glassView.tintColor = NSColor.black.withAlphaComponent(0.05) + } else { + // Even lighter tint for light mode + glassView.tintColor = NSColor.white.withAlphaComponent(0.02) + } + } + + override func viewDidMoveToWindow() { + super.viewDidMoveToWindow() + + // Ensure the window is configured for transparency + if let window = self.window { + window.backgroundColor = NSColor.clear + window.isOpaque = false + } + } + + override func draw(_ rect: NSRect) { + // Don't call super.draw(rect) to avoid the parent's opaque background + // The glass effect will handle the visual appearance + return + } + + override func viewDidChangeEffectiveAppearance() { + super.viewDidChangeEffectiveAppearance() + updateGlassTint() + } +} |