blob: e5f4c86ed3b125e68523ddaa77ae02f6d648cdd8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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()
}
}
|