From cfb906a0ceb18846ac52561c5def88d155c5e54b Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 1 Sep 2025 07:58:09 +0000 Subject: [PATCH] Increase the escape delay when waiting for an RGB response no matter when it is triggered (they can also be sent on resize). GitHub issue 4569. --- server-client.c | 4 ++-- tty-keys.c | 7 ++++--- tty.c | 46 ++++++++++++++++++++++++++++++++-------------- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/server-client.c b/server-client.c index 6a82900a..67311458 100644 --- a/server-client.c +++ b/server-client.c @@ -3358,7 +3358,7 @@ server_client_dispatch(struct imsg *imsg, void *arg) break; server_client_update_latest(c); tty_resize(&c->tty); - tty_repeat_requests(&c->tty); + tty_repeat_requests(&c->tty, 0); recalculate_sizes(); if (c->overlay_resize == NULL) server_client_clear_overlay(c); @@ -3958,5 +3958,5 @@ server_client_report_theme(struct client *c, enum client_theme theme) * Request foreground and background colour again. Don't forward 2031 to * panes until a response is received. */ - tty_puts(&c->tty, "\033]10;?\033\\\033]11;?\033\\"); + tty_repeat_requests(&c->tty, 1); } diff --git a/tty-keys.c b/tty-keys.c index 267b5379..a367d022 100644 --- a/tty-keys.c +++ b/tty-keys.c @@ -937,7 +937,8 @@ partial_key: delay = options_get_number(global_options, "escape-time"); if (delay == 0) delay = 1; - if ((tty->flags & TTY_ALL_REQUEST_FLAGS) != TTY_ALL_REQUEST_FLAGS) { + if ((tty->flags & (TTY_WAITFG|TTY_WAITBG) || + (tty->flags & TTY_ALL_REQUEST_FLAGS) != TTY_ALL_REQUEST_FLAGS)) { log_debug("%s: increasing delay for active query", c->name); if (delay < 500) delay = 500; @@ -1686,14 +1687,14 @@ tty_keys_colours(struct tty *tty, const char *buf, size_t len, size_t *size, else log_debug("fg is %s", colour_tostring(n)); *fg = n; - tty->flags |= TTY_HAVEFG; + tty->flags &= ~TTY_WAITFG; } else if (n != -1) { if (c != NULL) log_debug("%s bg is %s", c->name, colour_tostring(n)); else log_debug("bg is %s", colour_tostring(n)); *bg = n; - tty->flags |= TTY_HAVEBG; + tty->flags &= ~TTY_WAITBG; } return (0); diff --git a/tty.c b/tty.c index 0fd0ce71..9ecc0ca9 100644 --- a/tty.c +++ b/tty.c @@ -44,11 +44,11 @@ static void tty_cursor_pane_unless_wrap(struct tty *, const struct tty_ctx *, u_int, u_int); static void tty_colours(struct tty *, const struct grid_cell *); static void tty_check_fg(struct tty *, struct colour_palette *, - struct grid_cell *); + struct grid_cell *); static void tty_check_bg(struct tty *, struct colour_palette *, - struct grid_cell *); + struct grid_cell *); static void tty_check_us(struct tty *, struct colour_palette *, - struct grid_cell *); + struct grid_cell *); static void tty_colours_fg(struct tty *, const struct grid_cell *); static void tty_colours_bg(struct tty *, const struct grid_cell *); static void tty_colours_us(struct tty *, const struct grid_cell *); @@ -306,9 +306,23 @@ tty_start_timer_callback(__unused int fd, __unused short events, void *data) struct client *c = tty->client; log_debug("%s: start timer fired", c->name); + if ((tty->flags & (TTY_HAVEDA|TTY_HAVEDA2|TTY_HAVEXDA)) == 0) tty_update_features(tty); tty->flags |= TTY_ALL_REQUEST_FLAGS; + + tty->flags &= ~(TTY_WAITBG|TTY_WAITFG); +} + +static void +tty_start_start_timer(struct tty *tty) +{ + struct client *c = tty->client; + struct timeval tv = { .tv_sec = TTY_QUERY_TIMEOUT }; + + log_debug("%s: start timer started", c->name); + evtimer_set(&tty->start_timer, tty_start_timer_callback, tty); + evtimer_add(&tty->start_timer, &tv); } void @@ -316,7 +330,6 @@ tty_start_tty(struct tty *tty) { struct client *c = tty->client; struct termios tio; - struct timeval tv = { .tv_sec = TTY_QUERY_TIMEOUT }; setblocking(c->fd, 0); event_add(&tty->event_in, NULL); @@ -356,8 +369,7 @@ tty_start_tty(struct tty *tty) tty_puts(tty, "\033[?2031h\033[?996n"); } - evtimer_set(&tty->start_timer, tty_start_timer_callback, tty); - evtimer_add(&tty->start_timer, &tv); + tty_start_start_timer(tty); tty->flags |= TTY_STARTED; tty_invalidate(tty); @@ -383,29 +395,35 @@ tty_send_requests(struct tty *tty) tty_puts(tty, "\033[>c"); if (~tty->flags & TTY_HAVEXDA) tty_puts(tty, "\033[>q"); - tty_puts(tty, "\033]10;?\033\\"); - tty_puts(tty, "\033]11;?\033\\"); + tty_puts(tty, "\033]10;?\033\\\033]11;?\033\\"); + tty->flags |= (TTY_WAITBG|TTY_WAITFG); } else tty->flags |= TTY_ALL_REQUEST_FLAGS; tty->last_requests = time(NULL); } void -tty_repeat_requests(struct tty *tty) +tty_repeat_requests(struct tty *tty, int force) { + struct client *c = tty->client; time_t t = time(NULL); + u_int n = t - tty->last_requests; if (~tty->flags & TTY_STARTED) return; - if (t - tty->last_requests <= TTY_REQUEST_LIMIT) + if (!force && n <= TTY_REQUEST_LIMIT) { + log_debug("%s: not repeating requests (%u seconds)", c->name, n); return; + } + log_debug("%s: %srepeating requests (%u seconds)", c->name, force ? "(force) " : "" , n); tty->last_requests = t; if (tty->term->flags & TERM_VT100LIKE) { - tty_puts(tty, "\033]10;?\033\\"); - tty_puts(tty, "\033]11;?\033\\"); - } + tty_puts(tty, "\033]10;?\033\\\033]11;?\033\\"); + tty->flags |= (TTY_WAITBG|TTY_WAITFG); + } + tty_start_start_timer(tty); } void @@ -1643,7 +1661,7 @@ tty_sync_end(struct tty *tty) tty->flags &= ~TTY_SYNCING; if (tty_term_has(tty->term, TTYC_SYNC)) { - log_debug("%s sync end", tty->client->name); + log_debug("%s sync end", tty->client->name); tty_putcode_i(tty, TTYC_SYNC, 2); } }