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: an auto-hiding overlay scrollbar on every pane

RoversX96f828d952e4
diff --git a/thinkterm-i18n/i18n/de-DE.ftl b/thinkterm-i18n/i18n/de-DE.ftl
index 234f9642..444edc8f 100644
--- a/thinkterm-i18n/i18n/de-DE.ftl
+++ b/thinkterm-i18n/i18n/de-DE.ftl
@@ -136,6 +136,8 @@ 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-overlay-scrollbar = Bildlaufleiste
+settings-overlay-scrollbar-description = Beim Scrollen erscheint am rechten Rand des Fensterbereichs eine schmale Bildlaufleiste, die danach ausblendet; sie lässt sich ziehen.
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 4134567e..a5cddd51 100644
--- a/thinkterm-i18n/i18n/en-US.ftl
+++ b/thinkterm-i18n/i18n/en-US.ftl
@@ -136,6 +136,8 @@ 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-overlay-scrollbar = Scrollbar
+settings-overlay-scrollbar-description = A thin scrollbar appears over the right edge of a pane while it scrolls and fades out afterwards; it can be dragged.
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 112738f9..a059e63c 100644
--- a/thinkterm-i18n/i18n/fr-FR.ftl
+++ b/thinkterm-i18n/i18n/fr-FR.ftl
@@ -136,6 +136,8 @@ 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-overlay-scrollbar = Barre de défilement
+settings-overlay-scrollbar-description = Une fine barre de défilement apparaît sur le bord droit du volet pendant le défilement puis disparaît en fondu ; elle peut être glissée.
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 06ef70ec..419934f8 100644
--- a/thinkterm-i18n/i18n/ja-JP.ftl
+++ b/thinkterm-i18n/i18n/ja-JP.ftl
@@ -133,6 +133,8 @@ settings-scroll-mode = スクロール方式
settings-scroll-mode-description = スムーズはトラックパッド・指・ホイールの移動量どおりにテキストを動かし、ステップは 1 行ずつ移動します。
settings-scroll-mode-stepped = ステップ
settings-scroll-mode-smooth = スムーズ
+settings-overlay-scrollbar = スクロールバー
+settings-overlay-scrollbar-description = スクロール中はペインの右端に細いスクロールバーが表示され、その後フェードアウトします。ドラッグもできます。
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 f088b69e..20e1c179 100644
--- a/thinkterm-i18n/i18n/zh-CN.ftl
+++ b/thinkterm-i18n/i18n/zh-CN.ftl
@@ -133,6 +133,8 @@ settings-scroll-mode = 滚动方式
settings-scroll-mode-description = 平滑:文本按触控板、手指或滚轮的实际位移移动;逐行:每次跳一整行。
settings-scroll-mode-stepped = 逐行
settings-scroll-mode-smooth = 平滑
+settings-overlay-scrollbar = 滚动条
+settings-overlay-scrollbar-description = 滚动时在面板右侧显示一条细滚动条,停止后自动淡出;可以拖动。
settings-bottom-quote = 底部语录
settings-bottom-quote-description = 在终端窗口底部显示一条简短语录。
settings-quote-font-size = 语录字号
diff --git a/wezterm-gui/src/native_settings.rs b/wezterm-gui/src/native_settings.rs
index fa17d515..34a11a56 100644
--- a/wezterm-gui/src/native_settings.rs
+++ b/wezterm-gui/src/native_settings.rs
@@ -224,9 +224,18 @@ pub(crate) struct NativeAppearanceSettings {
pub(crate) color_scheme: Option<String>,
}
-#[derive(Debug, Clone, Default, Deserialize, Serialize)]
+fn default_true() -> bool {
+ true
+}
+
+#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub(crate) struct NativeTerminalSettings {
+ /// The thin auto-hiding scrollbar drawn over each pane's right edge.
+ /// Off means no indicator at all; the Lua `enable_scroll_bar` gutter is
+ /// a separate, older thing and wins when it is on.
+ #[serde(default = "default_true")]
+ pub(crate) overlay_scrollbar: bool,
pub(crate) font_size: Option<f64>,
pub(crate) font_family: Option<String>,
pub(crate) remote_pane_resize_mode: NativeRemotePaneResizeMode,
@@ -240,6 +249,23 @@ pub(crate) struct NativeTerminalSettings {
pub(crate) default_shell: Option<Vec<String>>,
}
+impl Default for NativeTerminalSettings {
+ fn default() -> Self {
+ Self {
+ overlay_scrollbar: true,
+ font_size: None,
+ font_family: None,
+ remote_pane_resize_mode: NativeRemotePaneResizeMode::default(),
+ scroll_mode: NativeScrollMode::default(),
+ bottom_quote_enabled: false,
+ bottom_quote_mode: NativeBottomQuoteMode::default(),
+ bottom_quote_interval_minutes: None,
+ bottom_quote_font_size: None,
+ default_shell: None,
+ }
+ }
+}
+
pub(crate) fn remote_pane_resize_mode() -> NativeRemotePaneResizeMode {
load().terminal.remote_pane_resize_mode
}
@@ -250,6 +276,11 @@ pub(crate) fn scroll_mode() -> NativeScrollMode {
load_shared().terminal.scroll_mode
}
+/// Read once per painted pane, through the shared handle.
+pub(crate) fn overlay_scrollbar() -> bool {
+ load_shared().terminal.overlay_scrollbar
+}
+
/// 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/scrollbar.rs b/wezterm-gui/src/scrollbar.rs
index d742b1ae..d05b0ffa 100644
--- a/wezterm-gui/src/scrollbar.rs
+++ b/wezterm-gui/src/scrollbar.rs
@@ -16,13 +16,29 @@ impl ScrollHit {
viewport: Option<StableRowIndex>,
max_thumb_height: usize,
min_thumb_size: usize,
+ ) -> Self {
+ Self::thumb_px(pane, viewport, 0.0, max_thumb_height, min_thumb_size)
+ }
+
+ /// `thumb`, with the smooth-scroll remainder folded in: `viewport_frac`
+ /// is how far into the top row the view sits, as a fraction of a row
+ /// (`viewport_px / cell height`), so the thumb moves between the
+ /// positions two whole rows would give it.
+ pub fn thumb_px(
+ pane: &dyn Pane,
+ viewport: Option<StableRowIndex>,
+ viewport_frac: f32,
+ max_thumb_height: usize,
+ min_thumb_size: usize,
) -> Self {
let render_dims = pane.get_dimensions();
- let scroll_top = render_dims
+ let scroll_top = (render_dims
.physical_top
.saturating_sub(viewport.unwrap_or(render_dims.physical_top))
- as f32;
+ as f32
+ - viewport_frac.clamp(0.0, 1.0))
+ .max(0.0);
let scroll_size = render_dims.scrollback_rows as f32;
@@ -36,10 +52,14 @@ impl ScrollHit {
}
.ceil() as usize;
- let scroll_percent =
- 1.0 - (scroll_top / (render_dims.physical_top - render_dims.scrollback_top) as f32);
+ let travel = (render_dims.physical_top - render_dims.scrollback_top) as f32;
+ let scroll_percent = if travel > 0.0 {
+ (1.0 - scroll_top / travel).clamp(0.0, 1.0)
+ } else {
+ 1.0
+ };
let thumb_top =
- (scroll_percent * (max_thumb_height.saturating_sub(thumb_size)) as f32).ceil() as usize;
+ (scroll_percent * (max_thumb_height.saturating_sub(thumb_size)) as f32).round() as usize;
Self {
top: thumb_top,
diff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rs
index 2f173070..4ba33689 100644
--- a/wezterm-gui/src/settings_window.rs
+++ b/wezterm-gui/src/settings_window.rs
@@ -868,6 +868,7 @@ enum SettingsAction {
ToggleBottomQuote,
CycleRemotePaneResizeMode,
CycleScrollMode,
+ ToggleOverlayScrollbar,
CycleBottomQuoteMode,
DecreaseBottomQuoteFontSize,
IncreaseBottomQuoteFontSize,
@@ -4003,6 +4004,40 @@ impl SettingsWindow {
};
self.save_and_apply_bottom_quote_settings(status);
}
+ SettingsAction::ToggleOverlayScrollbar => {
+ self.ui.open_dropdown = None;
+ self.native_settings.terminal.overlay_scrollbar =
+ !self.native_settings.terminal.overlay_scrollbar;
+ match crate::native_settings::save(&self.native_settings) {
+ Ok(()) => {
+ if let Some(front_end) = crate::frontend::try_front_end() {
+ front_end.invalidate_all_windows();
+ }
+ self.status = settings_tr(
+ "settings-status-value-now",
+ &[
+ ("setting", crate::i18n::tr("settings-overlay-scrollbar")),
+ (
+ "value",
+ crate::i18n::tr(
+ if self.native_settings.terminal.overlay_scrollbar {
+ "common-on"
+ } else {
+ "common-off"
+ },
+ ),
+ ),
+ ],
+ );
+ }
+ Err(err) => {
+ self.status = settings_tr(
+ "settings-status-terminal-error",
+ &[("error", format!("{err:#}"))],
+ );
+ }
+ }
+ }
SettingsAction::CycleScrollMode => {
self.ui.open_dropdown = None;
self.native_settings.terminal.scroll_mode =
@@ -6965,11 +7000,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 ten rows below; the count drives card height and scroll extent.
+ // Terminal currently paints eleven 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 = 10;
+ let row_count = 11;
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();
@@ -7074,6 +7109,17 @@ impl SettingsWindow {
row_x,
first_row_y + row_step * 6.0,
row_width,
+ &crate::i18n::tr("settings-overlay-scrollbar"),
+ &crate::i18n::tr("settings-overlay-scrollbar-description"),
+ self.native_settings.terminal.overlay_scrollbar,
+ SettingsAction::ToggleOverlayScrollbar,
+ true,
+ )?;
+ self.paint_toggle_setting_row(
+ layers,
+ row_x,
+ first_row_y + row_step * 7.0,
+ row_width,
&crate::i18n::tr("settings-bottom-quote"),
&crate::i18n::tr("settings-bottom-quote-description"),
self.native_settings.terminal.bottom_quote_enabled,
@@ -7083,7 +7129,7 @@ impl SettingsWindow {
self.paint_font_size_stepper_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-font-size"),
&crate::i18n::tr("settings-quote-font-size-description"),
@@ -7097,7 +7143,7 @@ impl SettingsWindow {
self.paint_action_setting_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-rotation"),
&crate::i18n::tr("settings-quote-rotation-description"),
@@ -7108,7 +7154,7 @@ impl SettingsWindow {
self.paint_font_size_stepper_row(
layers,
row_x,
- first_row_y + row_step * 9.0,
+ first_row_y + row_step * 10.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 92b9d4b4..503cf863 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -384,6 +384,11 @@ fn line_to_ele_shape_cache_budget(config: &ConfigHandle) -> usize {
config.line_to_ele_shape_cache_size.saturating_mul(2 * 1024)
}
+/// How long a pane's overlay scrollbar stays up after the view last moved,
+/// and how much of that is spent fading out.
+pub(crate) const OVERLAY_SCROLLBAR_SHOW: Duration = Duration::from_millis(1200);
+pub(crate) const OVERLAY_SCROLLBAR_FADE: Duration = Duration::from_millis(250);
+
const ATLAS_SIZE: usize = 128;
/// Ceiling on growing the glyph atlas to fit a working set, in texels per side.
@@ -706,6 +711,18 @@ pub(crate) enum ContextMenuApplicationAction {
ResolveLocalCopyConflict(transfer_walk::ConflictChoice),
}
+/// The scrollbar track a thumb, or the space above or below it, belongs
+/// to: which pane it scrolls and where the track runs, so a drag can be
+/// turned back into a row without knowing which window layout drew it.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub struct ScrollTrack {
+ pub pane_id: PaneId,
+ /// Top of the track in window pixels, and its height: the range the
+ /// thumb's top moves through is `track_top .. track_top + track_height - thumb`.
+ pub track_top: usize,
+ pub track_height: usize,
+}
+
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum UIItemType {
TabBar(TabBarItem),
@@ -819,9 +836,9 @@ pub enum UIItemType {
/// Backdrop of the command palette; the palette routes its own pointer
/// events, this item only keeps clicks from reading as terminal surface.
CommandPalette,
- AboveScrollThumb,
- ScrollThumb,
- BelowScrollThumb,
+ AboveScrollThumb(ScrollTrack),
+ ScrollThumb(ScrollTrack),
+ BelowScrollThumb(ScrollTrack),
Split(PositionedSplit),
/// Close button on the synthetic content-view tab.
ContentViewClose(ContentViewId),
@@ -1746,6 +1763,10 @@ pub struct PaneState {
/// 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>,
+ /// Overlay scrollbar: until when the pane's indicator stays up. Set
+ /// whenever the viewport moves, or the thumb is hovered or dragged;
+ /// the last stretch before it is spent fading out.
+ scrollbar_visible_until: Option<Instant>,
selection: Selection,
/// If is_some(), rather than display the actual tab
/// contents, we're overlaying a little internal application
@@ -3246,6 +3267,19 @@ impl TermWindow {
self.content_view_fade.is_some()
|| self.active_content_view_index().is_some()
|| self.workspace_sidebar_hover.needs_frames()
+ || self.overlay_scrollbar_owes_frames()
+ }
+
+ /// An overlay scrollbar that is still up has a fade to finish; the
+ /// wheel scrolls an unfocused window too, and a thumb left standing
+ /// until some output happens to repaint would be a visible glitch.
+ fn overlay_scrollbar_owes_frames(&self) -> bool {
+ let now = Instant::now();
+ self.pane_state.borrow().values().any(|state| {
+ state
+ .scrollbar_visible_until
+ .is_some_and(|until| until > now)
+ })
}
/// Tracks whether the user can see this window at all. macOS reports
@@ -8626,6 +8660,44 @@ impl TermWindow {
}
}
+ /// Keep the pane's overlay scrollbar up: the pointer is on its thumb,
+ /// or dragging it.
+ pub(crate) fn reveal_scrollbar(&mut self, pane_id: PaneId) {
+ self.pane_state(pane_id).scrollbar_visible_until =
+ Some(Instant::now() + OVERLAY_SCROLLBAR_SHOW);
+ }
+
+ /// How visible the pane's overlay scrollbar is right now: 1 while it
+ /// has more than the fade left, easing to 0 over the fade, 0 once it
+ /// has expired or was never shown. Dragging the thumb pins it at 1.
+ /// Also says when the next frame is due, so the caller can arm it.
+ pub(crate) fn overlay_scrollbar_opacity(
+ &self,
+ pane_id: PaneId,
+ now: Instant,
+ ) -> (f32, Option<Instant>) {
+ let dragging_this = self.dragging.as_ref().is_some_and(|(item, _)| {
+ matches!(item.item_type, UIItemType::ScrollThumb(track) if track.pane_id == pane_id)
+ });
+ if dragging_this {
+ return (1.0, None);
+ }
+ let Some(until) = self.pane_state(pane_id).scrollbar_visible_until else {
+ return (0.0, None);
+ };
+ let Some(remaining) = until.checked_duration_since(now) else {
+ return (0.0, None);
+ };
+ if remaining > OVERLAY_SCROLLBAR_FADE {
+ return (1.0, Some(until - OVERLAY_SCROLLBAR_FADE));
+ }
+ let t = remaining.as_secs_f32() / OVERLAY_SCROLLBAR_FADE.as_secs_f32();
+ (
+ crate::ui::anim::Easing::Smooth.apply(t),
+ Some(now + Duration::from_millis(16)),
+ )
+ }
+
/// 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.
@@ -10017,6 +10089,7 @@ impl TermWindow {
};
let mut state = self.pane_state(pane_id);
+ let moved = px != state.viewport_px || pos != state.viewport;
if px != state.viewport_px {
state.viewport_px = px;
}
@@ -10025,6 +10098,10 @@ impl TermWindow {
state.glide_remaining = 0.0;
state.glide_last_tick = None;
}
+ if moved {
+ // The overlay scrollbar shows where the view went.
+ state.scrollbar_visible_until = Some(Instant::now() + OVERLAY_SCROLLBAR_SHOW);
+ }
if pos != state.viewport {
state.viewport = pos;
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs
index 17d8ee97..8465c807 100644
--- a/wezterm-gui/src/termwindow/mouseevent.rs
+++ b/wezterm-gui/src/termwindow/mouseevent.rs
@@ -12,7 +12,7 @@ use crate::termwindow::ui::tokens::{
};
use crate::termwindow::{
pane_drop_action, pane_drop_zone, zone_split_request, GuiWin, MouseCapture, PaneDropKind,
- PaneDropZone, PaneNavAction, PaneTabDragState, PaneTabDropTarget, PositionedSplit, ScrollHit,
+ PaneDropZone, PaneNavAction, PaneTabDragState, PaneTabDropTarget, PositionedSplit, ScrollHit, ScrollTrack,
TabWheelSurface, TermWindowNotif, UIItem, UIItemType, TMB,
};
#[cfg(target_os = "macos")]
@@ -34,7 +34,6 @@ use mux::tab::{PositionedPane, SplitDirection};
use mux::window::WindowId as MuxWindowId;
use mux::Mux;
use mux_lua::MuxPane;
-use std::convert::TryInto;
use std::ops::Sub;
use std::rc::Rc;
use std::sync::atomic::{AtomicBool, Ordering};
@@ -1582,9 +1581,9 @@ impl super::TermWindow {
| UIItemType::ContextMenuBackdrop
| UIItemType::ContextMenuItem(_)
| UIItemType::CommandPalette
- | UIItemType::AboveScrollThumb
- | UIItemType::BelowScrollThumb
- | UIItemType::ScrollThumb
+ | UIItemType::AboveScrollThumb(_)
+ | UIItemType::BelowScrollThumb(_)
+ | UIItemType::ScrollThumb(_)
| UIItemType::Split(_)
| UIItemType::ContentViewClose(_) => {}
}
@@ -1703,9 +1702,9 @@ impl super::TermWindow {
| UIItemType::ContextMenuBackdrop
| UIItemType::ContextMenuItem(_)
| UIItemType::CommandPalette
- | UIItemType::AboveScrollThumb
- | UIItemType::BelowScrollThumb
- | UIItemType::ScrollThumb
+ | UIItemType::AboveScrollThumb(_)
+ | UIItemType::BelowScrollThumb(_)
+ | UIItemType::ScrollThumb(_)
| UIItemType::Split(_)
| UIItemType::ContentViewClose(_) => {}
}
@@ -1847,9 +1846,9 @@ impl super::TermWindow {
matches!(
item.item_type,
UIItemType::PaneNav { .. }
- | UIItemType::AboveScrollThumb
- | UIItemType::ScrollThumb
- | UIItemType::BelowScrollThumb
+ | UIItemType::AboveScrollThumb(_)
+ | UIItemType::ScrollThumb(_)
+ | UIItemType::BelowScrollThumb(_)
| UIItemType::Split(_)
)
});
@@ -2397,14 +2396,20 @@ impl super::TermWindow {
self.dragging.replace((item, start_event));
}
+ /// The pane a scrollbar track belongs to, if it is still around.
+ fn scroll_track_pane(&self, track: ScrollTrack) -> Option<Arc<dyn Pane>> {
+ Mux::get().get_pane(track.pane_id)
+ }
+
fn drag_scroll_thumb(
&mut self,
item: UIItem,
+ track: ScrollTrack,
start_event: MouseEvent,
event: MouseEvent,
context: &dyn WindowOps,
) {
- let pane = match self.get_active_pane_or_overlay() {
+ let pane = match self.scroll_track_pane(track) {
Some(pane) => pane,
None => return,
};
@@ -2412,26 +2417,19 @@ impl super::TermWindow {
let dims = pane.get_dimensions();
let current_viewport = self.get_viewport(pane.pane_id());
- let tab_bar_height = if self.show_tab_bar {
- self.tab_bar_pixel_height().unwrap_or(0.)
- } else {
- 0.
- };
- let (top_bar_height, bottom_bar_height) = if self.config.tab_bar_at_bottom {
- (0.0, tab_bar_height)
- } else {
- (tab_bar_height, 0.0)
- };
-
- let border = self.get_os_border();
- let y_offset = top_bar_height + border.top.get() as f32;
-
+ // The track the thumb was drawn on came with the item: the gutter
+ // bar's spans the window, the overlay's spans its pane's content.
let from_top = start_event.coords.y.saturating_sub(item.y as isize);
let effective_thumb_top = event
.coords
.y
- .saturating_sub(y_offset as isize + from_top)
+ .saturating_sub(track.track_top as isize + from_top)
.max(0) as usize;
+ let min_thumb = if self.show_scroll_bar {
+ self.min_scroll_bar_height() as usize
+ } else {
+ crate::ui::UiTokens::for_dpi(self.dimensions.dpi).scrollbar_min_thumb as usize
+ };
// Convert thumb top into a row index by reversing the math
// in ScrollHit::thumb
@@ -2439,12 +2437,11 @@ impl super::TermWindow {
effective_thumb_top,
&*pane,
current_viewport,
- self.dimensions.pixel_height.saturating_sub(
- y_offset as usize + border.bottom.get() + bottom_bar_height as usize,
- ),
- self.min_scroll_bar_height() as usize,
+ track.track_height,
+ min_thumb,
);
self.set_viewport(pane.pane_id(), Some(row), dims);
+ self.reveal_scrollbar(pane.pane_id());
context.invalidate();
self.dragging.replace((item, start_event));
}
@@ -2707,8 +2704,8 @@ impl super::TermWindow {
UIItemType::Split(split) => {
self.drag_split(item, split, start_event, x, y, context);
}
- UIItemType::ScrollThumb => {
- self.drag_scroll_thumb(item, start_event, event, context);
+ UIItemType::ScrollThumb(track) => {
+ self.drag_scroll_thumb(item, track, start_event, event, context);
}
UIItemType::WorkspaceSidebarResize => {
self.drag_workspace_sidebar_resize(item, start_event, event, context);
@@ -3569,13 +3566,16 @@ impl super::TermWindow {
UIItemType::TabBar(item) => {
self.mouse_event_tab_bar(item, event, context);
}
- UIItemType::AboveScrollThumb => {
+ UIItemType::AboveScrollThumb(track) => {
+ let pane = self.scroll_track_pane(track).unwrap_or(pane);
self.mouse_event_above_scroll_thumb(item, pane, event, context);
}
- UIItemType::ScrollThumb => {
+ UIItemType::ScrollThumb(track) => {
+ let pane = self.scroll_track_pane(track).unwrap_or(pane);
self.mouse_event_scroll_thumb(item, pane, event, context);
}
- UIItemType::BelowScrollThumb => {
+ UIItemType::BelowScrollThumb(track) => {
+ let pane = self.scroll_track_pane(track).unwrap_or(pane);
self.mouse_event_below_scroll_thumb(item, pane, event, context);
}
UIItemType::Split(split) => {
@@ -4348,9 +4348,14 @@ impl super::TermWindow {
UIItemType::ContextMenuItem(_) => {
context.set_cursor(Some(MouseCursor::Hand));
}
- UIItemType::AboveScrollThumb
- | UIItemType::ScrollThumb
- | UIItemType::BelowScrollThumb
+ UIItemType::ScrollThumb(track) => {
+ // Hovering the thumb keeps the overlay scrollbar up.
+ self.reveal_scrollbar(track.pane_id);
+ context.invalidate();
+ context.set_cursor(Some(MouseCursor::Arrow));
+ }
+ UIItemType::AboveScrollThumb(_)
+ | UIItemType::BelowScrollThumb(_)
| UIItemType::Split(_)
| UIItemType::PaneNav { .. } => {
context.set_cursor(Some(MouseCursor::Arrow));
@@ -7965,13 +7970,13 @@ impl super::TermWindow {
if let WMEK::Press(MousePress::Left) = event.kind {
let dims = pane.get_dimensions();
let current_viewport = self.get_viewport(pane.pane_id());
- // Page up
+ // Page up, by this pane's own height
self.set_viewport(
pane.pane_id(),
Some(
current_viewport
.unwrap_or(dims.physical_top)
- .saturating_sub(self.terminal_size.rows.try_into().unwrap()),
+ .saturating_sub(dims.viewport_rows as StableRowIndex),
),
dims,
);
@@ -7990,13 +7995,13 @@ impl super::TermWindow {
if let WMEK::Press(MousePress::Left) = event.kind {
let dims = pane.get_dimensions();
let current_viewport = self.get_viewport(pane.pane_id());
- // Page down
+ // Page down, by this pane's own height
self.set_viewport(
pane.pane_id(),
Some(
current_viewport
.unwrap_or(dims.physical_top)
- .saturating_add(self.terminal_size.rows.try_into().unwrap()),
+ .saturating_add(dims.viewport_rows as StableRowIndex),
),
dims,
);
diff --git a/wezterm-gui/src/termwindow/render/pane.rs b/wezterm-gui/src/termwindow/render/pane.rs
index fb2dd84d..cf417c5e 100644
--- a/wezterm-gui/src/termwindow/render/pane.rs
+++ b/wezterm-gui/src/termwindow/render/pane.rs
@@ -17,7 +17,7 @@ use crate::termwindow::ui::tokens::{
TAB_CLOSE_HOVER_RADIUS, TAB_CONTENT_INSET, TAB_ICON_SIZE,
TAB_VERTICAL_PADDING,
};
-use crate::termwindow::{PaneNavAction, ScrollHit, UIItem, UIItemType};
+use crate::termwindow::{PaneNavAction, ScrollHit, ScrollTrack, UIItem, UIItemType};
use crate::ui::UiPalette;
use crate::utilsprites::RenderMetrics;
use ::window::bitmaps::TextureRect;
@@ -1217,6 +1217,102 @@ impl crate::TermWindow {
Ok(())
}
+ /// The thin, auto-hiding scrollbar over the right edge of a pane's
+ /// content: a rounded thumb the height of the visible share of the
+ /// scrollback, positioned by the pixel, shown while the view moves and
+ /// fading out afterwards. Nothing is reserved for it in the layout.
+ /// The hit area is wider than the thumb so a 5px line can be grabbed.
+ fn paint_overlay_scrollbar(
+ &mut self,
+ layers: &mut TripleLayerQuadAllocator,
+ pos: &PositionedPane,
+ current_viewport: Option<StableRowIndex>,
+ viewport_frac: f32,
+ content_right: f32,
+ content_top: f32,
+ content_bottom: f32,
+ ) -> anyhow::Result<()> {
+ let pane_id = pos.pane.pane_id();
+ let dims = pos.pane.get_dimensions();
+ // Nothing to indicate while the whole history fits on screen.
+ if dims.scrollback_rows <= dims.viewport_rows {
+ return Ok(());
+ }
+ let now = Instant::now();
+ let (opacity, next_frame) = self.overlay_scrollbar_opacity(pane_id, now);
+ if let Some(due) = next_frame {
+ self.update_next_frame_time(Some(due));
+ }
+ if opacity <= 0.0 {
+ return Ok(());
+ }
+
+ let tokens = crate::ui::UiTokens::for_dpi(self.dimensions.dpi);
+ let ui_palette =
+ crate::ui::UiPalette::for_appearance(crate::native_settings::effective_appearance());
+ let track_top = content_top + tokens.scrollbar_margin_y;
+ let track_height =
+ (content_bottom - content_top - 2.0 * tokens.scrollbar_margin_y).max(0.0);
+ if track_height < tokens.scrollbar_min_thumb {
+ return Ok(());
+ }
+ let thumb = ScrollHit::thumb_px(
+ &*pos.pane,
+ current_viewport,
+ viewport_frac,
+ track_height as usize,
+ tokens.scrollbar_min_thumb as usize,
+ );
+ let thumb_x = content_right - tokens.scrollbar_inset - tokens.scrollbar_width;
+ let thumb_top = track_top + thumb.top as f32;
+
+ // Hit areas: a strip three thumbs wide, so the pointer need not
+ // land on the line itself. Pushed after the pane's own items, so
+ // they win the reverse walk in resolve_ui_item.
+ let hit_width = (tokens.scrollbar_width * 3.0).max(12.0);
+ let hit_x = (content_right - tokens.scrollbar_inset - hit_width).max(0.0) as usize;
+ let track = ScrollTrack {
+ pane_id,
+ track_top: track_top as usize,
+ track_height: track_height as usize,
+ };
+ self.ui_items.push(UIItem {
+ x: hit_x,
+ width: hit_width as usize,
+ y: track_top as usize,
+ height: thumb.top,
+ item_type: UIItemType::AboveScrollThumb(track),
+ });
+ self.ui_items.push(UIItem {
+ x: hit_x,
+ width: hit_width as usize,
+ y: thumb_top as usize,
+ height: thumb.height,
+ item_type: UIItemType::ScrollThumb(track),
+ });
+ self.ui_items.push(UIItem {
+ x: hit_x,
+ width: hit_width as usize,
+ y: thumb_top as usize + thumb.height,
+ height: (track_height as usize).saturating_sub(thumb.top + thumb.height),
+ item_type: UIItemType::BelowScrollThumb(track),
+ });
+
+ let gl_state = self.render_state.as_ref().unwrap();
+ let ctx = crate::ui::DrawContext::new(gl_state, self.dimensions, &self.render_metrics);
+ ctx.draw_rounded_rect(
+ layers,
+ 2,
+ thumb_x,
+ thumb_top,
+ tokens.scrollbar_width,
+ thumb.height as f32,
+ ui_palette.scrollbar_thumb.mul_alpha(opacity),
+ tokens.scrollbar_width / 2.0,
+ )
+ .context("overlay scrollbar thumb")
+ }
+
fn paint_pane_box_model(&mut self, pos: &PositionedPane) -> anyhow::Result<()> {
let pane_id = pos.pane.pane_id();
let output_generation = self
@@ -1491,27 +1587,31 @@ impl crate::TermWindow {
return Ok(());
}
- // TODO: we only have a single scrollbar in a single position.
- // We only update it for the active pane, but we should probably
- // do a per-pane scrollbar. That will require more extensive
- // changes to ScrollHit, mouse positioning, PositionedPane
- // and tab size calculation.
+ // The Lua `enable_scroll_bar` gutter: one window-wide bar for the
+ // active pane, kept as it was. The per-pane overlay scrollbar is
+ // drawn after the lines, at the end of this function.
if pos.is_active && self.show_scroll_bar {
let thumb_y_offset = top_bar_height as usize + border.top.get();
let min_height = self.min_scroll_bar_height();
+ let track_height = self.dimensions.pixel_height.saturating_sub(
+ thumb_y_offset + border.bottom.get() + bottom_bar_height as usize,
+ );
let info = ScrollHit::thumb(
&*pos.pane,
current_viewport,
- self.dimensions.pixel_height.saturating_sub(
- thumb_y_offset + border.bottom.get() + bottom_bar_height as usize,
- ),
+ track_height,
min_height as usize,
);
let abs_thumb_top = thumb_y_offset + info.top;
let thumb_size = info.height;
let color = palette.scrollbar_thumb.to_linear();
+ let track = ScrollTrack {
+ pane_id: pos.pane.pane_id(),
+ track_top: thumb_y_offset,
+ track_height,
+ };
// Adjust the scrollbar thumb position
let config = &self.config;
@@ -1525,14 +1625,14 @@ impl crate::TermWindow {
width: padding as usize,
y: thumb_y_offset,
height: info.top,
- item_type: UIItemType::AboveScrollThumb,
+ item_type: UIItemType::AboveScrollThumb(track),
});
self.ui_items.push(UIItem {
x: thumb_x,
width: padding as usize,
y: abs_thumb_top,
height: thumb_size,
- item_type: UIItemType::ScrollThumb,
+ item_type: UIItemType::ScrollThumb(track),
});
self.ui_items.push(UIItem {
x: thumb_x,
@@ -1542,7 +1642,7 @@ impl crate::TermWindow {
.dimensions
.pixel_height
.saturating_sub(abs_thumb_top + thumb_size),
- item_type: UIItemType::BelowScrollThumb,
+ item_type: UIItemType::BelowScrollThumb(track),
});
self.filled_rectangle(
@@ -1952,6 +2052,22 @@ impl crate::TermWindow {
if let Some(error) = render.error.take() {
return Err(error).context("error while calling with_lines_mut");
}
+
+ // The overlay scrollbar goes on after the text it sits over.
+ if !render.term_window.show_scroll_bar && crate::native_settings::overlay_scrollbar() {
+ let content_bottom = pane_top_pixel_y
+ + render_dims.viewport_rows as f32
+ * pane_render_metrics.cell_size.height as f32;
+ render.term_window.paint_overlay_scrollbar(
+ render.layers,
+ pos,
+ current_viewport,
+ scroll_px / pane_render_metrics.cell_size.height.max(1) as f32,
+ pane_content_right,
+ pane_top_pixel_y,
+ content_bottom,
+ )?;
+ }
if let Some(generation) = output_generation {
render
.term_window