From 042c91599020d11489e729022afbab2b2c03475a Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Fri, 19 Jun 2026 21:11:57 +0200 Subject: [PATCH] feat: report focus in and out events --- src/terminal.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/terminal.rs b/src/terminal.rs index 8c1b22f..73f8581 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -190,7 +190,7 @@ impl TerminalPaneGrid { let entity = tab_model.active(); if let Some(terminal) = tab_model.data::>(entity) { let mut terminal = terminal.lock().unwrap(); - terminal.is_focused = self.focus == *pane; + terminal.set_focused(self.focus == *pane); terminal.update(); } } @@ -200,7 +200,7 @@ impl TerminalPaneGrid { let entity = tab_model.active(); if let Some(terminal) = tab_model.data::>(entity) { let mut terminal = terminal.lock().unwrap(); - terminal.is_focused = false; + terminal.set_focused(false); terminal.update(); } } @@ -402,6 +402,22 @@ impl Terminal { self.zoom_adj = value; } + fn set_focused(&mut self, is_focused: bool) { + let focus_changed = self.is_focused != is_focused; + self.is_focused = is_focused; + + if focus_changed { + let report_focus = self.term.lock().mode().contains(TermMode::FOCUS_IN_OUT); + if report_focus { + const FOCUS_IN: &[u8] = b"\x1b[I"; + const FOCUS_OUT: &[u8] = b"\x1b[O"; + + let input = if is_focused { FOCUS_IN } else { FOCUS_OUT }; + self.input_no_scroll(input); + } + } + } + pub fn redraw(&self) -> bool { self.buffer.redraw() }