Skip to content

Commit

Permalink
display(apple): allow disabling of dynamic resolution
Browse files Browse the repository at this point in the history
Resolves #5873
  • Loading branch information
osy committed Mar 31, 2024
1 parent f9ab7e7 commit 15e2b6f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
7 changes: 6 additions & 1 deletion Configuration/UTMAppleConfigurationDisplay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -49,13 +52,15 @@ 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 {
var container = encoder.container(keyedBy: CodingKeys.self)
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions Platform/macOS/VMConfigAppleDisplayView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
}
}
}
Expand Down

0 comments on commit 15e2b6f

Please sign in to comment.