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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
//! tmux gateway session management and I/O routing.
//!
//! Covers:
//! - Session lifecycle: initiate, attach, disconnect, status queries
//! - Input routing: send_input_via_tmux, paste_via_tmux, tmux prefix-table keys
//! - Pane operations: split_pane_via_tmux, close_pane_via_tmux
//! - Clipboard + resize synchronization
//!
//! Profile auto-application on session connect lives in `gateway_profile`.
use crate::app::window_state::WindowState;
use crate::tmux::{SessionState, TmuxSession};
impl WindowState {
// =========================================================================
// Gateway Mode Session Management
// =========================================================================
/// Initiate a new tmux session via gateway mode.
///
/// This writes `tmux -CC new-session` to the active tab's PTY and enables
/// tmux control mode parsing. The session will be fully connected once we
/// receive the `%session-changed` notification.
///
/// # Arguments
/// * `session_name` - Optional session name. If None, tmux will auto-generate one.
pub fn initiate_tmux_gateway(&mut self, session_name: Option<&str>) -> anyhow::Result<()> {
if !self.config.load().tmux.tmux_enabled {
anyhow::bail!("tmux integration is disabled");
}
if self.tmux_state.tmux_session.is_some() && self.is_tmux_connected() {
anyhow::bail!("Already connected to a tmux session");
}
crate::debug_info!(
"TMUX",
"Initiating gateway mode session: {:?}",
session_name.unwrap_or("(auto)")
);
// An unnamed request uses `tmux_default_session` when set. It goes
// through attach-or-create (`-A`) like a named one, so a default
// session that already exists is reused instead of failing.
let default_session = self
.config
.load()
.tmux
.tmux_default_session
.clone()
.filter(|name| !name.trim().is_empty());
let cmd = match session_name.or(default_session.as_deref()) {
Some(name) => TmuxSession::create_or_attach_command(name),
None => TmuxSession::create_new_command(None),
};
// Get the active tab ID and write the command to its PTY
let gateway_tab_id = self
.tab_manager
.active_tab_id()
.ok_or_else(|| anyhow::anyhow!("No active tab available for tmux gateway"))?;
let tab = self
.tab_manager
.active_tab_mut()
.ok_or_else(|| anyhow::anyhow!("No active tab available for tmux gateway"))?;
// Write the command to the PTY
// try_lock: intentional — initiate_tmux_gateway is user-initiated but called from
// the sync event loop context. If the terminal is locked by the async PTY reader
// the command cannot be sent. On miss: bails with an error so the caller can retry.
if let Ok(term) = tab.terminal.try_read() {
crate::debug_info!(
"TMUX",
"Writing gateway command to tab {}: {}",
gateway_tab_id,
cmd.trim()
);
term.write(cmd.as_bytes())?;
// Enable tmux control mode parsing AFTER writing the command
term.set_tmux_control_mode(true);
crate::debug_info!(
"TMUX",
"Enabled tmux control mode parsing on tab {}",
gateway_tab_id
);
} else {
anyhow::bail!("Could not acquire terminal lock");
}
// Mark this tab as the gateway
tab.tmux.tmux_gateway_active = true;
// Store the gateway tab ID so we know where to send commands
self.tmux_state.tmux_gateway_tab_id = Some(gateway_tab_id);
crate::debug_info!(
"TMUX",
"Gateway tab set to {}, state: Initiating",
gateway_tab_id
);
// Create session and set gateway state
let mut session = TmuxSession::new();
session.set_gateway_initiating();
self.tmux_state.tmux_session = Some(session);
// Show toast
self.show_toast("tmux: Connecting...");
Ok(())
}
/// Attach to an existing tmux session via gateway mode.
///
/// This writes `tmux -CC attach -t session` to the active tab's PTY.
pub fn attach_tmux_gateway(&mut self, session_name: &str) -> anyhow::Result<()> {
if !self.config.load().tmux.tmux_enabled {
anyhow::bail!("tmux integration is disabled");
}
if self.tmux_state.tmux_session.is_some() && self.is_tmux_connected() {
anyhow::bail!("Already connected to a tmux session");
}
crate::debug_info!("TMUX", "Attaching to session via gateway: {}", session_name);
// Generate the attach command
let cmd = TmuxSession::create_attach_command(session_name);
// Get the active tab ID and write the command to its PTY
let gateway_tab_id = self
.tab_manager
.active_tab_id()
.ok_or_else(|| anyhow::anyhow!("No active tab available for tmux gateway"))?;
let tab = self
.tab_manager
.active_tab_mut()
.ok_or_else(|| anyhow::anyhow!("No active tab available for tmux gateway"))?;
// Write the command to the PTY
// try_lock: intentional — same rationale as initiate_tmux_gateway. On miss: bails
// so the user can retry the attach operation explicitly.
if let Ok(term) = tab.terminal.try_read() {
crate::debug_info!(
"TMUX",
"Writing attach command to tab {}: {}",
gateway_tab_id,
cmd.trim()
);
term.write(cmd.as_bytes())?;
term.set_tmux_control_mode(true);
crate::debug_info!(
"TMUX",
"Enabled tmux control mode parsing on tab {}",
gateway_tab_id
);
} else {
anyhow::bail!("Could not acquire terminal lock");
}
// Mark this tab as the gateway
tab.tmux.tmux_gateway_active = true;
// Store the gateway tab ID so we know where to send commands
self.tmux_state.tmux_gateway_tab_id = Some(gateway_tab_id);
crate::debug_info!(
"TMUX",
"Gateway tab set to {}, state: Initiating",
gateway_tab_id
);
// Create session and set gateway state
let mut session = TmuxSession::new();
session.set_gateway_initiating();
self.tmux_state.tmux_session = Some(session);
// Show toast
self.show_toast(format!("tmux: Attaching to '{}'...", session_name));
Ok(())
}
/// Disconnect from the current tmux session
pub fn disconnect_tmux_session(&mut self) {
// Restore gateway tab visibility before clearing state
self.show_gateway_tab();
// Clear the gateway tab ID
self.tmux_state.tmux_gateway_tab_id = None;
// First, disable tmux control mode on any gateway tabs
for tab in self.tab_manager.tabs_mut() {
if tab.tmux.tmux_gateway_active {
tab.tmux.tmux_gateway_active = false;
// try_lock: intentional — disconnect is called from the sync event loop.
// On miss: control mode stays on the terminal until the next frame; benign
// since the session is already being torn down and no further output arrives.
if let Ok(term) = tab.terminal.try_read() {
term.set_tmux_control_mode(false);
}
}
}
if let Some(mut session) = self.tmux_state.tmux_session.take() {
crate::debug_info!("TMUX", "Disconnecting from tmux session");
session.disconnect();
}
// Clear session name
self.tmux_state.tmux_session_name = None;
// Reset sync state
self.tmux_state.tmux_sync = crate::tmux::TmuxSync::new();
// Reset window title (now without tmux info)
self.update_window_title_with_tmux();
}
/// Check if tmux session is active
pub fn is_tmux_connected(&self) -> bool {
self.tmux_state
.tmux_session
.as_ref()
.is_some_and(|s| s.state() == SessionState::Connected)
}
/// Return true when a `tmux*` process is running under the active tab's
/// shell. Used by the input path to decide whether to encode Shift+Enter
/// as raw LF (iTerm2 convention) or as a CSI-u extended-keys sequence
/// that tmux's `extended-keys on` parser can relay to the inner app in
/// whatever keyboard protocol that app has negotiated (kitty/modifyOtherKeys).
pub fn shell_has_tmux_child(&self) -> bool {
use std::sync::atomic::Ordering;
let tab = match self.tab_manager.active_tab() {
Some(t) => t,
None => return false,
};
// Cache fallback: on `try_read` contention (frequent in release/LTO
// builds because the renderer holds the write lock briefly on every
// frame), fall back to the last-known result rather than reporting
// "no tmux". Returning `false` here was causing the Shift+Enter
// handler to send raw LF in shell context, which tmux mangles into
// Ctrl+J. See cached_has_tmux_child docs in src/tab/mod.rs.
match tab.terminal.try_read() {
Ok(term) => {
let has = term
.get_running_child_processes(&[])
.iter()
.any(|name| name.eq_ignore_ascii_case("tmux") || name.starts_with("tmux"));
tab.cached_has_tmux_child.store(has, Ordering::Relaxed);
has
}
Err(_) => tab.cached_has_tmux_child.load(Ordering::Relaxed),
}
}
/// Check if gateway mode is active (connected or connecting)
pub fn is_gateway_active(&self) -> bool {
self.tmux_state
.tmux_session
.as_ref()
.is_some_and(|s| s.is_gateway_active())
}
/// Update the tmux focused pane when a native pane is focused
///
/// This should be called when the user clicks on a pane to ensure
/// input is routed to the correct tmux pane. Callers hit-test the
/// ACTIVE tab's panes, so the pane resolves within that tab — native
/// pane ids restart at 1 in every tab, and the pane id alone would be
/// ambiguous across daemon windows.
pub fn set_tmux_focused_pane_from_native(&mut self, native_pane_id: crate::pane::PaneId) {
let Some(active_tab) = self.tab_manager.active_tab() else {
return;
};
let Some(tmux_pane_id) = self
.tmux_state
.tmux_pane_in_tab(active_tab.id, native_pane_id)
else {
return;
};
crate::debug_info!(
"TMUX",
"Setting focused pane: native {} -> tmux %{}",
native_pane_id,
tmux_pane_id
);
if let Some(session) = &mut self.tmux_state.tmux_session {
session.set_focused_pane(Some(tmux_pane_id));
} else if self.tmux_state.transport.is_some() {
// par-mux transport: remember the focused pane for input routing.
self.tmux_state.mux_focused_pane = Some(tmux_pane_id);
// Focusing a done agent's pane is seeing it — clear the
// done-unseen mark (roster surfaces render it as done ✓).
#[cfg(feature = "mux")]
self.tmux_state.agent_roster.mark_seen(tmux_pane_id);
}
}
/// Focus the native pane backing a tmux/par-mux pane id — the target of
/// the agent-roster palette picker's `agent-roster-focus:<pane>` rows
/// (A2b task 3). Returns `false` when no native pane currently maps to
/// the id (session ended, layout mid-rebuild) or the owning tab is gone;
/// the caller logs and no-ops.
pub(crate) fn focus_agent_roster_pane(&mut self, tmux_pane_id: u64) -> bool {
let Some((owner_tab_id, native_pane_id)) = self.tmux_state.tmux_pane_owner(tmux_pane_id)
else {
return false;
};
// D7 (UX.md M4): the owning tab may be HIDDEN — its last pane was
// closed while the daemon window kept running. Selecting the agent
// is a request to see that pane again, so the tab re-shows.
let Some(tab) = self.tab_manager.get_tab_mut(owner_tab_id) else {
return false;
};
tab.is_hidden = false;
// 1-based over VISIBLE tabs, the switch_to_tab_index contract. The
// owner counts as visible now whether or not it was when the row
// was picked — and computing the index over all tabs, 0-based,
// landed one tab to the left of the intended one (UX.md M13/B5).
let Some(visible_index) = self
.tab_manager
.visible_tabs()
.iter()
.position(|t| t.id == owner_tab_id)
else {
return false;
};
self.switch_to_tab_index(visible_index + 1);
if let Some(tab) = self.tab_manager.active_tab_mut()
&& let Some(pm) = tab.pane_manager_mut()
{
pm.focus_pane(native_pane_id);
}
// Sync the tmux/mux side so input routes to the newly focused pane.
self.set_tmux_focused_pane_from_native(native_pane_id);
self.set_scroll_target(0);
self.focus_state.needs_redraw = true;
self.request_redraw();
true
}
// =========================================================================
// Gateway Mode Input Routing
// =========================================================================
/// Write a command to the gateway tab's terminal.
///
/// The gateway tab is where the tmux control mode connection lives.
/// All tmux commands must be written to this tab, not the active tab.
pub(crate) fn write_to_gateway(&self, cmd: &str) -> bool {
let gateway_tab_id = match self.tmux_state.tmux_gateway_tab_id {
Some(id) => id,
None => {
crate::debug_trace!("TMUX", "No gateway tab ID set");
return false;
}
};
// try_lock: intentional — write_to_gateway is called from the sync event loop and
// from input handlers. Blocking would stall the GUI or create deadlock risk.
// On miss: the tmux command is silently dropped. For input this means a keypress
// is lost; for control commands (resize, split) the caller should retry as needed.
if let Some(tab) = self.tab_manager.get_tab(gateway_tab_id)
&& tab.tmux.tmux_gateway_active
&& let Ok(term) = tab.terminal.try_read()
{
match term.write(cmd.as_bytes()) {
Ok(()) => return true,
Err(e) => {
crate::debug_error!("TMUX", "PTY write failed (gateway command): {e}");
return false;
}
}
}
crate::debug_trace!("TMUX", "Failed to write to gateway tab");
false
}
/// Split the current pane via tmux control mode.
///
/// Writes split-window command to the gateway PTY.
///
/// # Arguments
/// * `vertical` - true for vertical split (side by side), false for horizontal (stacked)
///
/// Returns true if the command was sent successfully.
pub fn split_pane_via_tmux(&self, vertical: bool) -> bool {
if !self.config.load().tmux.tmux_enabled || !self.is_tmux_connected() {
return false;
}
let session = match &self.tmux_state.tmux_session {
Some(s) => s,
None => return false,
};
// Get the focused pane ID
let pane_id = session.focused_pane();
// Format the split command
let cmd = if vertical {
match pane_id {
Some(id) => format!("split-window -h -t %{}\n", id),
None => "split-window -h\n".to_string(),
}
} else {
match pane_id {
Some(id) => format!("split-window -v -t %{}\n", id),
None => "split-window -v\n".to_string(),
}
};
// Write to gateway tab
if self.write_to_gateway(&cmd) {
crate::debug_info!(
"TMUX",
"Sent {} split command via gateway",
if vertical { "vertical" } else { "horizontal" }
);
return true;
}
false
}
/// Close the focused pane via tmux control mode.
///
/// Writes kill-pane command to the gateway PTY.
///
/// Returns true if the command was sent successfully.
pub fn close_pane_via_tmux(&self) -> bool {
if !self.config.load().tmux.tmux_enabled || !self.is_tmux_connected() {
return false;
}
let session = match &self.tmux_state.tmux_session {
Some(s) => s,
None => return false,
};
// Get the focused pane ID
let pane_id = match session.focused_pane() {
Some(id) => id,
None => {
crate::debug_info!("TMUX", "No focused pane to close");
return false;
}
};
let cmd = format!("kill-pane -t %{}\n", pane_id);
// Write to gateway tab
if self.write_to_gateway(&cmd) {
crate::debug_info!("TMUX", "Sent kill-pane command for pane %{}", pane_id);
return true;
}
false
}
/// Sync clipboard content to tmux paste buffer.
///
/// Writes set-buffer command to the gateway PTY, or to the par-mux
/// daemon when a mux transport is attached (the panes live daemon-side
/// and there is no gateway tab to write to).
///
/// Returns true if the command was sent successfully.
pub fn sync_clipboard_to_tmux(&self, content: &str) -> bool {
// Check if clipboard sync is enabled
if !self.config.load().tmux.tmux_clipboard_sync {
return false;
}
// Don't sync empty content
if content.is_empty() {
return false;
}
let cmd = crate::tmux::set_buffer_command(content);
// par-mux transport: set-buffer is session-wide (the daemon's
// single default buffer), so the command needs no pane target.
#[cfg(feature = "mux")]
if let Some(transport) = self.tmux_state.transport.as_ref() {
return match transport.send_command(&cmd) {
Ok(_) => {
crate::debug_trace!(
"MUX",
"Synced {} chars to daemon paste buffer",
content.len()
);
true
}
Err(e) => {
crate::debug_error!("MUX", "set-buffer failed: {e}");
false
}
};
}
if !self.config.load().tmux.tmux_enabled || !self.is_tmux_connected() {
return false;
}
// Write to gateway tab
if self.write_to_gateway(&format!("{cmd}\n")) {
crate::debug_trace!(
"TMUX",
"Synced {} chars to tmux paste buffer",
content.len()
);
return true;
}
false
}
// =========================================================================
// Pane Resize Sync
// =========================================================================
/// Sync pane resize to tmux after a divider drag.
///
/// When the user resizes panes by dragging a divider in par-term, this
/// sends the new pane sizes to tmux so external clients see the same layout.
///
/// # Arguments
/// * `is_horizontal_divider` - true if dragging a horizontal divider (changes heights),
/// false if dragging a vertical divider (changes widths)
pub fn sync_pane_resize_to_tmux(&self, is_horizontal_divider: bool) {
// par-mux transport: the same absolute resize-pane form, sent
// through the daemon client. Without it a divider drag resized only
// the native panes — the daemon PTYs kept their old size and never
// sent SIGWINCH, so htop and friends never reflowed.
#[cfg(feature = "mux")]
let mux_transport = self.tmux_state.transport.as_ref();
#[cfg(not(feature = "mux"))]
let mux_transport: Option<&Box<dyn super::tmux_state::TmuxTransport>> = None;
// Only sync if tmux gateway is active (or a mux transport is)
if !self.is_gateway_active() && mux_transport.is_none() {
return;
}
// Cell dimensions from the renderer; without one (headless tests),
// from the mirror itself: a daemon-driven pane's terminal holds its
// daemon grid size.
let (cell_width, cell_height) = match &self.renderer {
Some(r) => (r.cell_width(), r.cell_height()),
None => match self.mirror_cell_metrics() {
Some(m) => m,
None => return,
},
};
// The zoomed pane's daemon identity, captured while sizing panes,
// and whether its own resize was accepted — the inputs to the zoom
// re-assert after the send loop.
let mut zoomed_tmux_pane: Option<crate::tmux::TmuxPaneId> = None;
let mut zoomed_resize_accepted = false;
// Get pane sizes from active tab's pane manager
let pane_sizes: Vec<(crate::tmux::TmuxPaneId, usize, usize)> = if let Some(tab) =
self.tab_manager.active_tab()
&& let Some(pm) = tab.pane_manager()
{
pm.all_panes()
.iter()
.filter_map(|pane| {
// Get the tmux pane ID for this native pane (tab-scoped:
// pane ids restart at 1 in every tab)
let tmux_pane_id = self.tmux_state.tmux_pane_in_tab(tab.id, pane.id)?;
// While zoomed, the zoomed pane's bounds are the whole
// tab; the daemon owns the tree cell beneath, and a
// full-tab extent would be rejected as spanning the
// axis — size that cell, not the zoom display.
let bounds = if pm.zoomed_pane_id() == Some(pane.id) {
zoomed_tmux_pane = Some(tmux_pane_id);
pm.zoomed_pane_tree_bounds().unwrap_or(pane.bounds)
} else {
pane.bounds
};
// Calculate size in columns/rows
let cols = (bounds.width / cell_width).floor() as usize;
let rows = (bounds.height / cell_height).floor() as usize;
Some((tmux_pane_id, cols.max(1), rows.max(1)))
})
.collect()
} else {
return;
};
// Send resize commands for each pane, but only for the dimension that changed
// Horizontal divider: changes height (rows) - use -y
// Vertical divider: changes width (cols) - use -x
for (tmux_pane_id, cols, rows) in pane_sizes {
let cmd = if is_horizontal_divider {
format!("resize-pane -t %{} -y {}\n", tmux_pane_id, rows)
} else {
format!("resize-pane -t %{} -x {}\n", tmux_pane_id, cols)
};
let sent = match mux_transport {
Some(transport) => match transport.send_command(cmd.trim_end()) {
Ok(lines) => {
// The daemon's reply is an empty body only when it
// accepted the resize (a non-empty one is an %error
// block, which leaves the daemon untouched).
if zoomed_tmux_pane == Some(tmux_pane_id)
&& lines.iter().all(|l| l.trim().is_empty())
{
zoomed_resize_accepted = true;
}
true
}
Err(e) => {
crate::debug_error!("MUX", "resize-pane failed: {e}");
false
}
},
None => self.write_to_gateway(&cmd),
};
if sent {
crate::debug_info!(
"TMUX",
"Synced pane %{} {} resize to {}",
tmux_pane_id,
if is_horizontal_divider {
"height"
} else {
"width"
},
if is_horizontal_divider { rows } else { cols }
);
}
}
// The daemon clears a zoom on every accepted non-Z layout mutation
// (ARC-090 remedy), so the resizes above left it unzoomed and the
// mirror follows the unflagged broadcast. `-Z` toggles: an accepted
// resize guarantees the daemon already unzoomed, so re-asserting it
// now re-zooms instead of unzooming. Sent after the whole loop so a
// later sibling resize cannot unzoom again.
if let Some(transport) = mux_transport
&& let Some(id) = zoomed_tmux_pane
&& zoomed_resize_accepted
{
match transport.send_command(&format!("resize-pane -Z -t %{id}")) {
Ok(lines) if lines.iter().all(|l| l.trim().is_empty()) => {
crate::debug_info!("MUX", "re-asserted zoom on %{} after resize", id);
}
Ok(lines) => {
crate::debug_error!(
"MUX",
"zoom re-assert on %{} rejected: {}",
id,
lines.join("\n")
);
}
Err(e) => {
crate::debug_error!("MUX", "zoom re-assert on %{} failed: {e}", id);
}
}
}
}
/// Pixels per cell of the active tab's mirror, from its first pane's
/// bounds and terminal grid.
fn mirror_cell_metrics(&self) -> Option<(f32, f32)> {
let pane = *self
.tab_manager
.active_tab()?
.pane_manager()?
.all_panes()
.first()?;
let (cols, rows) = pane.terminal.try_read().ok()?.dimensions();
(cols > 0 && rows > 0 && pane.bounds.width > 0.0).then(|| {
(
pane.bounds.width / cols as f32,
pane.bounds.height / rows as f32,
)
})
}
// =========================================================================
// Gateway Tab Visibility
// =========================================================================
/// Hide the gateway tab from the tab bar once tmux windows are active.
///
/// Called after the first tmux window tab is created so the control-mode
/// connection tab no longer clutters the tab bar. The tab still exists and
/// all PTY I/O continues to flow through it; it is simply excluded from the
/// visible tab list. The tab is restored when the session ends.
///
/// No-op when `config.tmux_hide_gateway_tab` is false.
pub(crate) fn hide_gateway_tab(&mut self) {
if !self.config.load().tmux.tmux_hide_gateway_tab {
return;
}
if let Some(gateway_tab_id) = self.tmux_state.tmux_gateway_tab_id
&& let Some(tab) = self.tab_manager.get_tab_mut(gateway_tab_id)
&& !tab.is_hidden
{
tab.is_hidden = true;
crate::debug_info!(
"TMUX",
"Gateway tab {} hidden (tmux windows active)",
gateway_tab_id
);
}
}
/// Restore the gateway tab to the tab bar when no tmux windows are active.
pub(crate) fn show_gateway_tab(&mut self) {
if let Some(gateway_tab_id) = self.tmux_state.tmux_gateway_tab_id
&& let Some(tab) = self.tab_manager.get_tab_mut(gateway_tab_id)
&& tab.is_hidden
{
tab.is_hidden = false;
crate::debug_info!("TMUX", "Gateway tab {} restored to tab bar", gateway_tab_id);
}
}
}