self.screen?.backingScaleFactor ?? 1.0
}
- init(_ button: NSRect?) {
+ var recordingContentView: RecordingContentView {
+ self.contentView as! RecordingContentView
+ }
+
+ init(_ configuration: CaptureSessionConfiguration, _ button: NSRect?) {
let screens = NSScreen.screens
var boundingBox = NSZeroRect
self.isReleasedWhenClosed = false
self.collectionBehavior = [.canJoinAllSpaces]
- self.center()
self.isMovableByWindowBackground = false
self.isMovable = false
+ self.canHide = false
self.titlebarAppearsTransparent = true
self.setFrame(boundingBox, display: true)
self.titleVisibility = .hidden
- let recordingView = RecordingContentView()
+ let recordingView = RecordingContentView(configuration, frame: boundingBox)
recordingView.frame = boundingBox
recordingView.button = button
self.contentView = recordingView
self.level = .screenSaver
self.isOpaque = false
self.hasShadow = false
- self.makeKeyAndOrderFront(nil)
}
// MARK: - Window Behavior Overrides
class RecordingContentView: NSView {
+ init(_ configuration: CaptureSessionConfiguration, frame: NSRect) {
+ super.init(frame: frame)
+ preventResize = configuration.preventResize
+ preventMove = configuration.preventMove
+ autoStart = configuration.autoStart
+
+ if configuration.x != nil || configuration.y != nil || configuration.width != nil || configuration.height != nil {
+ box = NSRect(
+ x: configuration.x ?? Int(frame.width / 2.0),
+ y: configuration.y ?? Int(frame.height / 2.0),
+ width: configuration.width ?? 400,
+ height: configuration.height ?? 400
+ )
+ }
+
+ if autoStart {
+ DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
+ NotificationCenter.default.post(name: .startRecording, object: nil, userInfo: nil)
+ }
+ }
+ }
+
+ required init?(coder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+
public var button: NSRect? = nil
@Published public var box: NSRect? = nil
public var state: RecordingWindowState = .idle
private var mouseLocation: NSPoint = NSPoint()
private var origin: NSPoint = NSPoint()
private var boxOrigin: NSPoint = NSPoint()
+ private var preventResize = false
+ private var preventMove = false
+ private var autoStart = false
private var resizeBox: NSRect? {
if let box {
}
}
- if resizeBox!.contains(origin) {
+ if resizeBox!.contains(origin) && !preventResize {
self.origin = NSPoint(x: box.minX, y: box.maxY)
state = .resizing
return
}
- if box.contains(origin) {
+ if box.contains(origin) && !preventMove {
state = .moving
self.boxOrigin = NSPoint(x: box.origin.x, y: box.origin.y)
return
}
}
+ if preventResize || preventMove {
+ return
+ }
+
state = .drawing
}