Skip to content

Commit 332a662

Browse files
committed
display(apple): support resizing view with new APIs
1 parent 2d47233 commit 332a662

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Platform/macOS/Display/VMDisplayAppleDisplayWindowController.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ class VMDisplayAppleDisplayWindowController: VMDisplayAppleWindowController {
2323
mainView as? VZVirtualMachineView
2424
}
2525

26+
var supportsReconfiguration: Bool {
27+
guard #available(macOS 14, *) else {
28+
return false
29+
}
30+
guard let display = appleVM.apple?.graphicsDevices.first?.displays.first else {
31+
return false
32+
}
33+
return display.value(forKey: "_supportsReconfiguration") as? Bool ?? false
34+
}
35+
36+
private var aspectRatioLocked: Bool = false
37+
2638
override func windowDidLoad() {
2739
mainView = VZVirtualMachineView()
2840
captureMouseToolbarButton.image = captureMouseToolbarButton.alternateImage // show capture keyboard image
@@ -31,6 +43,9 @@ class VMDisplayAppleDisplayWindowController: VMDisplayAppleWindowController {
3143

3244
override func enterLive() {
3345
appleView.virtualMachine = appleVM.apple
46+
if #available(macOS 14, *) {
47+
appleView.automaticallyReconfiguresDisplay = true
48+
}
3449
super.enterLive()
3550
}
3651

@@ -59,6 +74,7 @@ class VMDisplayAppleDisplayWindowController: VMDisplayAppleWindowController {
5974
let size = windowSize(for: primaryDisplay)
6075
let frame = window.frameRect(forContentRect: CGRect(origin: window.frame.origin, size: size))
6176
window.contentAspectRatio = size
77+
aspectRatioLocked = true
6278
window.minSize = NSSize(width: 400, height: 400)
6379
window.setFrame(frame, display: false, animate: true)
6480
super.updateWindowFrame()
@@ -81,4 +97,11 @@ class VMDisplayAppleDisplayWindowController: VMDisplayAppleWindowController {
8197
captureMouseToolbarButton.state = .off
8298
captureMouseButtonPressed(self)
8399
}
100+
101+
func windowDidResize(_ notification: Notification) {
102+
if aspectRatioLocked && supportsReconfiguration {
103+
window!.resizeIncrements = NSSize(width: 1.0, height: 1.0)
104+
aspectRatioLocked = false
105+
}
106+
}
84107
}

0 commit comments

Comments
 (0)