feat: report focus in and out events

This commit is contained in:
Igor Matuszewski 2026-06-19 21:11:57 +02:00 committed by Michael Murphy
parent a5acc057af
commit 042c915990

View file

@ -190,7 +190,7 @@ impl TerminalPaneGrid {
let entity = tab_model.active(); let entity = tab_model.active();
if let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) { if let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
let mut terminal = terminal.lock().unwrap(); let mut terminal = terminal.lock().unwrap();
terminal.is_focused = self.focus == *pane; terminal.set_focused(self.focus == *pane);
terminal.update(); terminal.update();
} }
} }
@ -200,7 +200,7 @@ impl TerminalPaneGrid {
let entity = tab_model.active(); let entity = tab_model.active();
if let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) { if let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
let mut terminal = terminal.lock().unwrap(); let mut terminal = terminal.lock().unwrap();
terminal.is_focused = false; terminal.set_focused(false);
terminal.update(); terminal.update();
} }
} }
@ -402,6 +402,22 @@ impl Terminal {
self.zoom_adj = value; 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 { pub fn redraw(&self) -> bool {
self.buffer.redraw() self.buffer.redraw()
} }