1+ #include "nvim/math.h"
12#include "nvim/tui/termkey/termkey.h"
23#include "nvim/vterm/mouse.h"
34#include "nvim/vterm/vterm.h"
@@ -24,6 +25,9 @@ static void output_mouse(VTermState *state, int code, int pressed, int modifiers
2425 code = 3 ;
2526 }
2627
28+ if (code & 0x80 ) {
29+ break ;
30+ }
2731 vterm_push_output_sprintf_ctrl (state -> vt , C1_CSI , "M%c%c%c" ,
2832 (code | modifiers ) + 0x20 , col + 0x21 , row + 0x21 );
2933 break ;
@@ -74,11 +78,16 @@ void vterm_mouse_move(VTerm *vt, int row, int col, VTermModifier mod)
7478
7579 if ((state -> mouse_flags & MOUSE_WANT_DRAG && state -> mouse_buttons )
7680 || (state -> mouse_flags & MOUSE_WANT_MOVE )) {
77- int button = state -> mouse_buttons & 0x01 ? 1
78- : state -> mouse_buttons & 0x02 ? 2
79- : state -> mouse_buttons &
80- 0x04 ? 3 : 4 ;
81- output_mouse (state , button - 1 + 0x20 , 1 , (int )mod , col , row );
81+ if (state -> mouse_buttons ) {
82+ int button = xctz ((uint64_t )state -> mouse_buttons ) + 1 ;
83+ if (button < 4 ) {
84+ output_mouse (state , button - 1 + 0x20 , 1 , (int )mod , col , row );
85+ } else if (button >= 8 && button < 12 ) {
86+ output_mouse (state , button - 8 + 0x80 + 0x20 , 1 , (int )mod , col , row );
87+ }
88+ } else {
89+ output_mouse (state , 3 + 0x20 , 1 , (int )mod , col , row );
90+ }
8291 }
8392}
8493
@@ -88,16 +97,16 @@ void vterm_mouse_button(VTerm *vt, int button, bool pressed, VTermModifier mod)
8897
8998 int old_buttons = state -> mouse_buttons ;
9099
91- if (button > 0 && button <= 3 ) {
100+ if (( button > 0 && button <= 3 ) || ( button >= 8 && button <= 11 ) ) {
92101 if (pressed ) {
93102 state -> mouse_buttons |= (1 << (button - 1 ));
94103 } else {
95104 state -> mouse_buttons &= ~(1 << (button - 1 ));
96105 }
97106 }
98107
99- // Most of the time we don't get button releases from 4/5
100- if (state -> mouse_buttons == old_buttons && button < 4 ) {
108+ // Most of the time we don't get button releases from 4/5/6/7
109+ if (state -> mouse_buttons == old_buttons && ( button < 4 || button > 7 ) ) {
101110 return ;
102111 }
103112
@@ -109,5 +118,7 @@ void vterm_mouse_button(VTerm *vt, int button, bool pressed, VTermModifier mod)
109118 output_mouse (state , button - 1 , pressed , (int )mod , state -> mouse_col , state -> mouse_row );
110119 } else if (button < 8 ) {
111120 output_mouse (state , button - 4 + 0x40 , pressed , (int )mod , state -> mouse_col , state -> mouse_row );
121+ } else if (button < 12 ) {
122+ output_mouse (state , button - 8 + 0x80 , pressed , (int )mod , state -> mouse_col , state -> mouse_row );
112123 }
113124}
0 commit comments