From 7e4c63a33750250e738204284e35e4ec8d61b6ec Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Mon, 7 Oct 2024 08:50:48 +0000 Subject: 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. --- usr.bin/tmux/server-client.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'usr.bin/tmux/server-client.c') 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 @@ -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 { -- cgit v1.2.3