]> git.r.bdr.sh - rbdr/captura/commitdiff
Save WIP -> Multimonitor change working
authorRuben Beltran del Rio <redacted>
Thu, 19 Oct 2023 18:57:25 +0000 (20:57 +0200)
committerRuben Beltran del Rio <redacted>
Thu, 19 Oct 2023 18:57:25 +0000 (20:57 +0200)
Captura/CapturaApp.swift
Captura/Presentation/Windows/RecordingWindow.swift

index 0d22e79e76f2d98947cc087a8eb73abe7390a4ac..67709a5df051374cad5322d3fe54b20fe7f7e972 100644 (file)
@@ -326,7 +326,10 @@ struct CapturaApp: App {
     if now - gifCallbackTimer > .nanoseconds(1_000_000_000 / UInt64(captureSessionConfiguration.frameRate)) {
       gifCallbackTimer = now
       DispatchQueue.main.async {
     if now - gifCallbackTimer > .nanoseconds(1_000_000_000 / UInt64(captureSessionConfiguration.frameRate)) {
       gifCallbackTimer = now
       DispatchQueue.main.async {
-        if let cgImage = frame.cgImage?.resize(by: self.pixelDensity) {
+        if var cgImage = frame.cgImage {
+          if self.pixelDensity > 1 {
+            cgImage = cgImage.resize(by: self.pixelDensity) ?? cgImage
+          }
           self.images.append(cgImage)
         }
       }
           self.images.append(cgImage)
         }
       }
index 370a47af63ed69d4b3e6f5c7457277f835a81d76..b5c44139cb6a26cac5b0d86c720379764a4c85af 100644 (file)
@@ -30,9 +30,8 @@ class RecordingWindow: NSWindow {
     self.titlebarAppearsTransparent = true
     self.setFrame(boundingBox, display: true)
     self.titleVisibility = .hidden
     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.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.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)
@@ -83,11 +82,33 @@ enum RecordingWindowState {
 
 class RecordingContentView: NSView {
   
 
 class RecordingContentView: NSView {
   
-  init(_ configuration: CaptureSessionConfiguration, frame: NSRect) {
+  init(_ configuration: CaptureSessionConfiguration, frame: NSRect, button: NSRect) {
     super.init(frame: frame)
     preventResize = configuration.preventResize
     preventMove = configuration.preventMove
     autoStart = configuration.autoStart
     super.init(frame: frame)
     preventResize = configuration.preventResize
     preventMove = configuration.preventMove
     autoStart = configuration.autoStart
+    self.button = button
+    
+    for screen in NSScreen.screens {
+      print(screen.frame)
+      // BEFORE YOU WENT TO BED:
+      // You were checking which screen contains the button, so you can calculate the offset which should give you
+      // the location of the button, which you can then use to draw the button at the same offset whenever you need
+      // to change screen! This would keep the behavior of pressing the record button.
+      // If this does work, remember to then test it with a Hi DPI display, because we might need to adjust for pixel
+      // density.
+      // Finally, if it does work, make sure the alternate monitor still responds, by adjusting the behavior of the
+      // real button
+      if screen.frame.intersects(button) {
+        print("CONTAINS! ->")
+        let relativeX = screen.frame.width - button.maxX
+        let relativeY = screen.frame.height - button.maxY
+        print("The rect is at (\(relativeX), \(relativeY)) relative to the top right of the screen frame.")
+      } else {
+        print("NO CONTAINS ->")
+      }
+      print(button)
+    }
     
     if configuration.x != nil || configuration.y != nil || configuration.width != nil || configuration.height != nil {
       box = NSRect(
     
     if configuration.x != nil || configuration.y != nil || configuration.width != nil || configuration.height != nil {
       box = NSRect(
@@ -109,6 +130,7 @@ class RecordingContentView: NSView {
     fatalError("init(coder:) has not been implemented")
   }
   
     fatalError("init(coder:) has not been implemented")
   }
   
+  private var buttons: [NSRect] = []
   public var button: NSRect? = nil
   @Published public var box: NSRect? = nil
   public var state: RecordingWindowState = .idle
   public var button: NSRect? = nil
   @Published public var box: NSRect? = nil
   public var state: RecordingWindowState = .idle
@@ -454,8 +476,8 @@ class RecordingContentView: NSView {
     if let currentScreen = self.window?.screen {
       if currentScreen != screen {
         let frame = screen?.frame ?? NSZeroRect
     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.updateTrackingAreas()
         
         if let window = self.window {