From 00f04ac65cedf882f9785c0aa20831523c554dd0 Mon Sep 17 00:00:00 2001 From: JJ Liebig Date: Fri, 7 Aug 2026 18:24:56 +0200 Subject: fix: avoid redundant Windows recent-history snapshots (#2474) refs #962 Co-authored-by: Can Celik --- src/ghostty/mod.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/ghostty/mod.rs') diff --git a/src/ghostty/mod.rs b/src/ghostty/mod.rs index ef67b86f..04ad87af 100644 --- a/src/ghostty/mod.rs +++ b/src/ghostty/mod.rs @@ -768,6 +768,9 @@ pub fn encode_focus(event: FocusEvent) -> Result, Error> { pub struct Terminal { raw: ffi::GhosttyTerminal, + max_scrollback: usize, + #[cfg(windows)] + tracked_row: ffi::GhosttyTrackedGridRef, callback_state: Box, kitty_fingerprints: Mutex>, kitty_empty_generation: Cell>, @@ -788,6 +791,9 @@ impl Terminal { let mut terminal = Self { raw, + max_scrollback, + #[cfg(windows)] + tracked_row: ptr::null_mut(), callback_state: Box::new(TerminalCallbackState { size_report: ffi::GhosttySizeReportSize { rows, @@ -1033,6 +1039,10 @@ impl Terminal { self.get_usize(ffi::GhosttyTerminalData_GHOSTTY_TERMINAL_DATA_SCROLLBACK_ROWS) } + pub fn max_scrollback(&self) -> usize { + self.max_scrollback + } + pub fn scrollbar(&self) -> Result { let mut out = ffi::GhosttyTerminalScrollbar::default(); unsafe { @@ -1050,6 +1060,22 @@ impl Terminal { }) } + #[cfg(windows)] + pub(crate) fn track_row(&mut self, y: u32) -> Option { + let mut point = ffi::GhosttyPointCoordinate::default(); + let tag = ffi::GhosttyPointTag_GHOSTTY_POINT_TAG_SCREEN; + let result = + unsafe { ffi::ghostty_tracked_grid_ref_point(self.tracked_row, tag, &mut point) }; + let terminal = self.raw; + let target = ghostty_viewport_point(0, y); + unsafe { + ffi::ghostty_tracked_grid_ref_free(self.tracked_row); + self.tracked_row = ptr::null_mut(); + let _ = ffi::ghostty_terminal_grid_ref_track(terminal, target, &mut self.tracked_row); + } + (result == ffi::GhosttyResult_GHOSTTY_SUCCESS).then_some(point.y as usize) + } + pub fn screen_cell(&self, x: u16, y: u32) -> Result<(CellWide, Vec), Error> { let grid_ref = self.grid_ref(ghostty_screen_point(x, y))?; let wide = grid_ref_wide(&grid_ref)?; @@ -1834,6 +1860,8 @@ impl Drop for Terminal { fn drop(&mut self) { // SAFETY: freeing a null or live handle is allowed by the C API. unsafe { + #[cfg(windows)] + ffi::ghostty_tracked_grid_ref_free(self.tracked_row); ffi::ghostty_terminal_free(self.raw); } } -- cgit v1.2.3