Skip to content

Commit 78bc852

Browse files
committed
display(macOS): support dynamic resolution with Accessibility API resize
Resolves #5577
1 parent e789a9c commit 78bc852

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Platform/macOS/Display/VMDisplayQemuMetalWindowController.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ class VMDisplayQemuMetalWindowController: VMDisplayQemuWindowController {
3535
private var isDisplaySizeDynamic: Bool = false
3636
private var isFullScreen: Bool = false
3737
private let minDynamicSize = CGSize(width: 800, height: 600)
38+
private let resizeDebounceSecs: Double = 1
3839
private let resizeTimeoutSecs: Double = 5
40+
private var debounceResize: DispatchWorkItem?
3941
private var cancelResize: DispatchWorkItem?
4042

4143
private var localEventMonitor: Any? = nil
@@ -341,11 +343,31 @@ extension VMDisplayQemuMetalWindowController {
341343
}
342344
}
343345

346+
func windowDidResize(_ notification: Notification) {
347+
guard self.isDisplaySizeDynamic, let window = self.window else {
348+
return
349+
}
350+
debounceResize?.cancel()
351+
debounceResize = DispatchWorkItem {
352+
self._handleResizeEnd(for: window)
353+
}
354+
// when resizing with a mouse drag, we get flooded with this notification
355+
// when using accessibility APIs, we do not get a `windowDidEndLiveResize` notification
356+
DispatchQueue.main.asyncAfter(deadline: .now() + resizeDebounceSecs, execute: debounceResize!)
357+
}
358+
344359
func windowDidEndLiveResize(_ notification: Notification) {
345360
guard self.isDisplaySizeDynamic, let window = self.window else {
346361
return
347362
}
363+
_handleResizeEnd(for: window)
364+
}
365+
366+
private func _handleResizeEnd(for window: NSWindow) {
367+
debounceResize?.cancel()
368+
debounceResize = nil
348369
_ = updateGuestResolution(for: window, frameSize: window.frame.size)
370+
cancelResize?.cancel()
349371
cancelResize = DispatchWorkItem {
350372
if let vmDisplay = self.vmDisplay {
351373
self.displaySizeDidChange(size: vmDisplay.displaySize)

0 commit comments

Comments
 (0)