From ffb89049131a1e381c7d2b313acb953009bae067 Mon Sep 17 00:00:00 2001 From: symphorien Date: Sun, 22 Apr 2018 17:26:04 +0000 Subject: [PATCH] tui/input.c: add support for mouse release events in urxvt (#8309) Some terminals don't report which buttons are involved in some mouse events. For example, the urxvt protocol (http://www.huge-man-linux.net/man7/urxvt.html section "Mouse reporting") does not report which button has been released. In this case libtermkey reports button 0 (http://www.leonerd.org.uk/code/libtermkey/doc/termkey_interpret_mouse.3.html) Up to now, forward_mouse_event did not handle button==0. On press events there is not much we can do, and we keep the current behavior which is dropping the event. But on drag-and-release events we can compensate by remembering the last button pressed. fixes #3182 for urxvt fixes #5400 --- src/nvim/tui/input.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index b04a6ce4f9..0362820687 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -170,11 +170,21 @@ static void forward_mouse_event(TermInput *input, TermKeyKey *key) char buf[64]; size_t len = 0; int button, row, col; + static int last_pressed_button = 0; TermKeyMouseEvent ev; termkey_interpret_mouse(input->tk, key, &ev, &button, &row, &col); - if (ev != TERMKEY_MOUSE_PRESS && ev != TERMKEY_MOUSE_DRAG - && ev != TERMKEY_MOUSE_RELEASE) { + if ((ev == TERMKEY_MOUSE_RELEASE || ev == TERMKEY_MOUSE_DRAG) + && button == 0) { + // Some terminals (like urxvt) don't report which button was released. + // libtermkey reports button 0 in this case. + // For drag and release, we can reasonably infer the button to be the last + // pressed one. + button = last_pressed_button; + } + + if (button == 0 || (ev != TERMKEY_MOUSE_PRESS && ev != TERMKEY_MOUSE_DRAG + && ev != TERMKEY_MOUSE_RELEASE)) { return; } @@ -210,6 +220,7 @@ static void forward_mouse_event(TermInput *input, TermKeyKey *key) "ScrollWheelDown"); } else { len += (size_t)snprintf(buf + len, sizeof(buf) - len, "Mouse"); + last_pressed_button = button; } break; case TERMKEY_MOUSE_DRAG: