Skip to content

Commit

Permalink
display(apple): support resizing view with new APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
osy committed Aug 24, 2023
1 parent 2d47233 commit 332a662
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Platform/macOS/Display/VMDisplayAppleDisplayWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ class VMDisplayAppleDisplayWindowController: VMDisplayAppleWindowController {
mainView as? VZVirtualMachineView
}

var supportsReconfiguration: Bool {
guard #available(macOS 14, *) else {
return false
}
guard let display = appleVM.apple?.graphicsDevices.first?.displays.first else {
return false
}
return display.value(forKey: "_supportsReconfiguration") as? Bool ?? false
}

private var aspectRatioLocked: Bool = false

override func windowDidLoad() {
mainView = VZVirtualMachineView()
captureMouseToolbarButton.image = captureMouseToolbarButton.alternateImage // show capture keyboard image
Expand All @@ -31,6 +43,9 @@ class VMDisplayAppleDisplayWindowController: VMDisplayAppleWindowController {

override func enterLive() {
appleView.virtualMachine = appleVM.apple
if #available(macOS 14, *) {
appleView.automaticallyReconfiguresDisplay = true
}
super.enterLive()
}

Expand Down Expand Up @@ -59,6 +74,7 @@ class VMDisplayAppleDisplayWindowController: VMDisplayAppleWindowController {
let size = windowSize(for: primaryDisplay)
let frame = window.frameRect(forContentRect: CGRect(origin: window.frame.origin, size: size))
window.contentAspectRatio = size
aspectRatioLocked = true
window.minSize = NSSize(width: 400, height: 400)
window.setFrame(frame, display: false, animate: true)
super.updateWindowFrame()
Expand All @@ -81,4 +97,11 @@ class VMDisplayAppleDisplayWindowController: VMDisplayAppleWindowController {
captureMouseToolbarButton.state = .off
captureMouseButtonPressed(self)
}

func windowDidResize(_ notification: Notification) {
if aspectRatioLocked && supportsReconfiguration {
window!.resizeIncrements = NSSize(width: 1.0, height: 1.0)
aspectRatioLocked = false
}
}
}

0 comments on commit 332a662

Please sign in to comment.