@@ -2733,10 +2733,12 @@ final class TerminalSurface: Identifiable, ObservableObject {
27332733 private let maxPendingTextBytes = 1_048_576
27342734 private var backgroundSurfaceStartQueued = false
27352735 private var surfaceCallbackContext : Unmanaged < GhosttySurfaceCallbackContext > ?
2736- /// Tracks the last focus state to avoid sending redundant focus events.
2737- /// This prevents prompt redraw issues with zsh themes like Powerlevel10k.
2736+ /// The desired focus state for the Ghostty C surface. May be set before the
2737+ /// C surface exists (e.g. during layout restoration); `createSurface` syncs
2738+ /// it on creation. Also used as a dedup guard to avoid redundant
2739+ /// `ghostty_surface_set_focus` calls (prevents prompt redraws with P10k).
27382740 /// Initialized to `true` to match Ghostty's default (Terminal.zig focused=true).
2739- private var lastFocusState : Bool = true
2741+ private var desiredFocusState : Bool = true
27402742#if DEBUG
27412743 private var needsConfirmCloseOverrideForTesting : Bool ?
27422744#endif
@@ -3554,7 +3556,7 @@ final class TerminalSurface: Identifiable, ObservableObject {
35543556 // logically unfocused before the C surface existed (e.g. during layout
35553557 // restoration). Always sync unconditionally so we don't couple to
35563558 // Ghostty's default.
3557- ghostty_surface_set_focus ( createdSurface, lastFocusState )
3559+ ghostty_surface_set_focus ( createdSurface, desiredFocusState )
35583560
35593561 NotificationCenter . default. post (
35603562 name: . terminalSurfaceDidBecomeReady,
@@ -3680,18 +3682,18 @@ final class TerminalSurface: Identifiable, ObservableObject {
36803682 surfaceView. applyWindowBackgroundIfActive ( )
36813683 }
36823684
3683- /// Keep `lastFocusState ` in sync when the hosted view's responder chain
3685+ /// Keep `desiredFocusState ` in sync when the hosted view's responder chain
36843686 /// calls `ghostty_surface_set_focus` directly (bypassing `setFocus`).
36853687 /// Without this, `createSurface` would replay a stale state on recreation.
36863688 func recordExternalFocusState( _ focused: Bool ) {
3687- lastFocusState = focused
3689+ desiredFocusState = focused
36883690 }
36893691
36903692 func setFocus( _ focused: Bool ) {
36913693 // Only send focus events when the state changes to avoid redundant
36923694 // prompt redraws with zsh themes like Powerlevel10k.
3693- guard focused != lastFocusState else { return }
3694- lastFocusState = focused
3695+ guard focused != desiredFocusState else { return }
3696+ desiredFocusState = focused
36953697 // Track desired state even before the C surface exists (e.g. during
36963698 // layout restoration). createSurface syncs the state once created.
36973699 guard let surface = surface else { return }
0 commit comments