Patch 9.0.1168

6 views
Skip to first unread message

Bram Moolenaar

unread,
Jan 10, 2023, 7:38:19 AM1/10/23
to vim...@googlegroups.com

Patch 9.0.1168
Problem: Code to enable/disable mouse is not from terminfo/termcap.
Solution: Request the "XM" entry and use it to set 'ttymouse' if possible.
Files: runtime/doc/options.txt, src/term.c, src/proto/term.pro,
src/termdefs.h, src/os_unix.c, src/optiondefs.h


*** ../vim-9.0.1167/runtime/doc/options.txt 2022-12-15 13:14:17.407527409 +0000
--- runtime/doc/options.txt 2023-01-10 12:30:39.140845488 +0000
***************
*** 8628,8633 ****
--- 8679,8687 ----
set to a name that starts with "xterm", "mlterm", "screen", "tmux",
"st" (full match only), "st-" or "stterm", and 'ttymouse' is not set
already.
+ If the terminfo/termcap entry "XM" exists and the first number is
+ "1006" then 'ttymouse' will be set to "sgr". This works for many
+ modern terminals.
Additionally, if vim is compiled with the |+termresponse| feature and
|t_RV| is set to the escape sequence to request the xterm version
number, more intelligent detection is done.
*** ../vim-9.0.1167/src/term.c 2023-01-01 18:03:55.472613188 +0000
--- src/term.c 2023-01-09 20:58:41.933966628 +0000
***************
*** 473,478 ****
--- 473,479 ----
{(int)KS_CGP, "\033[13t"},
# endif
{(int)KS_CRV, "\033[>c"},
+ {(int)KS_CXM, "\033[?1006;1000%?%p1%{1}%=%th%el%;"},
{(int)KS_RFG, "\033]10;?\007"},
{(int)KS_RBG, "\033]11;?\007"},
{(int)KS_U7, "\033[6n"},
***************
*** 1229,1234 ****
--- 1230,1236 ----
{(int)KS_CWP, "[%dCWP%d]"},
# endif
{(int)KS_CRV, "[CRV]"},
+ {(int)KS_CXM, "[CXM]"},
{(int)KS_U7, "[U7]"},
{(int)KS_RFG, "[RFG]"},
{(int)KS_RBG, "[RBG]"},
***************
*** 1721,1727 ****
{KS_BC, "bc"}, {KS_CSB,"Sb"}, {KS_CSF,"Sf"},
{KS_CAB,"AB"}, {KS_CAF,"AF"}, {KS_CAU,"AU"},
{KS_LE, "le"},
! {KS_ND, "nd"}, {KS_OP, "op"}, {KS_CRV, "RV"},
{KS_VS, "vs"}, {KS_CVS, "VS"},
{KS_CIS, "IS"}, {KS_CIE, "IE"},
{KS_CSC, "SC"}, {KS_CEC, "EC"},
--- 1723,1730 ----
{KS_BC, "bc"}, {KS_CSB,"Sb"}, {KS_CSF,"Sf"},
{KS_CAB,"AB"}, {KS_CAF,"AF"}, {KS_CAU,"AU"},
{KS_LE, "le"},
! {KS_ND, "nd"}, {KS_OP, "op"},
! {KS_CRV, "RV"}, {KS_CXM, "XM"},
{KS_VS, "vs"}, {KS_CVS, "VS"},
{KS_CIS, "IS"}, {KS_CIE, "IE"},
{KS_CSC, "SC"}, {KS_CEC, "EC"},
***************
*** 2107,2114 ****
else
T_CCS = empty_option;

! // Special case: "kitty" does not normally have a "RV" entry in terminfo,
! // but we need to request the version for several other things to work.
if (strstr((char *)term, "kitty") != NULL
&& (T_CRV == NULL || *T_CRV == NUL))
T_CRV = (char_u *)"\033[>c";
--- 2110,2117 ----
else
T_CCS = empty_option;

! // Special case: "kitty" may not have a "RV" entry in terminfo, but we need
! // to request the version for several other things to work.
if (strstr((char *)term, "kitty") != NULL
&& (T_CRV == NULL || *T_CRV == NUL))
T_CRV = (char_u *)"\033[>c";
***************
*** 2156,2161 ****
--- 2159,2180 ----
init_term_props(FALSE);
#endif

+ // If the first number in t_XM is 1006 then the terminal will support SGR
+ // mouse reporting.
+ int did_set_ttym = FALSE;
+ if (T_CXM != NULL && *T_CXM != NUL && !option_was_set((char_u *)"ttym"))
+ {
+ char_u *p = T_CXM;
+
+ while (*p != NUL && !VIM_ISDIGIT(*p))
+ ++p;
+ if (getdigits(&p) == 1006)
+ {
+ did_set_ttym = TRUE;
+ set_option_value_give_err((char_u *)"ttym", 0L, (char_u *)"sgr", 0);
+ }
+ }
+
#if defined(UNIX) || defined(VMS)
/*
* For Unix, set the 'ttymouse' option to the type of mouse to be used.
***************
*** 2173,2179 ****
p = (char_u *)"xterm";
}
# endif
! if (p != NULL)
{
set_option_value_give_err((char_u *)"ttym", 0L, p, 0);
// Reset the WAS_SET flag, 'ttymouse' can be set to "sgr" or
--- 2192,2198 ----
p = (char_u *)"xterm";
}
# endif
! if (p != NULL && !did_set_ttym)
{
set_option_value_give_err((char_u *)"ttym", 0L, p, 0);
// Reset the WAS_SET flag, 'ttymouse' can be set to "sgr" or
***************
*** 2801,2808 ****
if (out_pos > OUT_SIZE - MAX_ESC_SEQ_LEN)
out_flush();

! while (*s)
! out_char_nf(*s++);

// For testing we write one string at a time.
if (p_wd)
--- 2820,2827 ----
if (out_pos > OUT_SIZE - MAX_ESC_SEQ_LEN)
out_flush();

! for (char_u *p = s; *p != NUL; ++p)
! out_char_nf(*p);

// For testing we write one string at a time.
if (p_wd)
***************
*** 2942,2947 ****
--- 2961,2975 ----
OUT_STR(tgoto((char *)T_CDL, 0, line_count));
}

+ #if defined(UNIX) || defined(PROTO)
+ void
+ term_enable_mouse(int enable)
+ {
+ int on = enable ? 1 : 0;
+ OUT_STR(tgoto((char *)T_CXM, 0, on));
+ }
+ #endif
+
#if defined(HAVE_TGETENT) || defined(PROTO)
void
term_set_winpos(int x, int y)
*** ../vim-9.0.1167/src/proto/term.pro 2023-01-01 18:03:55.472613188 +0000
--- src/proto/term.pro 2023-01-09 20:58:51.141957028 +0000
***************
*** 25,30 ****
--- 25,31 ----
void term_cursor_right(int i);
void term_append_lines(int line_count);
void term_delete_lines(int line_count);
+ void term_enable_mouse(int enable);
void term_set_winpos(int x, int y);
int term_get_winpos(int *x, int *y, varnumber_T timeout);
void term_set_winsize(int height, int width);
*** ../vim-9.0.1167/src/termdefs.h 2022-12-30 21:10:20.665095951 +0000
--- src/termdefs.h 2023-01-09 20:19:13.772932274 +0000
***************
*** 95,100 ****
--- 95,101 ----
KS_CGP, // get window position
KS_CWS, // set window size in characters
KS_CRV, // request version string
+ KS_CXM, // enable/disable mouse reporting
KS_RFG, // request foreground color
KS_RBG, // request background color
KS_CSI, // start insert mode (bar cursor)
***************
*** 205,210 ****
--- 206,212 ----
#define T_CEI (TERM_STR(KS_CEI)) // end insert mode
#define T_CSR (TERM_STR(KS_CSR)) // start replace mode
#define T_CRV (TERM_STR(KS_CRV)) // request version string
+ #define T_CXM (TERM_STR(KS_CXM)) // enable/disable mouse reporting
#define T_RFG (TERM_STR(KS_RFG)) // request foreground RGB
#define T_RBG (TERM_STR(KS_RBG)) // request background RGB
#define T_OP (TERM_STR(KS_OP)) // original color pair
*** ../vim-9.0.1167/src/os_unix.c 2022-12-19 18:56:44.173594364 +0000
--- src/os_unix.c 2023-01-09 20:59:09.117938310 +0000
***************
*** 3780,3786 ****
}
#endif

! if (ttym_flags == TTYM_SGR)
{
// SGR mode supports columns above 223
out_str_nf((char_u *)(on ? "\033[?1006h" : "\033[?1006l"));
--- 3780,3790 ----
}
#endif

! if (T_CXM != NULL && *T_CXM != NUL)
! {
! term_enable_mouse(on);
! }
! else if (ttym_flags == TTYM_SGR)
{
// SGR mode supports columns above 223
out_str_nf((char_u *)(on ? "\033[?1006h" : "\033[?1006l"));
*** ../vim-9.0.1167/src/optiondefs.h 2022-12-15 13:14:17.411527402 +0000
--- src/optiondefs.h 2023-01-09 20:43:43.114961381 +0000
***************
*** 2934,2939 ****
--- 2934,2940 ----
p_term("t_vs", T_VS)
p_term("t_WP", T_CWP)
p_term("t_WS", T_CWS)
+ p_term("t_XM", T_CXM)
p_term("t_xn", T_XN)
p_term("t_xs", T_XS)
p_term("t_ZH", T_CZH)
*** ../vim-9.0.1167/src/version.c 2023-01-09 20:07:56.713533250 +0000
--- src/version.c 2023-01-10 12:32:38.977122577 +0000
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 1168,
/**/

--
Team-building exercises come in many forms but they all trace their roots back
to the prison system. In your typical team-building exercise the employees
are subjected to a variety of unpleasant situations until they become either a
cohesive team or a ring of car jackers.
(Scott Adams - The Dilbert principle)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

John Marriott

unread,
Jan 10, 2023, 1:55:19 PM1/10/23
to vim...@googlegroups.com

On 10-Jan-2023 23:38, Bram Moolenaar wrote:
> Patch 9.0.1168
> Problem: Code to enable/disable mouse is not from terminfo/termcap.
> Solution: Request the "XM" entry and use it to set 'ttymouse' if possible.
> Files: runtime/doc/options.txt, src/term.c, src/proto/term.pro,
> src/termdefs.h, src/os_unix.c, src/optiondefs.h
>
>
>
After this patch msys64 (clang 15.0.5) gives this warning:
<snip>
clang -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
-DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -D__USE_MINGW_ANSI_STDIO
-pipe -Wall -O3 -fomit-frame-pointer -fpie -fPIE -DFEAT_GUI_MSWIN
-DFEAT_CLIPBOARD term.c -o gobjx86-64/term.o
term.c:2164:9: warning: variable 'did_set_ttym' set but not used
[-Wunused-but-set-variable]
    int did_set_ttym = FALSE;
        ^
1 warning generated.
</snip>

The attached patch tries to fix it.

Cheers
John
term.c.9.0.1168.patch

Bram Moolenaar

unread,
Jan 10, 2023, 2:17:57 PM1/10/23
to vim...@googlegroups.com, John Marriott
I'll include it, thanks.

--
I recommend ordering large cargo containers of paper towels to make up
whatever budget underruns you have. Paper products are always useful and they
have the advantage of being completely flushable if you need to make room in
the storage area later.
Reply all
Reply to author
Forward
0 new messages