self.titlebarAppearsTransparent = true
self.setFrame(boundingBox, display: true)
self.titleVisibility = .hidden
- let recordingView = RecordingContentView(configuration, frame: boundingBox)
+ let recordingView = RecordingContentView(configuration, frame: boundingBox, button: button ?? NSZeroRect)
recordingView.frame = boundingBox
- recordingView.button = button
self.contentView = recordingView
- //self.backgroundColor = NSColor(white: 1.0, alpha: 0.001)
- self.backgroundColor = NSColor(red: 1.0, green: 0.0, blue: 1.0, alpha: 0.5)
+ self.backgroundColor = NSColor(white: 1.0, alpha: 0.001)
+ // uncomment below to debug window placement visually
+ // self.backgroundColor = NSColor(red: 1.0, green: 0.0, blue: 1.0, alpha: 0.5)
self.level = .screenSaver
self.isOpaque = false
self.hasShadow = false
-
- print("AAAAH INIT CHANGE")
- print("AAAAH FRAME X: \(recordingView.frame.minX) \(recordingView.frame.maxX) // Y: \(recordingView.frame.minY) \(recordingView.frame.maxY)")
- print("AAAAH BOUNDS X: \(recordingView.bounds.minX) \(recordingView.bounds.maxX) // Y: \(recordingView.bounds.minY) \(recordingView.bounds.maxY)")
- print("AAAAH WIN F X: \(self.frame.minX) \(self.frame.maxX) // Y: \(self.frame.minY) \(self.frame.maxY)")
}
// MARK: - Window Behavior Overrides
class RecordingContentView: NSView {
- init(_ configuration: CaptureSessionConfiguration, frame: NSRect) {
+ init(_ configuration: CaptureSessionConfiguration, frame: NSRect, button: NSRect) {
+ self.buttonSize = button.size
+ var buttonOffset = NSPoint()
+ for screen in NSScreen.screens {
+ if screen.frame.intersects(button) {
+ let relativeY = screen.frame.height - (button.minY - screen.frame.minY)
+ let relativeX = screen.frame.width - (button.minX - screen.frame.minX)
+ buttonOffset = NSPoint(x: relativeX, y: relativeY)
+ }
+ }
+ self.buttonOffset = buttonOffset
super.init(frame: frame)
preventResize = configuration.preventResize
preventMove = configuration.preventMove
autoStart = configuration.autoStart
+ self.bounds = frame
+ self.button = NSRect(x: frame.maxX - buttonOffset.x, y: frame.maxY - buttonOffset.y, width: buttonSize.width, height: buttonSize.height)
+
if configuration.x != nil || configuration.y != nil || configuration.width != nil || configuration.height != nil {
box = NSRect(
x: configuration.x ?? Int(frame.width / 2.0),
fatalError("init(coder:) has not been implemented")
}
+ private let buttonSize: NSSize
+ private let buttonOffset: NSPoint
public var button: NSRect? = nil
@Published public var box: NSRect? = nil
public var state: RecordingWindowState = .idle
let dashLength: CGFloat = 5.0
let lineWidth = 0.5
-
- if let button {
- let buttonPath = NSBezierPath()
- buttonPath.move(to: NSPoint(x: button.minX, y: button.minY))
- buttonPath.line(to: NSPoint(x: button.maxX, y: button.minY))
- buttonPath.line(to: NSPoint(x: button.maxX, y: button.maxY))
- buttonPath.line(to: NSPoint(x: button.minX, y: button.maxY))
- buttonPath.line(to: NSPoint(x: button.minX, y: button.minY))
- NSColor(red: 1, green: 0, blue: 1, alpha: 1).setFill()
- buttonPath.fill()
- }
+
+// Uncomment below to debug button placement visually
+// if let button {
+// let buttonPath = NSBezierPath()
+// buttonPath.move(to: NSPoint(x: button.minX, y: button.minY))
+// buttonPath.line(to: NSPoint(x: button.maxX, y: button.minY))
+// buttonPath.line(to: NSPoint(x: button.maxX, y: button.maxY))
+// buttonPath.line(to: NSPoint(x: button.minX, y: button.maxY))
+// buttonPath.line(to: NSPoint(x: button.minX, y: button.minY))
+// NSColor(red: 1, green: 0, blue: 1, alpha: 1).setFill()
+// buttonPath.fill()
+// }
if state == .idle && box == nil {
let blackLine = NSBezierPath()
}
private func moveWindow() {
- print("AAAAH BEFORE WE CHANGE")
- print("AAAAH FRAME X: \(self.frame.minX) \(self.frame.maxX) // Y: \(self.frame.minY) \(self.frame.maxY)")
- print("AAAAH BOUNDS X: \(self.bounds.minX) \(self.bounds.maxX) // Y: \(self.bounds.minY) \(self.bounds.maxY)")
- print("AAAAH WIN F X: \(self.window?.frame.minX) \(self.window?.frame.maxX) // Y: \(self.window?.frame.minY) \(self.window?.frame.maxY)")
let screen = NSScreen.screenWithMouse
if let currentScreen = self.window?.screen {
if currentScreen != screen {
let frame = screen?.frame ?? NSZeroRect
- self.frame = frame
- self.bounds = frame
+ self.frame = CGRect(origin: NSZeroPoint, size: frame.size)
+ self.bounds = CGRect(origin: NSZeroPoint, size: frame.size)
self.updateTrackingAreas()
if let window = self.window {
self.bounds = frame
+ self.button = NSRect(x: frame.maxX - buttonOffset.x, y: frame.maxY - buttonOffset.y, width: buttonSize.width, height: buttonSize.height)
window.setFrame(frame, display: true, animate: false)
window.makeKeyAndOrderFront(nil)
window.orderFrontRegardless()
- print("AAAAH AFTER CHANGE")
- print("AAAAH FRAME X: \(self.frame.minX) \(self.frame.maxX) // Y: \(self.frame.minY) \(self.frame.maxY)")
- print("AAAAH BOUNDS X: \(self.bounds.minX) \(self.bounds.maxX) // Y: \(self.bounds.minY) \(self.bounds.maxY)")
- print("AAAAH WIN F X: \(self.window?.frame.minX) \(self.window?.frame.maxX) // Y: \(self.window?.frame.minY) \(self.window?.frame.maxY)")
}
}
}