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(gui): let pane focus follow the mouse
RoversXab2442093766
diff --git a/thinkterm-i18n/i18n/de-DE.ftl b/thinkterm-i18n/i18n/de-DE.ftlindex 45701426..666e4021 100644--- a/thinkterm-i18n/i18n/de-DE.ftl+++ b/thinkterm-i18n/i18n/de-DE.ftl@@ -181,6 +181,8 @@ settings-selection-style-rounded = Abgerundetsettings-selection-style-square = Eckigsettings-copy-on-select = Beim Auswählen kopierensettings-copy-on-select-description = Ausgewählter Text kommt sofort in die Zwischenablage. Aus: Auswählen wählt nur aus, kopiert wird mit dem Kopierkürzel oder per Rechtsklick.+settings-focus-follows-mouse = Fokus folgt der Maus+settings-focus-follows-mouse-description = Der Bereich unter dem Mauszeiger erhält den Fokus, ohne Klick. Nicht beim Ziehen und nicht, solange eine andere App vorne ist.settings-terminal-quote-heading = Zitatesettings-terminal-font-size-from-lua = Hier gespeichert und sofort auf offene Terminals angewendet. thinkterm.lua gibt { $value } an.settings-quotes-file = Zitatdateidiff --git a/thinkterm-i18n/i18n/en-US.ftl b/thinkterm-i18n/i18n/en-US.ftlindex c6b8f729..df2e8bbb 100644--- a/thinkterm-i18n/i18n/en-US.ftl+++ b/thinkterm-i18n/i18n/en-US.ftl@@ -181,6 +181,8 @@ settings-selection-style-rounded = Roundedsettings-selection-style-square = Squaresettings-copy-on-select = Copy on selectsettings-copy-on-select-description = Selected text goes straight to the clipboard. Off, selecting only selects: copy with the copy shortcut or a right click.+settings-focus-follows-mouse = Focus follows mouse+settings-focus-follows-mouse-description = The pane under the mouse takes the focus, without a click. Not while dragging, or while another app is in front.settings-terminal-quote-heading = Quotessettings-terminal-font-size-from-lua = Saved here and applied to open terminals at once. thinkterm.lua says { $value }.settings-quotes-file = Quotes filediff --git a/thinkterm-i18n/i18n/fr-FR.ftl b/thinkterm-i18n/i18n/fr-FR.ftlindex 34d7e980..74561df2 100644--- a/thinkterm-i18n/i18n/fr-FR.ftl+++ b/thinkterm-i18n/i18n/fr-FR.ftl@@ -181,6 +181,8 @@ settings-selection-style-rounded = Arrondiesettings-selection-style-square = Carréesettings-copy-on-select = Copier à la sélectionsettings-copy-on-select-description = Le texte sélectionné va directement dans le presse-papiers. Désactivé, sélectionner ne fait que sélectionner : copiez avec le raccourci de copie ou un clic droit.+settings-focus-follows-mouse = Le focus suit la souris+settings-focus-follows-mouse-description = Le volet sous la souris prend le focus, sans clic. Pas pendant un glisser, ni quand une autre app est au premier plan.settings-terminal-quote-heading = Citationssettings-terminal-font-size-from-lua = Enregistrée ici et appliquée aussitôt aux terminaux ouverts. thinkterm.lua indique { $value }.settings-quotes-file = Fichier des citationsdiff --git a/thinkterm-i18n/i18n/ja-JP.ftl b/thinkterm-i18n/i18n/ja-JP.ftlindex 356c705a..acd055ff 100644--- a/thinkterm-i18n/i18n/ja-JP.ftl+++ b/thinkterm-i18n/i18n/ja-JP.ftl@@ -178,6 +178,8 @@ settings-selection-style-rounded = 角丸settings-selection-style-square = 四角settings-copy-on-select = 選択時にコピーsettings-copy-on-select-description = 選択した文字をそのままクリップボードに入れます。オフにすると選択するだけになり、コピーはコピーのショートカットか右クリックで行います。+settings-focus-follows-mouse = フォーカスをマウスに追従+settings-focus-follows-mouse-description = マウスを乗せたペインに、クリックしなくてもフォーカスが移ります。ドラッグ中や、ほかのアプリを使っているあいだは切り替わりません。settings-terminal-quote-heading = 引用文settings-terminal-font-size-from-lua = ここで保存し、開いているターミナルにすぐ適用します。thinkterm.lua の値は { $value } です。settings-quotes-file = 引用文ファイルdiff --git a/thinkterm-i18n/i18n/zh-CN.ftl b/thinkterm-i18n/i18n/zh-CN.ftlindex 51807ad0..662508c9 100644--- a/thinkterm-i18n/i18n/zh-CN.ftl+++ b/thinkterm-i18n/i18n/zh-CN.ftl@@ -178,6 +178,8 @@ settings-selection-style-rounded = 圆角settings-selection-style-square = 直角settings-copy-on-select = 选中时自动复制settings-copy-on-select-description = 选中的文字直接放进剪贴板。关掉后,选中只是选中,要复制就用复制快捷键或右键。+settings-focus-follows-mouse = 焦点跟随鼠标+settings-focus-follows-mouse-description = 鼠标移到哪个窗格,焦点就到哪个窗格,不用点击。拖动选择时,或者正在用别的应用时,不会切换。settings-terminal-quote-heading = 语录settings-terminal-font-size-from-lua = 在这里保存,立即应用到已打开的终端。thinkterm.lua 中为 { $value }。settings-quotes-file = 语录文件diff --git a/wezterm-gui/src/native_settings.rs b/wezterm-gui/src/native_settings.rsindex f4349892..a3a508f2 100644--- a/wezterm-gui/src/native_settings.rs+++ b/wezterm-gui/src/native_settings.rs@@ -658,6 +658,9 @@ pub(crate) struct NativeTerminalSettings {pub(crate) right_click: NativeRightClick,#[serde(deserialize_with = "choice_or_default")]pub(crate) copy_effect: NativeCopyEffect,+ /// The pane the mouse moves onto takes the focus, without a click.+ #[serde(default)]+ pub(crate) focus_follows_mouse: bool,/// See [`NativeTextContrast`]. `Off` defers to the Lua/// `text_min_contrast_ratio`, which is itself off unless set.#[serde(deserialize_with = "text_contrast_or_default")]@@ -684,6 +687,7 @@ impl Default for NativeTerminalSettings {copy_on_select: true,right_click: NativeRightClick::default(),copy_effect: NativeCopyEffect::default(),+ focus_follows_mouse: false,text_contrast: NativeTextContrast::default(),bottom_quote_enabled: false,bottom_quote_mode: NativeBottomQuoteMode::default(),@@ -729,6 +733,11 @@ pub(crate) fn copy_effect() -> NativeCopyEffect {load_shared().terminal.copy_effect}+/// Read when the mouse moves onto another pane, through the shared handle.+pub(crate) fn focus_follows_mouse() -> bool {+ load_shared().terminal.focus_follows_mouse+}+/// The contrast floor in force, or `None` to leave colours alone. The/// settings window wins when it names a ratio; `Off` hands the question back/// to the configuration file.@@ -3090,19 +3099,22 @@ mod tests {assert_eq!(settings.terminal.scroll_mode, NativeScrollMode::Stepped);assert_eq!(settings.localization.language.as_deref(), Some("ja-JP"));- // Selecting copies unless turned off.+ // Selecting copies unless turned off; the focus waits for a click+ // unless turned on.assert!(settings.terminal.copy_on_select);+ assert!(!settings.terminal.focus_follows_mouse);// The ones this build knows still read as written.let json = r#"{ "version": 1, "terminal": {"selection_style": "square", "copy_on_select": false, "right_click": "copy_or_paste",- "copy_effect": "color"+ "copy_effect": "color", "focus_follows_mouse": true} }"#;let settings: ThinkTermNativeSettings = serde_json::from_str(json).unwrap();assert!(!settings.terminal.copy_on_select);assert_eq!(settings.terminal.selection_style, NativeSelectionStyle::Square);assert_eq!(settings.terminal.right_click, NativeRightClick::CopyOrPaste);assert_eq!(settings.terminal.copy_effect, NativeCopyEffect::Color);+ assert!(settings.terminal.focus_follows_mouse);}/// The four this build does know still round-trip.diff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rsindex 06769ab8..43f352a3 100644--- a/wezterm-gui/src/settings_window.rs+++ b/wezterm-gui/src/settings_window.rs@@ -1314,6 +1314,7 @@ impl SettingsSection {"settings-right-click","settings-right-click-paste","settings-copy-effect",+ "settings-focus-follows-mouse","settings-split-animation",].iter()@@ -1838,6 +1839,7 @@ enum SettingsAction {SetScrollMode(crate::native_settings::NativeScrollMode),SetSelectionStyle(crate::native_settings::NativeSelectionStyle),ToggleCopyOnSelect,+ ToggleFocusFollowsMouse,SetRightClick(crate::native_settings::NativeRightClick),SetCopyEffect(crate::native_settings::NativeCopyEffect),/// Hand the choosing to the command palette's scheme list, which already@@ -6245,6 +6247,19 @@ impl SettingsWindow {terminal.copy_on_select = on})}+ SettingsAction::ToggleFocusFollowsMouse => {+ let on = !self.native_settings.terminal.focus_follows_mouse;+ let done = settings_tr(+ "settings-status-value-now",+ &[+ ("setting", crate::i18n::tr("settings-focus-follows-mouse")),+ ("value", crate::i18n::tr(if on { "common-on" } else { "common-off" })),+ ],+ );+ self.apply_terminal_change("settings-focus-follows-mouse", done, |terminal| {+ terminal.focus_follows_mouse = on+ })+ }SettingsAction::SetSelectionStyle(style) => self.apply_terminal_choice("settings-selection-style",localized_selection_style_label(style),@@ -13008,6 +13023,26 @@ impl SettingsWindow {rows.rule(),)?);+ let (tx, tw) = this.paint_row_tile(+ layers,+ row_x,+ rows.y,+ row_width,+ SvgIcon::Mouse,+ TileColor::Indigo,+ )?;+ rows.add(this.paint_toggle_setting_row(+ layers,+ tx,+ rows.y,+ tw,+ &crate::i18n::tr("settings-focus-follows-mouse"),+ &crate::i18n::tr("settings-focus-follows-mouse-description"),+ this.native_settings.terminal.focus_follows_mouse,+ SettingsAction::ToggleFocusFollowsMouse,+ rows.rule(),+ )?);+Ok(rows.bottom)})?;diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rsindex bd50b3de..93e182af 100644--- a/wezterm-gui/src/termwindow/mod.rs+++ b/wezterm-gui/src/termwindow/mod.rs@@ -2982,6 +2982,13 @@ pub struct TermWindow {current_modifier_and_leds: (Modifiers, KeyboardLedStatus),current_mouse_buttons: Vec<MousePress>,current_mouse_capture: Option<MouseCapture>,+ /// The cell (window row, column) the mouse last moved over in the+ /// terminal area, forgotten when it moves anywhere else. Focus follows+ /// the mouse when it crosses from one pane into another as the panes+ /// lie now -- not whenever the focused pane differs, nor when another+ /// pane comes under a resting mouse: a pane picked from the keyboard+ /// keeps the focus until the mouse goes somewhere.+ last_pointer_cell: Option<(i64, usize)>,opengl_info: Option<String>,@@ -4760,6 +4767,7 @@ impl TermWindow {preview_scale_hold: RefCell::new(HashMap::new()),current_mouse_buttons: vec![],current_mouse_capture: None,+ last_pointer_cell: None,last_mouse_click: None,current_highlight: None,quad_generation: 0,diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rsindex 6838dfe1..d4d942d9 100644--- a/wezterm-gui/src/termwindow/mouseevent.rs+++ b/wezterm-gui/src/termwindow/mouseevent.rs@@ -1983,6 +1983,13 @@ impl super::TermWindow {pub fn mouse_event_impl(&mut self, event: MouseEvent, context: &dyn WindowOps) {log::trace!("{:?}", event);+ // A move that does not reach the terminal -- the tab bar, a sidebar+ // -- leaves no cell behind: coming back is coming into a pane.+ let pointer_cell_before = if matches!(event.kind, WMEK::Move) {+ self.last_pointer_cell.take()+ } else {+ self.last_pointer_cell+ };self.plugin_panel_saw_button(&event.kind);if self.recording_overlay_mouse(&event, context) {return;@@ -2613,6 +2620,7 @@ impl super::TermWindow {event,context,capture_mouse,+ pointer_cell_before,);}}@@ -2630,6 +2638,8 @@ impl super::TermWindow {&& event.coords.y as usize <= self.dimensions.pixel_height});self.current_mouse_event = None;+ // Coming back in is coming into a pane.+ self.last_pointer_cell = None;// No hover surface outlives the pointer leaving the window.self.update_hover_tooltip(None);// The machine reads `Away` now: cancels an Arming, starts a grace.@@ -9153,6 +9163,7 @@ impl super::TermWindow {event: MouseEvent,context: &dyn WindowOps,capture_mouse: bool,+ pointer_cell_before: Option<(i64, usize)>,) {let mut is_click_to_focus_pane = false;@@ -9167,14 +9178,35 @@ impl super::TermWindow {self.current_mouse_capture,Some(MouseCapture::TerminalPane(_)));+ // A release belongs to the pane the press went to, and is measured+ // there however far the drag went.+ let measured_in_pane = is_already_captured || matches!(event.kind, WMEK::Release(_));- for pos in self.get_panes_to_render() {- if !is_already_captured- && row >= pos.top as i64+ let panes = self.get_panes_to_render();+ let covers = |pos: &PositionedPane, (row, column): (i64, usize)| {+ row >= pos.top as i64&& row <= (pos.top + pos.height) as i64&& column >= pos.left&& column <= pos.left + pos.width- {+ };+ let cell = (row, column);+ let is_over = move |pos: &PositionedPane| covers(pos, cell);+ // A move that takes the mouse into another pane: the one under it+ // now did not have it a move ago. Kept track of during a drag too,+ // so the pane a drag ends over is not entered by the next nudge.+ let crossed_into = if matches!(event.kind, WMEK::Move) {+ self.last_pointer_cell = Some(cell);+ panes+ .iter()+ .find(|pos| is_over(pos))+ .filter(|pos| !pointer_cell_before.is_some_and(|before| covers(pos, before)))+ .map(|pos| pos.pane.pane_id())+ } else {+ None+ };++ for pos in panes.iter() {+ if !measured_in_pane && is_over(pos) {if pane.pane_id() != pos.pane.pane_id() {// We're over a pane that isn't activematch &event.kind {@@ -9187,12 +9219,30 @@ impl super::TermWindow {is_click_to_focus_pane = true;}WMEK::Move => {- // ThinkTerm keeps pane focus explicit. The upstream- // focus-follows-mouse behavior makes split panes- // appear to switch while scrolling pane-local tabs.+ // ThinkTerm keeps pane focus explicit unless the+ // settings ask for it to follow the mouse: then+ // only as the mouse comes into the pane, in the+ // window in front, with no button held, and not+ // while another device has this terminal.+ if crossed_into == Some(pos.pane.pane_id())+ && self.focused.is_some()+ && event.mouse_buttons == WMB::NONE+ && !self.frontend_takeover_claimable()+ && crate::native_settings::focus_follows_mouse()+ {+ let mux = Mux::get();+ mux.get_active_tab_for_window(self.mux_window_id)+ .map(|tab| tab.set_active_idx(pos.index));+ context.invalidate();+ }+ // The motion is the hovered pane's either way:+ // its position is measured in that pane, and+ // given to the focused one it lit up whatever+ // sat at the same spot there.+ pane = Arc::clone(&pos.pane);}- WMEK::Release(_) | WMEK::HorzWheel(_) => {}- WMEK::VertWheel(_) => {+ WMEK::Release(_) => {}+ WMEK::VertWheel(_) | WMEK::HorzWheel(_) => {// Let wheel events route to the hovered pane,// even if it doesn't have focuspane = Arc::clone(&pos.pane);@@ -9206,7 +9256,7 @@ impl super::TermWindow {x_pixel_offset = position.x_pixel_offset;y_pixel_offset = position.y_pixel_offset;break;- } else if is_already_captured && pane.pane_id() == pos.pane.pane_id() {+ } else if measured_in_pane && pane.pane_id() == pos.pane.pane_id() {let position = self.click_position_for_pane(&event, &pane, &pos);column = position.column;row = position.row;