From b5c33ca2b769e87e86e1ed6d2c19dfce14c242c0 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 25 Dec 2025 18:05:15 +0000 Subject: [PATCH 1/2] Add selection_mode format variable for copy mode, from Mike Jonkmans in GitHub issue 4773. --- tmux.1 | 1 + window-copy.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/tmux.1 b/tmux.1 index fe228dd2..a93a002e 100644 --- a/tmux.1 +++ b/tmux.1 @@ -6238,6 +6238,7 @@ The following variables are available, where appropriate: .It Li "selection_active" Ta "" Ta "1 if selection started and changes with the cursor in copy mode" .It Li "selection_end_x" Ta "" Ta "X position of the end of the selection" .It Li "selection_end_y" Ta "" Ta "Y position of the end of the selection" +.It Li "selection_mode" Ta "" Ta "Selection mode" .It Li "selection_present" Ta "" Ta "1 if selection started in copy mode" .It Li "selection_start_x" Ta "" Ta "X position of the start of the selection" .It Li "selection_start_y" Ta "" Ta "Y position of the start of the selection" diff --git a/window-copy.c b/window-copy.c index f8700555..87d0dea8 100644 --- a/window-copy.c +++ b/window-copy.c @@ -956,6 +956,18 @@ window_copy_formats(struct window_mode_entry *wme, struct format_tree *ft) format_add(ft, "selection_present", "0"); } + switch (data->selflag) { + case SEL_CHAR: + format_add(ft, "selection_mode", "char"); + break; + case SEL_WORD: + format_add(ft, "selection_mode", "word"); + break; + case SEL_LINE: + format_add(ft, "selection_mode", "line"); + break; + } + format_add(ft, "search_present", "%d", data->searchmark != NULL); format_add(ft, "search_timed_out", "%d", data->timeout); if (data->searchcount != -1) { From f72832cc085be4fdc0220be340087b2110feb4cf Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 25 Dec 2025 18:07:00 +0000 Subject: [PATCH 2/2] Add focus-follows-mouse option, from Barry Wasdell in GitHub issue 4771. --- options-table.c | 7 +++++++ server-client.c | 17 ++++++++++++++--- tmux.1 | 6 ++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/options-table.c b/options-table.c index f056966d..78299328 100644 --- a/options-table.c +++ b/options-table.c @@ -665,6 +665,13 @@ const struct options_table_entry options_table[] = { .text = "Time for which status line messages should appear." }, + { .name = "focus-follows-mouse", + .type = OPTIONS_TABLE_FLAG, + .scope = OPTIONS_TABLE_SESSION, + .default_num = 0, + .text = "Whether moving the mouse into a pane selects it." + }, + { .name = "history-limit", .type = OPTIONS_TABLE_NUMBER, .scope = OPTIONS_TABLE_SESSION, diff --git a/server-client.c b/server-client.c index 2732f1fe..4cef9083 100644 --- a/server-client.c +++ b/server-client.c @@ -1064,8 +1064,16 @@ have_event: case NOTYPE: break; case MOVE: - if (where == PANE) + if (where == PANE) { key = KEYC_MOUSEMOVE_PANE; + if (wp != NULL && + wp != w->active && + options_get_number(s->options, "focus-follows-mouse")) { + window_set_active_pane(w, wp, 1); + server_redraw_window_borders(w); + server_status_window(w); + } + } if (where == STATUS) key = KEYC_MOUSEMOVE_STATUS; if (where == STATUS_LEFT) @@ -2973,7 +2981,8 @@ server_client_reset_state(struct client *c) /* * Set mouse mode if requested. To support dragging, always use button - * mode. + * mode. For focus-follows-mouse, we need all-motion mode to receive + * movement events. */ if (options_get_number(oo, "mouse")) { if (c->overlay_draw == NULL) { @@ -2983,7 +2992,9 @@ server_client_reset_state(struct client *c) mode |= MODE_MOUSE_ALL; } } - if (~mode & MODE_MOUSE_ALL) + if (options_get_number(oo, "focus-follows-mouse")) + mode |= MODE_MOUSE_ALL; + else if (~mode & MODE_MOUSE_ALL) mode |= MODE_MOUSE_BUTTON; } diff --git a/tmux.1 b/tmux.1 index a93a002e..4b88e203 100644 --- a/tmux.1 +++ b/tmux.1 @@ -4242,6 +4242,12 @@ passed through to applications running in .Nm . Attached clients should be detached and attached again after changing this option. +.It Xo Ic focus-follows-mouse +.Op Ic on | off +.Xc +When enabled and +.Ic mouse +is on, moving the mouse into a pane selects it. .It Xo Ic get-clipboard .Op Ic both | request | buffer | off .Xc