0
0
mirror of https://github.com/vim/vim.git synced 2025-11-15 23:14:06 -05:00

patch 9.1.1907: xterm: no support for mouse buttons 8 and 9

Problem:  xterm: no support for mouse buttons 8 and 9
Solution: Add support for terminals with xterm-like mouse functionality
          (notuxic)

closes: #18719

Signed-off-by: notuxic <notuxic@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
notuxic
2025-11-11 17:52:45 +00:00
committed by Christian Brabandt
parent efc3be77bb
commit 7dd51d3542
5 changed files with 75 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
*term.txt* For Vim version 9.1. Last change: 2025 Nov 09 *term.txt* For Vim version 9.1. Last change: 2025 Nov 11
VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1167,7 +1167,8 @@ Mouse clicks can be mapped. The codes for mouse clicks are:
The X1 and X2 buttons refer to the extra buttons found on some mice. The The X1 and X2 buttons refer to the extra buttons found on some mice. The
'Microsoft Explorer' mouse has these buttons available to the right thumb. 'Microsoft Explorer' mouse has these buttons available to the right thumb.
Currently X1 and X2 only work on Win32 and X11 environments. Currently, X1 and X2 work only on Win32 and X11 environments, and in terminals
that support xterm-like mouse functionality.
Examples: > Examples: >
:noremap <MiddleMouse> <LeftMouse><MiddleMouse> :noremap <MiddleMouse> <LeftMouse><MiddleMouse>

View File

@@ -2316,6 +2316,10 @@ check_termcode_mouse(
* 0x23 = any button release * 0x23 = any button release
* 0x60 = button 4 down (scroll wheel down) * 0x60 = button 4 down (scroll wheel down)
* 0x61 = button 5 down (scroll wheel up) * 0x61 = button 5 down (scroll wheel up)
* 0x62 = button 6 down (scroll wheel left)
* 0x63 = button 7 down (scroll wheel right)
* 0xa0 = button 8 down (backward button)
* 0xa1 = button 9 down (forward button)
* add 0x04 for SHIFT * add 0x04 for SHIFT
* add 0x08 for ALT * add 0x08 for ALT
* add 0x10 for CTRL * add 0x10 for CTRL
@@ -2470,7 +2474,7 @@ check_termcode_mouse(
* Linux console with GPM and the MS-DOS or Win32 console * Linux console with GPM and the MS-DOS or Win32 console
* (multi-clicks use >= 0x60). * (multi-clicks use >= 0x60).
*/ */
if (mouse_code >= MOUSEWHEEL_LOW if (mouse_code >= MOUSEWHEEL_LOW && mouse_code < MOUSESIDEBUTTONS_LOW
# ifdef FEAT_GUI # ifdef FEAT_GUI
&& !gui.in_use && !gui.in_use
# endif # endif
@@ -2993,7 +2997,13 @@ check_termcode_mouse(
held_button = MOUSE_RELEASE; held_button = MOUSE_RELEASE;
} }
else else
{
#if defined(UNIX)
if (use_xterm_mouse() && orig_mouse_code >= MOUSESIDEBUTTONS_LOW)
current_button = (current_button) ? MOUSE_X2 : MOUSE_X1;
#endif
key_name[1] = get_pseudo_mouse_code(current_button, is_click, is_drag); key_name[1] = get_pseudo_mouse_code(current_button, is_click, is_drag);
}
// Make sure the mouse position is valid. Some terminals may return weird // Make sure the mouse position is valid. Some terminals may return weird

View File

@@ -1641,6 +1641,62 @@ func Test_mouse_termcodes()
%bw! %bw!
endfunc endfunc
" Test buttons 8 and 9 for xterm-like terminal mouse support
func Test_term_mouse_side_buttons()
new
let save_mouse = &mouse
let save_term = &term
let save_ttymouse = &ttymouse
call test_override('no_query_mouse', 1)
set mouse=a term=xterm
call WaitForResponses()
for ttymouse_val in g:Ttymouse_values
let msg = 'ttymouse=' .. ttymouse_val
exe 'set ttymouse=' .. ttymouse_val
let mouse_codes = [
\ ["<X1Mouse>", TerminalEscapeCode(128, 1, 1, 'M')],
\ ["<X1Drag>", TerminalEscapeCode(128+32, 1, 1, 'M')],
\ ["<X2Mouse>", TerminalEscapeCode(129, 1, 1, 'M')],
\ ["<X2Drag>", TerminalEscapeCode(129+32, 1, 1, 'M')],
\ ["<S-X1Mouse>", TerminalEscapeCode(128+4, 1, 1, 'M')],
\ ["<S-X2Mouse>", TerminalEscapeCode(129+4, 1, 1, 'M')],
\ ["<M-X1Mouse>", TerminalEscapeCode(128+8, 1, 1, 'M')],
\ ["<M-X2Mouse>", TerminalEscapeCode(129+8, 1, 1, 'M')],
\ ["<C-X1Mouse>", TerminalEscapeCode(128+16, 1, 1, 'M')],
\ ["<C-X2Mouse>", TerminalEscapeCode(129+16, 1, 1, 'M')],
\ ]
for [outstr, code] in mouse_codes
exe "normal ggC\<C-K>" . code
call assert_equal(outstr, getline(1), msg)
endfor
endfor
" ttymouse_val 'sgr'
let msg = 'ttymouse=sgr'
exe 'set ttymouse=sgr'
let mouse_codes = [
\ ["<X1Mouse>", TerminalEscapeCode(128, 1, 1, 'M')],
\ ["<X1Release>", TerminalEscapeCode(128, 1, 1, 'm')],
\ ["<X2Mouse>", TerminalEscapeCode(129, 1, 1, 'M')],
\ ["<X2Release>", TerminalEscapeCode(129, 1, 1, 'm')],
\ ]
for [outstr, code] in mouse_codes
exe "normal ggC\<C-K>" . code
call assert_equal(outstr, getline(1), msg)
endfor
let &mouse = save_mouse
let &term = save_term
let &ttymouse = save_ttymouse
call test_override('no_query_mouse', 0)
bwipe!
endfunc
" This only checks if the sequence is recognized. " This only checks if the sequence is recognized.
" This must be after other tests, because it has side effects to xterm " This must be after other tests, because it has side effects to xterm
" properties. " properties.

View File

@@ -729,6 +729,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1907,
/**/ /**/
1906, 1906,
/**/ /**/

View File

@@ -2095,6 +2095,9 @@ typedef int sock_T;
// Lowest button code for using the mouse wheel (xterm only) // Lowest button code for using the mouse wheel (xterm only)
#define MOUSEWHEEL_LOW 0x60 #define MOUSEWHEEL_LOW 0x60
// Lowest button code for extra mouse buttons 8-11
#define MOUSESIDEBUTTONS_LOW 0xa0
#define MOUSE_CLICK_MASK 0x03 #define MOUSE_CLICK_MASK 0x03
#define NUM_MOUSE_CLICKS(code) \ #define NUM_MOUSE_CLICKS(code) \