Mercurial > vim
comparison src/term.c @ 18135:1868ec23360e v8.1.2062
patch 8.1.2062: the mouse code is spread out
Commit: https://github.com/vim/vim/commit/b20b9e14ddd8db111e886ad0494e15b955159426
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Sep 21 20:48:04 2019 +0200
patch 8.1.2062: the mouse code is spread out
Problem: The mouse code is spread out.
Solution: Move all the mouse code to mouse.c. (Yegappan Lakshmanan,
closes #4959)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 21 Sep 2019 21:00:07 +0200 |
parents | 59f8948b7590 |
children | 0ec6521e9d80 |
comparison
equal
deleted
inserted
replaced
18134:c06a2bc8144f | 18135:1868ec23360e |
---|---|
85 #if defined(FEAT_GUI) \ | 85 #if defined(FEAT_GUI) \ |
86 || (defined(FEAT_MOUSE) && (!defined(UNIX) || defined(FEAT_MOUSE_XTERM) \ | 86 || (defined(FEAT_MOUSE) && (!defined(UNIX) || defined(FEAT_MOUSE_XTERM) \ |
87 || defined(FEAT_MOUSE_GPM) || defined(FEAT_SYSMOUSE))) | 87 || defined(FEAT_MOUSE_GPM) || defined(FEAT_SYSMOUSE))) |
88 static int get_bytes_from_buf(char_u *, char_u *, int); | 88 static int get_bytes_from_buf(char_u *, char_u *, int); |
89 #endif | 89 #endif |
90 static void del_termcode(char_u *name); | |
91 static void del_termcode_idx(int idx); | 90 static void del_termcode_idx(int idx); |
92 static int find_term_bykeys(char_u *src); | 91 static int find_term_bykeys(char_u *src); |
93 static int term_is_builtin(char_u *name); | 92 static int term_is_builtin(char_u *name); |
94 static int term_7to8bit(char_u *p); | 93 static int term_7to8bit(char_u *p); |
95 | 94 |
2046 * may redefine t_TI etc. | 2045 * may redefine t_TI etc. |
2047 */ | 2046 */ |
2048 if (starting != NO_SCREEN) | 2047 if (starting != NO_SCREEN) |
2049 { | 2048 { |
2050 starttermcap(); /* may change terminal mode */ | 2049 starttermcap(); /* may change terminal mode */ |
2051 #ifdef FEAT_MOUSE | |
2052 setmouse(); /* may start using the mouse */ | 2050 setmouse(); /* may start using the mouse */ |
2053 #endif | |
2054 #ifdef FEAT_TITLE | 2051 #ifdef FEAT_TITLE |
2055 maketitle(); /* may display window title */ | 2052 maketitle(); /* may display window title */ |
2056 #endif | 2053 #endif |
2057 } | 2054 } |
2058 | 2055 |
2098 may_req_termresponse(); | 2095 may_req_termresponse(); |
2099 #endif | 2096 #endif |
2100 | 2097 |
2101 return OK; | 2098 return OK; |
2102 } | 2099 } |
2103 | |
2104 #if defined(FEAT_MOUSE) || defined(PROTO) | |
2105 | |
2106 # ifdef FEAT_MOUSE_TTY | |
2107 # define HMT_NORMAL 1 | |
2108 # define HMT_NETTERM 2 | |
2109 # define HMT_DEC 4 | |
2110 # define HMT_JSBTERM 8 | |
2111 # define HMT_PTERM 16 | |
2112 # define HMT_URXVT 32 | |
2113 # define HMT_GPM 64 | |
2114 # define HMT_SGR 128 | |
2115 # define HMT_SGR_REL 256 | |
2116 static int has_mouse_termcode = 0; | |
2117 # endif | |
2118 | |
2119 # if (!defined(UNIX) || defined(FEAT_MOUSE_TTY)) || defined(PROTO) | |
2120 void | |
2121 set_mouse_termcode( | |
2122 int n, /* KS_MOUSE, KS_NETTERM_MOUSE or KS_DEC_MOUSE */ | |
2123 char_u *s) | |
2124 { | |
2125 char_u name[2]; | |
2126 | |
2127 name[0] = n; | |
2128 name[1] = KE_FILLER; | |
2129 add_termcode(name, s, FALSE); | |
2130 # ifdef FEAT_MOUSE_TTY | |
2131 # ifdef FEAT_MOUSE_JSB | |
2132 if (n == KS_JSBTERM_MOUSE) | |
2133 has_mouse_termcode |= HMT_JSBTERM; | |
2134 else | |
2135 # endif | |
2136 # ifdef FEAT_MOUSE_NET | |
2137 if (n == KS_NETTERM_MOUSE) | |
2138 has_mouse_termcode |= HMT_NETTERM; | |
2139 else | |
2140 # endif | |
2141 # ifdef FEAT_MOUSE_DEC | |
2142 if (n == KS_DEC_MOUSE) | |
2143 has_mouse_termcode |= HMT_DEC; | |
2144 else | |
2145 # endif | |
2146 # ifdef FEAT_MOUSE_PTERM | |
2147 if (n == KS_PTERM_MOUSE) | |
2148 has_mouse_termcode |= HMT_PTERM; | |
2149 else | |
2150 # endif | |
2151 # ifdef FEAT_MOUSE_URXVT | |
2152 if (n == KS_URXVT_MOUSE) | |
2153 has_mouse_termcode |= HMT_URXVT; | |
2154 else | |
2155 # endif | |
2156 # ifdef FEAT_MOUSE_GPM | |
2157 if (n == KS_GPM_MOUSE) | |
2158 has_mouse_termcode |= HMT_GPM; | |
2159 else | |
2160 # endif | |
2161 if (n == KS_SGR_MOUSE) | |
2162 has_mouse_termcode |= HMT_SGR; | |
2163 else if (n == KS_SGR_MOUSE_RELEASE) | |
2164 has_mouse_termcode |= HMT_SGR_REL; | |
2165 else | |
2166 has_mouse_termcode |= HMT_NORMAL; | |
2167 # endif | |
2168 } | |
2169 # endif | |
2170 | |
2171 # if ((defined(UNIX) || defined(VMS)) \ | |
2172 && defined(FEAT_MOUSE_TTY)) || defined(PROTO) | |
2173 void | |
2174 del_mouse_termcode( | |
2175 int n) /* KS_MOUSE, KS_NETTERM_MOUSE or KS_DEC_MOUSE */ | |
2176 { | |
2177 char_u name[2]; | |
2178 | |
2179 name[0] = n; | |
2180 name[1] = KE_FILLER; | |
2181 del_termcode(name); | |
2182 # ifdef FEAT_MOUSE_TTY | |
2183 # ifdef FEAT_MOUSE_JSB | |
2184 if (n == KS_JSBTERM_MOUSE) | |
2185 has_mouse_termcode &= ~HMT_JSBTERM; | |
2186 else | |
2187 # endif | |
2188 # ifdef FEAT_MOUSE_NET | |
2189 if (n == KS_NETTERM_MOUSE) | |
2190 has_mouse_termcode &= ~HMT_NETTERM; | |
2191 else | |
2192 # endif | |
2193 # ifdef FEAT_MOUSE_DEC | |
2194 if (n == KS_DEC_MOUSE) | |
2195 has_mouse_termcode &= ~HMT_DEC; | |
2196 else | |
2197 # endif | |
2198 # ifdef FEAT_MOUSE_PTERM | |
2199 if (n == KS_PTERM_MOUSE) | |
2200 has_mouse_termcode &= ~HMT_PTERM; | |
2201 else | |
2202 # endif | |
2203 # ifdef FEAT_MOUSE_URXVT | |
2204 if (n == KS_URXVT_MOUSE) | |
2205 has_mouse_termcode &= ~HMT_URXVT; | |
2206 else | |
2207 # endif | |
2208 # ifdef FEAT_MOUSE_GPM | |
2209 if (n == KS_GPM_MOUSE) | |
2210 has_mouse_termcode &= ~HMT_GPM; | |
2211 else | |
2212 # endif | |
2213 if (n == KS_SGR_MOUSE) | |
2214 has_mouse_termcode &= ~HMT_SGR; | |
2215 else if (n == KS_SGR_MOUSE_RELEASE) | |
2216 has_mouse_termcode &= ~HMT_SGR_REL; | |
2217 else | |
2218 has_mouse_termcode &= ~HMT_NORMAL; | |
2219 # endif | |
2220 } | |
2221 # endif | |
2222 #endif | |
2223 | 2100 |
2224 #ifdef HAVE_TGETENT | 2101 #ifdef HAVE_TGETENT |
2225 /* | 2102 /* |
2226 * Call tgetent() | 2103 * Call tgetent() |
2227 * Return error message if it fails, NULL if it's OK. | 2104 * Return error message if it fails, NULL if it's OK. |
3572 // be before mch_settmode(). | 3449 // be before mch_settmode(). |
3573 } | 3450 } |
3574 out_flush(); | 3451 out_flush(); |
3575 mch_settmode(tmode); // machine specific function | 3452 mch_settmode(tmode); // machine specific function |
3576 cur_tmode = tmode; | 3453 cur_tmode = tmode; |
3577 #ifdef FEAT_MOUSE | |
3578 if (tmode == TMODE_RAW) | 3454 if (tmode == TMODE_RAW) |
3579 setmouse(); // may switch mouse on | 3455 setmouse(); // may switch mouse on |
3580 #endif | |
3581 out_flush(); | 3456 out_flush(); |
3582 } | 3457 } |
3583 #ifdef FEAT_TERMRESPONSE | 3458 #ifdef FEAT_TERMRESPONSE |
3584 may_req_termresponse(); | 3459 may_req_termresponse(); |
3585 #endif | 3460 #endif |
3808 int | 3683 int |
3809 swapping_screen(void) | 3684 swapping_screen(void) |
3810 { | 3685 { |
3811 return (full_screen && *T_TI != NUL); | 3686 return (full_screen && *T_TI != NUL); |
3812 } | 3687 } |
3813 | |
3814 #if defined(FEAT_MOUSE) || defined(PROTO) | |
3815 /* | |
3816 * setmouse() - switch mouse on/off depending on current mode and 'mouse' | |
3817 */ | |
3818 void | |
3819 setmouse(void) | |
3820 { | |
3821 # ifdef FEAT_MOUSE_TTY | |
3822 int checkfor; | |
3823 # endif | |
3824 | |
3825 # ifdef FEAT_MOUSESHAPE | |
3826 update_mouseshape(-1); | |
3827 # endif | |
3828 | |
3829 # ifdef FEAT_MOUSE_TTY /* Should be outside proc, but may break MOUSESHAPE */ | |
3830 # ifdef FEAT_GUI | |
3831 /* In the GUI the mouse is always enabled. */ | |
3832 if (gui.in_use) | |
3833 return; | |
3834 # endif | |
3835 /* be quick when mouse is off */ | |
3836 if (*p_mouse == NUL || has_mouse_termcode == 0) | |
3837 return; | |
3838 | |
3839 /* don't switch mouse on when not in raw mode (Ex mode) */ | |
3840 if (cur_tmode != TMODE_RAW) | |
3841 { | |
3842 mch_setmouse(FALSE); | |
3843 return; | |
3844 } | |
3845 | |
3846 if (VIsual_active) | |
3847 checkfor = MOUSE_VISUAL; | |
3848 else if (State == HITRETURN || State == ASKMORE || State == SETWSIZE) | |
3849 checkfor = MOUSE_RETURN; | |
3850 else if (State & INSERT) | |
3851 checkfor = MOUSE_INSERT; | |
3852 else if (State & CMDLINE) | |
3853 checkfor = MOUSE_COMMAND; | |
3854 else if (State == CONFIRM || State == EXTERNCMD) | |
3855 checkfor = ' '; /* don't use mouse for ":confirm" or ":!cmd" */ | |
3856 else | |
3857 checkfor = MOUSE_NORMAL; /* assume normal mode */ | |
3858 | |
3859 if (mouse_has(checkfor)) | |
3860 mch_setmouse(TRUE); | |
3861 else | |
3862 mch_setmouse(FALSE); | |
3863 # endif | |
3864 } | |
3865 | |
3866 /* | |
3867 * Return TRUE if | |
3868 * - "c" is in 'mouse', or | |
3869 * - 'a' is in 'mouse' and "c" is in MOUSE_A, or | |
3870 * - the current buffer is a help file and 'h' is in 'mouse' and we are in a | |
3871 * normal editing mode (not at hit-return message). | |
3872 */ | |
3873 int | |
3874 mouse_has(int c) | |
3875 { | |
3876 char_u *p; | |
3877 | |
3878 for (p = p_mouse; *p; ++p) | |
3879 switch (*p) | |
3880 { | |
3881 case 'a': if (vim_strchr((char_u *)MOUSE_A, c) != NULL) | |
3882 return TRUE; | |
3883 break; | |
3884 case MOUSE_HELP: if (c != MOUSE_RETURN && curbuf->b_help) | |
3885 return TRUE; | |
3886 break; | |
3887 default: if (c == *p) return TRUE; break; | |
3888 } | |
3889 return FALSE; | |
3890 } | |
3891 | |
3892 /* | |
3893 * Return TRUE when 'mousemodel' is set to "popup" or "popup_setpos". | |
3894 */ | |
3895 int | |
3896 mouse_model_popup(void) | |
3897 { | |
3898 return (p_mousem[0] == 'p'); | |
3899 } | |
3900 #endif | |
3901 | 3688 |
3902 /* | 3689 /* |
3903 * By outputting the 'cursor very visible' termcap code, for some windowed | 3690 * By outputting the 'cursor very visible' termcap code, for some windowed |
3904 * terminals this makes the screen scrolled to the correct position. | 3691 * terminals this makes the screen scrolled to the correct position. |
3905 * Used when starting Vim or returning from a shell. | 3692 * Used when starting Vim or returning from a shell. |
4305 if (i >= tc_len) | 4092 if (i >= tc_len) |
4306 return NULL; | 4093 return NULL; |
4307 return &termcodes[i].name[0]; | 4094 return &termcodes[i].name[0]; |
4308 } | 4095 } |
4309 | 4096 |
4310 static void | 4097 void |
4311 del_termcode(char_u *name) | 4098 del_termcode(char_u *name) |
4312 { | 4099 { |
4313 int i; | 4100 int i; |
4314 | 4101 |
4315 if (termcodes == NULL) /* nothing there yet */ | 4102 if (termcodes == NULL) /* nothing there yet */ |
5296 /* URXVT 1015 mouse reporting mode: | 5083 /* URXVT 1015 mouse reporting mode: |
5297 * Almost identical to xterm mouse mode, except the values | 5084 * Almost identical to xterm mouse mode, except the values |
5298 * are decimal instead of bytes. | 5085 * are decimal instead of bytes. |
5299 * | 5086 * |
5300 * \033[%d;%d;%dM | 5087 * \033[%d;%d;%dM |
5301 * ^-- row | 5088 * ^-- row |
5302 * ^----- column | 5089 * ^----- column |
5303 * ^-------- code | 5090 * ^-------- code |
5304 * | 5091 * |
5305 * SGR 1006 mouse reporting mode: | 5092 * SGR 1006 mouse reporting mode: |
5306 * Almost identical to xterm mouse mode, except the values | 5093 * Almost identical to xterm mouse mode, except the values |
5307 * are decimal instead of bytes. | 5094 * are decimal instead of bytes. |
5308 * | 5095 * |
5309 * \033[<%d;%d;%dM | 5096 * \033[<%d;%d;%dM |
5310 * ^-- row | 5097 * ^-- row |
5311 * ^----- column | 5098 * ^----- column |
5312 * ^-------- code | 5099 * ^-------- code |
5313 * | 5100 * |
5314 * \033[<%d;%d;%dm : mouse release event | 5101 * \033[<%d;%d;%dm : mouse release event |
5315 * ^-- row | 5102 * ^-- row |
5316 * ^----- column | 5103 * ^----- column |
5317 * ^-------- code | 5104 * ^-------- code |
5318 */ | 5105 */ |
5319 p = modifiers_start; | 5106 p = modifiers_start; |
5320 if (p == NULL) | 5107 if (p == NULL) |
5321 return -1; | 5108 return -1; |
5322 | 5109 |