From bf77d77669396f17003dc2eeed32ec8ea9d07133 Mon Sep 17 00:00:00 2001 From: Chris Campbell Date: Thu, 29 Apr 2021 23:55:23 -0400 Subject: [PATCH 1/2] Expand workaround for macOS 11 WebView origin offset bug. Fixes #2916 Move the code that twiddles the window frame from DetailWebView.viewDidEndLiveResize() into a new bigSurOffsetFix() API so it can also be called by setFrameSize() when the frame size is changed outside of a live resize. --- Mac/MainWindow/Detail/DetailWebView.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Mac/MainWindow/Detail/DetailWebView.swift b/Mac/MainWindow/Detail/DetailWebView.swift index 7252adde2..146708f2c 100644 --- a/Mac/MainWindow/Detail/DetailWebView.swift +++ b/Mac/MainWindow/Detail/DetailWebView.swift @@ -53,7 +53,17 @@ final class DetailWebView: WKWebView { override func viewDidEndLiveResize() { super.viewDidEndLiveResize() evaluateJavaScript("document.body.style.overflow = 'visible';", completionHandler: nil) + bigSurOffsetFix() + } + + override func setFrameSize(_ newSize: NSSize) { + super.setFrameSize(newSize) + if (!self.inLiveResize) { + bigSurOffsetFix() + } + } + private func bigSurOffsetFix() { /* On macOS 11, when a user exits full screen or exits zoomed mode by disconnecting an external display From 364f3a76392f7bf0026f8c0627e1c813dc1fda15 Mon Sep 17 00:00:00 2001 From: Chris Campbell Date: Fri, 30 Apr 2021 00:52:15 -0400 Subject: [PATCH 2/2] Prevent infinite loop in DetailWebView.setFrameSize() DetailWebView.setFrameSize() calls bigSurOffsetFix(), which changes the window's frame, which ultimately calls setFrameSize() again (which calls bigSurOffsetFix(), etc). In practice, this isn't causing an infinite loop (I think NSWindow.setFrame(_:display:) is smart enough to prevent reentrancy) but it's still dangerous to have such a glaring logic error in the code. --- Mac/MainWindow/Detail/DetailWebView.swift | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Mac/MainWindow/Detail/DetailWebView.swift b/Mac/MainWindow/Detail/DetailWebView.swift index 146708f2c..a6e4a5c45 100644 --- a/Mac/MainWindow/Detail/DetailWebView.swift +++ b/Mac/MainWindow/Detail/DetailWebView.swift @@ -58,11 +58,13 @@ final class DetailWebView: WKWebView { override func setFrameSize(_ newSize: NSSize) { super.setFrameSize(newSize) - if (!self.inLiveResize) { + if (!inLiveResize) { bigSurOffsetFix() } } + private var inBigSurOffsetFix = false + private func bigSurOffsetFix() { /* On macOS 11, when a user exits full screen @@ -76,6 +78,17 @@ final class DetailWebView: WKWebView { guard var frame = window?.frame else { return } + + guard !inBigSurOffsetFix else { + return + } + + inBigSurOffsetFix = true + + defer { + inBigSurOffsetFix = false + } + frame.size = NSSize(width: window!.frame.width, height: window!.frame.height - 1) window!.setFrame(frame, display: false) frame.size = NSSize(width: window!.frame.width, height: window!.frame.height + 1)