Skip to content

Commit 1502f4a

Browse files
committed
updated for version 7.3.632
Problem: Cannot select beyond 222 columns with the mouse in xterm. Solution: Add support for SGR mouse tracking. (Hayaki Saito)
1 parent 2d2022b commit 1502f4a

File tree

8 files changed

+137
-19
lines changed

8 files changed

+137
-19
lines changed

runtime/doc/options.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7437,6 +7437,7 @@ A jump table for the options with a short description can be found at |Q_op|.
74377437
or "xterm2" already. The main use of this option is to set it to
74387438
"xterm", when the terminal name doesn't start with "xterm", but it can
74397439
handle xterm mouse codes.
7440+
The "sgr" value will be set if the xterm version is 277 or later.
74407441
The "xterm2" value will be set if the xterm version is reported to be
74417442
95 or higher. This only works when compiled with the |+termresponse|
74427443
feature and if |t_RV| is set to the escape sequence to request the

src/feature.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,9 @@
10561056
# ifdef FEAT_BIG
10571057
# define FEAT_MOUSE_URXVT
10581058
# endif
1059+
# ifdef FEAT_BIG
1060+
# define FEAT_MOUSE_SGR
1061+
# endif
10591062
# if defined(FEAT_NORMAL) && (defined(MSDOS) || defined(WIN3264))
10601063
# define DOS_MOUSE
10611064
# endif
@@ -1077,6 +1080,11 @@
10771080
# define FEAT_MOUSE_XTERM
10781081
#endif
10791082

1083+
/* sgr is a small variation of mouse_xterm, and shares its code */
1084+
#if defined(FEAT_MOUSE_SGR) && !defined(FEAT_MOUSE_XTERM)
1085+
# define FEAT_MOUSE_XTERM
1086+
#endif
1087+
10801088
/* Define FEAT_MOUSE when any of the above is defined or FEAT_GUI. */
10811089
#if !defined(FEAT_MOUSE_TTY) \
10821090
&& (defined(FEAT_MOUSE_XTERM) \
@@ -1087,7 +1095,8 @@
10871095
|| defined(FEAT_MOUSE_JSB) \
10881096
|| defined(FEAT_MOUSE_PTERM) \
10891097
|| defined(FEAT_SYSMOUSE) \
1090-
|| defined(FEAT_MOUSE_URXVT))
1098+
|| defined(FEAT_MOUSE_URXVT) \
1099+
|| defined(FEAT_MOUSE_SGR))
10911100
# define FEAT_MOUSE_TTY /* include non-GUI mouse support */
10921101
#endif
10931102
#if !defined(FEAT_MOUSE) && (defined(FEAT_MOUSE_TTY) || defined(FEAT_GUI))

src/keymap.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@
110110
/* Used for the urxvt mouse. */
111111
#define KS_URXVT_MOUSE 238
112112

113+
/* Used for the sgr mouse. */
114+
#define KS_SGR_MOUSE 237
115+
113116
/*
114117
* Filler used after KS_SPECIAL and others
115118
*/
@@ -412,6 +415,7 @@ enum key_extra
412415
#define K_JSBTERM_MOUSE TERMCAP2KEY(KS_JSBTERM_MOUSE, KE_FILLER)
413416
#define K_PTERM_MOUSE TERMCAP2KEY(KS_PTERM_MOUSE, KE_FILLER)
414417
#define K_URXVT_MOUSE TERMCAP2KEY(KS_URXVT_MOUSE, KE_FILLER)
418+
#define K_SGR_MOUSE TERMCAP2KEY(KS_SGR_MOUSE, KE_FILLER)
415419

416420
#define K_SELECT TERMCAP2KEY(KS_SELECT, KE_FILLER)
417421
#define K_TEAROFF TERMCAP2KEY(KS_TEAROFF, KE_FILLER)

src/misc2.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,6 +2432,9 @@ static struct key_name_entry
24322432
#endif
24332433
#ifdef FEAT_MOUSE_URXVT
24342434
{K_URXVT_MOUSE, (char_u *)"UrxvtMouse"},
2435+
#endif
2436+
#ifdef FEAT_MOUSE_SGR
2437+
{K_SGR_MOUSE, (char_u *)"SgrMouse"},
24352438
#endif
24362439
{K_LEFTMOUSE, (char_u *)"LeftMouse"},
24372440
{K_LEFTMOUSE_NM, (char_u *)"LeftMouseNM"},

src/option.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ EXTERN long p_ttyscroll; /* 'ttyscroll' */
822822
EXTERN char_u *p_ttym; /* 'ttymouse' */
823823
EXTERN unsigned ttym_flags;
824824
# ifdef IN_OPTION_C
825-
static char *(p_ttym_values[]) = {"xterm", "xterm2", "dec", "netterm", "jsbterm", "pterm", "urxvt", NULL};
825+
static char *(p_ttym_values[]) = {"xterm", "xterm2", "dec", "netterm", "jsbterm", "pterm", "urxvt", "sgr", NULL};
826826
# endif
827827
# define TTYM_XTERM 0x01
828828
# define TTYM_XTERM2 0x02
@@ -831,6 +831,7 @@ static char *(p_ttym_values[]) = {"xterm", "xterm2", "dec", "netterm", "jsbterm"
831831
# define TTYM_JSBTERM 0x10
832832
# define TTYM_PTERM 0x20
833833
# define TTYM_URXVT 0x40
834+
# define TTYM_SGR 0x80
834835
#endif
835836
EXTERN char_u *p_udir; /* 'undodir' */
836837
EXTERN long p_ul; /* 'undolevels' */

src/os_unix.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2159,10 +2159,13 @@ use_xterm_like_mouse(name)
21592159
* Return 1 for "xterm".
21602160
* Return 2 for "xterm2".
21612161
* Return 3 for "urxvt".
2162+
* Return 4 for "sgr".
21622163
*/
21632164
int
21642165
use_xterm_mouse()
21652166
{
2167+
if (ttym_flags == TTYM_SGR)
2168+
return 4;
21662169
if (ttym_flags == TTYM_URXVT)
21672170
return 3;
21682171
if (ttym_flags == TTYM_XTERM2)
@@ -3339,7 +3342,8 @@ mch_setmouse(on)
33393342
xterm_mouse_vers = use_xterm_mouse();
33403343

33413344
# ifdef FEAT_MOUSE_URXVT
3342-
if (ttym_flags == TTYM_URXVT) {
3345+
if (ttym_flags == TTYM_URXVT)
3346+
{
33433347
out_str_nf((char_u *)
33443348
(on
33453349
? IF_EB("\033[?1015h", ESC_STR "[?1015h")
@@ -3348,6 +3352,17 @@ mch_setmouse(on)
33483352
}
33493353
# endif
33503354

3355+
# ifdef FEAT_MOUSE_SGR
3356+
if (ttym_flags == TTYM_SGR)
3357+
{
3358+
out_str_nf((char_u *)
3359+
(on
3360+
? IF_EB("\033[?1006h", ESC_STR "[?1006h")
3361+
: IF_EB("\033[?1006l", ESC_STR "[?1006l")));
3362+
ison = on;
3363+
}
3364+
# endif
3365+
33513366
if (xterm_mouse_vers > 0)
33523367
{
33533368
if (on) /* enable mouse events, use mouse tracking if available */
@@ -3577,6 +3592,27 @@ check_mouse_termcode()
35773592
else
35783593
del_mouse_termcode(KS_URXVT_MOUSE);
35793594
# endif
3595+
# ifdef FEAT_MOUSE_SGR
3596+
/* same as the dec mouse */
3597+
if (use_xterm_mouse() == 4
3598+
# ifdef FEAT_GUI
3599+
&& !gui.in_use
3600+
# endif
3601+
)
3602+
{
3603+
set_mouse_termcode(KS_SGR_MOUSE, (char_u *)(term_is_8bit(T_NAME)
3604+
? IF_EB("\233<", CSI_STR "<")
3605+
: IF_EB("\033[<", ESC_STR "[<")));
3606+
3607+
if (*p_mouse != NUL)
3608+
{
3609+
mch_setmouse(FALSE);
3610+
setmouse();
3611+
}
3612+
}
3613+
else
3614+
del_mouse_termcode(KS_SGR_MOUSE);
3615+
# endif
35803616
}
35813617
#endif
35823618

src/term.c

Lines changed: 73 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,6 +1997,7 @@ set_termname(term)
19971997
# define HMT_JSBTERM 8
19981998
# define HMT_PTERM 16
19991999
# define HMT_URXVT 32
2000+
# define HMT_SGR 64
20002001
static int has_mouse_termcode = 0;
20012002
# endif
20022003

@@ -2036,6 +2037,11 @@ set_mouse_termcode(n, s)
20362037
if (n == KS_URXVT_MOUSE)
20372038
has_mouse_termcode |= HMT_URXVT;
20382039
else
2040+
# endif
2041+
# ifdef FEAT_MOUSE_SGR
2042+
if (n == KS_SGR_MOUSE)
2043+
has_mouse_termcode |= HMT_SGR;
2044+
else
20392045
# endif
20402046
has_mouse_termcode |= HMT_NORMAL;
20412047
# endif
@@ -2078,6 +2084,11 @@ del_mouse_termcode(n)
20782084
if (n == KS_URXVT_MOUSE)
20792085
has_mouse_termcode &= ~HMT_URXVT;
20802086
else
2087+
# endif
2088+
# ifdef FEAT_MOUSE_SGR
2089+
if (n == KS_SGR_MOUSE)
2090+
has_mouse_termcode &= ~HMT_SGR;
2091+
else
20812092
# endif
20822093
has_mouse_termcode &= ~HMT_NORMAL;
20832094
# endif
@@ -4023,7 +4034,8 @@ check_termcode(max_offset, buf, bufsize, buflen)
40234034
#ifdef FEAT_TERMRESPONSE
40244035
if (key_name[0] == NUL
40254036
/* URXVT mouse uses <ESC>[#;#;#M, but we are matching <ESC>[ */
4026-
|| key_name[0] == KS_URXVT_MOUSE)
4037+
|| key_name[0] == KS_URXVT_MOUSE
4038+
|| key_name[0] == KS_SGR_MOUSE)
40274039
{
40284040
/* Check for xterm version string: "<Esc>[>{x};{vers};{y}c". Also
40294041
* eat other possible responses to t_RV, rxvt returns
@@ -4061,6 +4073,16 @@ check_termcode(max_offset, buf, bufsize, buflen)
40614073

40624074
if (tp[1 + (tp[0] != CSI)] == '>' && j == 2)
40634075
{
4076+
# ifdef TTYM_SGR
4077+
if (extra >= 277
4078+
# ifdef TTYM_URXVT
4079+
&& ttym_flags != TTYM_URXVT
4080+
# endif
4081+
)
4082+
set_option_value((char_u *)"ttym", 0L,
4083+
(char_u *)"sgr", 0);
4084+
else
4085+
# endif
40644086
/* if xterm version >= 95 use mouse dragging */
40654087
if (extra >= 95
40664088
# ifdef TTYM_URXVT
@@ -4147,21 +4169,24 @@ check_termcode(max_offset, buf, bufsize, buflen)
41474169
/*
41484170
* If it is a mouse click, get the coordinates.
41494171
*/
4150-
if (key_name[0] == (int)KS_MOUSE
4172+
if (key_name[0] == KS_MOUSE
41514173
# ifdef FEAT_MOUSE_JSB
4152-
|| key_name[0] == (int)KS_JSBTERM_MOUSE
4174+
|| key_name[0] == KS_JSBTERM_MOUSE
41534175
# endif
41544176
# ifdef FEAT_MOUSE_NET
4155-
|| key_name[0] == (int)KS_NETTERM_MOUSE
4177+
|| key_name[0] == KS_NETTERM_MOUSE
41564178
# endif
41574179
# ifdef FEAT_MOUSE_DEC
4158-
|| key_name[0] == (int)KS_DEC_MOUSE
4180+
|| key_name[0] == KS_DEC_MOUSE
41594181
# endif
41604182
# ifdef FEAT_MOUSE_PTERM
4161-
|| key_name[0] == (int)KS_PTERM_MOUSE
4183+
|| key_name[0] == KS_PTERM_MOUSE
41624184
# endif
41634185
# ifdef FEAT_MOUSE_URXVT
4164-
|| key_name[0] == (int)KS_URXVT_MOUSE
4186+
|| key_name[0] == KS_URXVT_MOUSE
4187+
# endif
4188+
# ifdef FEAT_MOUSE_SGR
4189+
|| key_name[0] == KS_SGR_MOUSE
41654190
# endif
41664191
)
41674192
{
@@ -4243,8 +4268,9 @@ check_termcode(max_offset, buf, bufsize, buflen)
42434268
}
42444269
}
42454270

4246-
# ifdef FEAT_MOUSE_URXVT
4247-
if (key_name[0] == (int)KS_URXVT_MOUSE)
4271+
# if defined(FEAT_MOUSE_URXVT) || defined(FEAT_MOUSE_SGR)
4272+
if (key_name[0] == KS_URXVT_MOUSE
4273+
|| key_name[0] == KS_SGR_MOUSE)
42484274
{
42494275
for (;;)
42504276
{
@@ -4256,39 +4282,67 @@ check_termcode(max_offset, buf, bufsize, buflen)
42564282
* ^-- row
42574283
* ^----- column
42584284
* ^-------- code
4285+
*
4286+
* SGR 1006 mouse reporting mode:
4287+
* Almost identical to xterm mouse mode, except the values
4288+
* are decimal instead of bytes.
4289+
*
4290+
* \033[<%d;%d;%dM
4291+
* ^-- row
4292+
* ^----- column
4293+
* ^-------- code
4294+
*
4295+
* \033[<%d;%d;%dm : mouse release event
4296+
* ^-- row
4297+
* ^----- column
4298+
* ^-------- code
42594299
*/
42604300
p = tp + slen;
42614301

42624302
mouse_code = getdigits(&p);
42634303
if (*p++ != ';')
42644304
return -1;
42654305

4306+
/* when mouse reporting is SGR, add 32 to mouse code */
4307+
if (key_name[0] == KS_SGR_MOUSE)
4308+
mouse_code += 32;
4309+
42664310
mouse_col = getdigits(&p) - 1;
42674311
if (*p++ != ';')
42684312
return -1;
42694313

42704314
mouse_row = getdigits(&p) - 1;
4271-
if (*p++ != 'M')
4315+
if (key_name[0] == KS_SGR_MOUSE && *p == 'm')
4316+
mouse_code |= MOUSE_RELEASE;
4317+
else if (*p != 'M')
42724318
return -1;
4319+
p++;
42734320

42744321
slen += (int)(p - (tp + slen));
42754322

42764323
/* skip this one if next one has same code (like xterm
42774324
* case) */
42784325
j = termcodes[idx].len;
4279-
if (STRNCMP(tp, tp + slen, (size_t)j) == 0) {
4280-
/* check if the command is complete by looking for the
4281-
* M */
4326+
if (STRNCMP(tp, tp + slen, (size_t)j) == 0)
4327+
{
42824328
int slen2;
42834329
int cmd_complete = 0;
4284-
for (slen2 = slen; slen2 < len; slen2++) {
4285-
if (tp[slen2] == 'M') {
4330+
4331+
/* check if the command is complete by looking for the
4332+
* 'M' */
4333+
for (slen2 = slen; slen2 < len; slen2++)
4334+
{
4335+
if (tp[slen2] == 'M'
4336+
|| (key_name[0] == KS_SGR_MOUSE
4337+
&& tp[slen2] == 'm'))
4338+
{
42864339
cmd_complete = 1;
42874340
break;
42884341
}
42894342
}
42904343
p += j;
4291-
if (cmd_complete && getdigits(&p) == mouse_code) {
4344+
if (cmd_complete && getdigits(&p) == mouse_code)
4345+
{
42924346
slen += j; /* skip the \033[ */
42934347
continue;
42944348
}
@@ -4301,6 +4355,9 @@ check_termcode(max_offset, buf, bufsize, buflen)
43014355
if (key_name[0] == (int)KS_MOUSE
43024356
#ifdef FEAT_MOUSE_URXVT
43034357
|| key_name[0] == (int)KS_URXVT_MOUSE
4358+
#endif
4359+
#ifdef FEAT_MOUSE_SGR
4360+
|| key_name[0] == KS_SGR_MOUSE
43044361
#endif
43054362
)
43064363
{

src/version.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,11 @@ static char *(features[]) =
384384
# else
385385
"-mouse_urxvt",
386386
# endif
387+
# ifdef FEAT_MOUSE_SGR
388+
"+mouse_sgr",
389+
# else
390+
"-mouse_sgr",
391+
# endif
387392
#endif
388393
#ifdef __QNX__
389394
# ifdef FEAT_MOUSE_PTERM
@@ -714,6 +719,8 @@ static char *(features[]) =
714719

715720
static int included_patches[] =
716721
{ /* Add new patch number below this line */
722+
/**/
723+
632,
717724
/**/
718725
631,
719726
/**/

0 commit comments

Comments
 (0)