Merge pull request #1189 from mitchellh/macos-restore-blur

macos: wait for window to become visible to set blur
This commit is contained in:
Mitchell Hashimoto
2023-12-29 21:59:05 -08:00
committed by GitHub

View File

@ -532,10 +532,33 @@ extension Ghostty {
} }
override func viewDidMoveToWindow() { override func viewDidMoveToWindow() {
guard let window = self.window else { return } // Set our background blur if requested
guard let surface = self.surface else { return } setWindowBackgroundBlur(window)
// Try to set the initial window size if we have one
setInitialWindowSize()
}
/// This function sets the window background to blur if it is configured on the surface.
private func setWindowBackgroundBlur(_ targetWindow: NSWindow?) {
// Surface must desire transparency
guard let surface = self.surface,
ghostty_surface_transparent(surface) else { return }
// Our target should always be our own view window
guard let target = targetWindow,
let window = self.window,
target == window else { return }
// If our window is not visible, then delay this. This is possible specifically
// during state restoration but probably in other scenarios as well. To delay,
// we just loop directly on the dispatch queue.
guard window.isVisible else {
// Weak window so that if the window changes or is destroyed we aren't holding a ref
DispatchQueue.main.async { [weak self, weak window] in self?.setWindowBackgroundBlur(window) }
return
}
if ghostty_surface_transparent(surface) {
// Set the window transparency settings // Set the window transparency settings
window.isOpaque = false window.isOpaque = false
window.hasShadow = false window.hasShadow = false
@ -545,10 +568,6 @@ extension Ghostty {
ghostty_set_window_background_blur(surface, Unmanaged.passUnretained(window).toOpaque()) ghostty_set_window_background_blur(surface, Unmanaged.passUnretained(window).toOpaque())
} }
// Try to set the initial window size if we have one
setInitialWindowSize()
}
/// Sets the initial window size requested by the Ghostty config. /// Sets the initial window size requested by the Ghostty config.
/// ///
/// This only works under certain conditions: /// This only works under certain conditions: