mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: avoid showing overlay if gained focus recently
This commit is contained in:
@ -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.
|
||||
@ -294,6 +296,19 @@ 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;
|
||||
|
@ -30,6 +30,10 @@ 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) {
|
||||
|
Reference in New Issue
Block a user