diff --git a/macos/Sources/Ghostty/SurfaceView.swift b/macos/Sources/Ghostty/SurfaceView.swift index c6556e838..9ec41f95d 100644 --- a/macos/Sources/Ghostty/SurfaceView.swift +++ b/macos/Sources/Ghostty/SurfaceView.swift @@ -153,7 +153,8 @@ extension Ghostty { size: surfaceSize, overlay: ghostty.config.resizeOverlay, position: ghostty.config.resizeOverlayPosition, - duration: ghostty.config.resizeOverlayDuration) + duration: ghostty.config.resizeOverlayDuration, + focusInstant: surfaceView.focusInstant) } } @@ -274,6 +275,7 @@ extension Ghostty { let overlay: Ghostty.Config.ResizeOverlay let position: Ghostty.Config.ResizeOverlayPosition let duration: UInt + let focusInstant: Any? // This is the last size that we processed. This is how we handle our // timer state. @@ -293,7 +295,20 @@ extension Ghostty { // Hidden if we already processed this size. if (lastSize == geoSize) { return true; } - + + // If we were focused recently we hide it as well. This avoids showing + // the resize overlay when SwiftUI is lazily resizing. + if #available(macOS 13, iOS 16, *) { + if let instant = focusInstant as? ContinuousClock.Instant { + let d = instant.duration(to: ContinuousClock.now) + if (d < .milliseconds(500)) { + // Avoid this size completely. + lastSize = geoSize + return true; + } + } + } + // Hidden depending on overlay config switch (overlay) { case .never: return true; diff --git a/macos/Sources/Ghostty/SurfaceView_AppKit.swift b/macos/Sources/Ghostty/SurfaceView_AppKit.swift index 3d6c17750..1a68a2ea0 100644 --- a/macos/Sources/Ghostty/SurfaceView_AppKit.swift +++ b/macos/Sources/Ghostty/SurfaceView_AppKit.swift @@ -29,7 +29,11 @@ extension Ghostty { // The hovered URL string @Published var hoverUrl: String? = nil - + + // The time this surface last became focused. This is a ContinuousClock.Instant + // on supported platforms. + @Published var focusInstant: Any? = nil + // An initial size to request for a window. This will only affect // then the view is moved to a new window. var initialSize: NSSize? = nil @@ -208,6 +212,13 @@ extension Ghostty { guard self.focused != focused else { return } self.focused = focused ghostty_surface_set_focus(surface, focused) + + // On macOS 13+ we can store our continuous clock... + if #available(macOS 13, iOS 16, *) { + if (focused) { + focusInstant = ContinuousClock.now + } + } } func sizeDidChange(_ size: CGSize) {