macos: avoid showing overlay if gained focus recently

This commit is contained in:
Mitchell Hashimoto
2024-08-11 11:07:07 -07:00
parent 4680c87c8b
commit 2e0e8897e7
2 changed files with 29 additions and 3 deletions

View File

@ -153,7 +153,8 @@ extension Ghostty {
size: surfaceSize, size: surfaceSize,
overlay: ghostty.config.resizeOverlay, overlay: ghostty.config.resizeOverlay,
position: ghostty.config.resizeOverlayPosition, 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 overlay: Ghostty.Config.ResizeOverlay
let position: Ghostty.Config.ResizeOverlayPosition let position: Ghostty.Config.ResizeOverlayPosition
let duration: UInt let duration: UInt
let focusInstant: Any?
// This is the last size that we processed. This is how we handle our // This is the last size that we processed. This is how we handle our
// timer state. // timer state.
@ -294,6 +296,19 @@ extension Ghostty {
// Hidden if we already processed this size. // Hidden if we already processed this size.
if (lastSize == geoSize) { return true; } 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 // Hidden depending on overlay config
switch (overlay) { switch (overlay) {
case .never: return true; case .never: return true;

View File

@ -30,6 +30,10 @@ extension Ghostty {
// The hovered URL string // The hovered URL string
@Published var hoverUrl: String? = nil @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 // An initial size to request for a window. This will only affect
// then the view is moved to a new window. // then the view is moved to a new window.
var initialSize: NSSize? = nil var initialSize: NSSize? = nil
@ -208,6 +212,13 @@ extension Ghostty {
guard self.focused != focused else { return } guard self.focused != focused else { return }
self.focused = focused self.focused = focused
ghostty_surface_set_focus(surface, 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) { func sizeDidChange(_ size: CGSize) {