From 835a6c0cf088437e318783c96b142c7dc26c290f Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 13 Jan 2020 08:12:53 +0000 Subject: [PATCH] Be more specific in the DSR we are looking for so it doesn't get confused with mouse sequences. Also set a flag and don't bother checking for it if we have already seen it (same for DA), and don't check if we never asked for it. --- tmux.h | 2 ++ tty-keys.c | 14 ++++++++++++++ tty.c | 5 +++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tmux.h b/tmux.h index 75e483c5..adc1a240 100644 --- a/tmux.h +++ b/tmux.h @@ -1227,6 +1227,8 @@ struct tty { #define TTY_OPENED 0x20 #define TTY_FOCUS 0x40 #define TTY_BLOCK 0x80 +#define TTY_HAVEDA 0x100 +#define TTY_HAVEDSR 0x200 int flags; struct tty_term *term; diff --git a/tty-keys.c b/tty-keys.c index 5054c424..968f67ca 100644 --- a/tty-keys.c +++ b/tty-keys.c @@ -1020,6 +1020,8 @@ tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len, int flags = 0; *size = 0; + if (tty->flags & TTY_HAVEDA) + return (-1); /* First three bytes are always \033[?. */ if (buf[0] != '\033') @@ -1064,7 +1066,10 @@ tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len, for (i = 1; i < n; i++) log_debug("%s: DA feature: %d", c->name, p[i]); log_debug("%s: received DA %.*s", c->name, (int)*size, buf); + tty_set_flags(tty, flags); + tty->flags |= TTY_HAVEDA; + return (0); } @@ -1082,6 +1087,8 @@ tty_keys_device_status_report(struct tty *tty, const char *buf, size_t len, int flags = 0; *size = 0; + if (tty->flags & TTY_HAVEDSR) + return (-1); /* First three bytes are always \033[. */ if (buf[0] != '\033') @@ -1092,6 +1099,10 @@ tty_keys_device_status_report(struct tty *tty, const char *buf, size_t len, return (-1); if (len == 2) return (1); + if (buf[2] != 'I') + return (-1); + if (len == 3) + return (1); /* Copy the rest up to a 'n'. */ for (i = 0; i < (sizeof tmp) - 1 && buf[2 + i] != 'n'; i++) { @@ -1108,6 +1119,9 @@ tty_keys_device_status_report(struct tty *tty, const char *buf, size_t len, if (strncmp(tmp, "ITERM2 ", 7) == 0) flags |= TERM_DECSLRM; log_debug("%s: received DSR %.*s", c->name, (int)*size, buf); + tty_set_flags(tty, flags); + tty->flags |= TTY_HAVEDSR; + return (0); } diff --git a/tty.c b/tty.c index 2d4b4cc0..a1324528 100644 --- a/tty.c +++ b/tty.c @@ -327,8 +327,9 @@ tty_start_tty(struct tty *tty) tty->flags |= TTY_FOCUS; tty_puts(tty, "\033[?1004h"); } - tty_puts(tty, "\033[c\033[1337n"); - } + tty_puts(tty, "\033[c\033[1337n"); /* DA and DSR */ + } else + tty->flags |= (TTY_HAVEDA|TTY_HAVEDSR); tty->flags |= TTY_STARTED; tty_invalidate(tty);