-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverlayWindow.swift
More file actions
51 lines (40 loc) · 1.25 KB
/
OverlayWindow.swift
File metadata and controls
51 lines (40 loc) · 1.25 KB
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
import Cocoa
import SwiftUI
class OverlayWindow: NSWindow {
private var initialLocation: NSPoint = .zero
override var canBecomeKey: Bool { true }
init(view: NSView) {
let screenSize = NSScreen.main?.frame ?? .zero
let frame = CGRect(
x: screenSize.midX - 150,
y: screenSize.midY - 100,
width: 300,
height: 180
)
super.init(
contentRect: frame,
styleMask: [.borderless],
backing: .buffered,
defer: false
)
isOpaque = false
backgroundColor = .clear
level = .floating
hasShadow = false
ignoresMouseEvents = false
collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]
contentView = view
makeKeyAndOrderFront(nil)
}
// Drag to move
override func mouseDown(with event: NSEvent) {
initialLocation = event.locationInWindow
}
override func mouseDragged(with event: NSEvent) {
var newOrigin = frame.origin
let currentLocation = event.locationInWindow
newOrigin.x += currentLocation.x - initialLocation.x
newOrigin.y += currentLocation.y - initialLocation.y
setFrameOrigin(newOrigin)
}
}