From a94696defa108dcddc39d50596e69266e595eb74 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 19 Jun 2014 07:26:43 +0000 Subject: [PATCH] Some terminals send spurious releases for mouse wheel in SGR mouse mode, this causes confusion when tmux uses SGR outside but the application inside tmux is using conventional xterm mouse reporting. So suppress obviously bad input. From Timothy Allen, SF bug 128. --- tty-keys.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tty-keys.c b/tty-keys.c index 297e22c8..aaea06c6 100644 --- a/tty-keys.c +++ b/tty-keys.c @@ -475,6 +475,8 @@ tty_keys_next(struct tty *tty) goto complete_key; case -1: /* no, or not valid */ break; + case -2: /* yes, but we don't care. */ + goto discard_key; case 1: /* partial */ goto partial_key; } @@ -586,6 +588,14 @@ complete_key: server_client_handle_key(tty->client, key); return (1); + +discard_key: + log_debug("discard key %.*s %#x", (int) size, buf, key); + + /* Remove data from buffer. */ + evbuffer_drain(tty->event->input, size); + + return (1); } /* Key timer callback. */ @@ -730,6 +740,15 @@ tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size) sgr = 1; sgr_rel = (c == 'm'); + /* + * Some terminals (like PuTTY 0.63) mistakenly send + * button-release events for scroll-wheel button-press event. + * Discard it before it reaches any program running inside + * tmux. + */ + if (sgr_rel && (sgr_b & 64)) + return (-2); + /* Figure out what b would be in old format. */ b = sgr_b; if (sgr_rel)