blob: 60d133793de7e7a9bcf785d98a0f6fd875f17384 (
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
|
import Cocoa
import SwiftUI
class HotlinePanel: NSPanel {
init(_ view: HotlinePanelView) {
super.init(contentRect: .zero, styleMask: [.nonactivatingPanel, .titled, .closable, .utilityWindow, .fullSizeContentView], backing: .buffered, defer: false)
// Make sure that the panel is in front of almost all other windows
self.isFloatingPanel = false
self.level = .floating
self.hidesOnDeactivate = true
self.animationBehavior = .utilityWindow
// Allow the panel to appear in a fullscreen space
self.collectionBehavior.insert(.fullScreenAuxiliary)
// Don't delete panel state when it's closed.
self.isReleasedWhenClosed = false
self.standardWindowButton(.closeButton)?.isHidden = true
self.standardWindowButton(.zoomButton)?.isHidden = true
self.standardWindowButton(.miniaturizeButton)?.isHidden = true
// Make it transparent, the view inside will have to set the background.
// This is necessary because otherwise, we will have some space for the titlebar on top of the height of the view itself which we don't want.
self.isOpaque = false
self.backgroundColor = .clear
// Since we don't show a statusbar, this allows us to drag the window by its background instead of the titlebar.
self.isMovableByWindowBackground = true
self.titlebarAppearsTransparent = true
let hostingView = NSHostingView(rootView: view.edgesIgnoringSafeArea(.top))
hostingView.sizingOptions = [.standardBounds]
self.contentView = hostingView
self.cascadeTopLeft(from: NSMakePoint(16, 16))
}
override var canBecomeKey: Bool {
return false
}
override var canBecomeMain: Bool {
return false
}
}
|