]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1907: xterm: no support for mouse buttons 8 and 9 v9.1.1907
authornotuxic <notuxic@gmail.com>
Tue, 11 Nov 2025 17:52:45 +0000 (17:52 +0000)
committerChristian Brabandt <cb@256bit.org>
Tue, 11 Nov 2025 17:52:45 +0000 (17:52 +0000)
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>
runtime/doc/term.txt
src/mouse.c
src/testdir/test_termcodes.vim
src/version.c
src/vim.h

index 784105fe6ec5452389d7861fb34519bf853d9fd0..4504c62d316519f973a69643062f17bc24e1d59d 100644 (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
@@ -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
 '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: >
        :noremap <MiddleMouse> <LeftMouse><MiddleMouse>
index 4bd1e592fcf50209ad9ffe970bc8f35a65fdc2b0..d11491005c9cda2b1ca5d9e1832db1c7b14ce516 100644 (file)
@@ -2316,6 +2316,10 @@ check_termcode_mouse(
         *         0x23 = any button release
         *         0x60 = button 4 down (scroll wheel down)
         *         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 0x08 for ALT
         *      add 0x10 for CTRL
@@ -2470,7 +2474,7 @@ check_termcode_mouse(
         * Linux console with GPM and the MS-DOS or Win32 console
         * (multi-clicks use >= 0x60).
         */
-       if (mouse_code >= MOUSEWHEEL_LOW
+       if (mouse_code >= MOUSEWHEEL_LOW && mouse_code < MOUSESIDEBUTTONS_LOW
 #  ifdef FEAT_GUI
                && !gui.in_use
 #  endif
@@ -2993,7 +2997,13 @@ check_termcode_mouse(
        held_button = MOUSE_RELEASE;
     }
     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);
+    }
 
 
     // Make sure the mouse position is valid.  Some terminals may return weird
index 652a1bf8c18c8369b47f7eb80921c2d49acfd62f..ffe3576ff0e26c5ee31cf21c973e6e1c43d628b2 100644 (file)
@@ -1641,6 +1641,62 @@ func Test_mouse_termcodes()
   %bw!
 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 must be after other tests, because it has side effects to xterm
 " properties.
index acb1c5d7cb91787a003ac715e52bf2a176a29a28..5578ccfc627d0815b8215cb69fc763a68c0083b1 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1907,
 /**/
     1906,
 /**/
index 58823ec78641768529521485a4b43b4eea8cc0f8..e41a68f1c2855566142729e0503dc1fa6d3f3c20 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -2095,6 +2095,9 @@ typedef int sock_T;
 // Lowest button code for using the mouse wheel (xterm only)
 #define MOUSEWHEEL_LOW         0x60
 
+// Lowest button code for extra mouse buttons 8-11
+#define MOUSESIDEBUTTONS_LOW           0xa0
+
 #define MOUSE_CLICK_MASK       0x03
 
 #define NUM_MOUSE_CLICKS(code) \