diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/terminal.c | 22 | ||||
-rw-r--r-- | src/nvim/vterm/mouse.c | 27 |
2 files changed, 38 insertions, 11 deletions
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 197a225209..897c393488 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -792,17 +792,23 @@ static int terminal_execute(VimState *state, int key) case K_LEFTMOUSE: case K_LEFTDRAG: case K_LEFTRELEASE: - case K_MOUSEMOVE: case K_MIDDLEMOUSE: case K_MIDDLEDRAG: case K_MIDDLERELEASE: case K_RIGHTMOUSE: case K_RIGHTDRAG: case K_RIGHTRELEASE: + case K_X1MOUSE: + case K_X1DRAG: + case K_X1RELEASE: + case K_X2MOUSE: + case K_X2DRAG: + case K_X2RELEASE: case K_MOUSEDOWN: case K_MOUSEUP: case K_MOUSELEFT: case K_MOUSERIGHT: + case K_MOUSEMOVE: if (send_mouse_event(s->term, key)) { return 0; } @@ -1804,8 +1810,6 @@ static bool send_mouse_event(Terminal *term, int c) pressed = true; FALLTHROUGH; case K_LEFTRELEASE: button = 1; break; - case K_MOUSEMOVE: - button = 0; break; case K_MIDDLEDRAG: case K_MIDDLEMOUSE: pressed = true; FALLTHROUGH; @@ -1816,6 +1820,16 @@ static bool send_mouse_event(Terminal *term, int c) pressed = true; FALLTHROUGH; case K_RIGHTRELEASE: button = 3; break; + case K_X1DRAG: + case K_X1MOUSE: + pressed = true; FALLTHROUGH; + case K_X1RELEASE: + button = 8; break; + case K_X2DRAG: + case K_X2MOUSE: + pressed = true; FALLTHROUGH; + case K_X2RELEASE: + button = 9; break; case K_MOUSEDOWN: pressed = true; button = 4; break; case K_MOUSEUP: @@ -1824,6 +1838,8 @@ static bool send_mouse_event(Terminal *term, int c) pressed = true; button = 7; break; case K_MOUSERIGHT: pressed = true; button = 6; break; + case K_MOUSEMOVE: + button = 0; break; default: return false; } diff --git a/src/nvim/vterm/mouse.c b/src/nvim/vterm/mouse.c index 9b8be4b60a..2f3b1d9e2f 100644 --- a/src/nvim/vterm/mouse.c +++ b/src/nvim/vterm/mouse.c @@ -1,3 +1,4 @@ +#include "nvim/math.h" #include "nvim/tui/termkey/termkey.h" #include "nvim/vterm/mouse.h" #include "nvim/vterm/vterm.h" @@ -24,6 +25,9 @@ static void output_mouse(VTermState *state, int code, int pressed, int modifiers code = 3; } + if (code & 0x80) { + break; + } vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "M%c%c%c", (code | modifiers) + 0x20, col + 0x21, row + 0x21); break; @@ -74,11 +78,16 @@ void vterm_mouse_move(VTerm *vt, int row, int col, VTermModifier mod) if ((state->mouse_flags & MOUSE_WANT_DRAG && state->mouse_buttons) || (state->mouse_flags & MOUSE_WANT_MOVE)) { - int button = state->mouse_buttons & 0x01 ? 1 - : state->mouse_buttons & 0x02 ? 2 - : state->mouse_buttons & - 0x04 ? 3 : 4; - output_mouse(state, button - 1 + 0x20, 1, (int)mod, col, row); + if (state->mouse_buttons) { + int button = xctz((uint64_t)state->mouse_buttons) + 1; + if (button < 4) { + output_mouse(state, button - 1 + 0x20, 1, (int)mod, col, row); + } else if (button >= 8 && button < 12) { + output_mouse(state, button - 8 + 0x80 + 0x20, 1, (int)mod, col, row); + } + } else { + output_mouse(state, 3 + 0x20, 1, (int)mod, col, row); + } } } @@ -88,7 +97,7 @@ void vterm_mouse_button(VTerm *vt, int button, bool pressed, VTermModifier mod) int old_buttons = state->mouse_buttons; - if (button > 0 && button <= 3) { + if ((button > 0 && button <= 3) || (button >= 8 && button <= 11)) { if (pressed) { state->mouse_buttons |= (1 << (button - 1)); } else { @@ -96,8 +105,8 @@ void vterm_mouse_button(VTerm *vt, int button, bool pressed, VTermModifier mod) } } - // Most of the time we don't get button releases from 4/5 - if (state->mouse_buttons == old_buttons && button < 4) { + // Most of the time we don't get button releases from 4/5/6/7 + if (state->mouse_buttons == old_buttons && (button < 4 || button > 7)) { return; } @@ -109,5 +118,7 @@ void vterm_mouse_button(VTerm *vt, int button, bool pressed, VTermModifier mod) output_mouse(state, button - 1, pressed, (int)mod, state->mouse_col, state->mouse_row); } else if (button < 8) { output_mouse(state, button - 4 + 0x40, pressed, (int)mod, state->mouse_col, state->mouse_row); + } else if (button < 12) { + output_mouse(state, button - 8 + 0x80, pressed, (int)mod, state->mouse_col, state->mouse_row); } } |