Skip to content

Commit 7dd51d3

Browse files
notuxicchrisbra
authored andcommitted
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 <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent efc3be7 commit 7dd51d3

5 files changed

Lines changed: 75 additions & 3 deletions

File tree

runtime/doc/term.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*term.txt* For Vim version 9.1. Last change: 2025 Nov 09
1+
*term.txt* For Vim version 9.1. Last change: 2025 Nov 11
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1167,7 +1167,8 @@ Mouse clicks can be mapped. The codes for mouse clicks are:
11671167

11681168
The X1 and X2 buttons refer to the extra buttons found on some mice. The
11691169
'Microsoft Explorer' mouse has these buttons available to the right thumb.
1170-
Currently X1 and X2 only work on Win32 and X11 environments.
1170+
Currently, X1 and X2 work only on Win32 and X11 environments, and in terminals
1171+
that support xterm-like mouse functionality.
11711172

11721173
Examples: >
11731174
:noremap <MiddleMouse> <LeftMouse><MiddleMouse>

src/mouse.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2316,6 +2316,10 @@ check_termcode_mouse(
23162316
* 0x23 = any button release
23172317
* 0x60 = button 4 down (scroll wheel down)
23182318
* 0x61 = button 5 down (scroll wheel up)
2319+
* 0x62 = button 6 down (scroll wheel left)
2320+
* 0x63 = button 7 down (scroll wheel right)
2321+
* 0xa0 = button 8 down (backward button)
2322+
* 0xa1 = button 9 down (forward button)
23192323
* add 0x04 for SHIFT
23202324
* add 0x08 for ALT
23212325
* add 0x10 for CTRL
@@ -2470,7 +2474,7 @@ check_termcode_mouse(
24702474
* Linux console with GPM and the MS-DOS or Win32 console
24712475
* (multi-clicks use >= 0x60).
24722476
*/
2473-
if (mouse_code >= MOUSEWHEEL_LOW
2477+
if (mouse_code >= MOUSEWHEEL_LOW && mouse_code < MOUSESIDEBUTTONS_LOW
24742478
# ifdef FEAT_GUI
24752479
&& !gui.in_use
24762480
# endif
@@ -2993,7 +2997,13 @@ check_termcode_mouse(
29932997
held_button = MOUSE_RELEASE;
29942998
}
29952999
else
3000+
{
3001+
#if defined(UNIX)
3002+
if (use_xterm_mouse() && orig_mouse_code >= MOUSESIDEBUTTONS_LOW)
3003+
current_button = (current_button) ? MOUSE_X2 : MOUSE_X1;
3004+
#endif
29963005
key_name[1] = get_pseudo_mouse_code(current_button, is_click, is_drag);
3006+
}
29973007

29983008

29993009
// Make sure the mouse position is valid. Some terminals may return weird

src/testdir/test_termcodes.vim

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,62 @@ func Test_mouse_termcodes()
16411641
%bw!
16421642
endfunc
16431643

1644+
" Test buttons 8 and 9 for xterm-like terminal mouse support
1645+
func Test_term_mouse_side_buttons()
1646+
new
1647+
let save_mouse = &mouse
1648+
let save_term = &term
1649+
let save_ttymouse = &ttymouse
1650+
call test_override('no_query_mouse', 1)
1651+
set mouse=a term=xterm
1652+
call WaitForResponses()
1653+
1654+
for ttymouse_val in g:Ttymouse_values
1655+
let msg = 'ttymouse=' .. ttymouse_val
1656+
exe 'set ttymouse=' .. ttymouse_val
1657+
1658+
let mouse_codes = [
1659+
\ ["<X1Mouse>", TerminalEscapeCode(128, 1, 1, 'M')],
1660+
\ ["<X1Drag>", TerminalEscapeCode(128+32, 1, 1, 'M')],
1661+
\ ["<X2Mouse>", TerminalEscapeCode(129, 1, 1, 'M')],
1662+
\ ["<X2Drag>", TerminalEscapeCode(129+32, 1, 1, 'M')],
1663+
\ ["<S-X1Mouse>", TerminalEscapeCode(128+4, 1, 1, 'M')],
1664+
\ ["<S-X2Mouse>", TerminalEscapeCode(129+4, 1, 1, 'M')],
1665+
\ ["<M-X1Mouse>", TerminalEscapeCode(128+8, 1, 1, 'M')],
1666+
\ ["<M-X2Mouse>", TerminalEscapeCode(129+8, 1, 1, 'M')],
1667+
\ ["<C-X1Mouse>", TerminalEscapeCode(128+16, 1, 1, 'M')],
1668+
\ ["<C-X2Mouse>", TerminalEscapeCode(129+16, 1, 1, 'M')],
1669+
\ ]
1670+
1671+
for [outstr, code] in mouse_codes
1672+
exe "normal ggC\<C-K>" . code
1673+
call assert_equal(outstr, getline(1), msg)
1674+
endfor
1675+
endfor
1676+
1677+
" ttymouse_val 'sgr'
1678+
let msg = 'ttymouse=sgr'
1679+
exe 'set ttymouse=sgr'
1680+
1681+
let mouse_codes = [
1682+
\ ["<X1Mouse>", TerminalEscapeCode(128, 1, 1, 'M')],
1683+
\ ["<X1Release>", TerminalEscapeCode(128, 1, 1, 'm')],
1684+
\ ["<X2Mouse>", TerminalEscapeCode(129, 1, 1, 'M')],
1685+
\ ["<X2Release>", TerminalEscapeCode(129, 1, 1, 'm')],
1686+
\ ]
1687+
1688+
for [outstr, code] in mouse_codes
1689+
exe "normal ggC\<C-K>" . code
1690+
call assert_equal(outstr, getline(1), msg)
1691+
endfor
1692+
1693+
let &mouse = save_mouse
1694+
let &term = save_term
1695+
let &ttymouse = save_ttymouse
1696+
call test_override('no_query_mouse', 0)
1697+
bwipe!
1698+
endfunc
1699+
16441700
" This only checks if the sequence is recognized.
16451701
" This must be after other tests, because it has side effects to xterm
16461702
" properties.

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,8 @@ static char *(features[]) =
729729

730730
static int included_patches[] =
731731
{ /* Add new patch number below this line */
732+
/**/
733+
1907,
732734
/**/
733735
1906,
734736
/**/

src/vim.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,9 @@ typedef int sock_T;
20952095
// Lowest button code for using the mouse wheel (xterm only)
20962096
#define MOUSEWHEEL_LOW 0x60
20972097

2098+
// Lowest button code for extra mouse buttons 8-11
2099+
#define MOUSESIDEBUTTONS_LOW 0xa0
2100+
20982101
#define MOUSE_CLICK_MASK 0x03
20992102

21002103
#define NUM_MOUSE_CLICKS(code) \

0 commit comments

Comments
 (0)