Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tart set: support --{,no-}display-auto-reconfigure #954

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Sources/tart/Commands/Run.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

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