Ariver
2026-06-10 71acd11e8d5349672da8b1b6bb254e9a25ff4e51
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 AppKit
import CoreGraphics
 
@MainActor
public enum OverlayWindowPolicy {
    public static let styleMask: NSWindow.StyleMask = [
        .borderless,
        .fullSizeContentView,
        .nonactivatingPanel
    ]
 
    public static let collectionBehavior: NSWindow.CollectionBehavior = [
        .canJoinAllSpaces,
        .fullScreenAuxiliary,
        .stationary,
        .transient,
        .ignoresCycle
    ]
 
    public static let levelOffsetBelowMainMenu: CGWindowLevel = 1
 
    public static var quickSwitchLevel: NSWindow.Level {
        let mainMenuLevel = CGWindowLevelForKey(.mainMenuWindow)
        return NSWindow.Level(rawValue: Int(mainMenuLevel - levelOffsetBelowMainMenu))
    }
 
    public static var currentLevel: CGWindowLevel {
        CGWindowLevel(quickSwitchLevel.rawValue)
    }
 
    public static func apply(to panel: NSPanel, on screen: NSScreen?) {
        panel.styleMask = styleMask
        panel.collectionBehavior = collectionBehavior
        panel.level = quickSwitchLevel
        panel.hidesOnDeactivate = false
        panel.isReleasedWhenClosed = false
        panel.isOpaque = false
        panel.backgroundColor = .clear
 
        if let screen {
            panel.setFrame(screen.frame, display: false)
        }
    }
 
    public static func isBelowRescueSystemWindows(_ level: NSWindow.Level = quickSwitchLevel) -> Bool {
        level.rawValue < Int(CGWindowLevelForKey(.mainMenuWindow))
    }
}