Skip to content

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.

gui: scroll the scrollback by the pixel, with a Scrolling setting

RoversXafb0d487535f
diff --git a/thinkterm-i18n/i18n/de-DE.ftl b/thinkterm-i18n/i18n/de-DE.ftl
index 706306fc..357646d3 100644
--- a/thinkterm-i18n/i18n/de-DE.ftl
+++ b/thinkterm-i18n/i18n/de-DE.ftl
@@ -132,6 +132,10 @@ settings-remote-pane-resize-mode-description = Auto aktualisiert bei schnellen V
settings-remote-pane-resize-mode-auto = Auto
settings-remote-pane-resize-mode-live = Live
settings-remote-pane-resize-mode-on-release = Beim Loslassen
+settings-scroll-mode = Scrollen
+settings-scroll-mode-description = Weich bewegt den Text genau so weit, wie Trackpad, Finger oder Rad sich bewegt haben; Zeilenweise springt jeweils eine ganze Zeile.
+settings-scroll-mode-stepped = Zeilenweise
+settings-scroll-mode-smooth = Weich
settings-bottom-quote = Zitat am unteren Rand
settings-bottom-quote-description = Zeigt ein kurzes Zitat am unteren Rand des Terminalfensters.
settings-quote-font-size = Schriftgröße des Zitats
diff --git a/thinkterm-i18n/i18n/en-US.ftl b/thinkterm-i18n/i18n/en-US.ftl
index 729cf995..b1da2926 100644
--- a/thinkterm-i18n/i18n/en-US.ftl
+++ b/thinkterm-i18n/i18n/en-US.ftl
@@ -132,6 +132,10 @@ settings-remote-pane-resize-mode-description = Auto updates continuously on fast
settings-remote-pane-resize-mode-auto = Auto
settings-remote-pane-resize-mode-live = Live
settings-remote-pane-resize-mode-on-release = On release
+settings-scroll-mode = Scrolling
+settings-scroll-mode-description = Smooth moves the text by the exact distance a trackpad, touch or wheel travelled; Stepped jumps a whole line at a time.
+settings-scroll-mode-stepped = Stepped
+settings-scroll-mode-smooth = Smooth
settings-bottom-quote = Bottom Quote
settings-bottom-quote-description = Show a short quote at the bottom of the terminal window.
settings-quote-font-size = Quote Font Size
diff --git a/thinkterm-i18n/i18n/fr-FR.ftl b/thinkterm-i18n/i18n/fr-FR.ftl
index 8b976f0f..b0209b63 100644
--- a/thinkterm-i18n/i18n/fr-FR.ftl
+++ b/thinkterm-i18n/i18n/fr-FR.ftl
@@ -132,6 +132,10 @@ settings-remote-pane-resize-mode-description = En mode Auto, la taille est mise
settings-remote-pane-resize-mode-auto = Auto
settings-remote-pane-resize-mode-live = Direct
settings-remote-pane-resize-mode-on-release = Au relâchement
+settings-scroll-mode = Défilement
+settings-scroll-mode-description = Fluide déplace le texte exactement de la distance parcourue par le pavé tactile, le doigt ou la molette ; Par ligne saute une ligne entière à la fois.
+settings-scroll-mode-stepped = Par ligne
+settings-scroll-mode-smooth = Fluide
settings-bottom-quote = Citation inférieure
settings-bottom-quote-description = Affiche une courte citation en bas de la fenêtre du terminal.
settings-quote-font-size = Taille de la citation
diff --git a/thinkterm-i18n/i18n/ja-JP.ftl b/thinkterm-i18n/i18n/ja-JP.ftl
index 8ec7c0fe..be113cb4 100644
--- a/thinkterm-i18n/i18n/ja-JP.ftl
+++ b/thinkterm-i18n/i18n/ja-JP.ftl
@@ -129,6 +129,10 @@ settings-remote-pane-resize-mode-description = 自動では高速な接続で継
settings-remote-pane-resize-mode-auto = 自動
settings-remote-pane-resize-mode-live = ライブ
settings-remote-pane-resize-mode-on-release = 離したとき
+settings-scroll-mode = スクロール方式
+settings-scroll-mode-description = スムーズはトラックパッド・指・ホイールの移動量どおりにテキストを動かし、ステップは 1 行ずつ移動します。
+settings-scroll-mode-stepped = ステップ
+settings-scroll-mode-smooth = スムーズ
settings-bottom-quote = 下部の引用文
settings-bottom-quote-description = ターミナルウィンドウの下部に短い引用文を表示します。
settings-quote-font-size = 引用文のフォントサイズ
diff --git a/thinkterm-i18n/i18n/zh-CN.ftl b/thinkterm-i18n/i18n/zh-CN.ftl
index 2eb16dc1..c90f1222 100644
--- a/thinkterm-i18n/i18n/zh-CN.ftl
+++ b/thinkterm-i18n/i18n/zh-CN.ftl
@@ -129,6 +129,10 @@ settings-remote-pane-resize-mode-description = 自动模式在连接较快时持
settings-remote-pane-resize-mode-auto = 自动
settings-remote-pane-resize-mode-live = 实时
settings-remote-pane-resize-mode-on-release = 松手后
+settings-scroll-mode = 滚动方式
+settings-scroll-mode-description = 平滑:文本按触控板、手指或滚轮的实际位移移动;逐行:每次跳一整行。
+settings-scroll-mode-stepped = 逐行
+settings-scroll-mode-smooth = 平滑
settings-bottom-quote = 底部语录
settings-bottom-quote-description = 在终端窗口底部显示一条简短语录。
settings-quote-font-size = 语录字号
diff --git a/thinkterm-render/src/quad.rs b/thinkterm-render/src/quad.rs
index 48503719..aeeb86d6 100644
--- a/thinkterm-render/src/quad.rs
+++ b/thinkterm-render/src/quad.rs
@@ -763,6 +763,30 @@ impl HeapQuadAllocator {
Ok(())
}
+ /// `apply_to`, with every quad shifted by `offset` on the way out and
+ /// nothing else touched: no cropping, no texture arithmetic, no
+ /// allocation. The replay for rows that are wholly inside their pane
+ /// while the pane is scrolled by a fraction of a row; the two rows at
+ /// the edges go through `apply_to_clipped_at` instead.
+ pub fn apply_to_at(
+ &self,
+ other: &mut dyn TripleLayerQuadAllocatorTrait,
+ offset_x: f32,
+ offset_y: f32,
+ ) -> anyhow::Result<()> {
+ for (layer_num, quads) in self.layers() {
+ for quad in quads {
+ let mut vertices = quad.to_vertices();
+ for vertex in vertices.iter_mut() {
+ vertex.position[0] += offset_x;
+ vertex.position[1] += offset_y;
+ }
+ other.extend_with(layer_num, &vertices);
+ }
+ }
+ Ok(())
+ }
+
/// Copy every recorded quad into `other`, cropped to `clip` and scaled to
/// `opacity`.
/// Flatten the recorded quads into a plain vertex stream: sub-layer 0,
diff --git a/wezterm-gui/src/native_settings.rs b/wezterm-gui/src/native_settings.rs
index 30ae2b1d..fa17d515 100644
--- a/wezterm-gui/src/native_settings.rs
+++ b/wezterm-gui/src/native_settings.rs
@@ -175,6 +175,30 @@ impl NativeRemotePaneResizeMode {
}
}
+/// How the terminal scrolls its scrollback under a wheel, trackpad or
+/// finger: a whole row at a time, or by the exact distance travelled.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize, Serialize)]
+#[serde(rename_all = "snake_case")]
+pub(crate) enum NativeScrollMode {
+ Stepped,
+ Smooth,
+}
+
+impl Default for NativeScrollMode {
+ fn default() -> Self {
+ Self::Smooth
+ }
+}
+
+impl NativeScrollMode {
+ pub(crate) fn next(self) -> Self {
+ match self {
+ Self::Stepped => Self::Smooth,
+ Self::Smooth => Self::Stepped,
+ }
+ }
+}
+
impl Default for NativeBottomQuoteMode {
fn default() -> Self {
Self::Timed
@@ -206,6 +230,7 @@ pub(crate) struct NativeTerminalSettings {
pub(crate) font_size: Option<f64>,
pub(crate) font_family: Option<String>,
pub(crate) remote_pane_resize_mode: NativeRemotePaneResizeMode,
+ pub(crate) scroll_mode: NativeScrollMode,
pub(crate) bottom_quote_enabled: bool,
pub(crate) bottom_quote_mode: NativeBottomQuoteMode,
pub(crate) bottom_quote_interval_minutes: Option<u32>,
@@ -219,6 +244,12 @@ pub(crate) fn remote_pane_resize_mode() -> NativeRemotePaneResizeMode {
load().terminal.remote_pane_resize_mode
}
+/// Read on every wheel event, so through the shared handle rather than
+/// `load`, which deep-clones the whole settings tree.
+pub(crate) fn scroll_mode() -> NativeScrollMode {
+ load_shared().terminal.scroll_mode
+}
+
/// The shell the user picked, if any. Read on every local spawn, so it
/// goes through the cached handle rather than `load`, which deep-clones
/// the whole settings tree.
diff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rs
index 06bf4090..2f173070 100644
--- a/wezterm-gui/src/settings_window.rs
+++ b/wezterm-gui/src/settings_window.rs
@@ -754,6 +754,14 @@ fn localized_remote_pane_resize_mode_label(mode: NativeRemotePaneResizeMode) ->
})
}
+fn localized_scroll_mode_label(mode: crate::native_settings::NativeScrollMode) -> String {
+ use crate::native_settings::NativeScrollMode;
+ crate::i18n::tr(match mode {
+ NativeScrollMode::Stepped => "settings-scroll-mode-stepped",
+ NativeScrollMode::Smooth => "settings-scroll-mode-smooth",
+ })
+}
+
fn settings_tr(id: &'static str, values: &[(&'static str, String)]) -> String {
let mut args = FluentArgs::new();
for (name, value) in values {
@@ -859,6 +867,7 @@ enum SettingsAction {
QuitApplication,
ToggleBottomQuote,
CycleRemotePaneResizeMode,
+ CycleScrollMode,
CycleBottomQuoteMode,
DecreaseBottomQuoteFontSize,
IncreaseBottomQuoteFontSize,
@@ -3994,6 +4003,33 @@ impl SettingsWindow {
};
self.save_and_apply_bottom_quote_settings(status);
}
+ SettingsAction::CycleScrollMode => {
+ self.ui.open_dropdown = None;
+ self.native_settings.terminal.scroll_mode =
+ self.native_settings.terminal.scroll_mode.next();
+ match crate::native_settings::save(&self.native_settings) {
+ Ok(()) => {
+ self.status = settings_tr(
+ "settings-status-value-now",
+ &[
+ ("setting", crate::i18n::tr("settings-scroll-mode")),
+ (
+ "value",
+ localized_scroll_mode_label(
+ self.native_settings.terminal.scroll_mode,
+ ),
+ ),
+ ],
+ );
+ }
+ Err(err) => {
+ self.status = settings_tr(
+ "settings-status-terminal-error",
+ &[("error", format!("{err:#}"))],
+ );
+ }
+ }
+ }
SettingsAction::CycleRemotePaneResizeMode => {
self.ui.open_dropdown = None;
self.native_settings.terminal.remote_pane_resize_mode =
@@ -6929,11 +6965,11 @@ impl SettingsWindow {
let row_step = self.settings_row_step();
let section_y = self.ui_px(CONTENT_SECTION_Y) - scroll;
// Each settings card owns its row count because rows are painted manually.
- // Terminal currently paints nine rows below; the count drives card height and scroll extent.
+ // Terminal currently paints ten rows below; the count drives card height and scroll extent.
// What must stay in sync with paint_open_dropdown_overlay is not this
// number but each row's `row_step * N` multiplier, which that function
// copies by hand to place an open menu.
- let row_count = 9;
+ let row_count = 10;
let (card_y, first_row_y) = self.settings_card_geometry(section_y, row_count);
let card_height = self.settings_card_height(row_count);
let button_y = card_y + card_height + self.settings_section_card_gap();
@@ -7022,11 +7058,22 @@ impl SettingsWindow {
SettingsAction::CycleRemotePaneResizeMode,
true,
)?;
- self.paint_toggle_setting_row(
+ self.paint_action_setting_row(
layers,
row_x,
first_row_y + row_step * 5.0,
row_width,
+ &crate::i18n::tr("settings-scroll-mode"),
+ &crate::i18n::tr("settings-scroll-mode-description"),
+ &localized_scroll_mode_label(self.native_settings.terminal.scroll_mode),
+ SettingsAction::CycleScrollMode,
+ true,
+ )?;
+ self.paint_toggle_setting_row(
+ layers,
+ row_x,
+ first_row_y + row_step * 6.0,
+ row_width,
&crate::i18n::tr("settings-bottom-quote"),
&crate::i18n::tr("settings-bottom-quote-description"),
self.native_settings.terminal.bottom_quote_enabled,
@@ -7036,7 +7083,7 @@ impl SettingsWindow {
self.paint_font_size_stepper_row(
layers,
row_x,
- first_row_y + row_step * 6.0,
+ first_row_y + row_step * 7.0,
row_width,
&crate::i18n::tr("settings-quote-font-size"),
&crate::i18n::tr("settings-quote-font-size-description"),
@@ -7050,7 +7097,7 @@ impl SettingsWindow {
self.paint_action_setting_row(
layers,
row_x,
- first_row_y + row_step * 7.0,
+ first_row_y + row_step * 8.0,
row_width,
&crate::i18n::tr("settings-quote-rotation"),
&crate::i18n::tr("settings-quote-rotation-description"),
@@ -7061,7 +7108,7 @@ impl SettingsWindow {
self.paint_font_size_stepper_row(
layers,
row_x,
- first_row_y + row_step * 8.0,
+ first_row_y + row_step * 9.0,
row_width,
&crate::i18n::tr("settings-quote-interval"),
&crate::i18n::tr("settings-quote-interval-description"),
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index c88a594f..92b9d4b4 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -1734,6 +1734,18 @@ pub struct PaneState {
/// Otherwise, the viewport is at the bottom of the
/// scrollback.
viewport: Option<StableRowIndex>,
+ /// Smooth scrolling: how far, in physical pixels, the row `viewport`
+ /// is cut off at its top. Always in `[0, cell height)` and always 0
+ /// while following the bottom; every row-granular caller of
+ /// `set_viewport` leaves it 0.
+ viewport_px: f32,
+ /// Smooth scrolling: distance, in physical pixels, that a wheel notch
+ /// still has to travel. Consumed a fraction per frame by
+ /// `advance_scroll_glide`; positive is down, towards newer rows.
+ glide_remaining: f32,
+ /// When the glide last advanced, so a frame that comes late moves the
+ /// viewport by the time that actually passed.
+ glide_last_tick: Option<Instant>,
selection: Selection,
/// If is_some(), rather than display the actual tab
/// contents, we're overlaying a little internal application
@@ -2288,6 +2300,10 @@ pub struct TermWindow {
/// picture from a dedicated texture; the pane renderer then keeps that
/// line out of the line quad cache, whose replay would lose the picture.
dedicated_image_in_line: std::cell::Cell<bool>,
+ /// Smooth scrolling: the vertical shift the line replay applies while
+ /// a pane is scrolled by a fraction of a row, for painters that bypass
+ /// the line layers (dedicated image composites). 0 outside the loop.
+ line_render_y_offset: std::cell::Cell<f32>,
/// The (layer, cell) whose latest picture went to a dedicated texture,
/// so pictures stacked above it in the same cell follow it there and
/// keep their z-order; reset at the start of every line.
@@ -3707,6 +3723,7 @@ impl TermWindow {
card_composites: RefCell::new(Vec::new()),
image_composites: RefCell::new(Default::default()),
dedicated_image_in_line: std::cell::Cell::new(false),
+ line_render_y_offset: std::cell::Cell::new(0.0),
dedicated_image_cell: std::cell::Cell::new(None),
content_view_last_composites: RefCell::new(Vec::new()),
card_scratch: RefCell::new(None),
@@ -8470,11 +8487,38 @@ impl TermWindow {
}
fn scroll_by_current_event_wheel_delta(&mut self, pane: &Arc<dyn Pane>) -> anyhow::Result<()> {
- if let Some(event) = &self.current_mouse_event {
- let amount = match event.kind {
- MouseEventKind::VertWheel(amount) => -amount,
- _ => return Ok(()),
- };
+ let Some(event) = self.current_mouse_event.clone() else {
+ return Ok(());
+ };
+ let amount = match event.kind {
+ MouseEventKind::VertWheel(amount) => -amount,
+ _ => return Ok(()),
+ };
+ if crate::native_settings::scroll_mode() == crate::native_settings::NativeScrollMode::Smooth
+ {
+ // A device that reports pixels (a trackpad on macOS or Wayland,
+ // a precision touchpad on Windows) moves the viewport by exactly
+ // those pixels; a notched wheel glides the same distance over a
+ // few frames instead of jumping.
+ let cell_h = self.pane_cell_height(pane.pane_id());
+ if let Some(delta) = event.precise_scroll_delta {
+ if delta.y != 0.0 {
+ self.scroll_by_pixels(-delta.y, pane)?;
+ }
+ return Ok(());
+ }
+ if let Some(lines) = event.precise_wheel_lines {
+ if lines != 0.0 {
+ self.scroll_by_pixels(-lines * cell_h, pane)?;
+ }
+ return Ok(());
+ }
+ if amount != 0 {
+ self.start_scroll_glide(amount as f32 * cell_h, pane);
+ }
+ return Ok(());
+ }
+ if amount != 0 {
self.scroll_by_line(amount.into(), pane)?;
}
Ok(())
@@ -8493,6 +8537,121 @@ impl TermWindow {
Ok(())
}
+ /// The height of one cell of `pane_id` in physical pixels, honouring a
+ /// per-pane font scale.
+ pub(crate) fn pane_cell_height(&self, pane_id: PaneId) -> f32 {
+ let global = self.render_metrics.cell_size.height as f32;
+ let scale = self.pane_font_scale(pane_id);
+ if scale.to_bits() == self.fonts.get_font_scale().to_bits() {
+ return global.max(1.0);
+ }
+ self.pane_font_resources(scale)
+ .map(|(_, metrics)| metrics.cell_size.height as f32)
+ .unwrap_or(global)
+ .max(1.0)
+ }
+
+ /// Move the viewport by `delta_px` physical pixels (positive is down,
+ /// towards newer rows), carrying whole rows into `viewport` and keeping
+ /// the remainder in `viewport_px`.
+ fn scroll_by_pixels(&mut self, delta_px: f32, pane: &Arc<dyn Pane>) -> anyhow::Result<()> {
+ let dims = pane.get_dimensions();
+ let pane_id = pane.pane_id();
+ let cell_h = self.pane_cell_height(pane_id);
+ let (row, px) = {
+ let state = self.pane_state(pane_id);
+ (
+ state.viewport.unwrap_or(dims.physical_top),
+ state.viewport_px,
+ )
+ };
+ let (row, px) = Self::normalize_scroll_px(row, px, delta_px, cell_h);
+ self.set_viewport_px(pane_id, Some(row), px, dims);
+ if let Some(win) = self.window.as_ref() {
+ win.invalidate();
+ }
+ Ok(())
+ }
+
+ /// Queue `distance_px` of scrolling to be spread over the next frames.
+ fn start_scroll_glide(&mut self, distance_px: f32, pane: &Arc<dyn Pane>) {
+ {
+ let mut state = self.pane_state(pane.pane_id());
+ state.glide_remaining += distance_px;
+ state.glide_last_tick = Some(Instant::now());
+ }
+ // The first step lands at once, so a single notch is felt without
+ // waiting a frame; the rest follows from paint.
+ self.advance_scroll_glide(pane);
+ }
+
+ /// Pay out a slice of a pending glide, sized by the time since the last
+ /// slice, and ask for another frame while distance remains. Called once
+ /// per painted frame for each pane; free when nothing is gliding.
+ pub(crate) fn advance_scroll_glide(&mut self, pane: &Arc<dyn Pane>) {
+ const RATE: f32 = 22.0;
+ const SETTLED_PX: f32 = 0.5;
+ let pane_id = pane.pane_id();
+ let (remaining, last) = {
+ let state = self.pane_state(pane_id);
+ (state.glide_remaining, state.glide_last_tick)
+ };
+ if remaining == 0.0 {
+ return;
+ }
+ let now = Instant::now();
+ let dt = last
+ .map(|last| now.saturating_duration_since(last).as_secs_f32())
+ .unwrap_or(1.0 / 120.0)
+ .clamp(1.0 / 240.0, 1.0 / 30.0);
+ let step = if remaining.abs() <= SETTLED_PX {
+ remaining
+ } else {
+ remaining * (1.0 - (-RATE * dt).exp())
+ };
+ {
+ let mut state = self.pane_state(pane_id);
+ state.glide_remaining -= step;
+ state.glide_last_tick = Some(now);
+ if state.glide_remaining.abs() <= SETTLED_PX {
+ state.glide_remaining = 0.0;
+ state.glide_last_tick = None;
+ }
+ }
+ if let Err(err) = self.scroll_by_pixels(step, pane) {
+ log::warn!("scroll glide: {err:#}");
+ }
+ if self.pane_state(pane_id).glide_remaining != 0.0 {
+ self.update_next_frame_time(Some(now + Duration::from_millis(8)));
+ }
+ }
+
+ /// Carry `delta_px` into `(row, px)`: whole cells move the row, the
+ /// remainder stays in `[0, cell_h)`. `floor` rather than `trunc`, so
+ /// scrolling up through a row boundary is the mirror of scrolling down.
+ pub(crate) fn normalize_scroll_px(
+ row: StableRowIndex,
+ px: f32,
+ delta_px: f32,
+ cell_h: f32,
+ ) -> (StableRowIndex, f32) {
+ if !(cell_h > 0.0) {
+ return (row, 0.0);
+ }
+ let total = px + delta_px;
+ let rows = (total / cell_h).floor();
+ let mut px = total - rows * cell_h;
+ let mut rows = rows as isize;
+ // Float drift at a boundary must not leave px at cell_h.
+ if px >= cell_h {
+ px = 0.0;
+ rows += 1;
+ } else if px < 0.0 {
+ px = 0.0;
+ }
+ (row.saturating_add(rows), px)
+ }
+
fn move_tab_relative(&mut self, delta: isize) -> anyhow::Result<()> {
let mux = Mux::get();
let window = mux
@@ -9811,11 +9970,34 @@ impl TermWindow {
}
}
+ /// Row-granular viewport change: every caller that thinks in rows
+ /// (keys, prompt jumps, the copy overlay, stale-viewport fixes) lands on
+ /// a whole row, so any smooth-scroll remainder is dropped.
pub fn set_viewport(
&mut self,
pane_id: PaneId,
position: Option<StableRowIndex>,
dims: RenderableDimensions,
+ ) {
+ self.set_viewport_px(pane_id, position, 0.0, dims)
+ }
+
+ /// The pixel remainder of a smooth scroll for `pane_id`; 0 unless the
+ /// viewport sits between two rows.
+ pub fn get_viewport_px(&self, pane_id: PaneId) -> f32 {
+ self.pane_state(pane_id).viewport_px
+ }
+
+ /// The one place the viewport is written. `px` is how far `position`
+ /// is cut off at its top; it only survives when `position` was taken
+ /// as given -- a clamp at either end of the scrollback, or following
+ /// the bottom, always lands on a whole row.
+ pub fn set_viewport_px(
+ &mut self,
+ pane_id: PaneId,
+ position: Option<StableRowIndex>,
+ px: f32,
+ dims: RenderableDimensions,
) {
let pos = match position {
Some(pos) => {
@@ -9828,8 +10010,21 @@ impl TermWindow {
}
None => None,
};
+ let px = if pos.is_some() && pos == position && px.is_finite() {
+ px.max(0.0)
+ } else {
+ 0.0
+ };
let mut state = self.pane_state(pane_id);
+ if px != state.viewport_px {
+ state.viewport_px = px;
+ }
+ if pos.is_none() || pos != position {
+ // Nothing left to glide towards past the end.
+ state.glide_remaining = 0.0;
+ state.glide_last_tick = None;
+ }
if pos != state.viewport {
state.viewport = pos;
@@ -9858,7 +10053,11 @@ impl TermWindow {
}
fn scroll_to_bottom(&mut self, pane: &Arc<dyn Pane>) {
- self.pane_state(pane.pane_id()).viewport = None;
+ let mut state = self.pane_state(pane.pane_id());
+ state.viewport = None;
+ state.viewport_px = 0.0;
+ state.glide_remaining = 0.0;
+ state.glide_last_tick = None;
}
fn get_active_pane_no_overlay(&self) -> Option<Arc<dyn Pane>> {
@@ -10249,3 +10448,35 @@ mod occlusion_release_tests {
assert!(!occlusion_release_due(Some(past_grace()), true));
}
}
+
+#[cfg(test)]
+mod scroll_px_tests {
+ use super::TermWindow;
+
+ const CELL: f32 = 20.0;
+
+ #[test]
+ fn whole_cells_move_the_row_and_the_remainder_stays_in_range() {
+ assert_eq!(TermWindow::normalize_scroll_px(10, 0.0, 45.0, CELL), (12, 5.0));
+ assert_eq!(TermWindow::normalize_scroll_px(10, 5.0, 15.0, CELL), (11, 0.0));
+ assert_eq!(TermWindow::normalize_scroll_px(10, 5.0, 40.0, CELL), (12, 5.0));
+ let (_, px) = TermWindow::normalize_scroll_px(10, 19.9, 0.2, CELL);
+ assert!(px >= 0.0 && px < CELL, "px={px}");
+ }
+
+ #[test]
+ fn scrolling_up_mirrors_scrolling_down() {
+ // Five pixels into row 10, then twelve pixels up: seven pixels
+ // short of row 10's top, i.e. thirteen pixels into row 9.
+ assert_eq!(TermWindow::normalize_scroll_px(10, 5.0, -12.0, CELL), (9, 13.0));
+ // Back down by the same amount lands where it started.
+ assert_eq!(TermWindow::normalize_scroll_px(9, 13.0, 12.0, CELL), (10, 5.0));
+ // Exactly one row up from a row boundary is the previous boundary.
+ assert_eq!(TermWindow::normalize_scroll_px(10, 0.0, -20.0, CELL), (9, 0.0));
+ }
+
+ #[test]
+ fn a_zero_cell_height_never_produces_a_remainder() {
+ assert_eq!(TermWindow::normalize_scroll_px(10, 3.0, 50.0, 0.0), (10, 0.0));
+ }
+}
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs
index b271885a..17d8ee97 100644
--- a/wezterm-gui/src/termwindow/mouseevent.rs
+++ b/wezterm-gui/src/termwindow/mouseevent.rs
@@ -1742,7 +1742,10 @@ impl super::TermWindow {
let pane_nav_height = self.pane_nav_bar_height() as isize;
let local_x = event.coords.x.sub(pane_left);
- let local_y = event.coords.y.sub(pane_top + pane_nav_height);
+ // A smooth scroll draws the top row cut off by `viewport_px`, so
+ // the row under the pointer is that much further down the grid.
+ let scroll_px = self.get_viewport_px(pane.pane_id()).round() as isize;
+ let local_y = event.coords.y.sub(pane_top + pane_nav_height) + scroll_px;
let x = (local_x.max(0) as f32) / pane_cell_size.width.max(1) as f32;
let column = if !pane.is_mouse_grabbed() {
@@ -8503,6 +8506,20 @@ impl super::TermWindow {
}
}
WMEK::VertWheel(amount) => Some(match *amount {
+ // Less than a line of travel, but the device said how much:
+ // smooth scrolling moves the grid by exactly that, so the
+ // wheel binding still has to fire. An application that
+ // reports the mouse gets whole notches only, as before.
+ 0 if !pane.is_mouse_grabbed() && sub_line_wheel_direction(&event) != 0 => {
+ MouseEventTrigger::Down {
+ streak: 1,
+ button: if sub_line_wheel_direction(&event) > 0 {
+ MouseButton::WheelUp(1)
+ } else {
+ MouseButton::WheelDown(1)
+ },
+ }
+ }
0 => return,
1.. => MouseEventTrigger::Down {
streak: 1,
@@ -9182,3 +9199,19 @@ mod adaptive_tab_width_tests {
);
}
}
+
+/// Which way a wheel event that travelled less than a whole line was
+/// going, from the finer data the device supplied: positive is up (towards
+/// older rows), 0 when there is no such data.
+fn sub_line_wheel_direction(event: &::window::MouseEvent) -> i8 {
+ let travel = event
+ .precise_scroll_delta
+ .map(|delta| delta.y)
+ .filter(|y| *y != 0.0)
+ .or(event.precise_wheel_lines.filter(|lines| *lines != 0.0));
+ match travel {
+ Some(value) if value > 0.0 => 1,
+ Some(_) => -1,
+ None => 0,
+ }
+}
diff --git a/wezterm-gui/src/termwindow/render/mod.rs b/wezterm-gui/src/termwindow/render/mod.rs
index a18c2e68..d0b26b0e 100644
--- a/wezterm-gui/src/termwindow/render/mod.rs
+++ b/wezterm-gui/src/termwindow/render/mod.rs
@@ -752,7 +752,11 @@ impl crate::TermWindow {
let mut quad = Quad { vert: &mut vert };
let cell_width = params.render_metrics.cell_size.width as f32;
let cell_height = params.render_metrics.cell_size.height as f32;
- let pos_y = (self.dimensions.pixel_height as f32 / -2.) + params.top_pixel_y;
+ // Composites bypass the line's quad layers, so the smooth-scroll
+ // shift the replay applies to those has to be applied here by hand.
+ let pos_y = (self.dimensions.pixel_height as f32 / -2.)
+ + params.top_pixel_y
+ + self.line_render_y_offset.get();
let pos_x = (self.dimensions.pixel_width as f32 / -2.)
+ params.left_pixel_x
+ (cell_idx as f32 * cell_width);
diff --git a/wezterm-gui/src/termwindow/render/pane.rs b/wezterm-gui/src/termwindow/render/pane.rs
index 70e316a2..fb2dd84d 100644
--- a/wezterm-gui/src/termwindow/render/pane.rs
+++ b/wezterm-gui/src/termwindow/render/pane.rs
@@ -1288,6 +1288,9 @@ impl crate::TermWindow {
}
let pane_id = pos.pane.pane_id();
+ // A wheel notch in smooth mode is paid out over frames; this frame's
+ // slice moves the viewport before it is read below.
+ self.advance_scroll_glide(&pos.pane);
let current_viewport = self.get_viewport(pane_id);
let dims = pos.pane.get_dimensions();
let global_render_metrics = self.render_metrics;
@@ -1570,18 +1573,55 @@ impl crate::TermWindow {
palette.cursor_fg == global_cursor_fg && palette.cursor_bg == global_cursor_bg;
{
+ // A smooth scroll cuts the top row off by `scroll_px`, which
+ // uncovers that much of one more row at the bottom; it is drawn
+ // too, and the two edge rows are cropped to the pane. The clamp
+ // in set_viewport_px keeps the extra row inside the terminal.
+ let scroll_px = match current_viewport {
+ Some(_) => self.get_viewport_px(pane_id),
+ None => 0.0,
+ };
+ let extra_row = if scroll_px > 0.0 { 1 } else { 0 };
let stable_range = match current_viewport {
- Some(top) => top..top + render_dims.viewport_rows as StableRowIndex,
+ Some(top) => top..top + (render_dims.viewport_rows + extra_row) as StableRowIndex,
None => {
dims.physical_top
..dims.physical_top + render_dims.viewport_rows as StableRowIndex
}
};
+ let row_count = (stable_range.end - stable_range.start).max(0) as usize;
pos.pane
.apply_hyperlinks(stable_range.clone(), &self.config.hyperlink_rules);
+ /// Copy one line's recorded quads into the frame, shifted up by
+ /// the smooth-scroll remainder. Only the rows at the pane's top
+ /// and bottom can poke out of it, so only those pay for
+ /// cropping; the rest are moved as they are. With no remainder
+ /// this is the plain replay it always was.
+ fn replay_line(
+ layers: &mut dyn TripleLayerQuadAllocatorTrait,
+ heap: &HeapQuadAllocator,
+ scroll_px: f32,
+ pane_clip: QuadClipRect,
+ line_idx: usize,
+ row_count: usize,
+ ) -> anyhow::Result<()> {
+ if scroll_px == 0.0 {
+ return heap.apply_to(layers);
+ }
+ let edge = line_idx == 0 || line_idx + 1 >= row_count;
+ if edge {
+ heap.apply_to_clipped_at(layers, 0.0, -scroll_px, pane_clip, 1.0)
+ } else {
+ heap.apply_to_at(layers, 0.0, -scroll_px)
+ }
+ }
+
struct LineRender<'a, 'b> {
+ scroll_px: f32,
+ pane_clip: QuadClipRect,
+ row_count: usize,
term_window: &'a mut crate::TermWindow,
selrange: Option<SelectionRange>,
rectangular: bool,
@@ -1621,12 +1661,27 @@ impl crate::TermWindow {
stable_range.start,
&render_dims,
left_pixel_x,
- pane_top_pixel_y,
+ // The rows are drawn shifted up by the smooth-scroll
+ // remainder; the IME popup follows the drawn cursor.
+ pane_top_pixel_y - scroll_px,
pane_render_metrics.cell_size,
);
}
+ let pane_clip = QuadClipRect::from_top_left_pixels(
+ left_pixel_x,
+ pane_top_pixel_y,
+ left_pixel_x
+ + render_dims.cols as f32 * pane_render_metrics.cell_size.width as f32,
+ pane_top_pixel_y
+ + render_dims.viewport_rows as f32
+ * pane_render_metrics.cell_size.height as f32,
+ &self.dimensions,
+ );
let mut render = LineRender {
+ scroll_px,
+ pane_clip,
+ row_count,
term_window: self,
selrange,
rectangular,
@@ -1751,10 +1806,15 @@ impl crate::TermWindow {
false
};
if !expired && !hover_changed {
- cached_quad
- .layers
- .apply_to(self.layers)
- .context("cached_quad.layers.apply_to")?;
+ replay_line(
+ self.layers,
+ &cached_quad.layers,
+ self.scroll_px,
+ self.pane_clip,
+ line_idx,
+ self.row_count,
+ )
+ .context("cached_quad.layers.apply_to")?;
self.term_window.update_next_frame_time(cached_quad.expires);
return Ok(());
}
@@ -1830,8 +1890,15 @@ impl crate::TermWindow {
let expires = self.term_window.has_animation.borrow().as_ref().cloned();
self.term_window.update_next_frame_time(next_due);
- buf.apply_to(self.layers)
- .context("HeapQuadAllocator::apply_to")?;
+ replay_line(
+ self.layers,
+ &buf,
+ self.scroll_px,
+ self.pane_clip,
+ line_idx,
+ self.row_count,
+ )
+ .context("HeapQuadAllocator::apply_to")?;
let quad_value = LineQuadCacheValue {
layers: buf,
@@ -1877,7 +1944,11 @@ impl crate::TermWindow {
.term_window
.track_pane_output_generations_for_frame
.then(|| mux::Mux::get().pane_output_generation(pane_id));
+ // Painters that bypass the line layers (dedicated image
+ // composites) read the same shift from here for the duration.
+ render.term_window.line_render_y_offset.set(-scroll_px);
pos.pane.with_lines_mut(stable_range.clone(), &mut render);
+ render.term_window.line_render_y_offset.set(0.0);
if let Some(error) = render.error.take() {
return Err(error).context("error while calling with_lines_mut");
}
diff --git a/wezterm-input-types/src/lib.rs b/wezterm-input-types/src/lib.rs
index 9c629252..0f712a57 100644
--- a/wezterm-input-types/src/lib.rs
+++ b/wezterm-input-types/src/lib.rs
@@ -1303,6 +1303,11 @@ pub struct MouseEvent {
pub scroll_phase: Option<ScrollPhase>,
/// Native momentum scroll phase when available.
pub momentum_phase: Option<ScrollPhase>,
+ /// Wheel travel in lines with the fraction kept, for devices that
+ /// report finer steps than a line (a precision touchpad on Windows)
+ /// without a pixel-precise delta. Same sign as `VertWheel`. Only the
+ /// terminal grid reads it; chrome keeps using the integer kind.
+ pub precise_wheel_lines: Option<f32>,
}
#[derive(Debug, Clone)]
diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs
index a7effd9a..8bcb9410 100644
--- a/window/src/os/macos/window.rs
+++ b/window/src/os/macos/window.rs
@@ -3783,6 +3783,7 @@ impl WindowView {
precise_scroll_delta,
scroll_phase,
momentum_phase,
+ precise_wheel_lines: None,
};
if let Some(myself) = Self::get_this(this) {
diff --git a/window/src/os/wayland/window.rs b/window/src/os/wayland/window.rs
index df34ca78..f5a3cdaa 100644
--- a/window/src/os/wayland/window.rs
+++ b/window/src/os/wayland/window.rs
@@ -978,6 +978,7 @@ impl WaylandWindowInner {
precise_scroll_delta: None,
scroll_phase: None,
momentum_phase: None,
+ precise_wheel_lines: None,
};
self.events.dispatch(WindowEvent::MouseEvent(event));
}
@@ -1029,6 +1030,7 @@ impl WaylandWindowInner {
precise_scroll_delta: None,
scroll_phase: None,
momentum_phase: None,
+ precise_wheel_lines: None,
};
self.events.dispatch(WindowEvent::MouseEvent(event));
}
@@ -1059,6 +1061,7 @@ impl WaylandWindowInner {
}),
scroll_phase: None,
momentum_phase: None,
+ precise_wheel_lines: None,
};
self.events.dispatch(WindowEvent::MouseEvent(event));
}
@@ -1085,6 +1088,7 @@ impl WaylandWindowInner {
}),
scroll_phase: None,
momentum_phase: None,
+ precise_wheel_lines: None,
};
self.events.dispatch(WindowEvent::MouseEvent(event));
}
diff --git a/window/src/os/windows/window.rs b/window/src/os/windows/window.rs
index 0207811c..d057b888 100644
--- a/window/src/os/windows/window.rs
+++ b/window/src/os/windows/window.rs
@@ -2556,6 +2556,7 @@ unsafe fn mouse_button(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) ->
precise_scroll_delta: None,
scroll_phase: None,
momentum_phase: None,
+ precise_wheel_lines: None,
};
inner
.borrow_mut()
@@ -2609,6 +2610,7 @@ unsafe fn nc_mouse_button(
precise_scroll_delta: None,
scroll_phase: None,
momentum_phase: None,
+ precise_wheel_lines: None,
};
inner
.borrow_mut()
@@ -2645,6 +2647,7 @@ unsafe fn mouse_move(hwnd: HWND, _msg: UINT, wparam: WPARAM, lparam: LPARAM) ->
precise_scroll_delta: None,
scroll_phase: None,
momentum_phase: None,
+ precise_wheel_lines: None,
};
inner.events.dispatch(WindowEvent::MouseEvent(event));
@@ -2684,6 +2687,7 @@ unsafe fn nc_mouse_move(hwnd: HWND, _msg: UINT, wparam: WPARAM, lparam: LPARAM)
precise_scroll_delta: None,
scroll_phase: None,
momentum_phase: None,
+ precise_wheel_lines: None,
};
inner.events.dispatch(WindowEvent::MouseEvent(event));
@@ -2767,7 +2771,11 @@ unsafe fn mouse_wheel(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) ->
inner.vscroll_remainder,
position
);
- if position == 0 {
+ // A precision touchpad sends many deltas smaller than a line.
+ // They still go out, as VertWheel(0) with the fractional travel
+ // beside it, so a surface that scrolls by pixels can follow
+ // them; everything else treats VertWheel(0) as nothing.
+ if position == 0 && delta == 0 {
return Some(0);
}
MouseEventKind::VertWheel(position)
@@ -2779,6 +2787,13 @@ unsafe fn mouse_wheel(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) ->
precise_scroll_delta: None,
scroll_phase: None,
momentum_phase: None,
+ // The travel in lines before it was rounded to notches, so a
+ // sub-line step is not lost; horizontal wheels keep the old path.
+ precise_wheel_lines: if msg == WM_MOUSEWHEEL {
+ Some(scaled_delta as f32 / WHEEL_DELTA as f32)
+ } else {
+ None
+ },
};
inner
.borrow_mut()
diff --git a/window/src/os/x11/window.rs b/window/src/os/x11/window.rs
index b654e135..e6740525 100644
--- a/window/src/os/x11/window.rs
+++ b/window/src/os/x11/window.rs
@@ -753,6 +753,7 @@ impl XWindowInner {
precise_scroll_delta: None,
scroll_phase: None,
momentum_phase: None,
+ precise_wheel_lines: None,
};
self.do_mouse_event(event)
}
@@ -1060,6 +1061,7 @@ impl XWindowInner {
precise_scroll_delta: None,
scroll_phase: None,
momentum_phase: None,
+ precise_wheel_lines: None,
};
self.do_mouse_event(event)?;
}