mirror of
https://github.com/neovim/neovim.git
synced 2025-10-17 23:31:51 +00:00
feat(terminal): forward X1 and X2 mouse events
Ref: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Other-buttons
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user