From 2e5da968ea3fb7105c56f7674caf822de41ec176 Mon Sep 17 00:00:00 2001 From: akbash Date: Tue, 14 Jul 2026 01:06:11 +0300 Subject: fix: forward outer focus events to panes (#1388) * fix: forward outer focus events to panes refs #1337 * fix: preserve ordered focus forwarding refs #1337 --------- Co-authored-by: akbash-bot <300245827+akbash-bot@users.noreply.github.com> Co-authored-by: Ogulcan Celik --- src/app/api.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/app/api.rs') diff --git a/src/app/api.rs b/src/app/api.rs index c013d271..d6d657b7 100644 --- a/src/app/api.rs +++ b/src/app/api.rs @@ -765,6 +765,17 @@ impl App { } pub(crate) fn sync_focus_events(&mut self) { + self.sync_focus_events_with_outer_event(None); + } + + pub(super) fn send_outer_focus_event(&mut self, event: crate::ghostty::FocusEvent) { + self.sync_focus_events_with_outer_event(Some(event)); + } + + fn sync_focus_events_with_outer_event( + &mut self, + outer_event: Option, + ) { let current_focus = self.state.active.and_then(|idx| { self.state .workspaces @@ -772,6 +783,9 @@ impl App { .and_then(|ws| ws.focused_pane_id().map(|pane_id| (idx, pane_id))) }); if current_focus == self.last_focus { + if let (Some((ws_idx, pane_id)), Some(event)) = (current_focus, outer_event) { + self.send_pane_focus_event(ws_idx, pane_id, event); + } return; } @@ -779,7 +793,14 @@ impl App { self.send_pane_focus_event(ws_idx, pane_id, crate::ghostty::FocusEvent::Lost); } if let Some((ws_idx, pane_id)) = current_focus { - self.send_pane_focus_event(ws_idx, pane_id, crate::ghostty::FocusEvent::Gained); + let event = outer_event.unwrap_or_else(|| { + if self.state.outer_terminal_focus == Some(false) { + crate::ghostty::FocusEvent::Lost + } else { + crate::ghostty::FocusEvent::Gained + } + }); + self.send_pane_focus_event(ws_idx, pane_id, event); self.emit_event(crate::api::schema::EventEnvelope { event: crate::api::schema::EventKind::WorkspaceFocused, data: crate::api::schema::EventData::WorkspaceFocused { -- cgit v1.2.3