diff options
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() + } +} |