A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
feat(render): show rendered cards on other windows
RoversX5e19250ca82c
diff --git a/wezterm-gui/src/termwindow/content_view.rs b/wezterm-gui/src/termwindow/content_view.rsindex 1b2a3276..b7624958 100644--- a/wezterm-gui/src/termwindow/content_view.rs+++ b/wezterm-gui/src/termwindow/content_view.rs@@ -548,6 +548,11 @@ pub(crate) struct TerminalPreviewRequest {/// into, which has to be ready when the terminal lands on it and must not/// show before then.pub prebuild: bool,+ /// The radius of the picture's corners, in pixels.+ pub corner_radius: f32,+ /// What to fill the picture with in place of the backgrounds its panes+ /// report, which a pane not on screen may not have heard of yet.+ pub background: Option<::window::color::LinearRgba>,}/// Progress of an SSH connection that a content view kicked off, pushed by thediff --git a/wezterm-gui/src/termwindow/live_overview.rs b/wezterm-gui/src/termwindow/live_overview.rsindex 934d47d4..dbedeee4 100644--- a/wezterm-gui/src/termwindow/live_overview.rs+++ b/wezterm-gui/src/termwindow/live_overview.rs@@ -1238,6 +1238,8 @@ impl LiveOverviewView {hold_scale: self.live_resizing,opacity: 0.0,prebuild: true,+ corner_radius: 0.0,+ background: None,});}} else {@@ -1258,6 +1260,8 @@ impl LiveOverviewView {hold_scale: self.live_resizing,opacity: 1.0 - arrived,prebuild: false,+ corner_radius: 0.0,+ background: None,});}}@@ -1270,6 +1274,8 @@ impl LiveOverviewView {hold_scale: self.live_resizing,opacity: arrived,prebuild: false,+ corner_radius: 0.0,+ background: None,});self.visible_panes.extend(snapshot.panes.iter().map(|pane| pane.pane_id));@@ -2917,7 +2923,7 @@ fn palette_identity(palette: &wezterm_term::color::ColorPalette) -> u64 {hasher.finish()}-fn capture_terminal_snapshot(tab_id: TabId) -> Option<TerminalPreviewSnapshot> {+pub(crate) fn capture_terminal_snapshot(tab_id: TabId) -> Option<TerminalPreviewSnapshot> {let tab = Mux::get().get_tab(tab_id)?;let tab_size = tab.get_size();if tab_size.cols == 0 || tab_size.rows == 0 {diff --git a/wezterm-gui/src/termwindow/render/draw.rs b/wezterm-gui/src/termwindow/render/draw.rsindex 3a5d9da7..cf4e0284 100644--- a/wezterm-gui/src/termwindow/render/draw.rs+++ b/wezterm-gui/src/termwindow/render/draw.rs@@ -141,6 +141,115 @@ fn composite_quad_verts(])}+/// Show `card`, rendered on this device already, on the `surface` of a window+/// with nothing else in it, and `thumbnail` over it. The card goes on as it+/// is rather than through the blend, which would count the alpha already in+/// its edges a second time and darken them.+pub(crate) fn show_card_on_surface(+ webgpu: &WebGpuState,+ surface: &wgpu::Surface<'static>,+ dimensions: Dimensions,+ card: &crate::termwindow::webgpu::CardRenderTexture,+ thumbnail: Option<&crate::termwindow::render::paint::CardComposite>,+) -> anyhow::Result<()> {+ use crate::quad::{V_BOT_LEFT, V_BOT_RIGHT, V_TOP_LEFT, V_TOP_RIGHT};+ use wgpu::util::DeviceExt;++ let output = surface.get_current_texture()?;+ let mut encoder = webgpu+ .device+ .create_command_encoder(&wgpu::CommandEncoderDescriptor {+ label: Some("Card Window Encoder"),+ });+ encoder.copy_texture_to_texture(+ card.texture.as_image_copy(),+ output.texture.as_image_copy(),+ wgpu::Extent3d {+ width: card.width.min(output.texture.width()),+ height: card.height.min(output.texture.height()),+ depth_or_array_layers: 1,+ },+ );+ let thumbnail =+ thumbnail.and_then(|picture| Some((picture, composite_quad_verts(picture, &dimensions)?)));+ let drawing = thumbnail.map(|(picture, verts)| {+ let vertices = webgpu+ .device+ .create_buffer_init(&wgpu::util::BufferInitDescriptor {+ label: Some("Card Window Vertices"),+ usage: wgpu::BufferUsages::VERTEX,+ contents: bytemuck::cast_slice(&verts),+ });+ let indices = [+ V_TOP_LEFT,+ V_TOP_RIGHT,+ V_BOT_LEFT,+ V_TOP_RIGHT,+ V_BOT_LEFT,+ V_BOT_RIGHT,+ ]+ .map(|corner| corner as u32);+ let index = webgpu+ .device+ .create_buffer_init(&wgpu::util::BufferInitDescriptor {+ label: Some("Card Window Indices"),+ usage: wgpu::BufferUsages::INDEX,+ contents: bytemuck::cast_slice(&indices),+ });+ (picture, vertices, index)+ });+ if let Some((picture, vertices, index)) = &drawing {+ let projection = euclid::Transform3D::<f32, f32, f32>::ortho(+ -(dimensions.pixel_width as f32) / 2.0,+ dimensions.pixel_width as f32 / 2.0,+ dimensions.pixel_height as f32 / 2.0,+ -(dimensions.pixel_height as f32) / 2.0,+ -1.0,+ 1.0,+ )+ .to_arrays_transposed();+ let uniforms = webgpu.card_uniform(0, ShaderUniform {+ foreground_text_hsb: [1.0; 3],+ milliseconds: 0,+ viewport_and_corner: [+ dimensions.pixel_width as f32,+ dimensions.pixel_height as f32,+ 0.0,+ 0.0,+ ],+ window_border: [0.0; 4],+ projection,+ });+ let view = output+ .texture+ .create_view(&wgpu::TextureViewDescriptor::default());+ let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {+ label: Some("Card Window Pass"),+ color_attachments: &[Some(wgpu::RenderPassColorAttachment {+ view: &view,+ resolve_target: None,+ ops: wgpu::Operations {+ load: wgpu::LoadOp::Load,+ store: wgpu::StoreOp::Store,+ },+ })],+ depth_stencil_attachment: None,+ occlusion_query_set: None,+ timestamp_writes: None,+ });+ pass.set_pipeline(&webgpu.render_pipeline);+ pass.set_bind_group(0, &uniforms, &[]);+ pass.set_bind_group(1, &picture.texture.bind_group, &[]);+ pass.set_bind_group(2, &picture.texture.bind_group, &[]);+ pass.set_vertex_buffer(0, vertices.slice(..));+ pass.set_index_buffer(index.slice(..), wgpu::IndexFormat::Uint32);+ pass.draw_indexed(0..6, 0, 0..1);+ }+ webgpu.queue.submit(std::iter::once(encoder.finish()));+ output.present();+ Ok(())+}+#[derive(Clone, Copy, Debug, PartialEq)]pub(crate) struct WindowBorder {pub width: f32,@@ -342,7 +451,7 @@ pub(crate) fn draw_webgpu_layers(viewport_and_corner: [pending.texture.width as f32,pending.texture.height as f32,- 0.0,+ pending.corner_radius,0.0,],window_border: [0.0; 4],diff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rsindex 6330e826..70c5ab11 100644--- a/wezterm-gui/src/termwindow/render/paint.rs+++ b/wezterm-gui/src/termwindow/render/paint.rs@@ -212,6 +212,8 @@ pub(crate) struct PreviewGeometryKey {/// start and end, and each flip re-keyed all cards at once -- a full/// same-frame rebuild of the overview to draw the identical picture.scale_bits: u64,+ corner_radius: u32,+ background: Option<[u32; 4]>,pixel_width: usize,pixel_height: usize,dpi: usize,@@ -319,6 +321,8 @@ pub(crate) struct PendingCardRender {pub quad_count: usize,/// The rect (top-left window pixels) the verts were recorded against.pub area: RectF,+ /// The radius the texture's corners are cut to.+ pub corner_radius: f32,}/// One textured quad standing in for a card's thousands of glyph quads,@@ -475,6 +479,10 @@ fn preview_quad_key(area_width: preview.area.size.width.to_bits(),area_height: preview.area.size.height.to_bits(),scale_bits: scale.to_bits(),+ corner_radius: preview.corner_radius.to_bits(),+ background: preview+ .background+ .map(|fill| [fill.0, fill.1, fill.2, fill.3].map(f32::to_bits)),// Quad positions are relative to the centre of the window.pixel_width: dimensions.pixel_width,pixel_height: dimensions.pixel_height,@@ -2636,7 +2644,7 @@ impl crate::TermWindow {/// Render live, read-only terminal thumbnails requested by a ContentView./// This reuses the normal screen-line renderer at a smaller font scale;/// panes are never resized and no input or focus is sent to them.- fn paint_terminal_previews(+ pub(crate) fn paint_terminal_previews(&mut self,layers: &mut TripleLayerQuadAllocator<'_>,previews: &[TerminalPreviewRequest],@@ -2757,7 +2765,22 @@ impl crate::TermWindow {/// Whether `tab_id`'s card has a finished picture of what its terminal/// shows now: a cached recording with something in it, and no rebuild of/// it still under way across frames.- fn preview_thumbnail_recorded(&self, tab_id: TabId) -> bool {+ /// The finished picture of `tab_id`'s card, as a texture.+ pub(crate) fn preview_picture(+ &self,+ tab_id: TabId,+ ) -> Option<Rc<crate::termwindow::webgpu::CardRenderTexture>> {+ if !self.preview_thumbnail_recorded(tab_id) {+ return None;+ }+ self.preview_quad_cache+ .borrow()+ .get(&tab_id)?+ .texture+ .clone()+ }++ pub(crate) fn preview_thumbnail_recorded(&self, tab_id: TabId) -> bool {self.preview_quad_cache.borrow().get(&tab_id)@@ -3008,6 +3031,7 @@ impl crate::TermWindow {first_vertex,quad_count,area: preview.area,+ corner_radius: preview.corner_radius,});if shown {self.card_composites.borrow_mut().push(CardComposite {@@ -3059,7 +3083,7 @@ impl crate::TermWindow {self.webgpu.is_some()}- fn create_card_texture(+ pub(crate) fn create_card_texture(&self,area: RectF,) -> anyhow::Result<Rc<crate::termwindow::webgpu::CardRenderTexture>> {@@ -3116,6 +3140,7 @@ impl crate::TermWindow {first_vertex,quad_count,area: recorded_area,+ corner_radius: preview.corner_radius,});}let Some(texture) = self@@ -3290,7 +3315,8 @@ impl crate::TermWindow {.map(|pane| pane.palette.resolve_bg(ColorAttribute::Default).to_linear()).expect("checked that the tab has panes");if *resume_pane == 0 && *resume_line == 0 {- self.filled_rectangle(layers, 0, preview.area, preview_background)?;+ let fill = preview.background.unwrap_or(preview_background);+ self.filled_rectangle(layers, 0, preview.area, fill)?;}// Quantization bounds the number of cached FontConfigurations even@@ -3434,7 +3460,9 @@ impl crate::TermWindow {layers,0,pane_bounds,- palette.resolve_bg(ColorAttribute::Default).to_linear(),+ preview+ .background+ .unwrap_or_else(|| palette.resolve_bg(ColorAttribute::Default).to_linear()),)?;}@@ -6058,6 +6086,26 @@ mod tests {assert_eq!(under(&items, 500), Some(UIItemType::WindowTabsTravelling));}+ #[test]+ fn a_preview_with_rounder_corners_is_another_picture() {+ let area = euclid::rect(0.0, 0.0, 100.0, 100.0);+ let dimensions = Dimensions {+ pixel_width: 800,+ pixel_height: 600,+ dpi: 96,+ };+ let geometry = |preview: &TerminalPreviewRequest| {+ preview_quad_key(preview, &dimensions, 0, 1.0).geometry+ };+ let plain = test_preview(area);+ let rounded = TerminalPreviewRequest {+ corner_radius: 8.0,+ ..test_preview(area)+ };+ assert!(geometry(&plain) == geometry(&test_preview(area)));+ assert!(geometry(&plain) != geometry(&rounded));+ }+fn test_preview(area: RectF) -> TerminalPreviewRequest {TerminalPreviewRequest {tab_id: 1,@@ -6071,6 +6119,8 @@ mod tests {hold_scale: false,opacity: 1.0,prebuild: false,+ corner_radius: 0.0,+ background: None,}}diff --git a/wezterm-gui/src/termwindow/webgpu.rs b/wezterm-gui/src/termwindow/webgpu.rsindex e31d698c..3706f2d1 100644--- a/wezterm-gui/src/termwindow/webgpu.rs+++ b/wezterm-gui/src/termwindow/webgpu.rs@@ -51,6 +51,7 @@ struct AtlasBindGroups {}pub struct WebGpuState {+ instance: wgpu::Instance,pub adapter_info: wgpu::AdapterInfo,pub downlevel_caps: wgpu::DownlevelCapabilities,pub surface: wgpu::Surface<'static>,@@ -103,6 +104,10 @@ impl RawHandlePair {display: window.display_handle().expect("display handle").as_raw(),}}++ fn surface_on(&self, instance: &wgpu::Instance) -> anyhow::Result<wgpu::Surface<'static>> {+ Ok(unsafe { instance.create_surface_unsafe(wgpu::SurfaceTargetUnsafe::from_window(self)?)? })+ }}impl HasWindowHandle for RawHandlePair {@@ -255,6 +260,20 @@ pub struct CardRenderTexture {impl CardRenderTexture {pub fn new(width: u32, height: u32, state: &WebGpuState) -> anyhow::Result<Self> {+ Self::with_copies(width, height, state, crate::framedump::enabled())+ }++ /// One that can be copied onto a surface rather than only drawn.+ pub fn copyable(width: u32, height: u32, state: &WebGpuState) -> anyhow::Result<Self> {+ Self::with_copies(width, height, state, true)+ }++ fn with_copies(+ width: u32,+ height: u32,+ state: &WebGpuState,+ copies: bool,+ ) -> anyhow::Result<Self> {let limit = state.device.limits().max_texture_dimension_2d;if width > limit || height > limit {anyhow::bail!(@@ -275,7 +294,7 @@ impl CardRenderTexture {sample_count: 1,dimension: wgpu::TextureDimension::D2,format,- usage: if crate::framedump::enabled() {+ usage: if copies {wgpu::TextureUsages::RENDER_ATTACHMENT| wgpu::TextureUsages::TEXTURE_BINDING| wgpu::TextureUsages::COPY_SRC@@ -491,9 +510,7 @@ impl WebGpuState {backends,..Default::default()});- let surface = unsafe {- instance.create_surface_unsafe(wgpu::SurfaceTargetUnsafe::from_window(&handle)?)?- };+ let surface = handle.surface_on(&instance)?;let mut adapter: Option<wgpu::Adapter> = None;@@ -675,6 +692,7 @@ impl WebGpuState {let pipeline = Pipeline::new(&device, config.format);Ok(Self {+ instance,adapter_info,downlevel_caps,surface,@@ -698,6 +716,25 @@ impl WebGpuState {})}+ /// A surface on this device for another window of ours, which can then+ /// show what this one has rendered without a device of its own. The+ /// handle goes with the surface.+ pub fn surface_for(+ &self,+ window: &Window,+ width: u32,+ height: u32,+ ) -> anyhow::Result<(wgpu::Surface<'static>, RawHandlePair)> {+ let handle = RawHandlePair::new(window);+ let surface = handle.surface_on(&self.instance)?;+ let mut config = self.config.borrow().clone();+ config.width = width;+ config.height = height;+ config.usage |= wgpu::TextureUsages::COPY_DST;+ surface.configure(&self.device, &config);+ Ok((surface, handle))+ }+/// Present a frame and tell the window, which wgpu does not: on Wayland/// the window paces its repaints by it (WindowOps::frame_presented).pub fn present(&self, output: wgpu::SurfaceTexture) {