]> git.r.bdr.sh - rbdr/captura/blobdiff - Captura/Domain/CapturaCaptureSession.swift
Add multimonitor support
[rbdr/captura] / Captura / Domain / CapturaCaptureSession.swift
index 80240e6a36d546b8618ede80808a072c7881d78f..89432822ce340547bad0c7774a00f5107502a426 100644 (file)
@@ -12,7 +12,11 @@ class CapturaCaptureSession: AVCaptureSession, AVCaptureFileOutputRecordingDeleg
     
     let displayId = screen.deviceDescription[NSDeviceDescriptionKey("NSScreenNumber")] as! CGDirectDisplayID
     let screenInput = AVCaptureScreenInput(displayID: displayId)
     
     let displayId = screen.deviceDescription[NSDeviceDescriptionKey("NSScreenNumber")] as! CGDirectDisplayID
     let screenInput = AVCaptureScreenInput(displayID: displayId)
-    screenInput?.cropRect = box.insetBy(dx: 1, dy: 1)
+    var croppingBox = NSOffsetRect(box, -screen.frame.origin.x, -screen.frame.origin.y)
+    if croppingBox.width.truncatingRemainder(dividingBy: 2) != 0 {
+      croppingBox.size.width -= 1
+    }
+    screenInput?.cropRect = croppingBox.insetBy(dx: 1, dy: 1)
     
     if self.canAddInput(screenInput!) {
       self.addInput(screenInput!)
     
     if self.canAddInput(screenInput!) {
       self.addInput(screenInput!)