diff options
| author | JJ Liebig <jonathan.liebig@gmail.com> | 2026-09-14 18:35:18 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-09-14 18:35:18 +0200 |
| commit | ad415672878a98bfac92d0e7abed0fc8db26e16a (patch) | |
| tree | cdbc98801405977b9282477fb080da6ad68635df /src/app | |
| parent | b5154541cc75f9f12b7c14964d4d277d505a5f45 (diff) | |
fix: scope window titles to each client view (#4130)
refs #4091
Diffstat (limited to 'src/app')
| -rw-r--r-- | src/app/window_title.rs | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/src/app/window_title.rs b/src/app/window_title.rs index 09d2f850..41ddce6f 100644 --- a/src/app/window_title.rs +++ b/src/app/window_title.rs @@ -46,11 +46,37 @@ impl App { /// Renders the configured outer window title, or `None` when window titles /// are disabled or every token resolved empty. pub(crate) fn window_title(&self) -> Option<String> { + let target = self.state.active.and_then(|workspace_index| { + self.state + .workspaces + .get(workspace_index) + .map(|workspace| (workspace_index, workspace.active_tab_index())) + }); + self.window_title_for_target(target) + } + + pub(crate) fn window_title_for( + &self, + workspace_index: usize, + tab_index: usize, + ) -> Option<String> { + self.window_title_for_target(Some((workspace_index, tab_index))) + } + + fn window_title_for_target(&self, target: Option<(usize, usize)>) -> Option<String> { let (template, hostname) = self.window_title_template.as_ref()?; - let workspace = self - .state - .active - .and_then(|ws_idx| self.state.workspaces.get(ws_idx)); + let workspace = + target.and_then(|(workspace_index, _)| self.state.workspaces.get(workspace_index)); + let tab = target.and_then(|(workspace_index, tab_index)| { + self.state + .workspaces + .get(workspace_index)? + .tabs + .get(tab_index) + }); + let terminal = tab + .and_then(|tab| tab.terminal_id(tab.layout.focused())) + .and_then(|terminal_id| self.state.terminals.get(terminal_id)); let mut title = String::new(); for part in template.parts() { @@ -65,22 +91,25 @@ impl App { } } WindowTitlePart::Token(WindowTitleToken::Tab) => { - if let Some(name) = workspace.and_then(|ws| ws.active_tab_display_name()) { + if let Some(name) = target.and_then(|(workspace_index, tab_index)| { + self.state + .workspaces + .get(workspace_index)? + .tab_display_name(tab_index) + }) { title.push_str(&name); } } WindowTitlePart::Token(WindowTitleToken::Pane) => { - if let Some(label) = self - .focused_terminal_state() - .and_then(|terminal| terminal.manual_label.as_deref()) + if let Some(label) = + terminal.and_then(|terminal| terminal.manual_label.as_deref()) { title.push_str(label); } } WindowTitlePart::Token(WindowTitleToken::TerminalTitle) => { - if let Some(terminal_title) = self - .focused_terminal_state() - .and_then(|terminal| terminal.terminal_title_stripped()) + if let Some(terminal_title) = + terminal.and_then(|terminal| terminal.terminal_title_stripped()) { title.push_str(&terminal_title); } @@ -90,12 +119,6 @@ impl App { Some(title) } - - fn focused_terminal_state(&self) -> Option<&crate::terminal::TerminalState> { - let workspace = self.state.workspaces.get(self.state.active?)?; - let terminal_id = workspace.terminal_id(workspace.focused_pane_id()?)?; - self.state.terminals.get(terminal_id) - } } #[cfg(test)] |
