From f1193b48910aed15a2c73cdb5784a26f2ea0f64c Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 9 Nov 2020 10:54:28 +0000 Subject: [PATCH] If mouse bits change, clear them all and set again to avoid problems with some bits implying others. GitHub issue 2458. --- tty.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/tty.c b/tty.c index bcbccca6..777b639b 100644 --- a/tty.c +++ b/tty.c @@ -694,28 +694,26 @@ tty_update_mode(struct tty *tty, int mode, struct screen *s) } if ((changed & ALL_MOUSE_MODES) && tty_term_has(tty->term, TTYC_KMOUS)) { - if ((mode & ALL_MOUSE_MODES) == 0) + /* + * If the mouse modes have changed, clear any that are set and + * apply again. There are differences in how terminals track + * the various bits. + */ + if (tty->mode & MODE_MOUSE_SGR) tty_puts(tty, "\033[?1006l"); - if ((changed & MODE_MOUSE_STANDARD) && - (~mode & MODE_MOUSE_STANDARD)) + if (tty->mode & MODE_MOUSE_STANDARD) tty_puts(tty, "\033[?1000l"); - if ((changed & MODE_MOUSE_BUTTON) && - (~mode & MODE_MOUSE_BUTTON)) + if (tty->mode & MODE_MOUSE_BUTTON) tty_puts(tty, "\033[?1002l"); - if ((changed & MODE_MOUSE_ALL) && - (~mode & MODE_MOUSE_ALL)) + if (tty->mode & MODE_MOUSE_ALL) tty_puts(tty, "\033[?1003l"); - if (mode & ALL_MOUSE_MODES) tty_puts(tty, "\033[?1006h"); - if ((changed & MODE_MOUSE_STANDARD) && - (mode & MODE_MOUSE_STANDARD)) + if (mode & MODE_MOUSE_STANDARD) tty_puts(tty, "\033[?1000h"); - if ((changed & MODE_MOUSE_BUTTON) && - (mode & MODE_MOUSE_BUTTON)) + if (mode & MODE_MOUSE_BUTTON) tty_puts(tty, "\033[?1002h"); - if ((changed & MODE_MOUSE_ALL) && - (mode & MODE_MOUSE_ALL)) + if (mode & MODE_MOUSE_ALL) tty_puts(tty, "\033[?1003h"); } if (changed & MODE_BRACKETPASTE) {