Skip to content

Commit

Permalink
tart set: support --{,no-}display-auto-reconfigure (#954)
Browse files Browse the repository at this point in the history
* tart set: support --{,no-}display-auto-reconfigure

* Remove extraneous spaces

* displayAutoReconfigure → displayRefit
  • Loading branch information
edigaryev authored Nov 20, 2024
1 parent 589d489 commit 8536c16
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Sources/tart/Commands/Run.swift
Original file line number Diff line number Diff line change
Expand Up @@ -764,12 +764,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
}

Expand Down
5 changes: 5 additions & 0 deletions Sources/tart/Commands/Set.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ struct Set: AsyncParsableCommand {
@Option(help: "VM display resolution in a format of <width>x<height>. 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

Expand Down Expand Up @@ -63,6 +66,8 @@ struct Set: AsyncParsableCommand {
}
}

vmConfig.displayRefit = displayRefit

if randomMAC {
vmConfig.macAddress = VZMACAddress.randomLocallyAdministered()
}
Expand Down
6 changes: 6 additions & 0 deletions Sources/tart/VMConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum CodingKeys: String, CodingKey {
case memorySize
case macAddress
case display
case displayRefit

// macOS-specific keys
case ecid
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 8536c16

Please sign in to comment.