@@ -35,7 +35,9 @@ class VMDisplayQemuMetalWindowController: VMDisplayQemuWindowController {
35
35
private var isDisplaySizeDynamic : Bool = false
36
36
private var isFullScreen : Bool = false
37
37
private let minDynamicSize = CGSize ( width: 800 , height: 600 )
38
+ private let resizeDebounceSecs : Double = 1
38
39
private let resizeTimeoutSecs : Double = 5
40
+ private var debounceResize : DispatchWorkItem ?
39
41
private var cancelResize : DispatchWorkItem ?
40
42
41
43
private var localEventMonitor : Any ? = nil
@@ -341,11 +343,31 @@ extension VMDisplayQemuMetalWindowController {
341
343
}
342
344
}
343
345
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
+
344
359
func windowDidEndLiveResize( _ notification: Notification ) {
345
360
guard self . isDisplaySizeDynamic, let window = self . window else {
346
361
return
347
362
}
363
+ _handleResizeEnd ( for: window)
364
+ }
365
+
366
+ private func _handleResizeEnd( for window: NSWindow ) {
367
+ debounceResize? . cancel ( )
368
+ debounceResize = nil
348
369
_ = updateGuestResolution ( for: window, frameSize: window. frame. size)
370
+ cancelResize? . cancel ( )
349
371
cancelResize = DispatchWorkItem {
350
372
if let vmDisplay = self . vmDisplay {
351
373
self . displaySizeDidChange ( size: vmDisplay. displaySize)
0 commit comments