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
fix(gui): follow the touchpad in the host, thread and project lists
RoversX4c52583012b5
diff --git a/wezterm-gui/src/ssh_hosts.rs b/wezterm-gui/src/ssh_hosts.rsindex 7a30ea3e..d7b4e76a 100644--- a/wezterm-gui/src/ssh_hosts.rs+++ b/wezterm-gui/src/ssh_hosts.rs@@ -138,6 +138,11 @@ pub fn list_hosts() -> Vec<(SshHostId, SshHostSpec)> {}pub fn list_all_hosts() -> Vec<SshHostEntry> {+ list_all_hosts_with(list_system_hosts())+}++/// [`list_all_hosts`] around a [`list_system_hosts`] the caller kept.+pub fn list_all_hosts_with(system_hosts: Vec<SshHostEntry>) -> Vec<SshHostEntry> {let mut entries: Vec<_> = list_hosts().into_iter().map(|(id, spec)| SshHostEntry {@@ -146,7 +151,7 @@ pub fn list_all_hosts() -> Vec<SshHostEntry> {spec,}).collect();- entries.extend(list_system_hosts());+ entries.extend(system_hosts);entries}@@ -735,8 +740,22 @@ pub fn forget_spaces_of_deleted_hosts() {crate::workspace_threads::purge_thread_refs_for_machines(&unreachable);}+/// When `~/.ssh/config` last changed and how long it is: enough for a caller+/// that keeps [`list_system_hosts`] to tell when to read it again.+pub type SshConfigStamp = (std::time::SystemTime, u64);++/// `None` when there is no file, or its time cannot be read.+pub fn system_ssh_config_stamp() -> Option<SshConfigStamp> {+ let meta = fs::metadata(system_ssh_config_path()).ok()?;+ Some((meta.modified().ok()?, meta.len()))+}++fn system_ssh_config_path() -> PathBuf {+ config::HOME_DIR.join(".ssh").join("config")+}+pub fn list_system_hosts() -> Vec<SshHostEntry> {- let path = config::HOME_DIR.join(".ssh").join("config");+ let path = system_ssh_config_path();match parse_system_ssh_config(&path) {Ok(hosts) => hosts,Err(err) => {diff --git a/wezterm-gui/src/termwindow/project_root_view.rs b/wezterm-gui/src/termwindow/project_root_view.rsindex c976d30d..8df4919e 100644--- a/wezterm-gui/src/termwindow/project_root_view.rs+++ b/wezterm-gui/src/termwindow/project_root_view.rs@@ -11,16 +11,16 @@ use crate::termwindow::ui::icons::SvgIcon;use crate::termwindow::ui::right_sidebar::{wrap_path_for_width, wrap_snippet_text_for_width};use crate::termwindow::{ContentViewId, TermWindow, TermWindowNotif};use crate::ui::{- draw_scrollbar, rect, wheel_delta_pixels, ButtonVariant, ControlState, DrawContext,- InteractionState,+ apply_wheel, draw_scrollbar, rect, ButtonVariant, ControlState, DrawContext, InteractionState,ScrollState, UiContext, UiPalette, UiTokens, WidgetKind,};use std::path::PathBuf;use std::rc::Rc;use std::sync::Mutex;+use std::time::Instant;use wezterm_font::LoadedFont;use window::WindowOps;-use window::{MouseEventKind as WMEK, MousePress, RectF};+use window::{MouseEvent, MouseEventKind as WMEK, MousePress, RectF};const CONTENT_MAX_W: f32 = 860.0;const PAD: f32 = 48.0;@@ -65,6 +65,8 @@ pub(crate) struct ProjectRootView {widgets: UiContext<ProjectRootAction>,interaction: InteractionState<ProjectRootAction>,scroll: ScrollState,+ /// The scroll was still gliding after the last paint.+ scroll_animating: bool,/// UI scale captured at paint time; mouse handlers get no `DrawContext`.last_ui_scale: f32,}@@ -87,6 +89,7 @@ impl ProjectRootView {widgets: UiContext::default(),interaction: InteractionState::default(),scroll: ScrollState::new(),+ scroll_animating: false,last_ui_scale: 1.0,}}@@ -197,6 +200,8 @@ impl ProjectRootView {) -> anyhow::Result<()> {self.widgets.clear();self.last_ui_scale = ctx.scale();+ // The glide a notched wheel was given lives in the scroll state.+ self.scroll_animating = self.scroll.advance_animation(Instant::now());ctx.draw_rect(layers,0,@@ -568,16 +573,6 @@ impl ProjectRootView {fn on_mouse_impl(&mut self, x: f32, y: f32, kind: WMEK) -> ContentViewResponse {let hit = self.widgets.hit_test(x, y).map(|target| target.action);match kind {- WMEK::VertWheel(amount) => {- let old = self.scroll.offset;- self.scroll- .scroll_by(wheel_delta_pixels(amount, self.last_ui_scale));- if (self.scroll.offset - old).abs() > 0.01 {- ContentViewResponse::Redraw- } else {- ContentViewResponse::Ignored- }- }WMEK::Move => {if self.interaction.hovered != hit {self.interaction.hovered = hit;@@ -709,6 +704,18 @@ impl ContentView for ProjectRootView {self.on_mouse_impl(x, y, kind)}+ fn on_wheel(&mut self, _x: f32, _y: f32, event: &MouseEvent) -> ContentViewResponse {+ if apply_wheel(event, &mut self.scroll, self.last_ui_scale) {+ ContentViewResponse::Redraw+ } else {+ ContentViewResponse::Ignored+ }+ }++ fn next_frame_time(&self) -> Option<Instant> {+ self.scroll_animating.then(Instant::now)+ }+fn on_key(&mut self,key: wezterm_term::KeyCode,diff --git a/wezterm-gui/src/termwindow/remote_thread_view.rs b/wezterm-gui/src/termwindow/remote_thread_view.rsindex 542cd3ee..80dc9672 100644--- a/wezterm-gui/src/termwindow/remote_thread_view.rs+++ b/wezterm-gui/src/termwindow/remote_thread_view.rs@@ -4,8 +4,7 @@ use crate::termwindow::content_view::{ContentView, ContentViewResponse, RemoteCouse crate::termwindow::ui::icons::SvgIcon;use crate::termwindow::TermWindow;use crate::ui::{- draw_scrollbar, rect, wheel_delta_pixels, ButtonVariant, ControlState, DrawContext,- InteractionState,+ apply_wheel, draw_scrollbar, rect, ButtonVariant, ControlState, DrawContext, InteractionState,ScrollState, UiContext, UiPalette, UiTokens, WidgetKind,};use crate::workspace_threads::{self, ThreadConnectionState};@@ -15,7 +14,7 @@ use std::rc::Rc;use std::time::{Duration, Instant};use wezterm_font::LoadedFont;use wezterm_term::{KeyCode, KeyModifiers};-use window::{MouseEventKind as WMEK, MousePress, RectF, WindowOps};+use window::{MouseEvent, MouseEventKind as WMEK, MousePress, RectF, WindowOps};const SPINNER_FRAMES: [&str; 10] = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];@@ -59,6 +58,8 @@ pub(crate) struct RemoteThreadView {widgets: UiContext<RemoteThreadAction>,interaction: InteractionState<RemoteThreadAction>,scroll: ScrollState,+ /// The scroll was still gliding after the last paint.+ scroll_animating: bool,/// UI scale captured at paint time; mouse handlers get no `DrawContext`.last_ui_scale: f32,}@@ -83,6 +84,7 @@ impl RemoteThreadView {widgets: UiContext::default(),interaction: InteractionState::default(),scroll: ScrollState::new(),+ scroll_animating: false,last_ui_scale: 1.0,}}@@ -121,6 +123,8 @@ impl RemoteThreadView {) -> anyhow::Result<()> {self.widgets.clear();self.last_ui_scale = ctx.scale();+ // The glide a notched wheel was given lives in the scroll state.+ self.scroll_animating = self.scroll.advance_animation(Instant::now());ctx.draw_rect(layers,0,@@ -548,16 +552,6 @@ impl RemoteThreadView {fn on_mouse_impl(&mut self, x: f32, y: f32, kind: WMEK) -> ContentViewResponse {let hit = self.widgets.hit_test(x, y).map(|target| target.action);match kind {- WMEK::VertWheel(amount) => {- let old = self.scroll.offset;- self.scroll- .scroll_by(wheel_delta_pixels(amount, self.last_ui_scale));- if (self.scroll.offset - old).abs() > 0.01 {- ContentViewResponse::Redraw- } else {- ContentViewResponse::Ignored- }- }WMEK::Move => {if self.interaction.hovered != hit {self.interaction.hovered = hit;@@ -670,6 +664,9 @@ impl ContentView for RemoteThreadView {}fn next_frame_time(&self) -> Option<Instant> {+ if self.scroll_animating {+ return Some(Instant::now());+ }match self.phase {ViewPhase::Connecting { .. } => Some(Instant::now() + Duration::from_millis(120)),_ => None,@@ -711,6 +708,14 @@ impl ContentView for RemoteThreadView {self.on_mouse_impl(x, y, kind)}+ fn on_wheel(&mut self, _x: f32, _y: f32, event: &MouseEvent) -> ContentViewResponse {+ if apply_wheel(event, &mut self.scroll, self.last_ui_scale) {+ ContentViewResponse::Redraw+ } else {+ ContentViewResponse::Ignored+ }+ }+fn on_key(&mut self, key: KeyCode, _mods: KeyModifiers) -> ContentViewResponse {match key {KeyCode::Escape => self.on_close_requested(),diff --git a/wezterm-gui/src/termwindow/ssh_hosts_view.rs b/wezterm-gui/src/termwindow/ssh_hosts_view.rsindex afe97790..8aa05aa9 100644--- a/wezterm-gui/src/termwindow/ssh_hosts_view.rs+++ b/wezterm-gui/src/termwindow/ssh_hosts_view.rs@@ -14,21 +14,22 @@ use crate::termwindow::ui::right_sidebar::wrap_snippet_text_for_width;use crate::termwindow::TermWindow;use crate::ui::anim::Easing;use crate::ui::{- card_grid, card_is_warm, card_rect, char_index_for_x, contains, draw_button,+ apply_wheel, card_grid, card_is_warm, card_rect, char_index_for_x, contains, draw_button,draw_button_on_layer, draw_icon_button, draw_scrollbar, draw_text_input,- draw_text_input_on_layer, draw_toggle, rect, row_visible, shared_grid_columns,- wheel_delta_pixels, ButtonSpec, ButtonVariant, CardGrid, ControlState, DrawContext,- EditModifiers, InputCaret, InteractionState, RowAlign, ScrollState, TextInputSpec,- TextInputState, UiContext, UiPalette, UiTokens, WidgetKind,+ draw_text_input_on_layer, draw_toggle, rect, row_visible, shared_grid_columns, ButtonSpec,+ ButtonVariant, CardGrid, ControlState, DrawContext, EditModifiers, InputCaret,+ InteractionState, RowAlign, ScrollState, TextInputSpec, TextInputState, UiContext, UiPalette,+ UiTokens, WidgetKind,};use crate::utilsprites::RenderMetrics;use crate::workspace_threads;use fluent_bundle::FluentArgs;use std::rc::Rc;+use std::time::Instant;use wezterm_font::LoadedFont;use wezterm_term::{KeyCode, KeyModifiers};use window::color::LinearRgba;-use window::{MouseEventKind as WMEK, MousePress, RectF};+use window::{MouseEvent, MouseEventKind as WMEK, MousePress, RectF};pub(crate) const SSH_HOSTS_CONTENT_VIEW_KEY: &str = "ssh-hosts";@@ -234,6 +235,13 @@ pub(crate) struct SshHostsView {widgets: UiContext<SshViewAction>,interaction: InteractionState<SshViewAction>,scroll: ScrollState,+ /// Either scroll state was still gliding after the last paint.+ scroll_animating: bool,+ /// `~/.ssh/config` as last read, with the stamp it had then. The list is+ /// rebuilt on every paint so hosts saved elsewhere show up, and the page+ /// paints for each scroll step and caret blink; the file is read again+ /// only when its stamp moves.+ system_hosts: Option<(ssh_hosts::SshConfigStamp, Vec<SshHostEntry>)>,}impl SshHostsView {@@ -259,6 +267,8 @@ impl SshHostsView {widgets: UiContext::default(),interaction: InteractionState::default(),scroll: ScrollState::new(),+ scroll_animating: false,+ system_hosts: None,};view.refresh();view@@ -276,7 +286,17 @@ impl SshHostsView {let needle = self.search.text().trim().to_ascii_lowercase();let show_system_hosts = !self.system_hosts_collapsed || !needle.is_empty();self.system_host_count = 0;- self.filtered = ssh_hosts::list_all_hosts()+ let stamp = ssh_hosts::system_ssh_config_stamp();+ let cached = match &self.system_hosts {+ Some((read_at, hosts)) if stamp == Some(*read_at) => Some(hosts.clone()),+ _ => None,+ };+ let system_hosts = cached.unwrap_or_else(|| {+ let hosts = ssh_hosts::list_system_hosts();+ self.system_hosts = stamp.map(|stamp| (stamp, hosts.clone()));+ hosts+ });+ self.filtered = ssh_hosts::list_all_hosts_with(system_hosts).into_iter().filter(|entry| {if needle.is_empty() {@@ -541,25 +561,6 @@ impl SshHostsView {fn on_mouse_impl(&mut self, x: f32, y: f32, kind: WMEK) -> ContentViewResponse {let hit = self.widgets.hit_test(x, y).map(|t| t.action);match kind {- WMEK::VertWheel(amount) => {- let scroll = if self.point_in_host_list(x, y) {- Some(&mut self.scroll)- } else if contains(self.form_area, x, y) {- Some(&mut self.form_scroll)- } else {- None- };- let Some(scroll) = scroll else {- return ContentViewResponse::Ignored;- };- let old = scroll.offset;- scroll.scroll_by(wheel_delta_pixels(amount, self.last_ui_scale));- if (scroll.offset - old).abs() > 0.01 {- ContentViewResponse::Redraw- } else {- ContentViewResponse::Ignored- }- }WMEK::Move => {if self.interaction.hovered != hit {self.interaction.hovered = hit;@@ -1348,6 +1349,10 @@ impl SshHostsView {let w = area.size.width;let h = area.size.height;self.last_ui_scale = ctx.px(1.0).max(0.01);+ // The glide a notched wheel was given lives in the scroll states.+ let now = Instant::now();+ self.scroll_animating =+ self.scroll.advance_animation(now) | self.form_scroll.advance_animation(now);ctx.draw_rect(layers, 0, ox, oy, w, h, palette.window_bg)?;@@ -2958,6 +2963,26 @@ impl ContentView for SshHostsView {self.on_mouse_impl(x, y, kind)}+ fn on_wheel(&mut self, x: f32, y: f32, event: &MouseEvent) -> ContentViewResponse {+ let scale = self.last_ui_scale;+ let scroll = if self.point_in_host_list(x, y) {+ &mut self.scroll+ } else if contains(self.form_area, x, y) {+ &mut self.form_scroll+ } else {+ return ContentViewResponse::Ignored;+ };+ if apply_wheel(event, scroll, scale) {+ ContentViewResponse::Redraw+ } else {+ ContentViewResponse::Ignored+ }+ }++ fn next_frame_time(&self) -> Option<Instant> {+ self.scroll_animating.then(Instant::now)+ }+fn on_key(&mut self, key: KeyCode, mods: KeyModifiers) -> ContentViewResponse {self.on_key_impl(key, mods)}@@ -3017,6 +3042,39 @@ mod tests {}}+ fn wheel(precise_y: Option<f32>, notches: i16) -> window::MouseEvent {+ window::MouseEvent {+ kind: window::MouseEventKind::VertWheel(notches),+ coords: window::Point::new(10, 10),+ screen_coords: window::ScreenPoint::new(10, 10),+ mouse_buttons: window::MouseButtons::NONE,+ modifiers: window::Modifiers::NONE,+ precise_scroll_delta: precise_y.map(|y| window::PreciseScrollDelta { x: 0.0, y }),+ scroll_phase: None,+ momentum_phase: None,+ precise_wheel_lines: None,+ }+ }++ #[test]+ fn the_host_list_follows_a_trackpad_and_glides_on_a_wheel() {+ use super::ContentView;+ let mut view = SshHostsView::new();+ view.list_area = crate::ui::rect(0.0, 0.0, 400.0, 300.0);+ view.scroll.set_extents(300.0, 3000.0);++ // A trackpad reports a few pixels at a time, alongside a wheel amount+ // of 0; read in whole notches, the list would not move at all.+ let response = view.on_wheel(10.0, 10.0, &wheel(Some(-7.5), 0));+ assert!(matches!(response, ContentViewResponse::Redraw));+ assert_eq!(view.scroll.offset, 7.5);++ // A notched wheel sets off a glide instead of jumping a whole step.+ view.on_wheel(10.0, 10.0, &wheel(None, -1));+ assert_eq!(view.scroll.offset, 7.5);+ assert!(view.scroll.velocity > 0.0);+ }+#[test]fn a_failure_shows_only_while_the_change_still_waits() {use crate::ssh_hosts::{ShellIntegrationFailure, ShellIntegrationRecord};diff --git a/wezterm-gui/src/ui/events.rs b/wezterm-gui/src/ui/events.rsindex 45865bb7..731b2881 100644--- a/wezterm-gui/src/ui/events.rs+++ b/wezterm-gui/src/ui/events.rs@@ -34,7 +34,13 @@ pub(crate) fn apply_wheel_to_area(if !contains(area, event.coords.x as f32, event.coords.y as f32) {return false;}+ apply_wheel(event, scroll, scale)+}+/// [`apply_wheel_to_area`] for a caller that has already picked the scroll+/// area under the pointer. A trackpad's pixels are taken as they come -- the+/// system already supplies the glide -- and a notched wheel is given one.+pub(crate) fn apply_wheel(event: &MouseEvent, scroll: &mut ScrollState, scale: f32) -> bool {scroll.set_phase(event.momentum_phase.or(event.scroll_phase));if let Some(delta) = precise_wheel_delta_pixels(event) {