1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Cannot select beyond 222 columns with the mouse in xterm.
12 Solution: Add support for SGR mouse tracking. (Hayaki Saito)
13 Files: runtime/doc/options.txt, src/feature.h, src/keymap.h, src/misc2.c,
14 src/option.h, src/os_unix.c, src/term.c, src/version.c
17 *** ../vim-7.3.631/runtime/doc/options.txt 2012-07-10 16:49:08.000000000 +0200
18 --- runtime/doc/options.txt 2012-08-15 16:04:26.000000000 +0200
22 jsbterm JSB term mouse handling.
24 pterm QNX pterm mouse handling.
26 + urxvt Mouse handling for the urxvt (rxvt-unicode) terminal.
28 + sgr Mouse handling for the terminal that emits SGR-styled
29 + mouse reporting. Works with xterm version 277 or
32 The mouse handling must be enabled at compile time |+mouse_xterm|
33 |+mouse_dec| |+mouse_netterm|.
37 or "xterm2" already. The main use of this option is to set it to
38 "xterm", when the terminal name doesn't start with "xterm", but it can
39 handle xterm mouse codes.
40 + The "sgr" value will be set if the xterm version is 277 or later.
41 The "xterm2" value will be set if the xterm version is reported to be
42 95 or higher. This only works when compiled with the |+termresponse|
43 feature and if |t_RV| is set to the escape sequence to request the
44 *** ../vim-7.3.631/src/feature.h 2012-04-25 16:50:44.000000000 +0200
45 --- src/feature.h 2012-08-15 15:46:07.000000000 +0200
50 # define FEAT_MOUSE_URXVT
53 + # define FEAT_MOUSE_SGR
55 # if defined(FEAT_NORMAL) && (defined(MSDOS) || defined(WIN3264))
61 # define FEAT_MOUSE_XTERM
64 + /* sgr is a small variation of mouse_xterm, and shares its code */
65 + #if defined(FEAT_MOUSE_SGR) && !defined(FEAT_MOUSE_XTERM)
66 + # define FEAT_MOUSE_XTERM
69 /* Define FEAT_MOUSE when any of the above is defined or FEAT_GUI. */
70 #if !defined(FEAT_MOUSE_TTY) \
71 && (defined(FEAT_MOUSE_XTERM) \
74 || defined(FEAT_MOUSE_JSB) \
75 || defined(FEAT_MOUSE_PTERM) \
76 || defined(FEAT_SYSMOUSE) \
77 ! || defined(FEAT_MOUSE_URXVT))
78 # define FEAT_MOUSE_TTY /* include non-GUI mouse support */
80 #if !defined(FEAT_MOUSE) && (defined(FEAT_MOUSE_TTY) || defined(FEAT_GUI))
82 || defined(FEAT_MOUSE_JSB) \
83 || defined(FEAT_MOUSE_PTERM) \
84 || defined(FEAT_SYSMOUSE) \
85 ! || defined(FEAT_MOUSE_URXVT) \
86 ! || defined(FEAT_MOUSE_SGR))
87 # define FEAT_MOUSE_TTY /* include non-GUI mouse support */
89 #if !defined(FEAT_MOUSE) && (defined(FEAT_MOUSE_TTY) || defined(FEAT_GUI))
90 *** ../vim-7.3.631/src/keymap.h 2012-01-20 17:15:47.000000000 +0100
91 --- src/keymap.h 2012-08-15 15:46:07.000000000 +0200
95 /* Used for the urxvt mouse. */
96 #define KS_URXVT_MOUSE 238
98 + /* Used for the sgr mouse. */
99 + #define KS_SGR_MOUSE 237
102 * Filler used after KS_SPECIAL and others
107 #define K_JSBTERM_MOUSE TERMCAP2KEY(KS_JSBTERM_MOUSE, KE_FILLER)
108 #define K_PTERM_MOUSE TERMCAP2KEY(KS_PTERM_MOUSE, KE_FILLER)
109 #define K_URXVT_MOUSE TERMCAP2KEY(KS_URXVT_MOUSE, KE_FILLER)
110 + #define K_SGR_MOUSE TERMCAP2KEY(KS_SGR_MOUSE, KE_FILLER)
112 #define K_SELECT TERMCAP2KEY(KS_SELECT, KE_FILLER)
113 #define K_TEAROFF TERMCAP2KEY(KS_TEAROFF, KE_FILLER)
114 *** ../vim-7.3.631/src/misc2.c 2012-08-15 14:04:50.000000000 +0200
115 --- src/misc2.c 2012-08-15 15:46:07.000000000 +0200
119 #ifdef FEAT_MOUSE_URXVT
120 {K_URXVT_MOUSE, (char_u *)"UrxvtMouse"},
122 + #ifdef FEAT_MOUSE_SGR
123 + {K_SGR_MOUSE, (char_u *)"SgrMouse"},
125 {K_LEFTMOUSE, (char_u *)"LeftMouse"},
126 {K_LEFTMOUSE_NM, (char_u *)"LeftMouseNM"},
127 {K_LEFTDRAG, (char_u *)"LeftDrag"},
128 *** ../vim-7.3.631/src/option.h 2012-07-10 16:49:08.000000000 +0200
129 --- src/option.h 2012-08-15 15:46:07.000000000 +0200
132 EXTERN char_u *p_ttym; /* 'ttymouse' */
133 EXTERN unsigned ttym_flags;
135 ! static char *(p_ttym_values[]) = {"xterm", "xterm2", "dec", "netterm", "jsbterm", "pterm", "urxvt", NULL};
137 # define TTYM_XTERM 0x01
138 # define TTYM_XTERM2 0x02
140 EXTERN char_u *p_ttym; /* 'ttymouse' */
141 EXTERN unsigned ttym_flags;
143 ! static char *(p_ttym_values[]) = {"xterm", "xterm2", "dec", "netterm", "jsbterm", "pterm", "urxvt", "sgr", NULL};
145 # define TTYM_XTERM 0x01
146 # define TTYM_XTERM2 0x02
150 # define TTYM_JSBTERM 0x10
151 # define TTYM_PTERM 0x20
152 # define TTYM_URXVT 0x40
153 + # define TTYM_SGR 0x80
155 EXTERN char_u *p_udir; /* 'undodir' */
156 EXTERN long p_ul; /* 'undolevels' */
157 *** ../vim-7.3.631/src/os_unix.c 2012-04-20 15:55:10.000000000 +0200
158 --- src/os_unix.c 2012-08-15 16:06:54.000000000 +0200
162 * Return 1 for "xterm".
163 * Return 2 for "xterm2".
164 * Return 3 for "urxvt".
165 + * Return 4 for "sgr".
170 + if (ttym_flags == TTYM_SGR)
172 if (ttym_flags == TTYM_URXVT)
174 if (ttym_flags == TTYM_XTERM2)
177 xterm_mouse_vers = use_xterm_mouse();
179 # ifdef FEAT_MOUSE_URXVT
180 ! if (ttym_flags == TTYM_URXVT) {
181 out_str_nf((char_u *)
183 ? IF_EB("\033[?1015h", ESC_STR "[?1015h")
185 xterm_mouse_vers = use_xterm_mouse();
187 # ifdef FEAT_MOUSE_URXVT
188 ! if (ttym_flags == TTYM_URXVT)
190 out_str_nf((char_u *)
192 ? IF_EB("\033[?1015h", ESC_STR "[?1015h")
199 + # ifdef FEAT_MOUSE_SGR
200 + if (ttym_flags == TTYM_SGR)
202 + out_str_nf((char_u *)
204 + ? IF_EB("\033[?1006h", ESC_STR "[?1006h")
205 + : IF_EB("\033[?1006l", ESC_STR "[?1006l")));
210 if (xterm_mouse_vers > 0)
212 if (on) /* enable mouse events, use mouse tracking if available */
217 del_mouse_termcode(KS_URXVT_MOUSE);
219 + # ifdef FEAT_MOUSE_SGR
220 + /* same as the dec mouse */
221 + if (use_xterm_mouse() == 4
227 + set_mouse_termcode(KS_SGR_MOUSE, (char_u *)(term_is_8bit(T_NAME)
228 + ? IF_EB("\233<", CSI_STR "<")
229 + : IF_EB("\033[<", ESC_STR "[<")));
231 + if (*p_mouse != NUL)
233 + mch_setmouse(FALSE);
238 + del_mouse_termcode(KS_SGR_MOUSE);
243 *** ../vim-7.3.631/src/term.c 2012-02-05 22:05:44.000000000 +0100
244 --- src/term.c 2012-08-15 16:14:09.000000000 +0200
248 # define HMT_JSBTERM 8
249 # define HMT_PTERM 16
250 # define HMT_URXVT 32
251 + # define HMT_SGR 64
252 static int has_mouse_termcode = 0;
258 has_mouse_termcode |= HMT_URXVT;
261 + # ifdef FEAT_MOUSE_SGR
262 + if (n == KS_SGR_MOUSE)
263 + has_mouse_termcode |= HMT_SGR;
266 has_mouse_termcode |= HMT_NORMAL;
272 has_mouse_termcode &= ~HMT_URXVT;
275 + # ifdef FEAT_MOUSE_SGR
276 + if (n == KS_SGR_MOUSE)
277 + has_mouse_termcode &= ~HMT_SGR;
280 has_mouse_termcode &= ~HMT_NORMAL;
285 #ifdef FEAT_TERMRESPONSE
286 if (key_name[0] == NUL
287 /* URXVT mouse uses <ESC>[#;#;#M, but we are matching <ESC>[ */
288 ! || key_name[0] == KS_URXVT_MOUSE)
290 /* Check for xterm version string: "<Esc>[>{x};{vers};{y}c". Also
291 * eat other possible responses to t_RV, rxvt returns
293 #ifdef FEAT_TERMRESPONSE
294 if (key_name[0] == NUL
295 /* URXVT mouse uses <ESC>[#;#;#M, but we are matching <ESC>[ */
296 ! || key_name[0] == KS_URXVT_MOUSE
297 ! || key_name[0] == KS_SGR_MOUSE)
299 /* Check for xterm version string: "<Esc>[>{x};{vers};{y}c". Also
300 * eat other possible responses to t_RV, rxvt returns
305 if (tp[1 + (tp[0] != CSI)] == '>' && j == 2)
310 + && ttym_flags != TTYM_URXVT
313 + set_option_value((char_u *)"ttym", 0L,
314 + (char_u *)"sgr", 0);
317 /* if xterm version >= 95 use mouse dragging */
323 * If it is a mouse click, get the coordinates.
325 ! if (key_name[0] == (int)KS_MOUSE
326 # ifdef FEAT_MOUSE_JSB
327 ! || key_name[0] == (int)KS_JSBTERM_MOUSE
329 # ifdef FEAT_MOUSE_NET
330 ! || key_name[0] == (int)KS_NETTERM_MOUSE
332 # ifdef FEAT_MOUSE_DEC
333 ! || key_name[0] == (int)KS_DEC_MOUSE
335 # ifdef FEAT_MOUSE_PTERM
336 ! || key_name[0] == (int)KS_PTERM_MOUSE
338 # ifdef FEAT_MOUSE_URXVT
339 ! || key_name[0] == (int)KS_URXVT_MOUSE
345 * If it is a mouse click, get the coordinates.
347 ! if (key_name[0] == KS_MOUSE
348 # ifdef FEAT_MOUSE_JSB
349 ! || key_name[0] == KS_JSBTERM_MOUSE
351 # ifdef FEAT_MOUSE_NET
352 ! || key_name[0] == KS_NETTERM_MOUSE
354 # ifdef FEAT_MOUSE_DEC
355 ! || key_name[0] == KS_DEC_MOUSE
357 # ifdef FEAT_MOUSE_PTERM
358 ! || key_name[0] == KS_PTERM_MOUSE
360 # ifdef FEAT_MOUSE_URXVT
361 ! || key_name[0] == KS_URXVT_MOUSE
363 ! # ifdef FEAT_MOUSE_SGR
364 ! || key_name[0] == KS_SGR_MOUSE
373 ! # ifdef FEAT_MOUSE_URXVT
374 ! if (key_name[0] == (int)KS_URXVT_MOUSE)
382 ! # if defined(FEAT_MOUSE_URXVT) || defined(FEAT_MOUSE_SGR)
383 ! if (key_name[0] == KS_URXVT_MOUSE
384 ! || key_name[0] == KS_SGR_MOUSE)
395 + * SGR 1006 mouse reporting mode:
396 + * Almost identical to xterm mouse mode, except the values
397 + * are decimal instead of bytes.
404 + * \033[<%d;%d;%dm : mouse release event
416 mouse_col = getdigits(&p) - 1;
420 mouse_row = getdigits(&p) - 1;
424 slen += (int)(p - (tp + slen));
426 /* skip this one if next one has same code (like xterm
428 j = termcodes[idx].len;
429 ! if (STRNCMP(tp, tp + slen, (size_t)j) == 0) {
430 ! /* check if the command is complete by looking for the
433 int cmd_complete = 0;
434 ! for (slen2 = slen; slen2 < len; slen2++) {
435 ! if (tp[slen2] == 'M') {
441 ! if (cmd_complete && getdigits(&p) == mouse_code) {
442 slen += j; /* skip the \033[ */
449 + /* when mouse reporting is SGR, add 32 to mouse code */
450 + if (key_name[0] == KS_SGR_MOUSE)
453 mouse_col = getdigits(&p) - 1;
457 mouse_row = getdigits(&p) - 1;
458 ! if (key_name[0] == KS_SGR_MOUSE && *p == 'm')
459 ! mouse_code |= MOUSE_RELEASE;
460 ! else if (*p != 'M')
464 slen += (int)(p - (tp + slen));
466 /* skip this one if next one has same code (like xterm
468 j = termcodes[idx].len;
469 ! if (STRNCMP(tp, tp + slen, (size_t)j) == 0)
472 int cmd_complete = 0;
474 ! /* check if the command is complete by looking for the
476 ! for (slen2 = slen; slen2 < len; slen2++)
478 ! if (tp[slen2] == 'M'
479 ! || (key_name[0] == KS_SGR_MOUSE
480 ! && tp[slen2] == 'm'))
487 ! if (cmd_complete && getdigits(&p) == mouse_code)
489 slen += j; /* skip the \033[ */
495 #ifdef FEAT_MOUSE_URXVT
496 || key_name[0] == (int)KS_URXVT_MOUSE
498 + #ifdef FEAT_MOUSE_SGR
499 + || key_name[0] == KS_SGR_MOUSE
503 # if !defined(MSWIN) && !defined(MSDOS)
504 *** ../vim-7.3.631/src/version.c 2012-08-15 14:04:50.000000000 +0200
505 --- src/version.c 2012-08-15 15:47:30.000000000 +0200
512 + # ifdef FEAT_MOUSE_SGR
519 # ifdef FEAT_MOUSE_PTERM
520 *** ../vim-7.3.631/src/version.c 2012-08-15 14:04:50.000000000 +0200
521 --- src/version.c 2012-08-15 15:47:30.000000000 +0200
525 { /* Add new patch number below this line */
531 hundred-and-one symptoms of being an internet addict:
532 243. You unsuccessfully try to download a pizza from www.dominos.com.
534 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
535 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
536 \\\ an exciting new programming language -- http://www.Zimbu.org ///
537 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///