From 903d1285474e6a1a8bfdc71e5c97f8037e5d801a Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 2 Sep 2023 20:03:10 +0000 Subject: [PATCH] Request terminal colours again on SIGWINCH but at most once every 30 seconds, GitHub issue 3582. --- usr.bin/tmux/server-client.c | 3 ++- usr.bin/tmux/tmux.h | 8 ++++---- usr.bin/tmux/tty-keys.c | 6 +----- usr.bin/tmux/tty.c | 28 +++++++++++++++++++++++----- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index c57e57ecf15..fb9f27ad311 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.401 2023/08/17 14:10:28 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.402 2023/09/02 20:03:10 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -2770,6 +2770,7 @@ server_client_dispatch(struct imsg *imsg, void *arg) break; server_client_update_latest(c); tty_resize(&c->tty); + tty_repeat_requests(&c->tty); recalculate_sizes(); if (c->overlay_resize == NULL) server_client_clear_overlay(c); diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index cdebd4b4f7b..74a86482af4 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1208 2023/09/02 09:17:23 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1209 2023/09/02 20:03:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1386,6 +1386,7 @@ struct tty { struct client *client; struct event start_timer; struct event clipboard_timer; + time_t last_requests; u_int sx; u_int sy; @@ -1437,10 +1438,8 @@ struct tty { #define TTY_HAVEXDA 0x200 #define TTY_SYNCING 0x400 #define TTY_HAVEDA2 0x800 /* Secondary DA. */ -#define TTY_HAVEFG 0x1000 -#define TTY_HAVEBG 0x2000 #define TTY_ALL_REQUEST_FLAGS \ - (TTY_HAVEDA|TTY_HAVEDA2|TTY_HAVEXDA|TTY_HAVEFG|TTY_HAVEBG) + (TTY_HAVEDA|TTY_HAVEDA2|TTY_HAVEXDA) int flags; struct tty_term *term; @@ -2333,6 +2332,7 @@ void tty_resize(struct tty *); void tty_set_size(struct tty *, u_int, u_int, u_int, u_int); void tty_start_tty(struct tty *); void tty_send_requests(struct tty *); +void tty_repeat_requests(struct tty *); void tty_stop_tty(struct tty *); void tty_set_title(struct tty *, const char *); void tty_set_path(struct tty *, const char *); diff --git a/usr.bin/tmux/tty-keys.c b/usr.bin/tmux/tty-keys.c index f72c6b36f82..38b4fe43540 100644 --- a/usr.bin/tmux/tty-keys.c +++ b/usr.bin/tmux/tty-keys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty-keys.c,v 1.167 2023/06/30 13:19:32 nicm Exp $ */ +/* $OpenBSD: tty-keys.c,v 1.168 2023/09/02 20:03:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1492,8 +1492,6 @@ tty_keys_colours(struct tty *tty, const char *buf, size_t len, size_t *size) int n; *size = 0; - if ((tty->flags & TTY_HAVEFG) && (tty->flags & TTY_HAVEBG)) - return (-1); /* First four bytes are always \033]1 and 0 or 1 and ;. */ if (buf[0] != '\033') @@ -1539,11 +1537,9 @@ tty_keys_colours(struct tty *tty, const char *buf, size_t len, size_t *size) if (n != -1 && buf[3] == '0') { log_debug("%s: foreground is %s", c->name, colour_tostring(n)); tty->fg = n; - tty->flags |= TTY_HAVEFG; } else if (n != -1) { log_debug("%s: background is %s", c->name, colour_tostring(n)); tty->bg = n; - tty->flags |= TTY_HAVEBG; } return (0); diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c index 00988286f83..efbc4a3cc4c 100644 --- a/usr.bin/tmux/tty.c +++ b/usr.bin/tmux/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.433 2023/09/02 09:17:23 nicm Exp $ */ +/* $OpenBSD: tty.c,v 1.434 2023/09/02 20:03:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -82,6 +82,7 @@ static void tty_check_overlay_range(struct tty *, u_int, u_int, u_int, #define TTY_BLOCK_STOP(tty) (1 + ((tty)->sx * (tty)->sy) / 8) #define TTY_QUERY_TIMEOUT 5 +#define TTY_REQUEST_LIMIT 30 void tty_create_log(void) @@ -369,12 +370,29 @@ tty_send_requests(struct tty *tty) tty_puts(tty, "\033[>c"); if (~tty->flags & TTY_HAVEXDA) tty_puts(tty, "\033[>q"); - if (~tty->flags & TTY_HAVEFG) - tty_puts(tty, "\033]10;?\033\\"); - if (~tty->flags & TTY_HAVEBG) - tty_puts(tty, "\033]11;?\033\\"); + tty_puts(tty, "\033]10;?\033\\"); + tty_puts(tty, "\033]11;?\033\\"); } else tty->flags |= TTY_ALL_REQUEST_FLAGS; + tty->last_requests = time (NULL); +} + +void +tty_repeat_requests(struct tty *tty) +{ + time_t t = time (NULL); + + if (~tty->flags & TTY_STARTED) + return; + + if (t - tty->last_requests <= TTY_REQUEST_LIMIT) + return; + tty->last_requests = t; + + if (tty->term->flags & TERM_VT100LIKE) { + tty_puts(tty, "\033]10;?\033\\"); + tty_puts(tty, "\033]11;?\033\\"); + } } void -- 2.20.1