1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//! Helper for creating a new tab when a tmux layout arrives without an existing tab mapping.
//!
//! Extracted from `layout.rs` to keep that file under the 800-line target.
use crate::app::window_state::WindowState;
use crate::tmux::{TmuxLayout, TmuxWindowId};
use super::layout::BoundsInfo;
impl WindowState {
/// Create a brand-new tab and apply the tmux layout to it.
///
/// Called when `handle_tmux_layout_change` receives a layout for a window
/// that has no existing tab mapping.
pub(super) fn create_tab_for_layout(
&mut self,
window_id: TmuxWindowId,
parsed_layout: &TmuxLayout,
pane_ids: &[crate::tmux::TmuxPaneId],
bounds_info: BoundsInfo,
) {
crate::debug_info!(
"TMUX",
"No tab mapping for window @{}, creating new tab for layout",
window_id
);
if self.config.load().tabs.max_tabs > 0
&& self.tab_manager.tab_count() >= self.config.load().tabs.max_tabs
{
return;
}
let grid_size = self.renderer.as_ref().map(|r| r.grid_size());
match self.tab_manager.new_tab(
&self.config.load(),
std::sync::Arc::clone(&self.runtime),
false,
grid_size,
) {
Ok(new_tab_id) => {
crate::debug_info!(
"TMUX",
"Created tab {} for tmux window @{}",
new_tab_id,
window_id
);
self.tmux_state.tmux_sync.map_window(window_id, new_tab_id);
if let Some(tab) = self.tab_manager.get_tab_mut(new_tab_id) {
tab.init_pane_manager();
// UX.md T8/M11: no "tmux" wording on a par-mux path —
// same placeholder rule as handle_tmux_window_add.
let prefix = if self.tmux_state.is_mux_attached() {
"par-mux"
} else {
"tmux"
};
tab.set_title(&format!("{} @{}", prefix, window_id));
if let Some(window) = &self.window {
tab.start_refresh_task(
std::sync::Arc::clone(&self.runtime),
std::sync::Arc::clone(window),
self.config.load().rendering.max_fps,
self.config.load().power.inactive_tab_fps,
);
}
if let Some((
size,
padding,
content_offset_y,
content_inset_right,
_cell_width,
_cell_height,
status_bar_height,
)) = bounds_info
&& let Some(pm) = tab.pane_manager_mut()
{
let content_width = size.width as f32 - padding * 2.0 - content_inset_right;
let content_height =
size.height as f32 - content_offset_y - padding - status_bar_height;
let bounds = crate::pane::PaneBounds::new(
padding,
content_offset_y,
content_width,
content_height,
);
pm.set_bounds(bounds);
}
if let Some(pm) = tab.pane_manager_mut() {
match pm.set_from_tmux_layout(
parsed_layout,
&self.config.load(),
std::sync::Arc::clone(&self.runtime),
) {
Ok(pane_mappings) => {
crate::debug_info!(
"TMUX",
"Storing pane mappings for new tab: {:?}",
pane_mappings
);
self.tmux_state
.set_tab_pane_mappings(new_tab_id, &pane_mappings);
// Size every new pane terminal to its layout
// cell. Panes are created at the config
// default (80x24); without this the reattach
// seed and all live output reflow at the
// wrong width (broken wrapping on reconnect)
// until some later resize happens to fire.
if let Some((_, _, _, _, cell_width, cell_height, _)) = bounds_info
{
pm.resize_all_terminals(cell_width, cell_height);
}
if !pane_ids.is_empty() {
tab.tmux.tmux_pane_id = Some(pane_ids[0]);
}
tab.attach_session_logging_to_panes();
self.request_pane_refresh(pane_ids);
self.focus_state.needs_redraw = true;
}
Err(e) => {
crate::debug_error!(
"TMUX",
"Failed to apply tmux layout to new tab: {}",
e
);
}
}
}
}
self.tab_manager.switch_to(new_tab_id);
// Hide the gateway tab now that a tmux window tab exists
self.hide_gateway_tab();
}
Err(e) => {
crate::debug_error!(
"TMUX",
"Failed to create tab for tmux window @{}: {}",
window_id,
e
);
}
}
}
}