X-Git-Url: https://git.r.bdr.sh/rbdr/captura/blobdiff_plain/a4e804275517af683afa1733e2db7c383c306f2b..cdc79b7d7c4829ba7a0371826b28f398f267c46a:/Captura/Presentation/Windows/RecordingWindow.swift?ds=sidebyside diff --git a/Captura/Presentation/Windows/RecordingWindow.swift b/Captura/Presentation/Windows/RecordingWindow.swift index 2bb9928..f5941dc 100644 --- a/Captura/Presentation/Windows/RecordingWindow.swift +++ b/Captura/Presentation/Windows/RecordingWindow.swift @@ -7,7 +7,11 @@ class RecordingWindow: NSWindow { 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 @@ -23,13 +27,13 @@ class RecordingWindow: NSWindow { 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 @@ -37,7 +41,6 @@ class RecordingWindow: NSWindow { self.level = .screenSaver self.isOpaque = false self.hasShadow = false - self.makeKeyAndOrderFront(nil) } // MARK: - Window Behavior Overrides @@ -77,12 +80,41 @@ enum RecordingWindowState { 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 { @@ -219,18 +251,22 @@ class RecordingContentView: NSView { } } - 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 }