From cc527d45fe4821cb11c484372a9f25c51c02e078 Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Tue, 2 Jun 2026 02:27:14 +0300 Subject: perf: retain terminal render updates --- src/kitty_graphics.rs | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'src/kitty_graphics.rs') diff --git a/src/kitty_graphics.rs b/src/kitty_graphics.rs index 90cf4006..4564bde6 100644 --- a/src/kitty_graphics.rs +++ b/src/kitty_graphics.rs @@ -215,6 +215,52 @@ pub(crate) fn encode_local_pane_graphics( bytes } +pub(crate) fn has_visible_pane_graphics( + app: &AppState, + terminal_runtimes: &TerminalRuntimeRegistry, + cell_size: HostCellSize, +) -> bool { + if app.mode != Mode::Terminal || !cell_size.is_known() { + return false; + } + + let Some(ws_idx) = app.active else { + return false; + }; + if app + .workspaces + .get(ws_idx) + .and_then(crate::workspace::Workspace::active_tab) + .is_none() + { + return false; + } + + for info in &app.view.pane_infos { + let Some(runtime) = app.runtime_for_pane_in_workspace(terminal_runtimes, ws_idx, info.id) + else { + continue; + }; + let scrollback_offset = runtime + .scroll_metrics() + .map(|m| m.offset_from_bottom as u32) + .unwrap_or(0); + for placement in runtime.kitty_image_placements_with_data_filter(|_| false) { + let host_placement = HostPlacement { + pane_id: info.id, + area: info.inner_rect, + cell_size, + placement, + scrollback_offset, + }; + if clipped_placement(&host_placement).is_some() { + return true; + } + } + } + false +} + fn encode_graphics_update( bytes: &mut Vec, placements: &[HostPlacement], @@ -328,6 +374,24 @@ pub(crate) fn clear_all_host_graphics() -> io::Result<()> { } impl HostGraphicsCache { + pub(crate) fn is_empty(&self) -> bool { + self.images.is_empty() && self.placements.is_empty() + } + + #[cfg(test)] + pub(crate) fn test_mark_non_empty(&mut self) { + self.images.insert( + HOST_IMAGE_ID_BASE, + ImageSignature { + image_width: 1, + image_height: 1, + format_code: 32, + data_len: 4, + data_fingerprint: 1, + }, + ); + } + pub(crate) fn clear_bytes(&mut self) -> Vec { let mut bytes = Vec::new(); for id in self.images.keys().copied().collect::>() { -- cgit v1.2.3