diff --git a/Sources/tart/Commands/Run.swift b/Sources/tart/Commands/Run.swift index ded19f9c..5b0269fe 100644 --- a/Sources/tart/Commands/Run.swift +++ b/Sources/tart/Commands/Run.swift @@ -740,12 +740,12 @@ struct VMView: NSViewRepresentable { machineView.capturesSystemKeys = capturesSystemKeys - // Enable automatic display reconfiguration - // for guests that support it + // If not specified, enable automatic display + // reconfiguration for guests that support it // // This is disabled for Linux because of poor HiDPI // support, which manifests in fonts being too small - if #available(macOS 14.0, *), vm.config.os != .linux { + if #available(macOS 14.0, *), vm.config.displayRefit ?? (vm.config.os != .linux) { machineView.automaticallyReconfiguresDisplay = true } diff --git a/Sources/tart/Commands/Set.swift b/Sources/tart/Commands/Set.swift index d4b1c9c9..d8a15fd1 100644 --- a/Sources/tart/Commands/Set.swift +++ b/Sources/tart/Commands/Set.swift @@ -17,6 +17,9 @@ struct Set: AsyncParsableCommand { @Option(help: "VM display resolution in a format of x. For example, 1200x800") var display: VMDisplayConfig? + @Flag(inversion: .prefixedNo, help: ArgumentHelp("Whether to automatically reconfigure the VM's display to fit the window")) + var displayRefit: Bool? = nil + @Flag(help: ArgumentHelp("Generate a new random MAC address for the VM.")) var randomMAC: Bool = false @@ -63,6 +66,8 @@ struct Set: AsyncParsableCommand { } } + vmConfig.displayRefit = displayRefit + if randomMAC { vmConfig.macAddress = VZMACAddress.randomLocallyAdministered() } diff --git a/Sources/tart/VMConfig.swift b/Sources/tart/VMConfig.swift index c70e07a2..869895df 100644 --- a/Sources/tart/VMConfig.swift +++ b/Sources/tart/VMConfig.swift @@ -24,6 +24,7 @@ enum CodingKeys: String, CodingKey { case memorySize case macAddress case display + case displayRefit // macOS-specific keys case ecid @@ -52,6 +53,7 @@ struct VMConfig: Codable { private(set) var memorySize: UInt64 var macAddress: VZMACAddress var display: VMDisplayConfig = VMDisplayConfig() + var displayRefit: Bool? init( platform: Platform, @@ -121,6 +123,7 @@ struct VMConfig: Codable { self.macAddress = macAddress display = try container.decodeIfPresent(VMDisplayConfig.self, forKey: .display) ?? VMDisplayConfig() + displayRefit = try container.decodeIfPresent(Bool.self, forKey: .displayRefit) } func encode(to encoder: Encoder) throws { @@ -136,6 +139,9 @@ struct VMConfig: Codable { try container.encode(memorySize, forKey: .memorySize) try container.encode(macAddress.string, forKey: .macAddress) try container.encode(display, forKey: .display) + if let displayRefit = displayRefit { + try container.encode(displayRefit, forKey: .displayRefit) + } } mutating func setCPU(cpuCount: Int) throws {