Explorar o código

display(apple): allow disabling of dynamic resolution

Resolves #5873
osy hai 1 ano
pai
achega
15e2b6f757

+ 6 - 1
Configuration/UTMAppleConfigurationDisplay.swift

@@ -26,13 +26,16 @@ struct UTMAppleConfigurationDisplay: Codable, Identifiable {
     var heightInPixels: Int = 1200
     
     var pixelsPerInch: Int = 80
-    
+
+    var isDynamicResolution: Bool = true
+
     let id = UUID()
     
     enum CodingKeys: String, CodingKey {
         case widthInPixels = "WidthPixels"
         case heightInPixels = "HeightPixels"
         case pixelsPerInch = "PixelsPerInch"
+        case isDynamicResolution = "DynamicResolution"
     }
     
     init() {
@@ -49,6 +52,7 @@ struct UTMAppleConfigurationDisplay: Codable, Identifiable {
         widthInPixels = try values.decode(Int.self, forKey: .widthInPixels)
         heightInPixels = try values.decode(Int.self, forKey: .heightInPixels)
         pixelsPerInch = try values.decode(Int.self, forKey: .pixelsPerInch)
+        isDynamicResolution = try values.decodeIfPresent(Bool.self, forKey: .isDynamicResolution) ?? true
     }
     
     func encode(to encoder: Encoder) throws {
@@ -56,6 +60,7 @@ struct UTMAppleConfigurationDisplay: Codable, Identifiable {
         try container.encode(widthInPixels, forKey: .widthInPixels)
         try container.encode(heightInPixels, forKey: .heightInPixels)
         try container.encode(pixelsPerInch, forKey: .pixelsPerInch)
+        try container.encode(isDynamicResolution, forKey: .isDynamicResolution)
     }
     
     #if arch(arm64)

+ 7 - 3
Platform/macOS/Display/VMDisplayAppleDisplayWindowController.swift

@@ -32,7 +32,11 @@ class VMDisplayAppleDisplayWindowController: VMDisplayAppleWindowController {
         }
         return display.value(forKey: "_supportsReconfiguration") as? Bool ?? false
     }
-    
+
+    var isDynamicResolution: Bool {
+        appleConfig.displays.first!.isDynamicResolution
+    }
+
     private var aspectRatioLocked: Bool = false
     
     @Setting("FullScreenAutoCapture") private var isFullScreenAutoCapture: Bool = false
@@ -46,7 +50,7 @@ class VMDisplayAppleDisplayWindowController: VMDisplayAppleWindowController {
     override func enterLive() {
         appleView.virtualMachine = appleVM.apple
         if #available(macOS 14, *) {
-            appleView.automaticallyReconfiguresDisplay = true
+            appleView.automaticallyReconfiguresDisplay = isDynamicResolution
         }
         super.enterLive()
     }
@@ -108,7 +112,7 @@ class VMDisplayAppleDisplayWindowController: VMDisplayAppleWindowController {
     }
     
     func windowDidResize(_ notification: Notification) {
-        if aspectRatioLocked && supportsReconfiguration {
+        if aspectRatioLocked && supportsReconfiguration && isDynamicResolution {
             window!.resizeIncrements = NSSize(width: 1.0, height: 1.0)
             aspectRatioLocked = false
         }

+ 4 - 0
Platform/macOS/VMConfigAppleDisplayView.swift

@@ -167,6 +167,10 @@ struct VMConfigAppleDisplayView: View {
             }
             Toggle("HiDPI (Retina)", isOn: isHidpi)
                 .help("Only available on macOS virtual machines.")
+            if #available(macOS 14, *) {
+                Toggle("Dynamic Resolution", isOn: $config.isDynamicResolution)
+                    .help("Only available on macOS 14+ virtual machines.")
+            }
         }
     }
 }