diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-07-24 02:39:42 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-07-24 02:39:51 +0300 |
| commit | 169a4fd90c20a00aec77d684ecec98b9f0f996cc (patch) | |
| tree | aa92f013e5380ff5d3253eeb6393f91b85f1c26b /src/ghostty/mod.rs | |
| parent | 1bcc55e47d94a10b154a180e01ee8c068b953337 (diff) | |
fix: answer XTWINOPS size queries in panes
refs #835
Diffstat (limited to 'src/ghostty/mod.rs')
| -rw-r--r-- | src/ghostty/mod.rs | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/src/ghostty/mod.rs b/src/ghostty/mod.rs index 1a2a8cbb..66182681 100644 --- a/src/ghostty/mod.rs +++ b/src/ghostty/mod.rs @@ -456,6 +456,26 @@ struct TerminalCallbackState { write_pty: Option<Box<WritePtyCallback>>, pwd_changes: Vec<Vec<u8>>, clipboard_writes: Vec<Vec<u8>>, + size_report: ffi::GhosttySizeReportSize, +} + +unsafe extern "C" fn size_trampoline( + _terminal: ffi::GhosttyTerminal, + userdata: *mut c_void, + out_size: *mut ffi::GhosttySizeReportSize, +) -> bool { + if userdata.is_null() || out_size.is_null() { + return false; + } + let state = unsafe { &*userdata.cast::<TerminalCallbackState>() }; + let size = state.size_report; + if size.rows == 0 || size.columns == 0 || size.cell_width == 0 || size.cell_height == 0 { + return false; + } + unsafe { + out_size.write(size); + } + true } unsafe extern "C" fn write_pty_trampoline( @@ -734,7 +754,14 @@ impl Terminal { let mut terminal = Self { raw, - callback_state: Box::default(), + callback_state: Box::new(TerminalCallbackState { + size_report: ffi::GhosttySizeReportSize { + rows, + columns: cols, + ..Default::default() + }, + ..Default::default() + }), kitty_fingerprints: Mutex::new(HashMap::new()), kitty_empty_generation: Cell::new(None), }; @@ -749,6 +776,12 @@ impl Terminal { .into_result()?; ffi::ghostty_terminal_set( terminal.raw, + ffi::GhosttyTerminalOption_GHOSTTY_TERMINAL_OPT_SIZE, + (size_trampoline as *const ()).cast(), + ) + .into_result()?; + ffi::ghostty_terminal_set( + terminal.raw, ffi::GhosttyTerminalOption_GHOSTTY_TERMINAL_OPT_PWD_CHANGED, (pwd_changed_trampoline as *const ()).cast(), ) @@ -799,13 +832,25 @@ impl Terminal { cell_width_px: u32, cell_height_px: u32, ) -> Result<(), Error> { - let cell_width_px = cell_width_px.max(1); - let cell_height_px = cell_height_px.max(1); + let size_report = ffi::GhosttySizeReportSize { + rows, + columns: cols, + cell_width: cell_width_px, + cell_height: cell_height_px, + }; // SAFETY: self.raw is valid and sizes are plain values. unsafe { - ffi::ghostty_terminal_resize(self.raw, cols, rows, cell_width_px, cell_height_px) - .into_result() + ffi::ghostty_terminal_resize( + self.raw, + cols, + rows, + cell_width_px.max(1), + cell_height_px.max(1), + ) + .into_result()?; } + self.callback_state.size_report = size_report; + Ok(()) } pub fn enable_kitty_graphics(&mut self) -> Result<(), Error> { |
