summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2024-10-07 08:50:48 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2024-10-07 08:50:48 +0000
commit7e4c63a33750250e738204284e35e4ec8d61b6ec (patch)
tree49d01c85b2fe9b59e2f0f9723e707aab12493217
parenta054ae2e1d116c6562ff5c04a18459242d9534a3 (diff)
Add initial-repeat-time option to allow the first repeat time to be
increased and later reduced, from David le Blanc in GitHub issue 4164.
-rw-r--r--usr.bin/tmux/options-table.c16
-rw-r--r--usr.bin/tmux/server-client.c33
-rw-r--r--usr.bin/tmux/tmux.127
-rw-r--r--usr.bin/tmux/tmux.h3
4 files changed, 66 insertions, 13 deletions
diff --git a/usr.bin/tmux/options-table.c b/usr.bin/tmux/options-table.c
index 93c60b6bf3c..69326c19004 100644
--- a/usr.bin/tmux/options-table.c
+++ b/usr.bin/tmux/options-table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options-table.c,v 1.180 2024/10/05 00:32:55 nicm Exp $ */
+/* $OpenBSD: options-table.c,v 1.181 2024/10/07 08:50:47 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -572,6 +572,18 @@ const struct options_table_entry options_table[] = {
"If changed, the new value applies only to new panes."
},
+ { .name = "initial-repeat-time",
+ .type = OPTIONS_TABLE_NUMBER,
+ .scope = OPTIONS_TABLE_SESSION,
+ .minimum = 0,
+ .maximum = 10000,
+ .default_num = 0,
+ .unit = "milliseconds",
+ .text = "Time to wait for a key binding to repeat the first time the "
+ "key is pressed, if it is bound with the '-r' flag. "
+ "Subsequent presses use the 'repeat-time' option."
+ },
+
{ .name = "key-table",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SESSION,
@@ -659,7 +671,7 @@ const struct options_table_entry options_table[] = {
.type = OPTIONS_TABLE_NUMBER,
.scope = OPTIONS_TABLE_SESSION,
.minimum = 0,
- .maximum = SHRT_MAX,
+ .maximum = 10000,
.default_num = 500,
.unit = "milliseconds",
.text = "Time to wait for a key binding to repeat, if it is bound "
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c
index c63c7628950..5c4539fada0 100644
--- a/usr.bin/tmux/server-client.c
+++ b/usr.bin/tmux/server-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server-client.c,v 1.411 2024/10/05 12:10:16 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.412 2024/10/07 08:50:47 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1866,6 +1866,26 @@ server_client_update_latest(struct client *c)
notify_client("client-active", c);
}
+/* Get repeat time. */
+static u_int
+server_client_repeat_time(struct client *c, struct key_binding *bd)
+{
+ struct session *s = c->session;
+ u_int repeat, initial;
+
+ if (~bd->flags & KEY_BINDING_REPEAT)
+ return (0);
+ repeat = options_get_number(s->options, "repeat-time");
+ if (repeat == 0)
+ return (0);
+ if ((~c->flags & CLIENT_REPEAT) || bd->key != c->last_key) {
+ initial = options_get_number(s->options, "initial-repeat-time");
+ if (initial != 0)
+ repeat = initial;
+ }
+ return (repeat);
+}
+
/*
* Handle data key input from client. This owns and can modify the key event it
* is given and is responsible for freeing it.
@@ -1884,7 +1904,7 @@ server_client_key_callback(struct cmdq_item *item, void *data)
struct timeval tv;
struct key_table *table, *first;
struct key_binding *bd;
- int xtimeout;
+ u_int repeat;
uint64_t flags, prefix_delay;
struct cmd_find_state fs;
key_code key0, prefix, prefix2;
@@ -2040,12 +2060,13 @@ try_again:
* If this is a repeating key, start the timer. Otherwise reset
* the client back to the root table.
*/
- xtimeout = options_get_number(s->options, "repeat-time");
- if (xtimeout != 0 && (bd->flags & KEY_BINDING_REPEAT)) {
+ repeat = server_client_repeat_time(c, bd);
+ if (repeat != 0) {
c->flags |= CLIENT_REPEAT;
+ c->last_key = bd->key;
- tv.tv_sec = xtimeout / 1000;
- tv.tv_usec = (xtimeout % 1000) * 1000L;
+ tv.tv_sec = repeat / 1000;
+ tv.tv_usec = (repeat % 1000) * 1000L;
evtimer_del(&c->repeat_timer);
evtimer_add(&c->repeat_timer, &tv);
} else {
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 3968f6760b5..0bb20ae6d61 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.962 2024/10/05 00:32:55 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.963 2024/10/07 08:50:47 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: October 5 2024 $
+.Dd $Mdocdate: October 7 2024 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -3687,8 +3687,10 @@ command used to switch to them from a key binding.
The
.Fl r
flag indicates this key may repeat, see the
+.Ic initial-repeat-time
+and
.Ic repeat-time
-option.
+options.
.Fl N
attaches a note to the key (shown with
.Ic list-keys
@@ -4436,6 +4438,20 @@ is in milliseconds.
Set the maximum number of lines held in window history.
This setting applies only to new windows - existing window histories are not
resized and retain the limit at the point they were created.
+.It Ic initial-repeat-time Ar time
+Set the time in milliseconds for the initial repeat when a key is bound with the
+.Fl r
+flag.
+This allows multiple commands to be entered without pressing the prefix key
+again.
+See also the
+.Ic repeat-time
+option.
+If
+.Ic initial-repeat-time
+is zero,
+.Ic repeat-time
+is used for the first key press.
.It Ic key-table Ar key-table
Set the default key table to
.Ar key-table
@@ -4544,7 +4560,7 @@ This respects the
option if it has been set.
If off, do not renumber the windows.
.It Ic repeat-time Ar time
-Allow multiple commands to be entered without pressing the prefix-key again
+Allow multiple commands to be entered without pressing the prefix key again
in the specified
.Ar time
milliseconds (the default is 500).
@@ -4555,6 +4571,9 @@ flag to
Repeat is enabled for the default keys bound to the
.Ic resize-pane
command.
+See also the
+.Ic initial-repeat-time
+option.
.It Xo Ic set-titles
.Op Ic on | off
.Xc
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index f8b52b2788a..1f6e4c4d9c2 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.1233 2024/10/04 19:16:13 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.1234 2024/10/07 08:50:47 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1909,6 +1909,7 @@ struct client {
char *exit_message;
struct key_table *keytable;
+ key_code last_key;
uint64_t redraw_panes;