Mercurial > vim
annotate src/ui.c @ 16243:3b79a3029947 v8.1.1126
patch 8.1.1126: build failure with +terminal but without tgetent
commit https://github.com/vim/vim/commit/3d3f21764a8003b90216ae6fb988af1dae5f5d70
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Apr 6 17:56:05 2019 +0200
patch 8.1.1126: build failure with +terminal but without tgetent
Problem: Build failure with +terminal but without tgetent.
Solution: Adjust #ifdef.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 06 Apr 2019 18:00:06 +0200 |
parents | c1698187c482 |
children | e0a6298bd70f |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ui.c: functions that handle the user interface. | |
12 * 1. Keyboard input stuff, and a bit of windowing stuff. These are called | |
13 * before the machine specific stuff (mch_*) so that we can call the GUI | |
14 * stuff instead if the GUI is running. | |
15 * 2. Clipboard stuff. | |
16 * 3. Input buffer stuff. | |
17 */ | |
18 | |
19 #include "vim.h" | |
20 | |
5136
28e6f5f88968
updated for version 7.3.1311
Bram Moolenaar <bram@vim.org>
parents:
5106
diff
changeset
|
21 #ifdef FEAT_CYGWIN_WIN32_CLIPBOARD |
28e6f5f88968
updated for version 7.3.1311
Bram Moolenaar <bram@vim.org>
parents:
5106
diff
changeset
|
22 # define WIN32_LEAN_AND_MEAN |
28e6f5f88968
updated for version 7.3.1311
Bram Moolenaar <bram@vim.org>
parents:
5106
diff
changeset
|
23 # include <windows.h> |
28e6f5f88968
updated for version 7.3.1311
Bram Moolenaar <bram@vim.org>
parents:
5106
diff
changeset
|
24 # include "winclip.pro" |
28e6f5f88968
updated for version 7.3.1311
Bram Moolenaar <bram@vim.org>
parents:
5106
diff
changeset
|
25 #endif |
28e6f5f88968
updated for version 7.3.1311
Bram Moolenaar <bram@vim.org>
parents:
5106
diff
changeset
|
26 |
7 | 27 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
28 ui_write(char_u *s, int len) |
7 | 29 { |
30 #ifdef FEAT_GUI | |
31 if (gui.in_use && !gui.dying && !gui.starting) | |
32 { | |
33 gui_write(s, len); | |
34 if (p_wd) | |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
35 gui_wait_for_chars(p_wd, typebuf.tb_change_cnt); |
7 | 36 return; |
37 } | |
38 #endif | |
39 #ifndef NO_CONSOLE | |
40 /* Don't output anything in silent mode ("ex -s") unless 'verbose' set */ | |
41 if (!(silent_mode && p_verbose == 0)) | |
42 { | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15665
diff
changeset
|
43 #if !defined(MSWIN) |
7 | 44 char_u *tofree = NULL; |
45 | |
46 if (output_conv.vc_type != CONV_NONE) | |
47 { | |
48 /* Convert characters from 'encoding' to 'termencoding'. */ | |
49 tofree = string_convert(&output_conv, s, &len); | |
50 if (tofree != NULL) | |
51 s = tofree; | |
52 } | |
53 #endif | |
54 | |
55 mch_write(s, len); | |
56 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15665
diff
changeset
|
57 # if !defined(MSWIN) |
7 | 58 if (output_conv.vc_type != CONV_NONE) |
59 vim_free(tofree); | |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
60 # endif |
7 | 61 } |
62 #endif | |
63 } | |
64 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15665
diff
changeset
|
65 #if defined(UNIX) || defined(VMS) || defined(PROTO) || defined(MSWIN) |
7 | 66 /* |
67 * When executing an external program, there may be some typed characters that | |
68 * are not consumed by it. Give them back to ui_inchar() and they are stored | |
69 * here for the next call. | |
70 */ | |
71 static char_u *ta_str = NULL; | |
72 static int ta_off; /* offset for next char to use when ta_str != NULL */ | |
73 static int ta_len; /* length of ta_str when it's not NULL*/ | |
74 | |
75 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
76 ui_inchar_undo(char_u *s, int len) |
7 | 77 { |
78 char_u *new; | |
79 int newlen; | |
80 | |
81 newlen = len; | |
82 if (ta_str != NULL) | |
83 newlen += ta_len - ta_off; | |
84 new = alloc(newlen); | |
85 if (new != NULL) | |
86 { | |
87 if (ta_str != NULL) | |
88 { | |
89 mch_memmove(new, ta_str + ta_off, (size_t)(ta_len - ta_off)); | |
90 mch_memmove(new + ta_len - ta_off, s, (size_t)len); | |
91 vim_free(ta_str); | |
92 } | |
93 else | |
94 mch_memmove(new, s, (size_t)len); | |
95 ta_str = new; | |
96 ta_len = newlen; | |
97 ta_off = 0; | |
98 } | |
99 } | |
100 #endif | |
101 | |
102 /* | |
3877 | 103 * ui_inchar(): low level input function. |
7 | 104 * Get characters from the keyboard. |
105 * Return the number of characters that are available. | |
106 * If "wtime" == 0 do not wait for characters. | |
107 * If "wtime" == -1 wait forever for characters. | |
108 * If "wtime" > 0 wait "wtime" milliseconds for a character. | |
109 * | |
110 * "tb_change_cnt" is the value of typebuf.tb_change_cnt if "buf" points into | |
111 * it. When typebuf.tb_change_cnt changes (e.g., when a message is received | |
112 * from a remote client) "buf" can no longer be used. "tb_change_cnt" is NULL | |
113 * otherwise. | |
114 */ | |
115 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
116 ui_inchar( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
117 char_u *buf, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
118 int maxlen, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
119 long wtime, /* don't use "time", MIPS cannot handle it */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
120 int tb_change_cnt) |
7 | 121 { |
122 int retval = 0; | |
123 | |
124 #if defined(FEAT_GUI) && (defined(UNIX) || defined(VMS)) | |
125 /* | |
126 * Use the typeahead if there is any. | |
127 */ | |
128 if (ta_str != NULL) | |
129 { | |
130 if (maxlen >= ta_len - ta_off) | |
131 { | |
132 mch_memmove(buf, ta_str + ta_off, (size_t)ta_len); | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
133 VIM_CLEAR(ta_str); |
7 | 134 return ta_len; |
135 } | |
136 mch_memmove(buf, ta_str + ta_off, (size_t)maxlen); | |
137 ta_off += maxlen; | |
138 return maxlen; | |
139 } | |
140 #endif | |
141 | |
170 | 142 #ifdef FEAT_PROFILE |
791 | 143 if (do_profiling == PROF_YES && wtime != 0) |
170 | 144 prof_inchar_enter(); |
145 #endif | |
146 | |
7 | 147 #ifdef NO_CONSOLE_INPUT |
148 /* Don't wait for character input when the window hasn't been opened yet. | |
149 * Do try reading, this works when redirecting stdin from a file. | |
150 * Must return something, otherwise we'll loop forever. If we run into | |
151 * this very often we probably got stuck, exit Vim. */ | |
152 if (no_console_input()) | |
153 { | |
154 static int count = 0; | |
155 | |
156 # ifndef NO_CONSOLE | |
15075
fd9c4b1a71aa
patch 8.1.0548: crash when job callback unloads a buffer
Bram Moolenaar <Bram@vim.org>
parents:
15052
diff
changeset
|
157 retval = mch_inchar(buf, maxlen, wtime, tb_change_cnt); |
228 | 158 if (retval > 0 || typebuf_changed(tb_change_cnt) || wtime >= 0) |
170 | 159 goto theend; |
7 | 160 # endif |
161 if (wtime == -1 && ++count == 1000) | |
162 read_error_exit(); | |
163 buf[0] = CAR; | |
170 | 164 retval = 1; |
165 goto theend; | |
7 | 166 } |
167 #endif | |
168 | |
1086 | 169 /* If we are going to wait for some time or block... */ |
170 if (wtime == -1 || wtime > 100L) | |
171 { | |
172 /* ... allow signals to kill us. */ | |
173 (void)vim_handle_signal(SIGNAL_UNBLOCK); | |
174 | |
175 /* ... there is no need for CTRL-C to interrupt something, don't let | |
176 * it set got_int when it was mapped. */ | |
6491 | 177 if ((mapped_ctrl_c | curbuf->b_mapped_ctrl_c) & get_real_state()) |
1086 | 178 ctrl_c_interrupts = FALSE; |
179 } | |
7 | 180 |
15653
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
181 /* |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
182 * Here we call gui_inchar() or mch_inchar(), the GUI or machine-dependent |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
183 * input function. The functionality they implement is like this: |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
184 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
185 * while (not timed out) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
186 * { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
187 * handle-resize; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
188 * parse-queued-messages; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
189 * if (waited for 'updatetime') |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
190 * trigger-cursorhold; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
191 * ui_wait_for_chars_or_timer() |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
192 * if (character available) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
193 * break; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
194 * } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
195 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
196 * ui_wait_for_chars_or_timer() does: |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
197 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
198 * while (not timed out) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
199 * { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
200 * if (any-timer-triggered) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
201 * invoke-timer-callback; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
202 * wait-for-character(); |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
203 * if (character available) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
204 * break; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
205 * } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
206 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
207 * wait-for-character() does: |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
208 * while (not timed out) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
209 * { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
210 * Wait for event; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
211 * if (something on channel) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
212 * read/write channel; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
213 * else if (resized) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
214 * handle_resize(); |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
215 * else if (system event) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
216 * deal-with-system-event; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
217 * else if (character available) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
218 * break; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
219 * } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
220 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
221 */ |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
222 |
7 | 223 #ifdef FEAT_GUI |
224 if (gui.in_use) | |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
225 retval = gui_inchar(buf, maxlen, wtime, tb_change_cnt); |
7 | 226 #endif |
227 #ifndef NO_CONSOLE | |
228 # ifdef FEAT_GUI | |
229 else | |
230 # endif | |
231 retval = mch_inchar(buf, maxlen, wtime, tb_change_cnt); | |
232 #endif | |
233 | |
1086 | 234 if (wtime == -1 || wtime > 100L) |
235 /* block SIGHUP et al. */ | |
236 (void)vim_handle_signal(SIGNAL_BLOCK); | |
237 | |
7 | 238 ctrl_c_interrupts = TRUE; |
239 | |
170 | 240 #ifdef NO_CONSOLE_INPUT |
241 theend: | |
242 #endif | |
243 #ifdef FEAT_PROFILE | |
791 | 244 if (do_profiling == PROF_YES && wtime != 0) |
170 | 245 prof_inchar_exit(); |
246 #endif | |
7 | 247 return retval; |
248 } | |
249 | |
15653
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
250 #if defined(UNIX) || defined(FEAT_GUI) || defined(PROTO) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
251 /* |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
252 * Common code for mch_inchar() and gui_inchar(): Wait for a while or |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
253 * indefinitely until characters are available, dealing with timers and |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
254 * messages on channels. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
255 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
256 * "buf" may be NULL if the available characters are not to be returned, only |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
257 * check if they are available. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
258 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
259 * Return the number of characters that are available. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
260 * If "wtime" == 0 do not wait for characters. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
261 * If "wtime" == n wait a short time for characters. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
262 * If "wtime" == -1 wait forever for characters. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
263 */ |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
264 int |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
265 inchar_loop( |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
266 char_u *buf, |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
267 int maxlen, |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
268 long wtime, // don't use "time", MIPS cannot handle it |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
269 int tb_change_cnt, |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
270 int (*wait_func)(long wtime, int *interrupted, int ignore_input), |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
271 int (*resize_func)(int check_only)) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
272 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
273 int len; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
274 int interrupted = FALSE; |
15665
31367ce5aac7
patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents:
15655
diff
changeset
|
275 int did_call_wait_func = FALSE; |
15653
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
276 int did_start_blocking = FALSE; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
277 long wait_time; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
278 long elapsed_time = 0; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
279 #ifdef ELAPSED_FUNC |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
280 elapsed_T start_tv; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
281 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
282 ELAPSED_INIT(start_tv); |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
283 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
284 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
285 /* repeat until we got a character or waited long enough */ |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
286 for (;;) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
287 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
288 /* Check if window changed size while we were busy, perhaps the ":set |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
289 * columns=99" command was used. */ |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
290 if (resize_func != NULL) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
291 resize_func(FALSE); |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
292 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
293 #ifdef MESSAGE_QUEUE |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
294 // Only process messages when waiting. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
295 if (wtime != 0) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
296 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
297 parse_queued_messages(); |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
298 // If input was put directly in typeahead buffer bail out here. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
299 if (typebuf_changed(tb_change_cnt)) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
300 return 0; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
301 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
302 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
303 if (wtime < 0 && did_start_blocking) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
304 // blocking and already waited for p_ut |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
305 wait_time = -1; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
306 else |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
307 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
308 if (wtime >= 0) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
309 wait_time = wtime; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
310 else |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
311 // going to block after p_ut |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
312 wait_time = p_ut; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
313 #ifdef ELAPSED_FUNC |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
314 elapsed_time = ELAPSED_FUNC(start_tv); |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
315 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
316 wait_time -= elapsed_time; |
15665
31367ce5aac7
patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents:
15655
diff
changeset
|
317 |
31367ce5aac7
patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents:
15655
diff
changeset
|
318 // If the waiting time is now zero or less, we timed out. However, |
31367ce5aac7
patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents:
15655
diff
changeset
|
319 // loop at least once to check for characters and events. Matters |
31367ce5aac7
patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents:
15655
diff
changeset
|
320 // when "wtime" is zero. |
31367ce5aac7
patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents:
15655
diff
changeset
|
321 if (wait_time <= 0 && did_call_wait_func) |
15653
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
322 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
323 if (wtime >= 0) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
324 // no character available within "wtime" |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
325 return 0; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
326 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
327 // No character available within 'updatetime'. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
328 did_start_blocking = TRUE; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
329 if (trigger_cursorhold() && maxlen >= 3 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
330 && !typebuf_changed(tb_change_cnt)) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
331 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
332 // Put K_CURSORHOLD in the input buffer or return it. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
333 if (buf == NULL) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
334 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
335 char_u ibuf[3]; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
336 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
337 ibuf[0] = CSI; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
338 ibuf[1] = KS_EXTRA; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
339 ibuf[2] = (int)KE_CURSORHOLD; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
340 add_to_input_buf(ibuf, 3); |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
341 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
342 else |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
343 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
344 buf[0] = K_SPECIAL; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
345 buf[1] = KS_EXTRA; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
346 buf[2] = (int)KE_CURSORHOLD; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
347 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
348 return 3; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
349 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
350 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
351 // There is no character available within 'updatetime' seconds: |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
352 // flush all the swap files to disk. Also done when |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
353 // interrupted by SIGWINCH. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
354 before_blocking(); |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
355 continue; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
356 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
357 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
358 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
359 #ifdef FEAT_JOB_CHANNEL |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
360 if (wait_time < 0 || wait_time > 100L) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
361 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
362 // Checking if a job ended requires polling. Do this at least |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
363 // every 100 msec. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
364 if (has_pending_job()) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
365 wait_time = 100L; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
366 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
367 // If there is readahead then parse_queued_messages() timed out and |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
368 // we should call it again soon. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
369 if (channel_any_readahead()) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
370 wait_time = 10L; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
371 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
372 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
373 #ifdef FEAT_BEVAL_GUI |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
374 if (p_beval && wait_time > 100L) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
375 // The 'balloonexpr' may indirectly invoke a callback while waiting |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
376 // for a character, need to check often. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
377 wait_time = 100L; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
378 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
379 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
380 // Wait for a character to be typed or another event, such as the winch |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
381 // signal or an event on the monitored file descriptors. |
15665
31367ce5aac7
patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents:
15655
diff
changeset
|
382 did_call_wait_func = TRUE; |
15653
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
383 if (wait_func(wait_time, &interrupted, FALSE)) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
384 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
385 // If input was put directly in typeahead buffer bail out here. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
386 if (typebuf_changed(tb_change_cnt)) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
387 return 0; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
388 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
389 // We might have something to return now. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
390 if (buf == NULL) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
391 // "buf" is NULL, we were just waiting, not actually getting |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
392 // input. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
393 return input_available(); |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
394 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
395 len = read_from_input_buf(buf, (long)maxlen); |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
396 if (len > 0) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
397 return len; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
398 continue; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
399 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
400 // Timed out or interrupted with no character available. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
401 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
402 #ifndef ELAPSED_FUNC |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
403 // estimate the elapsed time |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
404 elapsed_time += wait_time; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
405 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
406 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
407 if ((resize_func != NULL && resize_func(TRUE)) |
15655
2202ab00e9f9
patch 8.1.0835: GUI build fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
15653
diff
changeset
|
408 #if defined(FEAT_CLIENTSERVER) && defined(UNIX) |
15653
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
409 || server_waiting() |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
410 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
411 #ifdef MESSAGE_QUEUE |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
412 || interrupted |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
413 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
414 || wait_time > 0 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
415 || (wtime < 0 && !did_start_blocking)) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
416 // no character available, but something to be done, keep going |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
417 continue; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
418 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
419 // no character available or interrupted, return zero |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
420 break; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
421 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
422 return 0; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
423 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
424 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
425 |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
426 #if defined(FEAT_TIMERS) || defined(PROTO) |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
427 /* |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
428 * Wait for a timer to fire or "wait_func" to return non-zero. |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
429 * Returns OK when something was read. |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
430 * Returns FAIL when it timed out or was interrupted. |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
431 */ |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
432 int |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
433 ui_wait_for_chars_or_timer( |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
434 long wtime, |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
435 int (*wait_func)(long wtime, int *interrupted, int ignore_input), |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
436 int *interrupted, |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
437 int ignore_input) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
438 { |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
439 int due_time; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
440 long remaining = wtime; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
441 int tb_change_cnt = typebuf.tb_change_cnt; |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
442 # ifdef FEAT_JOB_CHANNEL |
15506
8b508af36a80
patch 8.1.0761: default value for brief_wait is wrong
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
443 int brief_wait = FALSE; |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
444 # endif |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
445 |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
446 // When waiting very briefly don't trigger timers. |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
447 if (wtime >= 0 && wtime < 10L) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
448 return wait_func(wtime, NULL, ignore_input); |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
449 |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
450 while (wtime < 0 || remaining > 0) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
451 { |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
452 // Trigger timers and then get the time in wtime until the next one is |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
453 // due. Wait up to that time. |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
454 due_time = check_due_timer(); |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
455 if (typebuf.tb_change_cnt != tb_change_cnt) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
456 { |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
457 /* timer may have used feedkeys() */ |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
458 return FAIL; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
459 } |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
460 if (due_time <= 0 || (wtime > 0 && due_time > remaining)) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
461 due_time = remaining; |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
462 # ifdef FEAT_JOB_CHANNEL |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
463 if ((due_time < 0 || due_time > 10L) |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
464 # ifdef FEAT_GUI |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
465 && !gui.in_use |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
466 # endif |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
467 && (has_pending_job() || channel_any_readahead())) |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
468 { |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
469 // There is a pending job or channel, should return soon in order |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
470 // to handle them ASAP. Do check for input briefly. |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
471 due_time = 10L; |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
472 brief_wait = TRUE; |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
473 } |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
474 # endif |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
475 if (wait_func(due_time, interrupted, ignore_input)) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
476 return OK; |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
477 if ((interrupted != NULL && *interrupted) |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
478 # ifdef FEAT_JOB_CHANNEL |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
479 || brief_wait |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
480 # endif |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
481 ) |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
482 // Nothing available, but need to return so that side effects get |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
483 // handled, such as handling a message on a channel. |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
484 return FAIL; |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
485 if (wtime > 0) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
486 remaining -= due_time; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
487 } |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
488 return FAIL; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
489 } |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
490 #endif |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
491 |
7 | 492 /* |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
493 * Return non-zero if a character is available. |
7 | 494 */ |
495 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
496 ui_char_avail(void) |
7 | 497 { |
498 #ifdef FEAT_GUI | |
499 if (gui.in_use) | |
500 { | |
501 gui_mch_update(); | |
502 return input_available(); | |
503 } | |
504 #endif | |
505 #ifndef NO_CONSOLE | |
506 # ifdef NO_CONSOLE_INPUT | |
507 if (no_console_input()) | |
508 return 0; | |
509 # endif | |
510 return mch_char_avail(); | |
511 #else | |
512 return 0; | |
513 #endif | |
514 } | |
515 | |
516 /* | |
517 * Delay for the given number of milliseconds. If ignoreinput is FALSE then we | |
518 * cancel the delay if a key is hit. | |
519 */ | |
520 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
521 ui_delay(long msec, int ignoreinput) |
7 | 522 { |
523 #ifdef FEAT_GUI | |
524 if (gui.in_use && !ignoreinput) | |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
525 gui_wait_for_chars(msec, typebuf.tb_change_cnt); |
7 | 526 else |
527 #endif | |
528 mch_delay(msec, ignoreinput); | |
529 } | |
530 | |
531 /* | |
532 * If the machine has job control, use it to suspend the program, | |
533 * otherwise fake it by starting a new shell. | |
534 * When running the GUI iconify the window. | |
535 */ | |
536 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
537 ui_suspend(void) |
7 | 538 { |
539 #ifdef FEAT_GUI | |
540 if (gui.in_use) | |
541 { | |
542 gui_mch_iconify(); | |
543 return; | |
544 } | |
545 #endif | |
546 mch_suspend(); | |
547 } | |
548 | |
549 #if !defined(UNIX) || !defined(SIGTSTP) || defined(PROTO) || defined(__BEOS__) | |
550 /* | |
551 * When the OS can't really suspend, call this function to start a shell. | |
552 * This is never called in the GUI. | |
553 */ | |
554 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
555 suspend_shell(void) |
7 | 556 { |
557 if (*p_sh == NUL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15404
diff
changeset
|
558 emsg(_(e_shellempty)); |
7 | 559 else |
560 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
561 msg_puts(_("new shell started\n")); |
7 | 562 do_shell(NULL, 0); |
563 } | |
564 } | |
565 #endif | |
566 | |
567 /* | |
568 * Try to get the current Vim shell size. Put the result in Rows and Columns. | |
569 * Use the new sizes as defaults for 'columns' and 'lines'. | |
570 * Return OK when size could be determined, FAIL otherwise. | |
571 */ | |
572 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
573 ui_get_shellsize(void) |
7 | 574 { |
575 int retval; | |
576 | |
577 #ifdef FEAT_GUI | |
578 if (gui.in_use) | |
579 retval = gui_get_shellsize(); | |
580 else | |
581 #endif | |
582 retval = mch_get_shellsize(); | |
583 | |
584 check_shellsize(); | |
585 | |
586 /* adjust the default for 'lines' and 'columns' */ | |
587 if (retval == OK) | |
588 { | |
589 set_number_default("lines", Rows); | |
590 set_number_default("columns", Columns); | |
591 } | |
592 return retval; | |
593 } | |
594 | |
595 /* | |
596 * Set the size of the Vim shell according to Rows and Columns, if possible. | |
597 * The gui_set_shellsize() or mch_set_shellsize() function will try to set the | |
598 * new size. If this is not possible, it will adjust Rows and Columns. | |
599 */ | |
600 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
601 ui_set_shellsize( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
602 int mustset UNUSED) /* set by the user */ |
7 | 603 { |
604 #ifdef FEAT_GUI | |
605 if (gui.in_use) | |
5106
c3a82208e143
updated for version 7.3.1296
Bram Moolenaar <bram@vim.org>
parents:
5037
diff
changeset
|
606 gui_set_shellsize(mustset, TRUE, RESIZE_BOTH); |
7 | 607 else |
608 #endif | |
609 mch_set_shellsize(); | |
610 } | |
611 | |
612 /* | |
613 * Called when Rows and/or Columns changed. Adjust scroll region and mouse | |
614 * region. | |
615 */ | |
616 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
617 ui_new_shellsize(void) |
7 | 618 { |
619 if (full_screen && !exiting) | |
620 { | |
621 #ifdef FEAT_GUI | |
622 if (gui.in_use) | |
623 gui_new_shellsize(); | |
624 else | |
625 #endif | |
626 mch_new_shellsize(); | |
627 } | |
628 } | |
629 | |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
630 #if (defined(FEAT_EVAL) \ |
16243
3b79a3029947
patch 8.1.1126: build failure with +terminal but without tgetent
Bram Moolenaar <Bram@vim.org>
parents:
16241
diff
changeset
|
631 && (defined(FEAT_GUI) \ |
3b79a3029947
patch 8.1.1126: build failure with +terminal but without tgetent
Bram Moolenaar <Bram@vim.org>
parents:
16241
diff
changeset
|
632 || (defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE)))) \ |
3b79a3029947
patch 8.1.1126: build failure with +terminal but without tgetent
Bram Moolenaar <Bram@vim.org>
parents:
16241
diff
changeset
|
633 || defined(FEAT_TERMINAL) \ |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
634 || defined(PROTO) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
635 /* |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
636 * Get the window position in pixels, if possible. |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
637 * Return FAIL when not possible. |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
638 */ |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
639 int |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
640 ui_get_winpos(int *x, int *y, varnumber_T timeout) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
641 { |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
642 # ifdef FEAT_GUI |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
643 if (gui.in_use) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
644 return gui_mch_get_winpos(x, y); |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
645 # endif |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
646 # if defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
647 return term_get_winpos(x, y, timeout); |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
648 # endif |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
649 } |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
650 #endif |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
651 |
7 | 652 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
653 ui_breakcheck(void) |
7 | 654 { |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
655 ui_breakcheck_force(FALSE); |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
656 } |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
657 |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
658 /* |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
659 * When "force" is true also check when the terminal is not in raw mode. |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
660 * This is useful to read input on channels. |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
661 */ |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
662 void |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
663 ui_breakcheck_force(int force) |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
664 { |
15052
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
665 static int recursive = FALSE; |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
666 int save_updating_screen = updating_screen; |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
667 |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
668 // We could be called recursively if stderr is redirected, calling |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
669 // fill_input_buf() calls settmode() when stdin isn't a tty. settmode() |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
670 // calls vgetorpeek() which calls ui_breakcheck() again. |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
671 if (recursive) |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
672 return; |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
673 recursive = TRUE; |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
674 |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
675 // We do not want gui_resize_shell() to redraw the screen here. |
10771
abc27e523e2a
patch 8.0.0275: the screen may be updated at the wrong time
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
676 ++updating_screen; |
abc27e523e2a
patch 8.0.0275: the screen may be updated at the wrong time
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
677 |
7 | 678 #ifdef FEAT_GUI |
679 if (gui.in_use) | |
680 gui_mch_update(); | |
681 else | |
682 #endif | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
683 mch_breakcheck(force); |
10771
abc27e523e2a
patch 8.0.0275: the screen may be updated at the wrong time
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
684 |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
685 if (save_updating_screen) |
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
686 updating_screen = TRUE; |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13876
diff
changeset
|
687 else |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13876
diff
changeset
|
688 reset_updating_screen(FALSE); |
15052
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
689 |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
690 recursive = FALSE; |
7 | 691 } |
692 | |
693 /***************************************************************************** | |
694 * Functions for copying and pasting text between applications. | |
695 * This is always included in a GUI version, but may also be included when the | |
696 * clipboard and mouse is available to a terminal version such as xterm. | |
697 * Note: there are some more functions in ops.c that handle selection stuff. | |
698 * | |
699 * Also note that the majority of functions here deal with the X 'primary' | |
700 * (visible - for Visual mode use) selection, and only that. There are no | |
701 * versions of these for the 'clipboard' selection, as Visual mode has no use | |
702 * for them. | |
703 */ | |
704 | |
705 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
706 | |
707 /* | |
708 * Selection stuff using Visual mode, for cutting and pasting text to other | |
709 * windows. | |
710 */ | |
711 | |
712 /* | |
713 * Call this to initialise the clipboard. Pass it FALSE if the clipboard code | |
714 * is included, but the clipboard can not be used, or TRUE if the clipboard can | |
715 * be used. Eg unix may call this with FALSE, then call it again with TRUE if | |
716 * the GUI starts. | |
717 */ | |
718 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
719 clip_init(int can_use) |
7 | 720 { |
721 VimClipboard *cb; | |
722 | |
723 cb = &clip_star; | |
724 for (;;) | |
725 { | |
726 cb->available = can_use; | |
727 cb->owned = FALSE; | |
728 cb->start.lnum = 0; | |
729 cb->start.col = 0; | |
730 cb->end.lnum = 0; | |
731 cb->end.col = 0; | |
732 cb->state = SELECT_CLEARED; | |
733 | |
734 if (cb == &clip_plus) | |
735 break; | |
736 cb = &clip_plus; | |
737 } | |
738 } | |
739 | |
740 /* | |
741 * Check whether the VIsual area has changed, and if so try to become the owner | |
742 * of the selection, and free any old converted selection we may still have | |
743 * lying around. If the VIsual mode has ended, make a copy of what was | |
744 * selected so we can still give it to others. Will probably have to make sure | |
745 * this is called whenever VIsual mode is ended. | |
746 */ | |
747 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
748 clip_update_selection(VimClipboard *clip) |
7 | 749 { |
3674 | 750 pos_T start, end; |
7 | 751 |
752 /* If visual mode is only due to a redo command ("."), then ignore it */ | |
753 if (!redo_VIsual_busy && VIsual_active && (State & NORMAL)) | |
754 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10771
diff
changeset
|
755 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 756 { |
757 start = VIsual; | |
758 end = curwin->w_cursor; | |
759 if (has_mbyte) | |
474 | 760 end.col += (*mb_ptr2len)(ml_get_cursor()) - 1; |
7 | 761 } |
762 else | |
763 { | |
764 start = curwin->w_cursor; | |
765 end = VIsual; | |
766 } | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10771
diff
changeset
|
767 if (!EQUAL_POS(clip->start, start) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10771
diff
changeset
|
768 || !EQUAL_POS(clip->end, end) |
3674 | 769 || clip->vmode != VIsual_mode) |
7 | 770 { |
3674 | 771 clip_clear_selection(clip); |
772 clip->start = start; | |
773 clip->end = end; | |
774 clip->vmode = VIsual_mode; | |
775 clip_free_selection(clip); | |
776 clip_own_selection(clip); | |
777 clip_gen_set_selection(clip); | |
7 | 778 } |
779 } | |
780 } | |
781 | |
782 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
783 clip_own_selection(VimClipboard *cbd) |
7 | 784 { |
785 /* | |
786 * Also want to check somehow that we are reading from the keyboard rather | |
787 * than a mapping etc. | |
788 */ | |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
789 #ifdef FEAT_X11 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
790 /* Always own the selection, we might have lost it without being |
2586 | 791 * notified, e.g. during a ":sh" command. */ |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
792 if (cbd->available) |
7 | 793 { |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
794 int was_owned = cbd->owned; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
795 |
7 | 796 cbd->owned = (clip_gen_own_selection(cbd) == OK); |
3674 | 797 if (!was_owned && (cbd == &clip_star || cbd == &clip_plus)) |
7 | 798 { |
620 | 799 /* May have to show a different kind of highlighting for the |
800 * selected area. There is no specific redraw command for this, | |
801 * just redraw all windows on the current buffer. */ | |
7 | 802 if (cbd->owned |
791 | 803 && (get_real_state() == VISUAL |
804 || get_real_state() == SELECTMODE) | |
3674 | 805 && (cbd == &clip_star ? clip_isautosel_star() |
806 : clip_isautosel_plus()) | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
807 && HL_ATTR(HLF_V) != HL_ATTR(HLF_VNC)) |
7 | 808 redraw_curbuf_later(INVERTED_ALL); |
809 } | |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
810 } |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
811 #else |
3877 | 812 /* Only own the clipboard when we didn't own it yet. */ |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
813 if (!cbd->owned && cbd->available) |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
814 cbd->owned = (clip_gen_own_selection(cbd) == OK); |
7 | 815 #endif |
816 } | |
817 | |
818 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
819 clip_lose_selection(VimClipboard *cbd) |
7 | 820 { |
821 #ifdef FEAT_X11 | |
822 int was_owned = cbd->owned; | |
823 #endif | |
3674 | 824 int visual_selection = FALSE; |
825 | |
826 if (cbd == &clip_star || cbd == &clip_plus) | |
827 visual_selection = TRUE; | |
7 | 828 |
829 clip_free_selection(cbd); | |
830 cbd->owned = FALSE; | |
831 if (visual_selection) | |
3674 | 832 clip_clear_selection(cbd); |
7 | 833 clip_gen_lose_selection(cbd); |
834 #ifdef FEAT_X11 | |
835 if (visual_selection) | |
836 { | |
837 /* May have to show a different kind of highlighting for the selected | |
838 * area. There is no specific redraw command for this, just redraw all | |
839 * windows on the current buffer. */ | |
840 if (was_owned | |
791 | 841 && (get_real_state() == VISUAL |
842 || get_real_state() == SELECTMODE) | |
3674 | 843 && (cbd == &clip_star ? |
844 clip_isautosel_star() : clip_isautosel_plus()) | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
845 && HL_ATTR(HLF_V) != HL_ATTR(HLF_VNC)) |
7 | 846 { |
847 update_curbuf(INVERTED_ALL); | |
848 setcursor(); | |
849 cursor_on(); | |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
850 out_flush_cursor(TRUE, FALSE); |
7 | 851 } |
852 } | |
853 #endif | |
854 } | |
855 | |
3674 | 856 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
857 clip_copy_selection(VimClipboard *clip) |
7 | 858 { |
3674 | 859 if (VIsual_active && (State & NORMAL) && clip->available) |
7 | 860 { |
3674 | 861 clip_update_selection(clip); |
862 clip_free_selection(clip); | |
863 clip_own_selection(clip); | |
864 if (clip->owned) | |
865 clip_get_selection(clip); | |
866 clip_gen_set_selection(clip); | |
7 | 867 } |
868 } | |
869 | |
870 /* | |
6116 | 871 * Save and restore clip_unnamed before doing possibly many changes. This |
872 * prevents accessing the clipboard very often which might slow down Vim | |
873 * considerably. | |
874 */ | |
6561 | 875 static int global_change_count = 0; /* if set, inside a start_global_changes */ |
11273
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
876 static int clipboard_needs_update = FALSE; /* clipboard needs to be updated */ |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
877 static int clip_did_set_selection = TRUE; |
6116 | 878 |
879 /* | |
880 * Save clip_unnamed and reset it. | |
881 */ | |
882 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
883 start_global_changes(void) |
6116 | 884 { |
6543 | 885 if (++global_change_count > 1) |
886 return; | |
6116 | 887 clip_unnamed_saved = clip_unnamed; |
6543 | 888 clipboard_needs_update = FALSE; |
6116 | 889 |
6543 | 890 if (clip_did_set_selection) |
6116 | 891 { |
892 clip_unnamed = FALSE; | |
893 clip_did_set_selection = FALSE; | |
894 } | |
895 } | |
896 | |
897 /* | |
11273
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
898 * Return TRUE if setting the clipboard was postponed, it already contains the |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
899 * right text. |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
900 */ |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
901 int |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
902 is_clipboard_needs_update() |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
903 { |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
904 return clipboard_needs_update; |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
905 } |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
906 |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
907 /* |
6116 | 908 * Restore clip_unnamed and set the selection when needed. |
909 */ | |
910 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
911 end_global_changes(void) |
6116 | 912 { |
6543 | 913 if (--global_change_count > 0) |
914 /* recursive */ | |
915 return; | |
916 if (!clip_did_set_selection) | |
6116 | 917 { |
918 clip_did_set_selection = TRUE; | |
919 clip_unnamed = clip_unnamed_saved; | |
6543 | 920 clip_unnamed_saved = FALSE; |
921 if (clipboard_needs_update) | |
6116 | 922 { |
6543 | 923 /* only store something in the clipboard, |
924 * if we have yanked anything to it */ | |
925 if (clip_unnamed & CLIP_UNNAMED) | |
926 { | |
927 clip_own_selection(&clip_star); | |
928 clip_gen_set_selection(&clip_star); | |
929 } | |
930 if (clip_unnamed & CLIP_UNNAMED_PLUS) | |
931 { | |
932 clip_own_selection(&clip_plus); | |
933 clip_gen_set_selection(&clip_plus); | |
934 } | |
6116 | 935 } |
936 } | |
11273
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
937 clipboard_needs_update = FALSE; |
6116 | 938 } |
939 | |
940 /* | |
7 | 941 * Called when Visual mode is ended: update the selection. |
942 */ | |
943 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
944 clip_auto_select(void) |
7 | 945 { |
3674 | 946 if (clip_isautosel_star()) |
947 clip_copy_selection(&clip_star); | |
948 if (clip_isautosel_plus()) | |
949 clip_copy_selection(&clip_plus); | |
7 | 950 } |
951 | |
952 /* | |
3674 | 953 * Return TRUE if automatic selection of Visual area is desired for the * |
954 * register. | |
7 | 955 */ |
956 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
957 clip_isautosel_star(void) |
7 | 958 { |
959 return ( | |
960 #ifdef FEAT_GUI | |
961 gui.in_use ? (vim_strchr(p_go, GO_ASEL) != NULL) : | |
962 #endif | |
3674 | 963 clip_autoselect_star); |
964 } | |
965 | |
966 /* | |
967 * Return TRUE if automatic selection of Visual area is desired for the + | |
968 * register. | |
969 */ | |
970 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
971 clip_isautosel_plus(void) |
3674 | 972 { |
973 return ( | |
974 #ifdef FEAT_GUI | |
975 gui.in_use ? (vim_strchr(p_go, GO_ASELPLUS) != NULL) : | |
976 #endif | |
977 clip_autoselect_plus); | |
7 | 978 } |
979 | |
980 | |
981 /* | |
982 * Stuff for general mouse selection, without using Visual mode. | |
983 */ | |
984 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
985 static void clip_invert_area(int, int, int, int, int how); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
986 static void clip_invert_rectangle(int row, int col, int height, int width, int invert); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
987 static void clip_get_word_boundaries(VimClipboard *, int, int); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
988 static int clip_get_line_end(int); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
989 static void clip_update_modeless_selection(VimClipboard *, int, int, |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
990 int, int); |
7 | 991 |
992 /* flags for clip_invert_area() */ | |
993 #define CLIP_CLEAR 1 | |
994 #define CLIP_SET 2 | |
995 #define CLIP_TOGGLE 3 | |
996 | |
997 /* | |
998 * Start, continue or end a modeless selection. Used when editing the | |
999 * command-line and in the cmdline window. | |
1000 */ | |
1001 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1002 clip_modeless(int button, int is_click, int is_drag) |
7 | 1003 { |
1004 int repeat; | |
1005 | |
1006 repeat = ((clip_star.mode == SELECT_MODE_CHAR | |
1007 || clip_star.mode == SELECT_MODE_LINE) | |
1008 && (mod_mask & MOD_MASK_2CLICK)) | |
1009 || (clip_star.mode == SELECT_MODE_WORD | |
1010 && (mod_mask & MOD_MASK_3CLICK)); | |
1011 if (is_click && button == MOUSE_RIGHT) | |
1012 { | |
1013 /* Right mouse button: If there was no selection, start one. | |
1014 * Otherwise extend the existing selection. */ | |
1015 if (clip_star.state == SELECT_CLEARED) | |
1016 clip_start_selection(mouse_col, mouse_row, FALSE); | |
1017 clip_process_selection(button, mouse_col, mouse_row, repeat); | |
1018 } | |
1019 else if (is_click) | |
1020 clip_start_selection(mouse_col, mouse_row, repeat); | |
1021 else if (is_drag) | |
1022 { | |
1023 /* Don't try extending a selection if there isn't one. Happens when | |
1024 * button-down is in the cmdline and them moving mouse upwards. */ | |
1025 if (clip_star.state != SELECT_CLEARED) | |
1026 clip_process_selection(button, mouse_col, mouse_row, repeat); | |
1027 } | |
1028 else /* release */ | |
1029 clip_process_selection(MOUSE_RELEASE, mouse_col, mouse_row, FALSE); | |
1030 } | |
1031 | |
1032 /* | |
1033 * Compare two screen positions ala strcmp() | |
1034 */ | |
1035 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1036 clip_compare_pos( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1037 int row1, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1038 int col1, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1039 int row2, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1040 int col2) |
7 | 1041 { |
1042 if (row1 > row2) return(1); | |
1043 if (row1 < row2) return(-1); | |
1044 if (col1 > col2) return(1); | |
1045 if (col1 < col2) return(-1); | |
8236
6d221d623c8e
commit https://github.com/vim/vim/commit/9e34110816522b081feb65ed5b2f4ec03d290e30
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
1046 return(0); |
7 | 1047 } |
1048 | |
1049 /* | |
1050 * Start the selection | |
1051 */ | |
1052 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1053 clip_start_selection(int col, int row, int repeated_click) |
7 | 1054 { |
1055 VimClipboard *cb = &clip_star; | |
1056 | |
1057 if (cb->state == SELECT_DONE) | |
3674 | 1058 clip_clear_selection(cb); |
7 | 1059 |
1060 row = check_row(row); | |
1061 col = check_col(col); | |
1062 col = mb_fix_col(col, row); | |
1063 | |
1064 cb->start.lnum = row; | |
1065 cb->start.col = col; | |
1066 cb->end = cb->start; | |
1067 cb->origin_row = (short_u)cb->start.lnum; | |
1068 cb->state = SELECT_IN_PROGRESS; | |
1069 | |
1070 if (repeated_click) | |
1071 { | |
1072 if (++cb->mode > SELECT_MODE_LINE) | |
1073 cb->mode = SELECT_MODE_CHAR; | |
1074 } | |
1075 else | |
1076 cb->mode = SELECT_MODE_CHAR; | |
1077 | |
1078 #ifdef FEAT_GUI | |
1079 /* clear the cursor until the selection is made */ | |
1080 if (gui.in_use) | |
1081 gui_undraw_cursor(); | |
1082 #endif | |
1083 | |
1084 switch (cb->mode) | |
1085 { | |
1086 case SELECT_MODE_CHAR: | |
1087 cb->origin_start_col = cb->start.col; | |
1088 cb->word_end_col = clip_get_line_end((int)cb->start.lnum); | |
1089 break; | |
1090 | |
1091 case SELECT_MODE_WORD: | |
1092 clip_get_word_boundaries(cb, (int)cb->start.lnum, cb->start.col); | |
1093 cb->origin_start_col = cb->word_start_col; | |
1094 cb->origin_end_col = cb->word_end_col; | |
1095 | |
1096 clip_invert_area((int)cb->start.lnum, cb->word_start_col, | |
1097 (int)cb->end.lnum, cb->word_end_col, CLIP_SET); | |
1098 cb->start.col = cb->word_start_col; | |
1099 cb->end.col = cb->word_end_col; | |
1100 break; | |
1101 | |
1102 case SELECT_MODE_LINE: | |
1103 clip_invert_area((int)cb->start.lnum, 0, (int)cb->start.lnum, | |
1104 (int)Columns, CLIP_SET); | |
1105 cb->start.col = 0; | |
1106 cb->end.col = Columns; | |
1107 break; | |
1108 } | |
1109 | |
1110 cb->prev = cb->start; | |
1111 | |
1112 #ifdef DEBUG_SELECTION | |
1113 printf("Selection started at (%u,%u)\n", cb->start.lnum, cb->start.col); | |
1114 #endif | |
1115 } | |
1116 | |
1117 /* | |
1118 * Continue processing the selection | |
1119 */ | |
1120 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1121 clip_process_selection( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1122 int button, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1123 int col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1124 int row, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1125 int_u repeated_click) |
7 | 1126 { |
1127 VimClipboard *cb = &clip_star; | |
1128 int diff; | |
1129 int slen = 1; /* cursor shape width */ | |
1130 | |
1131 if (button == MOUSE_RELEASE) | |
1132 { | |
1133 /* Check to make sure we have something selected */ | |
1134 if (cb->start.lnum == cb->end.lnum && cb->start.col == cb->end.col) | |
1135 { | |
1136 #ifdef FEAT_GUI | |
1137 if (gui.in_use) | |
1138 gui_update_cursor(FALSE, FALSE); | |
1139 #endif | |
1140 cb->state = SELECT_CLEARED; | |
1141 return; | |
1142 } | |
1143 | |
1144 #ifdef DEBUG_SELECTION | |
1145 printf("Selection ended: (%u,%u) to (%u,%u)\n", cb->start.lnum, | |
1146 cb->start.col, cb->end.lnum, cb->end.col); | |
1147 #endif | |
3674 | 1148 if (clip_isautosel_star() |
7 | 1149 || ( |
1150 #ifdef FEAT_GUI | |
1151 gui.in_use ? (vim_strchr(p_go, GO_ASELML) != NULL) : | |
1152 #endif | |
1153 clip_autoselectml)) | |
1154 clip_copy_modeless_selection(FALSE); | |
1155 #ifdef FEAT_GUI | |
1156 if (gui.in_use) | |
1157 gui_update_cursor(FALSE, FALSE); | |
1158 #endif | |
1159 | |
1160 cb->state = SELECT_DONE; | |
1161 return; | |
1162 } | |
1163 | |
1164 row = check_row(row); | |
1165 col = check_col(col); | |
1166 col = mb_fix_col(col, row); | |
1167 | |
1168 if (col == (int)cb->prev.col && row == cb->prev.lnum && !repeated_click) | |
1169 return; | |
1170 | |
1171 /* | |
1172 * When extending the selection with the right mouse button, swap the | |
1173 * start and end if the position is before half the selection | |
1174 */ | |
1175 if (cb->state == SELECT_DONE && button == MOUSE_RIGHT) | |
1176 { | |
1177 /* | |
1178 * If the click is before the start, or the click is inside the | |
1179 * selection and the start is the closest side, set the origin to the | |
1180 * end of the selection. | |
1181 */ | |
1182 if (clip_compare_pos(row, col, (int)cb->start.lnum, cb->start.col) < 0 | |
1183 || (clip_compare_pos(row, col, | |
1184 (int)cb->end.lnum, cb->end.col) < 0 | |
1185 && (((cb->start.lnum == cb->end.lnum | |
1186 && cb->end.col - col > col - cb->start.col)) | |
1187 || ((diff = (cb->end.lnum - row) - | |
1188 (row - cb->start.lnum)) > 0 | |
1189 || (diff == 0 && col < (int)(cb->start.col + | |
1190 cb->end.col) / 2))))) | |
1191 { | |
1192 cb->origin_row = (short_u)cb->end.lnum; | |
1193 cb->origin_start_col = cb->end.col - 1; | |
1194 cb->origin_end_col = cb->end.col; | |
1195 } | |
1196 else | |
1197 { | |
1198 cb->origin_row = (short_u)cb->start.lnum; | |
1199 cb->origin_start_col = cb->start.col; | |
1200 cb->origin_end_col = cb->start.col; | |
1201 } | |
1202 if (cb->mode == SELECT_MODE_WORD && !repeated_click) | |
1203 cb->mode = SELECT_MODE_CHAR; | |
1204 } | |
1205 | |
1206 /* set state, for when using the right mouse button */ | |
1207 cb->state = SELECT_IN_PROGRESS; | |
1208 | |
1209 #ifdef DEBUG_SELECTION | |
1210 printf("Selection extending to (%d,%d)\n", row, col); | |
1211 #endif | |
1212 | |
1213 if (repeated_click && ++cb->mode > SELECT_MODE_LINE) | |
1214 cb->mode = SELECT_MODE_CHAR; | |
1215 | |
1216 switch (cb->mode) | |
1217 { | |
1218 case SELECT_MODE_CHAR: | |
1219 /* If we're on a different line, find where the line ends */ | |
1220 if (row != cb->prev.lnum) | |
1221 cb->word_end_col = clip_get_line_end(row); | |
1222 | |
1223 /* See if we are before or after the origin of the selection */ | |
1224 if (clip_compare_pos(row, col, cb->origin_row, | |
1225 cb->origin_start_col) >= 0) | |
1226 { | |
1227 if (col >= (int)cb->word_end_col) | |
1228 clip_update_modeless_selection(cb, cb->origin_row, | |
1229 cb->origin_start_col, row, (int)Columns); | |
1230 else | |
1231 { | |
1232 if (has_mbyte && mb_lefthalve(row, col)) | |
1233 slen = 2; | |
1234 clip_update_modeless_selection(cb, cb->origin_row, | |
1235 cb->origin_start_col, row, col + slen); | |
1236 } | |
1237 } | |
1238 else | |
1239 { | |
1240 if (has_mbyte | |
1241 && mb_lefthalve(cb->origin_row, cb->origin_start_col)) | |
1242 slen = 2; | |
1243 if (col >= (int)cb->word_end_col) | |
1244 clip_update_modeless_selection(cb, row, cb->word_end_col, | |
1245 cb->origin_row, cb->origin_start_col + slen); | |
1246 else | |
1247 clip_update_modeless_selection(cb, row, col, | |
1248 cb->origin_row, cb->origin_start_col + slen); | |
1249 } | |
1250 break; | |
1251 | |
1252 case SELECT_MODE_WORD: | |
1253 /* If we are still within the same word, do nothing */ | |
1254 if (row == cb->prev.lnum && col >= (int)cb->word_start_col | |
1255 && col < (int)cb->word_end_col && !repeated_click) | |
1256 return; | |
1257 | |
1258 /* Get new word boundaries */ | |
1259 clip_get_word_boundaries(cb, row, col); | |
1260 | |
1261 /* Handle being after the origin point of selection */ | |
1262 if (clip_compare_pos(row, col, cb->origin_row, | |
1263 cb->origin_start_col) >= 0) | |
1264 clip_update_modeless_selection(cb, cb->origin_row, | |
1265 cb->origin_start_col, row, cb->word_end_col); | |
1266 else | |
1267 clip_update_modeless_selection(cb, row, cb->word_start_col, | |
1268 cb->origin_row, cb->origin_end_col); | |
1269 break; | |
1270 | |
1271 case SELECT_MODE_LINE: | |
1272 if (row == cb->prev.lnum && !repeated_click) | |
1273 return; | |
1274 | |
1275 if (clip_compare_pos(row, col, cb->origin_row, | |
1276 cb->origin_start_col) >= 0) | |
1277 clip_update_modeless_selection(cb, cb->origin_row, 0, row, | |
1278 (int)Columns); | |
1279 else | |
1280 clip_update_modeless_selection(cb, row, 0, cb->origin_row, | |
1281 (int)Columns); | |
1282 break; | |
1283 } | |
1284 | |
1285 cb->prev.lnum = row; | |
1286 cb->prev.col = col; | |
1287 | |
1288 #ifdef DEBUG_SELECTION | |
1289 printf("Selection is: (%u,%u) to (%u,%u)\n", cb->start.lnum, | |
1290 cb->start.col, cb->end.lnum, cb->end.col); | |
1291 #endif | |
1292 } | |
1293 | |
1294 # if defined(FEAT_GUI) || defined(PROTO) | |
1295 /* | |
1296 * Redraw part of the selection if character at "row,col" is inside of it. | |
1297 * Only used for the GUI. | |
1298 */ | |
1299 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1300 clip_may_redraw_selection(int row, int col, int len) |
7 | 1301 { |
1302 int start = col; | |
1303 int end = col + len; | |
1304 | |
1305 if (clip_star.state != SELECT_CLEARED | |
1306 && row >= clip_star.start.lnum | |
1307 && row <= clip_star.end.lnum) | |
1308 { | |
1309 if (row == clip_star.start.lnum && start < (int)clip_star.start.col) | |
1310 start = clip_star.start.col; | |
1311 if (row == clip_star.end.lnum && end > (int)clip_star.end.col) | |
1312 end = clip_star.end.col; | |
1313 if (end > start) | |
1314 clip_invert_area(row, start, row, end, 0); | |
1315 } | |
1316 } | |
1317 # endif | |
1318 | |
1319 /* | |
1320 * Called from outside to clear selected region from the display | |
1321 */ | |
1322 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1323 clip_clear_selection(VimClipboard *cbd) |
7 | 1324 { |
1325 | |
3674 | 1326 if (cbd->state == SELECT_CLEARED) |
7 | 1327 return; |
1328 | |
3674 | 1329 clip_invert_area((int)cbd->start.lnum, cbd->start.col, (int)cbd->end.lnum, |
1330 cbd->end.col, CLIP_CLEAR); | |
1331 cbd->state = SELECT_CLEARED; | |
7 | 1332 } |
1333 | |
1334 /* | |
1335 * Clear the selection if any lines from "row1" to "row2" are inside of it. | |
1336 */ | |
1337 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1338 clip_may_clear_selection(int row1, int row2) |
7 | 1339 { |
1340 if (clip_star.state == SELECT_DONE | |
1341 && row2 >= clip_star.start.lnum | |
1342 && row1 <= clip_star.end.lnum) | |
3674 | 1343 clip_clear_selection(&clip_star); |
7 | 1344 } |
1345 | |
1346 /* | |
1347 * Called before the screen is scrolled up or down. Adjusts the line numbers | |
1348 * of the selection. Call with big number when clearing the screen. | |
1349 */ | |
1350 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1351 clip_scroll_selection( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1352 int rows) /* negative for scroll down */ |
7 | 1353 { |
1354 int lnum; | |
1355 | |
1356 if (clip_star.state == SELECT_CLEARED) | |
1357 return; | |
1358 | |
1359 lnum = clip_star.start.lnum - rows; | |
1360 if (lnum <= 0) | |
1361 clip_star.start.lnum = 0; | |
1362 else if (lnum >= screen_Rows) /* scrolled off of the screen */ | |
1363 clip_star.state = SELECT_CLEARED; | |
1364 else | |
1365 clip_star.start.lnum = lnum; | |
1366 | |
1367 lnum = clip_star.end.lnum - rows; | |
1368 if (lnum < 0) /* scrolled off of the screen */ | |
1369 clip_star.state = SELECT_CLEARED; | |
1370 else if (lnum >= screen_Rows) | |
1371 clip_star.end.lnum = screen_Rows - 1; | |
1372 else | |
1373 clip_star.end.lnum = lnum; | |
1374 } | |
1375 | |
1376 /* | |
1377 * Invert a region of the display between a starting and ending row and column | |
1378 * Values for "how": | |
1379 * CLIP_CLEAR: undo inversion | |
1380 * CLIP_SET: set inversion | |
1381 * CLIP_TOGGLE: set inversion if pos1 < pos2, undo inversion otherwise. | |
1382 * 0: invert (GUI only). | |
1383 */ | |
1384 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1385 clip_invert_area( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1386 int row1, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1387 int col1, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1388 int row2, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1389 int col2, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1390 int how) |
7 | 1391 { |
1392 int invert = FALSE; | |
1393 | |
1394 if (how == CLIP_SET) | |
1395 invert = TRUE; | |
1396 | |
1397 /* Swap the from and to positions so the from is always before */ | |
1398 if (clip_compare_pos(row1, col1, row2, col2) > 0) | |
1399 { | |
1400 int tmp_row, tmp_col; | |
1401 | |
1402 tmp_row = row1; | |
1403 tmp_col = col1; | |
1404 row1 = row2; | |
1405 col1 = col2; | |
1406 row2 = tmp_row; | |
1407 col2 = tmp_col; | |
1408 } | |
1409 else if (how == CLIP_TOGGLE) | |
1410 invert = TRUE; | |
1411 | |
1412 /* If all on the same line, do it the easy way */ | |
1413 if (row1 == row2) | |
1414 { | |
1415 clip_invert_rectangle(row1, col1, 1, col2 - col1, invert); | |
1416 } | |
1417 else | |
1418 { | |
1419 /* Handle a piece of the first line */ | |
1420 if (col1 > 0) | |
1421 { | |
1422 clip_invert_rectangle(row1, col1, 1, (int)Columns - col1, invert); | |
1423 row1++; | |
1424 } | |
1425 | |
1426 /* Handle a piece of the last line */ | |
1427 if (col2 < Columns - 1) | |
1428 { | |
1429 clip_invert_rectangle(row2, 0, 1, col2, invert); | |
1430 row2--; | |
1431 } | |
1432 | |
1433 /* Handle the rectangle thats left */ | |
1434 if (row2 >= row1) | |
1435 clip_invert_rectangle(row1, 0, row2 - row1 + 1, (int)Columns, | |
1436 invert); | |
1437 } | |
1438 } | |
1439 | |
1440 /* | |
1441 * Invert or un-invert a rectangle of the screen. | |
1442 * "invert" is true if the result is inverted. | |
1443 */ | |
1444 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1445 clip_invert_rectangle( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1446 int row, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1447 int col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1448 int height, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1449 int width, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1450 int invert) |
7 | 1451 { |
1452 #ifdef FEAT_GUI | |
1453 if (gui.in_use) | |
1454 gui_mch_invert_rectangle(row, col, height, width); | |
1455 else | |
1456 #endif | |
1457 screen_draw_rectangle(row, col, height, width, invert); | |
1458 } | |
1459 | |
1460 /* | |
1461 * Copy the currently selected area into the '*' register so it will be | |
1462 * available for pasting. | |
1463 * When "both" is TRUE also copy to the '+' register. | |
1464 */ | |
1465 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1466 clip_copy_modeless_selection(int both UNUSED) |
7 | 1467 { |
1468 char_u *buffer; | |
1469 char_u *bufp; | |
1470 int row; | |
1471 int start_col; | |
1472 int end_col; | |
1473 int line_end_col; | |
1474 int add_newline_flag = FALSE; | |
1475 int len; | |
1476 char_u *p; | |
1477 int row1 = clip_star.start.lnum; | |
1478 int col1 = clip_star.start.col; | |
1479 int row2 = clip_star.end.lnum; | |
1480 int col2 = clip_star.end.col; | |
1481 | |
534 | 1482 /* Can't use ScreenLines unless initialized */ |
1483 if (ScreenLines == NULL) | |
1484 return; | |
1485 | |
7 | 1486 /* |
1487 * Make sure row1 <= row2, and if row1 == row2 that col1 <= col2. | |
1488 */ | |
1489 if (row1 > row2) | |
1490 { | |
1491 row = row1; row1 = row2; row2 = row; | |
1492 row = col1; col1 = col2; col2 = row; | |
1493 } | |
1494 else if (row1 == row2 && col1 > col2) | |
1495 { | |
1496 row = col1; col1 = col2; col2 = row; | |
1497 } | |
1498 /* correct starting point for being on right halve of double-wide char */ | |
1499 p = ScreenLines + LineOffset[row1]; | |
1500 if (enc_dbcs != 0) | |
1501 col1 -= (*mb_head_off)(p, p + col1); | |
1502 else if (enc_utf8 && p[col1] == 0) | |
1503 --col1; | |
1504 | |
1505 /* Create a temporary buffer for storing the text */ | |
1506 len = (row2 - row1 + 1) * Columns + 1; | |
1507 if (enc_dbcs != 0) | |
1508 len *= 2; /* max. 2 bytes per display cell */ | |
1509 else if (enc_utf8) | |
714 | 1510 len *= MB_MAXBYTES; |
7 | 1511 buffer = lalloc((long_u)len, TRUE); |
1512 if (buffer == NULL) /* out of memory */ | |
1513 return; | |
1514 | |
1515 /* Process each row in the selection */ | |
1516 for (bufp = buffer, row = row1; row <= row2; row++) | |
1517 { | |
1518 if (row == row1) | |
1519 start_col = col1; | |
1520 else | |
1521 start_col = 0; | |
1522 | |
1523 if (row == row2) | |
1524 end_col = col2; | |
1525 else | |
1526 end_col = Columns; | |
1527 | |
1528 line_end_col = clip_get_line_end(row); | |
1529 | |
1530 /* See if we need to nuke some trailing whitespace */ | |
1531 if (end_col >= Columns && (row < row2 || end_col > line_end_col)) | |
1532 { | |
1533 /* Get rid of trailing whitespace */ | |
1534 end_col = line_end_col; | |
1535 if (end_col < start_col) | |
1536 end_col = start_col; | |
1537 | |
1538 /* If the last line extended to the end, add an extra newline */ | |
1539 if (row == row2) | |
1540 add_newline_flag = TRUE; | |
1541 } | |
1542 | |
1543 /* If after the first row, we need to always add a newline */ | |
1544 if (row > row1 && !LineWraps[row - 1]) | |
1545 *bufp++ = NL; | |
1546 | |
1547 if (row < screen_Rows && end_col <= screen_Columns) | |
1548 { | |
1549 if (enc_dbcs != 0) | |
1550 { | |
944 | 1551 int i; |
1552 | |
7 | 1553 p = ScreenLines + LineOffset[row]; |
1554 for (i = start_col; i < end_col; ++i) | |
1555 if (enc_dbcs == DBCS_JPNU && p[i] == 0x8e) | |
1556 { | |
1557 /* single-width double-byte char */ | |
1558 *bufp++ = 0x8e; | |
1559 *bufp++ = ScreenLines2[LineOffset[row] + i]; | |
1560 } | |
1561 else | |
1562 { | |
1563 *bufp++ = p[i]; | |
1564 if (MB_BYTE2LEN(p[i]) == 2) | |
1565 *bufp++ = p[++i]; | |
1566 } | |
1567 } | |
1568 else if (enc_utf8) | |
1569 { | |
1570 int off; | |
714 | 1571 int i; |
761 | 1572 int ci; |
7 | 1573 |
1574 off = LineOffset[row]; | |
1575 for (i = start_col; i < end_col; ++i) | |
1576 { | |
1577 /* The base character is either in ScreenLinesUC[] or | |
1578 * ScreenLines[]. */ | |
1579 if (ScreenLinesUC[off + i] == 0) | |
1580 *bufp++ = ScreenLines[off + i]; | |
1581 else | |
1582 { | |
1583 bufp += utf_char2bytes(ScreenLinesUC[off + i], bufp); | |
761 | 1584 for (ci = 0; ci < Screen_mco; ++ci) |
7 | 1585 { |
714 | 1586 /* Add a composing character. */ |
761 | 1587 if (ScreenLinesC[ci][off + i] == 0) |
714 | 1588 break; |
761 | 1589 bufp += utf_char2bytes(ScreenLinesC[ci][off + i], |
7 | 1590 bufp); |
1591 } | |
1592 } | |
1593 /* Skip right halve of double-wide character. */ | |
1594 if (ScreenLines[off + i + 1] == 0) | |
1595 ++i; | |
1596 } | |
1597 } | |
1598 else | |
1599 { | |
1600 STRNCPY(bufp, ScreenLines + LineOffset[row] + start_col, | |
1601 end_col - start_col); | |
1602 bufp += end_col - start_col; | |
1603 } | |
1604 } | |
1605 } | |
1606 | |
1607 /* Add a newline at the end if the selection ended there */ | |
1608 if (add_newline_flag) | |
1609 *bufp++ = NL; | |
1610 | |
1611 /* First cleanup any old selection and become the owner. */ | |
1612 clip_free_selection(&clip_star); | |
1613 clip_own_selection(&clip_star); | |
1614 | |
1615 /* Yank the text into the '*' register. */ | |
1616 clip_yank_selection(MCHAR, buffer, (long)(bufp - buffer), &clip_star); | |
1617 | |
1618 /* Make the register contents available to the outside world. */ | |
1619 clip_gen_set_selection(&clip_star); | |
1620 | |
1621 #ifdef FEAT_X11 | |
1622 if (both) | |
1623 { | |
1624 /* Do the same for the '+' register. */ | |
1625 clip_free_selection(&clip_plus); | |
1626 clip_own_selection(&clip_plus); | |
1627 clip_yank_selection(MCHAR, buffer, (long)(bufp - buffer), &clip_plus); | |
1628 clip_gen_set_selection(&clip_plus); | |
1629 } | |
1630 #endif | |
1631 vim_free(buffer); | |
1632 } | |
1633 | |
1634 /* | |
1635 * Find the starting and ending positions of the word at the given row and | |
1636 * column. Only white-separated words are recognized here. | |
1637 */ | |
1638 #define CHAR_CLASS(c) (c <= ' ' ? ' ' : vim_iswordc(c)) | |
1639 | |
1640 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1641 clip_get_word_boundaries(VimClipboard *cb, int row, int col) |
7 | 1642 { |
1643 int start_class; | |
1644 int temp_col; | |
1645 char_u *p; | |
1646 int mboff; | |
1647 | |
534 | 1648 if (row >= screen_Rows || col >= screen_Columns || ScreenLines == NULL) |
7 | 1649 return; |
1650 | |
1651 p = ScreenLines + LineOffset[row]; | |
1652 /* Correct for starting in the right halve of a double-wide char */ | |
1653 if (enc_dbcs != 0) | |
1654 col -= dbcs_screen_head_off(p, p + col); | |
1655 else if (enc_utf8 && p[col] == 0) | |
1656 --col; | |
1657 start_class = CHAR_CLASS(p[col]); | |
1658 | |
1659 temp_col = col; | |
1660 for ( ; temp_col > 0; temp_col--) | |
1661 if (enc_dbcs != 0 | |
1662 && (mboff = dbcs_screen_head_off(p, p + temp_col - 1)) > 0) | |
1663 temp_col -= mboff; | |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1664 else if (CHAR_CLASS(p[temp_col - 1]) != start_class |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1665 && !(enc_utf8 && p[temp_col - 1] == 0)) |
7 | 1666 break; |
1667 cb->word_start_col = temp_col; | |
1668 | |
1669 temp_col = col; | |
1670 for ( ; temp_col < screen_Columns; temp_col++) | |
1671 if (enc_dbcs != 0 && dbcs_ptr2cells(p + temp_col) == 2) | |
1672 ++temp_col; | |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1673 else if (CHAR_CLASS(p[temp_col]) != start_class |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1674 && !(enc_utf8 && p[temp_col] == 0)) |
7 | 1675 break; |
1676 cb->word_end_col = temp_col; | |
1677 } | |
1678 | |
1679 /* | |
1680 * Find the column position for the last non-whitespace character on the given | |
1681 * line. | |
1682 */ | |
1683 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1684 clip_get_line_end(int row) |
7 | 1685 { |
1686 int i; | |
1687 | |
534 | 1688 if (row >= screen_Rows || ScreenLines == NULL) |
7 | 1689 return 0; |
1690 for (i = screen_Columns; i > 0; i--) | |
1691 if (ScreenLines[LineOffset[row] + i - 1] != ' ') | |
1692 break; | |
1693 return i; | |
1694 } | |
1695 | |
1696 /* | |
1697 * Update the currently selected region by adding and/or subtracting from the | |
1698 * beginning or end and inverting the changed area(s). | |
1699 */ | |
1700 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1701 clip_update_modeless_selection( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1702 VimClipboard *cb, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1703 int row1, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1704 int col1, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1705 int row2, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1706 int col2) |
7 | 1707 { |
1708 /* See if we changed at the beginning of the selection */ | |
1709 if (row1 != cb->start.lnum || col1 != (int)cb->start.col) | |
1710 { | |
1711 clip_invert_area(row1, col1, (int)cb->start.lnum, cb->start.col, | |
1712 CLIP_TOGGLE); | |
1713 cb->start.lnum = row1; | |
1714 cb->start.col = col1; | |
1715 } | |
1716 | |
1717 /* See if we changed at the end of the selection */ | |
1718 if (row2 != cb->end.lnum || col2 != (int)cb->end.col) | |
1719 { | |
1720 clip_invert_area((int)cb->end.lnum, cb->end.col, row2, col2, | |
1721 CLIP_TOGGLE); | |
1722 cb->end.lnum = row2; | |
1723 cb->end.col = col2; | |
1724 } | |
1725 } | |
1726 | |
1727 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1728 clip_gen_own_selection(VimClipboard *cbd) |
7 | 1729 { |
1730 #ifdef FEAT_XCLIPBOARD | |
1731 # ifdef FEAT_GUI | |
1732 if (gui.in_use) | |
1733 return clip_mch_own_selection(cbd); | |
1734 else | |
1735 # endif | |
1736 return clip_xterm_own_selection(cbd); | |
1737 #else | |
1738 return clip_mch_own_selection(cbd); | |
1739 #endif | |
1740 } | |
1741 | |
1742 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1743 clip_gen_lose_selection(VimClipboard *cbd) |
7 | 1744 { |
1745 #ifdef FEAT_XCLIPBOARD | |
1746 # ifdef FEAT_GUI | |
1747 if (gui.in_use) | |
1748 clip_mch_lose_selection(cbd); | |
1749 else | |
1750 # endif | |
1751 clip_xterm_lose_selection(cbd); | |
1752 #else | |
1753 clip_mch_lose_selection(cbd); | |
1754 #endif | |
1755 } | |
1756 | |
1757 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1758 clip_gen_set_selection(VimClipboard *cbd) |
7 | 1759 { |
6116 | 1760 if (!clip_did_set_selection) |
1761 { | |
1762 /* Updating postponed, so that accessing the system clipboard won't | |
15967
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1763 * hang Vim when accessing it many times (e.g. on a :g command). */ |
6543 | 1764 if ((cbd == &clip_plus && (clip_unnamed_saved & CLIP_UNNAMED_PLUS)) |
1765 || (cbd == &clip_star && (clip_unnamed_saved & CLIP_UNNAMED))) | |
1766 { | |
1767 clipboard_needs_update = TRUE; | |
6116 | 1768 return; |
6543 | 1769 } |
6116 | 1770 } |
7 | 1771 #ifdef FEAT_XCLIPBOARD |
1772 # ifdef FEAT_GUI | |
1773 if (gui.in_use) | |
1774 clip_mch_set_selection(cbd); | |
1775 else | |
1776 # endif | |
1777 clip_xterm_set_selection(cbd); | |
1778 #else | |
1779 clip_mch_set_selection(cbd); | |
1780 #endif | |
1781 } | |
1782 | |
1783 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1784 clip_gen_request_selection(VimClipboard *cbd) |
7 | 1785 { |
1786 #ifdef FEAT_XCLIPBOARD | |
1787 # ifdef FEAT_GUI | |
1788 if (gui.in_use) | |
1789 clip_mch_request_selection(cbd); | |
1790 else | |
1791 # endif | |
1792 clip_xterm_request_selection(cbd); | |
1793 #else | |
1794 clip_mch_request_selection(cbd); | |
1795 #endif | |
1796 } | |
1797 | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1798 #if (defined(FEAT_X11) && defined(USE_SYSTEM)) || defined(PROTO) |
4209 | 1799 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1800 clip_gen_owner_exists(VimClipboard *cbd UNUSED) |
4209 | 1801 { |
1802 #ifdef FEAT_XCLIPBOARD | |
1803 # ifdef FEAT_GUI_GTK | |
1804 if (gui.in_use) | |
1805 return clip_gtk_owner_exists(cbd); | |
1806 else | |
1807 # endif | |
1808 return clip_x11_owner_exists(cbd); | |
5184
c6dd0c545e5c
updated for version 7.4a.018
Bram Moolenaar <bram@vim.org>
parents:
5136
diff
changeset
|
1809 #else |
c6dd0c545e5c
updated for version 7.4a.018
Bram Moolenaar <bram@vim.org>
parents:
5136
diff
changeset
|
1810 return TRUE; |
4209 | 1811 #endif |
1812 } | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1813 #endif |
4209 | 1814 |
7 | 1815 #endif /* FEAT_CLIPBOARD */ |
1816 | |
1817 /***************************************************************************** | |
1818 * Functions that handle the input buffer. | |
1819 * This is used for any GUI version, and the unix terminal version. | |
1820 * | |
1821 * For Unix, the input characters are buffered to be able to check for a | |
1822 * CTRL-C. This should be done with signals, but I don't know how to do that | |
1823 * in a portable way for a tty in RAW mode. | |
1824 * | |
1825 * For the client-server code in the console the received keys are put in the | |
1826 * input buffer. | |
1827 */ | |
1828 | |
1829 #if defined(USE_INPUT_BUF) || defined(PROTO) | |
1830 | |
1831 /* | |
1832 * Internal typeahead buffer. Includes extra space for long key code | |
1833 * descriptions which would otherwise overflow. The buffer is considered full | |
1834 * when only this extra space (or part of it) remains. | |
1835 */ | |
15510
41fbbcea0f1b
patch 8.1.0763: nobody is using the Sun Workshop support
Bram Moolenaar <Bram@vim.org>
parents:
15506
diff
changeset
|
1836 #if defined(FEAT_JOB_CHANNEL) || defined(FEAT_CLIENTSERVER) |
7 | 1837 /* |
15510
41fbbcea0f1b
patch 8.1.0763: nobody is using the Sun Workshop support
Bram Moolenaar <Bram@vim.org>
parents:
15506
diff
changeset
|
1838 * NetBeans stuffs debugger commands into the input buffer. |
7 | 1839 * This requires a larger buffer... |
1840 * (Madsen) Go with this for remote input as well ... | |
1841 */ | |
1842 # define INBUFLEN 4096 | |
1843 #else | |
1844 # define INBUFLEN 250 | |
1845 #endif | |
1846 | |
1847 static char_u inbuf[INBUFLEN + MAX_KEY_CODE_LEN]; | |
1848 static int inbufcount = 0; /* number of chars in inbuf[] */ | |
1849 | |
1850 /* | |
1851 * vim_is_input_buf_full(), vim_is_input_buf_empty(), add_to_input_buf(), and | |
1852 * trash_input_buf() are functions for manipulating the input buffer. These | |
1853 * are used by the gui_* calls when a GUI is used to handle keyboard input. | |
1854 */ | |
1855 | |
1856 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1857 vim_is_input_buf_full(void) |
7 | 1858 { |
1859 return (inbufcount >= INBUFLEN); | |
1860 } | |
1861 | |
1862 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1863 vim_is_input_buf_empty(void) |
7 | 1864 { |
1865 return (inbufcount == 0); | |
1866 } | |
1867 | |
1868 #if defined(FEAT_OLE) || defined(PROTO) | |
1869 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1870 vim_free_in_input_buf(void) |
7 | 1871 { |
1872 return (INBUFLEN - inbufcount); | |
1873 } | |
1874 #endif | |
1875 | |
575 | 1876 #if defined(FEAT_GUI_GTK) || defined(PROTO) |
7 | 1877 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1878 vim_used_in_input_buf(void) |
7 | 1879 { |
1880 return inbufcount; | |
1881 } | |
1882 #endif | |
1883 | |
1884 /* | |
1885 * Return the current contents of the input buffer and make it empty. | |
1886 * The returned pointer must be passed to set_input_buf() later. | |
1887 */ | |
1888 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1889 get_input_buf(void) |
7 | 1890 { |
1891 garray_T *gap; | |
1892 | |
1893 /* We use a growarray to store the data pointer and the length. */ | |
1894 gap = (garray_T *)alloc((unsigned)sizeof(garray_T)); | |
1895 if (gap != NULL) | |
1896 { | |
1897 /* Add one to avoid a zero size. */ | |
1898 gap->ga_data = alloc((unsigned)inbufcount + 1); | |
1899 if (gap->ga_data != NULL) | |
1900 mch_memmove(gap->ga_data, inbuf, (size_t)inbufcount); | |
1901 gap->ga_len = inbufcount; | |
1902 } | |
1903 trash_input_buf(); | |
1904 return (char_u *)gap; | |
1905 } | |
1906 | |
1907 /* | |
1908 * Restore the input buffer with a pointer returned from get_input_buf(). | |
1909 * The allocated memory is freed, this only works once! | |
1910 */ | |
1911 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1912 set_input_buf(char_u *p) |
7 | 1913 { |
1914 garray_T *gap = (garray_T *)p; | |
1915 | |
1916 if (gap != NULL) | |
1917 { | |
1918 if (gap->ga_data != NULL) | |
1919 { | |
1920 mch_memmove(inbuf, gap->ga_data, gap->ga_len); | |
1921 inbufcount = gap->ga_len; | |
1922 vim_free(gap->ga_data); | |
1923 } | |
1924 vim_free(gap); | |
1925 } | |
1926 } | |
1927 | |
1928 /* | |
1929 * Add the given bytes to the input buffer | |
1930 * Special keys start with CSI. A real CSI must have been translated to | |
1931 * CSI KS_EXTRA KE_CSI. K_SPECIAL doesn't require translation. | |
1932 */ | |
1933 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1934 add_to_input_buf(char_u *s, int len) |
7 | 1935 { |
1936 if (inbufcount + len > INBUFLEN + MAX_KEY_CODE_LEN) | |
1937 return; /* Shouldn't ever happen! */ | |
1938 | |
1939 #ifdef FEAT_HANGULIN | |
1940 if ((State & (INSERT|CMDLINE)) && hangul_input_state_get()) | |
1941 if ((len = hangul_input_process(s, len)) == 0) | |
1942 return; | |
1943 #endif | |
1944 | |
1945 while (len--) | |
1946 inbuf[inbufcount++] = *s++; | |
1947 } | |
1948 | |
1949 /* | |
1950 * Add "str[len]" to the input buffer while escaping CSI bytes. | |
1951 */ | |
1952 void | |
1953 add_to_input_buf_csi(char_u *str, int len) | |
1954 { | |
1955 int i; | |
1956 char_u buf[2]; | |
1957 | |
1958 for (i = 0; i < len; ++i) | |
1959 { | |
1960 add_to_input_buf(str + i, 1); | |
1961 if (str[i] == CSI) | |
1962 { | |
1963 /* Turn CSI into K_CSI. */ | |
1964 buf[0] = KS_EXTRA; | |
1965 buf[1] = (int)KE_CSI; | |
1966 add_to_input_buf(buf, 2); | |
1967 } | |
1968 } | |
1969 } | |
1970 | |
1971 #if defined(FEAT_HANGULIN) || defined(PROTO) | |
1972 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1973 push_raw_key(char_u *s, int len) |
7 | 1974 { |
7208
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7080
diff
changeset
|
1975 char_u *tmpbuf; |
8393
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1976 char_u *inp = s; |
7208
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7080
diff
changeset
|
1977 |
8393
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1978 /* use the conversion result if possible */ |
7208
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7080
diff
changeset
|
1979 tmpbuf = hangul_string_convert(s, &len); |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7080
diff
changeset
|
1980 if (tmpbuf != NULL) |
8393
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1981 inp = tmpbuf; |
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1982 |
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1983 for (; len--; inp++) |
8366
6099e8185045
commit https://github.com/vim/vim/commit/00ded43a5a85df57abb74f9e3a38a401f6fbd8fd
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
1984 { |
8393
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1985 inbuf[inbufcount++] = *inp; |
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1986 if (*inp == CSI) |
8366
6099e8185045
commit https://github.com/vim/vim/commit/00ded43a5a85df57abb74f9e3a38a401f6fbd8fd
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
1987 { |
8393
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1988 /* Turn CSI into K_CSI. */ |
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1989 inbuf[inbufcount++] = KS_EXTRA; |
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1990 inbuf[inbufcount++] = (int)KE_CSI; |
8366
6099e8185045
commit https://github.com/vim/vim/commit/00ded43a5a85df57abb74f9e3a38a401f6fbd8fd
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
1991 } |
6099e8185045
commit https://github.com/vim/vim/commit/00ded43a5a85df57abb74f9e3a38a401f6fbd8fd
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
1992 } |
8393
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1993 vim_free(tmpbuf); |
7 | 1994 } |
1995 #endif | |
1996 | |
1997 /* Remove everything from the input buffer. Called when ^C is found */ | |
1998 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1999 trash_input_buf(void) |
7 | 2000 { |
2001 inbufcount = 0; | |
2002 } | |
2003 | |
2004 /* | |
2005 * Read as much data from the input buffer as possible up to maxlen, and store | |
2006 * it in buf. | |
2007 */ | |
2008 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2009 read_from_input_buf(char_u *buf, long maxlen) |
7 | 2010 { |
2011 if (inbufcount == 0) /* if the buffer is empty, fill it */ | |
2012 fill_input_buf(TRUE); | |
2013 if (maxlen > inbufcount) | |
2014 maxlen = inbufcount; | |
2015 mch_memmove(buf, inbuf, (size_t)maxlen); | |
2016 inbufcount -= maxlen; | |
2017 if (inbufcount) | |
2018 mch_memmove(inbuf, inbuf + maxlen, (size_t)inbufcount); | |
2019 return (int)maxlen; | |
2020 } | |
2021 | |
2022 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2023 fill_input_buf(int exit_on_error UNUSED) |
7 | 2024 { |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
2025 #if defined(UNIX) || defined(VMS) || defined(MACOS_X) |
7 | 2026 int len; |
2027 int try; | |
2028 static int did_read_something = FALSE; | |
2029 static char_u *rest = NULL; /* unconverted rest of previous read */ | |
2030 static int restlen = 0; | |
2031 int unconverted; | |
2032 #endif | |
2033 | |
2034 #ifdef FEAT_GUI | |
294 | 2035 if (gui.in_use |
2036 # ifdef NO_CONSOLE_INPUT | |
2037 /* Don't use the GUI input when the window hasn't been opened yet. | |
2038 * We get here from ui_inchar() when we should try reading from stdin. */ | |
2039 && !no_console_input() | |
2040 # endif | |
2041 ) | |
7 | 2042 { |
2043 gui_mch_update(); | |
2044 return; | |
2045 } | |
2046 #endif | |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
2047 #if defined(UNIX) || defined(VMS) || defined(MACOS_X) |
7 | 2048 if (vim_is_input_buf_full()) |
2049 return; | |
2050 /* | |
2051 * Fill_input_buf() is only called when we really need a character. | |
2052 * If we can't get any, but there is some in the buffer, just return. | |
2053 * If we can't get any, and there isn't any in the buffer, we give up and | |
2054 * exit Vim. | |
2055 */ | |
2056 # ifdef __BEOS__ | |
2057 /* | |
2058 * On the BeBox version (for now), all input is secretly performed within | |
2059 * beos_select() which is called from RealWaitForChar(). | |
2060 */ | |
2061 while (!vim_is_input_buf_full() && RealWaitForChar(read_cmd_fd, 0, NULL)) | |
2062 ; | |
2063 len = inbufcount; | |
2064 inbufcount = 0; | |
2065 # else | |
2066 | |
2067 if (rest != NULL) | |
2068 { | |
2069 /* Use remainder of previous call, starts with an invalid character | |
2070 * that may become valid when reading more. */ | |
2071 if (restlen > INBUFLEN - inbufcount) | |
2072 unconverted = INBUFLEN - inbufcount; | |
2073 else | |
2074 unconverted = restlen; | |
2075 mch_memmove(inbuf + inbufcount, rest, unconverted); | |
2076 if (unconverted == restlen) | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
2077 VIM_CLEAR(rest); |
7 | 2078 else |
2079 { | |
2080 restlen -= unconverted; | |
2081 mch_memmove(rest, rest + unconverted, restlen); | |
2082 } | |
2083 inbufcount += unconverted; | |
2084 } | |
2085 else | |
2086 unconverted = 0; | |
2087 | |
2088 len = 0; /* to avoid gcc warning */ | |
2089 for (try = 0; try < 100; ++try) | |
2090 { | |
13758
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
2091 size_t readlen = (size_t)((INBUFLEN - inbufcount) |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2092 / input_conv.vc_factor); |
13758
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
2093 # ifdef VMS |
13776
ef6de4674811
patch 8.0.1760: wrong number of arguments to vms_read()
Christian Brabandt <cb@256bit.org>
parents:
13758
diff
changeset
|
2094 len = vms_read((char *)inbuf + inbufcount, readlen); |
13758
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
2095 # else |
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
2096 len = read(read_cmd_fd, (char *)inbuf + inbufcount, readlen); |
7 | 2097 # endif |
169 | 2098 |
7 | 2099 if (len > 0 || got_int) |
2100 break; | |
2101 /* | |
2102 * If reading stdin results in an error, continue reading stderr. | |
2103 * This helps when using "foo | xargs vim". | |
2104 */ | |
2105 if (!did_read_something && !isatty(read_cmd_fd) && read_cmd_fd == 0) | |
2106 { | |
2107 int m = cur_tmode; | |
2108 | |
2109 /* We probably set the wrong file descriptor to raw mode. Switch | |
2110 * back to cooked mode, use another descriptor and set the mode to | |
2111 * what it was. */ | |
2112 settmode(TMODE_COOK); | |
2113 #ifdef HAVE_DUP | |
2114 /* Use stderr for stdin, also works for shell commands. */ | |
2115 close(0); | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
2116 vim_ignored = dup(2); |
7 | 2117 #else |
2118 read_cmd_fd = 2; /* read from stderr instead of stdin */ | |
2119 #endif | |
2120 settmode(m); | |
2121 } | |
2122 if (!exit_on_error) | |
2123 return; | |
2124 } | |
2125 # endif | |
2126 if (len <= 0 && !got_int) | |
2127 read_error_exit(); | |
2128 if (len > 0) | |
2129 did_read_something = TRUE; | |
2130 if (got_int) | |
2131 { | |
2132 /* Interrupted, pretend a CTRL-C was typed. */ | |
2133 inbuf[0] = 3; | |
2134 inbufcount = 1; | |
2135 } | |
2136 else | |
2137 { | |
2138 /* | |
2139 * May perform conversion on the input characters. | |
2140 * Include the unconverted rest of the previous call. | |
2141 * If there is an incomplete char at the end it is kept for the next | |
2142 * time, reading more bytes should make conversion possible. | |
2143 * Don't do this in the unlikely event that the input buffer is too | |
2144 * small ("rest" still contains more bytes). | |
2145 */ | |
2146 if (input_conv.vc_type != CONV_NONE) | |
2147 { | |
2148 inbufcount -= unconverted; | |
2149 len = convert_input_safe(inbuf + inbufcount, | |
2150 len + unconverted, INBUFLEN - inbufcount, | |
2151 rest == NULL ? &rest : NULL, &restlen); | |
2152 } | |
2153 while (len-- > 0) | |
2154 { | |
2155 /* | |
2156 * if a CTRL-C was typed, remove it from the buffer and set got_int | |
2157 */ | |
2158 if (inbuf[inbufcount] == 3 && ctrl_c_interrupts) | |
2159 { | |
2160 /* remove everything typed before the CTRL-C */ | |
2161 mch_memmove(inbuf, inbuf + inbufcount, (size_t)(len + 1)); | |
2162 inbufcount = 0; | |
2163 got_int = TRUE; | |
2164 } | |
2165 ++inbufcount; | |
2166 } | |
2167 } | |
7408
1886f2863437
commit https://github.com/vim/vim/commit/e7fedb6ebe72d9a475aa65109b77d5ed4667067a
Christian Brabandt <cb@256bit.org>
parents:
7208
diff
changeset
|
2168 #endif /* UNIX or VMS*/ |
7 | 2169 } |
7408
1886f2863437
commit https://github.com/vim/vim/commit/e7fedb6ebe72d9a475aa65109b77d5ed4667067a
Christian Brabandt <cb@256bit.org>
parents:
7208
diff
changeset
|
2170 #endif /* defined(UNIX) || defined(FEAT_GUI) || defined(VMS) */ |
7 | 2171 |
2172 /* | |
2173 * Exit because of an input read error. | |
2174 */ | |
2175 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2176 read_error_exit(void) |
7 | 2177 { |
2178 if (silent_mode) /* Normal way to exit for "ex -s" */ | |
2179 getout(0); | |
2180 STRCPY(IObuff, _("Vim: Error reading input, exiting...\n")); | |
2181 preserve_exit(); | |
2182 } | |
2183 | |
2184 #if defined(CURSOR_SHAPE) || defined(PROTO) | |
2185 /* | |
2186 * May update the shape of the cursor. | |
2187 */ | |
2188 void | |
12076
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
2189 ui_cursor_shape_forced(int forced) |
7 | 2190 { |
2191 # ifdef FEAT_GUI | |
2192 if (gui.in_use) | |
2193 gui_update_cursor_later(); | |
36 | 2194 else |
7 | 2195 # endif |
12076
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
2196 term_cursor_mode(forced); |
36 | 2197 |
7 | 2198 # ifdef MCH_CURSOR_SHAPE |
2199 mch_update_cursor(); | |
2200 # endif | |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2201 |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2202 # ifdef FEAT_CONCEAL |
13876
156ebdcb8ef5
patch 8.0.1809: various typos
Christian Brabandt <cb@256bit.org>
parents:
13776
diff
changeset
|
2203 conceal_check_cursor_line(); |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2204 # endif |
7 | 2205 } |
12076
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
2206 |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
2207 void |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
2208 ui_cursor_shape(void) |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
2209 { |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
2210 ui_cursor_shape_forced(FALSE); |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
2211 } |
7 | 2212 #endif |
2213 | |
2214 /* | |
2215 * Check bounds for column number | |
2216 */ | |
2217 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2218 check_col(int col) |
7 | 2219 { |
2220 if (col < 0) | |
2221 return 0; | |
2222 if (col >= (int)screen_Columns) | |
2223 return (int)screen_Columns - 1; | |
2224 return col; | |
2225 } | |
2226 | |
2227 /* | |
2228 * Check bounds for row number | |
2229 */ | |
2230 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2231 check_row(int row) |
7 | 2232 { |
2233 if (row < 0) | |
2234 return 0; | |
2235 if (row >= (int)screen_Rows) | |
2236 return (int)screen_Rows - 1; | |
2237 return row; | |
2238 } | |
2239 | |
2240 /* | |
2241 * Stuff for the X clipboard. Shared between VMS and Unix. | |
2242 */ | |
2243 | |
2244 #if defined(FEAT_XCLIPBOARD) || defined(FEAT_GUI_X11) || defined(PROTO) | |
2245 # include <X11/Xatom.h> | |
2246 # include <X11/Intrinsic.h> | |
2247 | |
2248 /* | |
2249 * Open the application context (if it hasn't been opened yet). | |
2250 * Used for Motif and Athena GUI and the xterm clipboard. | |
2251 */ | |
2252 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2253 open_app_context(void) |
7 | 2254 { |
2255 if (app_context == NULL) | |
2256 { | |
2257 XtToolkitInitialize(); | |
2258 app_context = XtCreateApplicationContext(); | |
2259 } | |
2260 } | |
2261 | |
2262 static Atom vim_atom; /* Vim's own special selection format */ | |
2263 static Atom vimenc_atom; /* Vim's extended selection format */ | |
3346 | 2264 static Atom utf8_atom; |
7 | 2265 static Atom compound_text_atom; |
2266 static Atom text_atom; | |
2267 static Atom targets_atom; | |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2268 static Atom timestamp_atom; /* Used to get a timestamp */ |
7 | 2269 |
2270 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2271 x11_setup_atoms(Display *dpy) |
7 | 2272 { |
2273 vim_atom = XInternAtom(dpy, VIM_ATOM_NAME, False); | |
2274 vimenc_atom = XInternAtom(dpy, VIMENC_ATOM_NAME,False); | |
3346 | 2275 utf8_atom = XInternAtom(dpy, "UTF8_STRING", False); |
7 | 2276 compound_text_atom = XInternAtom(dpy, "COMPOUND_TEXT", False); |
2277 text_atom = XInternAtom(dpy, "TEXT", False); | |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2278 targets_atom = XInternAtom(dpy, "TARGETS", False); |
7 | 2279 clip_star.sel_atom = XA_PRIMARY; |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2280 clip_plus.sel_atom = XInternAtom(dpy, "CLIPBOARD", False); |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2281 timestamp_atom = XInternAtom(dpy, "TIMESTAMP", False); |
7 | 2282 } |
2283 | |
2284 /* | |
2285 * X Selection stuff, for cutting and pasting text to other windows. | |
2286 */ | |
2287 | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2288 static Boolean clip_x11_convert_selection_cb(Widget w, Atom *sel_atom, Atom *target, Atom *type, XtPointer *value, long_u *length, int *format); |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2289 static void clip_x11_lose_ownership_cb(Widget w, Atom *sel_atom); |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2290 static void clip_x11_notify_cb(Widget w, Atom *sel_atom, Atom *target); |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2291 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2292 /* |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2293 * Property callback to get a timestamp for XtOwnSelection. |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2294 */ |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2295 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2296 clip_x11_timestamp_cb( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2297 Widget w, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2298 XtPointer n UNUSED, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2299 XEvent *event, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2300 Boolean *cont UNUSED) |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2301 { |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2302 Atom actual_type; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2303 int format; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2304 unsigned long nitems, bytes_after; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2305 unsigned char *prop=NULL; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2306 XPropertyEvent *xproperty=&event->xproperty; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2307 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2308 /* Must be a property notify, state can't be Delete (True), has to be |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2309 * one of the supported selection types. */ |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2310 if (event->type != PropertyNotify || xproperty->state |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2311 || (xproperty->atom != clip_star.sel_atom |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2312 && xproperty->atom != clip_plus.sel_atom)) |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2313 return; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2314 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2315 if (XGetWindowProperty(xproperty->display, xproperty->window, |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2316 xproperty->atom, 0, 0, False, timestamp_atom, &actual_type, &format, |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2317 &nitems, &bytes_after, &prop)) |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2318 return; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2319 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2320 if (prop) |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2321 XFree(prop); |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2322 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2323 /* Make sure the property type is "TIMESTAMP" and it's 32 bits. */ |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2324 if (actual_type != timestamp_atom || format != 32) |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2325 return; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2326 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2327 /* Get the selection, using the event timestamp. */ |
2586 | 2328 if (XtOwnSelection(w, xproperty->atom, xproperty->time, |
2329 clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb, | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2330 clip_x11_notify_cb) == OK) |
2586 | 2331 { |
2332 /* Set the "owned" flag now, there may have been a call to | |
2333 * lose_ownership_cb in between. */ | |
2334 if (xproperty->atom == clip_plus.sel_atom) | |
2335 clip_plus.owned = TRUE; | |
2336 else | |
2337 clip_star.owned = TRUE; | |
2338 } | |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2339 } |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2340 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2341 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2342 x11_setup_selection(Widget w) |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2343 { |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2344 XtAddEventHandler(w, PropertyChangeMask, False, |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2345 /*(XtEventHandler)*/clip_x11_timestamp_cb, (XtPointer)NULL); |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2346 } |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2347 |
7 | 2348 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2349 clip_x11_request_selection_cb( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2350 Widget w UNUSED, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2351 XtPointer success, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2352 Atom *sel_atom, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2353 Atom *type, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2354 XtPointer value, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2355 long_u *length, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2356 int *format) |
7 | 2357 { |
2896 | 2358 int motion_type = MAUTO; |
7 | 2359 long_u len; |
2360 char_u *p; | |
2361 char **text_list = NULL; | |
2362 VimClipboard *cbd; | |
2363 char_u *tmpbuf = NULL; | |
2364 | |
2365 if (*sel_atom == clip_plus.sel_atom) | |
2366 cbd = &clip_plus; | |
2367 else | |
2368 cbd = &clip_star; | |
2369 | |
2370 if (value == NULL || *length == 0) | |
2371 { | |
1719 | 2372 clip_free_selection(cbd); /* nothing received, clear register */ |
7 | 2373 *(int *)success = FALSE; |
2374 return; | |
2375 } | |
2376 p = (char_u *)value; | |
2377 len = *length; | |
2378 if (*type == vim_atom) | |
2379 { | |
2380 motion_type = *p++; | |
2381 len--; | |
2382 } | |
2383 | |
2384 else if (*type == vimenc_atom) | |
2385 { | |
2386 char_u *enc; | |
2387 vimconv_T conv; | |
2388 int convlen; | |
2389 | |
2390 motion_type = *p++; | |
2391 --len; | |
2392 | |
2393 enc = p; | |
2394 p += STRLEN(p) + 1; | |
2395 len -= p - enc; | |
2396 | |
2397 /* If the encoding of the text is different from 'encoding', attempt | |
2398 * converting it. */ | |
2399 conv.vc_type = CONV_NONE; | |
2400 convert_setup(&conv, enc, p_enc); | |
2401 if (conv.vc_type != CONV_NONE) | |
2402 { | |
2403 convlen = len; /* Need to use an int here. */ | |
2404 tmpbuf = string_convert(&conv, p, &convlen); | |
2405 len = convlen; | |
2406 if (tmpbuf != NULL) | |
2407 p = tmpbuf; | |
2408 convert_setup(&conv, NULL, NULL); | |
2409 } | |
2410 } | |
2411 | |
3346 | 2412 else if (*type == compound_text_atom |
2413 || *type == utf8_atom | |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2414 || (enc_dbcs != 0 && *type == text_atom)) |
7 | 2415 { |
2416 XTextProperty text_prop; | |
2417 int n_text = 0; | |
2418 int status; | |
2419 | |
2420 text_prop.value = (unsigned char *)value; | |
2421 text_prop.encoding = *type; | |
2422 text_prop.format = *format; | |
1719 | 2423 text_prop.nitems = len; |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2424 #if defined(X_HAVE_UTF8_STRING) |
4201 | 2425 if (*type == utf8_atom) |
2426 status = Xutf8TextPropertyToTextList(X_DISPLAY, &text_prop, | |
2427 &text_list, &n_text); | |
2428 else | |
2429 #endif | |
2430 status = XmbTextPropertyToTextList(X_DISPLAY, &text_prop, | |
7 | 2431 &text_list, &n_text); |
2432 if (status != Success || n_text < 1) | |
2433 { | |
2434 *(int *)success = FALSE; | |
2435 return; | |
2436 } | |
2437 p = (char_u *)text_list[0]; | |
2438 len = STRLEN(p); | |
2439 } | |
2440 clip_yank_selection(motion_type, p, (long)len, cbd); | |
2441 | |
2442 if (text_list != NULL) | |
2443 XFreeStringList(text_list); | |
2444 vim_free(tmpbuf); | |
2445 XtFree((char *)value); | |
2446 *(int *)success = TRUE; | |
2447 } | |
2448 | |
2449 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2450 clip_x11_request_selection( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2451 Widget myShell, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2452 Display *dpy, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2453 VimClipboard *cbd) |
7 | 2454 { |
2455 XEvent event; | |
2456 Atom type; | |
2457 static int success; | |
2458 int i; | |
1715 | 2459 time_t start_time; |
2460 int timed_out = FALSE; | |
7 | 2461 |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2462 for (i = 0; i < 6; i++) |
7 | 2463 { |
2464 switch (i) | |
2465 { | |
2466 case 0: type = vimenc_atom; break; | |
2467 case 1: type = vim_atom; break; | |
3346 | 2468 case 2: type = utf8_atom; break; |
2469 case 3: type = compound_text_atom; break; | |
2470 case 4: type = text_atom; break; | |
7 | 2471 default: type = XA_STRING; |
2472 } | |
4272 | 2473 if (type == utf8_atom |
2474 # if defined(X_HAVE_UTF8_STRING) | |
2475 && !enc_utf8 | |
2476 # endif | |
2477 ) | |
2478 /* Only request utf-8 when 'encoding' is utf8 and | |
2479 * Xutf8TextPropertyToTextList is available. */ | |
3346 | 2480 continue; |
1719 | 2481 success = MAYBE; |
7 | 2482 XtGetSelectionValue(myShell, cbd->sel_atom, type, |
2483 clip_x11_request_selection_cb, (XtPointer)&success, CurrentTime); | |
2484 | |
2485 /* Make sure the request for the selection goes out before waiting for | |
2486 * a response. */ | |
2487 XFlush(dpy); | |
2488 | |
2489 /* | |
2490 * Wait for result of selection request, otherwise if we type more | |
2491 * characters, then they will appear before the one that requested the | |
2492 * paste! Don't worry, we will catch up with any other events later. | |
2493 */ | |
1715 | 2494 start_time = time(NULL); |
1719 | 2495 while (success == MAYBE) |
7 | 2496 { |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2497 if (XCheckTypedEvent(dpy, PropertyNotify, &event) |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2498 || XCheckTypedEvent(dpy, SelectionNotify, &event) |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2499 || XCheckTypedEvent(dpy, SelectionRequest, &event)) |
1715 | 2500 { |
1719 | 2501 /* This is where clip_x11_request_selection_cb() should be |
2502 * called. It may actually happen a bit later, so we loop | |
2503 * until "success" changes. | |
2504 * We may get a SelectionRequest here and if we don't handle | |
2505 * it we hang. KDE klipper does this, for example. | |
2506 * We need to handle a PropertyNotify for large selections. */ | |
1715 | 2507 XtDispatchEvent(&event); |
1719 | 2508 continue; |
1715 | 2509 } |
7 | 2510 |
1715 | 2511 /* Time out after 2 to 3 seconds to avoid that we hang when the |
2512 * other process doesn't respond. Note that the SelectionNotify | |
2513 * event may still come later when the selection owner comes back | |
1719 | 2514 * to life and the text gets inserted unexpectedly. Don't know |
2515 * why that happens or how to avoid that :-(. */ | |
1715 | 2516 if (time(NULL) > start_time + 2) |
2517 { | |
2518 timed_out = TRUE; | |
2519 break; | |
2520 } | |
2521 | |
7 | 2522 /* Do we need this? Probably not. */ |
2523 XSync(dpy, False); | |
2524 | |
1715 | 2525 /* Wait for 1 msec to avoid that we eat up all CPU time. */ |
2526 ui_delay(1L, TRUE); | |
7 | 2527 } |
2528 | |
1719 | 2529 if (success == TRUE) |
7 | 2530 return; |
1715 | 2531 |
2532 /* don't do a retry with another type after timing out, otherwise we | |
2533 * hang for 15 seconds. */ | |
2534 if (timed_out) | |
2535 break; | |
7 | 2536 } |
2537 | |
2538 /* Final fallback position - use the X CUT_BUFFER0 store */ | |
1924 | 2539 yank_cut_buffer0(dpy, cbd); |
7 | 2540 } |
2541 | |
2542 static Boolean | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2543 clip_x11_convert_selection_cb( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2544 Widget w UNUSED, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2545 Atom *sel_atom, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2546 Atom *target, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2547 Atom *type, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2548 XtPointer *value, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2549 long_u *length, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2550 int *format) |
7 | 2551 { |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2552 static char_u *save_result = NULL; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2553 static long_u save_length = 0; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2554 char_u *string; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2555 int motion_type; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2556 VimClipboard *cbd; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2557 int i; |
7 | 2558 |
2559 if (*sel_atom == clip_plus.sel_atom) | |
2560 cbd = &clip_plus; | |
2561 else | |
2562 cbd = &clip_star; | |
2563 | |
2564 if (!cbd->owned) | |
2565 return False; /* Shouldn't ever happen */ | |
2566 | |
2567 /* requestor wants to know what target types we support */ | |
2568 if (*target == targets_atom) | |
2569 { | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2570 static Atom array[7]; |
7 | 2571 |
2572 *value = (XtPointer)array; | |
2573 i = 0; | |
2574 array[i++] = targets_atom; | |
2575 array[i++] = vimenc_atom; | |
2576 array[i++] = vim_atom; | |
3346 | 2577 if (enc_utf8) |
2578 array[i++] = utf8_atom; | |
2579 array[i++] = XA_STRING; | |
7 | 2580 array[i++] = text_atom; |
2581 array[i++] = compound_text_atom; | |
3346 | 2582 |
7 | 2583 *type = XA_ATOM; |
2584 /* This used to be: *format = sizeof(Atom) * 8; but that caused | |
2585 * crashes on 64 bit machines. (Peter Derr) */ | |
2586 *format = 32; | |
2587 *length = i; | |
2588 return True; | |
2589 } | |
2590 | |
2591 if ( *target != XA_STRING | |
2592 && *target != vimenc_atom | |
5956 | 2593 && (*target != utf8_atom || !enc_utf8) |
7 | 2594 && *target != vim_atom |
2595 && *target != text_atom | |
2596 && *target != compound_text_atom) | |
2597 return False; | |
2598 | |
2599 clip_get_selection(cbd); | |
2600 motion_type = clip_convert_selection(&string, length, cbd); | |
2601 if (motion_type < 0) | |
2602 return False; | |
2603 | |
2604 /* For our own format, the first byte contains the motion type */ | |
2605 if (*target == vim_atom) | |
2606 (*length)++; | |
2607 | |
2608 /* Our own format with encoding: motion 'encoding' NUL text */ | |
2609 if (*target == vimenc_atom) | |
2610 *length += STRLEN(p_enc) + 2; | |
2611 | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2612 if (save_length < *length || save_length / 2 >= *length) |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2613 *value = XtRealloc((char *)save_result, (Cardinal)*length + 1); |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2614 else |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2615 *value = save_result; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2616 if (*value == NULL) |
7 | 2617 { |
2618 vim_free(string); | |
2619 return False; | |
2620 } | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2621 save_result = (char_u *)*value; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2622 save_length = *length; |
7 | 2623 |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2624 if (*target == XA_STRING || (*target == utf8_atom && enc_utf8)) |
7 | 2625 { |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2626 mch_memmove(save_result, string, (size_t)(*length)); |
3346 | 2627 *type = *target; |
7 | 2628 } |
3346 | 2629 else if (*target == compound_text_atom || *target == text_atom) |
7 | 2630 { |
2631 XTextProperty text_prop; | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2632 char *string_nt = (char *)save_result; |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2633 int conv_result; |
7 | 2634 |
2635 /* create NUL terminated string which XmbTextListToTextProperty wants */ | |
2636 mch_memmove(string_nt, string, (size_t)*length); | |
2637 string_nt[*length] = NUL; | |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2638 conv_result = XmbTextListToTextProperty(X_DISPLAY, (char **)&string_nt, |
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2639 1, XCompoundTextStyle, &text_prop); |
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2640 if (conv_result != Success) |
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2641 { |
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2642 vim_free(string); |
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2643 return False; |
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2644 } |
7 | 2645 *value = (XtPointer)(text_prop.value); /* from plain text */ |
2646 *length = text_prop.nitems; | |
2647 *type = compound_text_atom; | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2648 XtFree((char *)save_result); |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2649 save_result = (char_u *)*value; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2650 save_length = *length; |
7 | 2651 } |
2652 else if (*target == vimenc_atom) | |
2653 { | |
2654 int l = STRLEN(p_enc); | |
2655 | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2656 save_result[0] = motion_type; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2657 STRCPY(save_result + 1, p_enc); |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2658 mch_memmove(save_result + l + 2, string, (size_t)(*length - l - 2)); |
7 | 2659 *type = vimenc_atom; |
2660 } | |
2661 else | |
2662 { | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2663 save_result[0] = motion_type; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2664 mch_memmove(save_result + 1, string, (size_t)(*length - 1)); |
7 | 2665 *type = vim_atom; |
2666 } | |
2667 *format = 8; /* 8 bits per char */ | |
2668 vim_free(string); | |
2669 return True; | |
2670 } | |
2671 | |
2672 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2673 clip_x11_lose_ownership_cb(Widget w UNUSED, Atom *sel_atom) |
7 | 2674 { |
2675 if (*sel_atom == clip_plus.sel_atom) | |
2676 clip_lose_selection(&clip_plus); | |
2677 else | |
2678 clip_lose_selection(&clip_star); | |
2679 } | |
2680 | |
2681 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2682 clip_x11_lose_selection(Widget myShell, VimClipboard *cbd) |
7 | 2683 { |
4209 | 2684 XtDisownSelection(myShell, cbd->sel_atom, |
2685 XtLastTimestampProcessed(XtDisplay(myShell))); | |
7 | 2686 } |
2687 | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2688 static void |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2689 clip_x11_notify_cb(Widget w UNUSED, Atom *sel_atom UNUSED, Atom *target UNUSED) |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2690 { |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2691 /* To prevent automatically freeing the selection value. */ |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2692 } |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2693 |
7 | 2694 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2695 clip_x11_own_selection(Widget myShell, VimClipboard *cbd) |
7 | 2696 { |
2586 | 2697 /* When using the GUI we have proper timestamps, use the one of the last |
2698 * event. When in the console we don't get events (the terminal gets | |
2699 * them), Get the time by a zero-length append, clip_x11_timestamp_cb will | |
2700 * be called with the current timestamp. */ | |
2701 #ifdef FEAT_GUI | |
2702 if (gui.in_use) | |
2703 { | |
2704 if (XtOwnSelection(myShell, cbd->sel_atom, | |
2705 XtLastTimestampProcessed(XtDisplay(myShell)), | |
2706 clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb, | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2707 clip_x11_notify_cb) == False) |
3312 | 2708 return FAIL; |
2586 | 2709 } |
2710 else | |
2711 #endif | |
2712 { | |
2713 if (!XChangeProperty(XtDisplay(myShell), XtWindow(myShell), | |
2714 cbd->sel_atom, timestamp_atom, 32, PropModeAppend, NULL, 0)) | |
3312 | 2715 return FAIL; |
2586 | 2716 } |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2717 /* Flush is required in a terminal as nothing else is doing it. */ |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2718 XFlush(XtDisplay(myShell)); |
7 | 2719 return OK; |
2720 } | |
2721 | |
2722 /* | |
2723 * Send the current selection to the clipboard. Do nothing for X because we | |
2724 * will fill in the selection only when requested by another app. | |
2725 */ | |
2726 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2727 clip_x11_set_selection(VimClipboard *cbd UNUSED) |
7 | 2728 { |
2729 } | |
4209 | 2730 |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2731 #if (defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) && defined(USE_SYSTEM)) \ |
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2732 || defined(PROTO) |
4209 | 2733 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2734 clip_x11_owner_exists(VimClipboard *cbd) |
4209 | 2735 { |
2736 return XGetSelectionOwner(X_DISPLAY, cbd->sel_atom) != None; | |
2737 } | |
7 | 2738 #endif |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2739 #endif |
7 | 2740 |
1924 | 2741 #if defined(FEAT_XCLIPBOARD) || defined(FEAT_GUI_X11) \ |
2742 || defined(FEAT_GUI_GTK) || defined(PROTO) | |
2743 /* | |
2744 * Get the contents of the X CUT_BUFFER0 and put it in "cbd". | |
2745 */ | |
2746 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2747 yank_cut_buffer0(Display *dpy, VimClipboard *cbd) |
1924 | 2748 { |
2749 int nbytes = 0; | |
2750 char_u *buffer = (char_u *)XFetchBuffer(dpy, &nbytes, 0); | |
2751 | |
2752 if (nbytes > 0) | |
2753 { | |
2754 int done = FALSE; | |
2755 | |
2756 /* CUT_BUFFER0 is supposed to be always latin1. Convert to 'enc' when | |
2757 * using a multi-byte encoding. Conversion between two 8-bit | |
2758 * character sets usually fails and the text might actually be in | |
2759 * 'enc' anyway. */ | |
2760 if (has_mbyte) | |
2761 { | |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
1961
diff
changeset
|
2762 char_u *conv_buf; |
1924 | 2763 vimconv_T vc; |
2764 | |
2765 vc.vc_type = CONV_NONE; | |
2766 if (convert_setup(&vc, (char_u *)"latin1", p_enc) == OK) | |
2767 { | |
2768 conv_buf = string_convert(&vc, buffer, &nbytes); | |
2769 if (conv_buf != NULL) | |
2770 { | |
2771 clip_yank_selection(MCHAR, conv_buf, (long)nbytes, cbd); | |
2772 vim_free(conv_buf); | |
2773 done = TRUE; | |
2774 } | |
2775 convert_setup(&vc, NULL, NULL); | |
2776 } | |
2777 } | |
2778 if (!done) /* use the text without conversion */ | |
2779 clip_yank_selection(MCHAR, buffer, (long)nbytes, cbd); | |
2780 XFree((void *)buffer); | |
2781 if (p_verbose > 0) | |
2782 { | |
2783 verbose_enter(); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
2784 verb_msg(_("Used CUT_BUFFER0 instead of empty selection")); |
1924 | 2785 verbose_leave(); |
2786 } | |
2787 } | |
2788 } | |
2789 #endif | |
2790 | |
7 | 2791 #if defined(FEAT_MOUSE) || defined(PROTO) |
2792 | |
2793 /* | |
2794 * Move the cursor to the specified row and column on the screen. | |
1226 | 2795 * Change current window if necessary. Returns an integer with the |
7 | 2796 * CURSOR_MOVED bit set if the cursor has moved or unset otherwise. |
2797 * | |
2798 * The MOUSE_FOLD_CLOSE bit is set when clicked on the '-' in a fold column. | |
2799 * The MOUSE_FOLD_OPEN bit is set when clicked on the '+' in a fold column. | |
2800 * | |
2801 * If flags has MOUSE_FOCUS, then the current window will not be changed, and | |
2802 * if the mouse is outside the window then the text will scroll, or if the | |
2803 * mouse was previously on a status line, then the status line may be dragged. | |
2804 * | |
2805 * If flags has MOUSE_MAY_VIS, then VIsual mode will be started before the | |
2806 * cursor is moved unless the cursor was on a status line. | |
2807 * This function returns one of IN_UNKNOWN, IN_BUFFER, IN_STATUS_LINE or | |
2808 * IN_SEP_LINE depending on where the cursor was clicked. | |
2809 * | |
2810 * If flags has MOUSE_MAY_STOP_VIS, then Visual mode will be stopped, unless | |
2811 * the mouse is on the status line of the same window. | |
2812 * | |
2813 * If flags has MOUSE_DID_MOVE, nothing is done if the mouse didn't move since | |
2814 * the last call. | |
2815 * | |
2816 * If flags has MOUSE_SETPOS, nothing is done, only the current position is | |
2817 * remembered. | |
2818 */ | |
2819 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2820 jump_to_mouse( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2821 int flags, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2822 int *inclusive, /* used for inclusive operator, can be NULL */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2823 int which_button) /* MOUSE_LEFT, MOUSE_RIGHT, MOUSE_MIDDLE */ |
7 | 2824 { |
2825 static int on_status_line = 0; /* #lines below bottom of window */ | |
2826 static int on_sep_line = 0; /* on separator right of window */ | |
12519
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2827 #ifdef FEAT_MENU |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2828 static int in_winbar = FALSE; |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2829 #endif |
7 | 2830 static int prev_row = -1; |
2831 static int prev_col = -1; | |
2832 static win_T *dragwin = NULL; /* window being dragged */ | |
2833 static int did_drag = FALSE; /* drag was noticed */ | |
2834 | |
2835 win_T *wp, *old_curwin; | |
2836 pos_T old_cursor; | |
2837 int count; | |
2838 int first; | |
2839 int row = mouse_row; | |
2840 int col = mouse_col; | |
2841 #ifdef FEAT_FOLDING | |
2842 int mouse_char; | |
2843 #endif | |
2844 | |
2845 mouse_past_bottom = FALSE; | |
2846 mouse_past_eol = FALSE; | |
2847 | |
2848 if (flags & MOUSE_RELEASED) | |
2849 { | |
2850 /* On button release we may change window focus if positioned on a | |
2851 * status line and no dragging happened. */ | |
2852 if (dragwin != NULL && !did_drag) | |
2853 flags &= ~(MOUSE_FOCUS | MOUSE_DID_MOVE); | |
2854 dragwin = NULL; | |
2855 did_drag = FALSE; | |
2856 } | |
2857 | |
2858 if ((flags & MOUSE_DID_MOVE) | |
2859 && prev_row == mouse_row | |
2860 && prev_col == mouse_col) | |
2861 { | |
2862 retnomove: | |
1226 | 2863 /* before moving the cursor for a left click which is NOT in a status |
7 | 2864 * line, stop Visual mode */ |
2865 if (on_status_line) | |
2866 return IN_STATUS_LINE; | |
2867 if (on_sep_line) | |
2868 return IN_SEP_LINE; | |
12831
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2869 #ifdef FEAT_MENU |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2870 if (in_winbar) |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2871 { |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2872 /* A quick second click may arrive as a double-click, but we use it |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2873 * as a second click in the WinBar. */ |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2874 if ((mod_mask & MOD_MASK_MULTI_CLICK) && !(flags & MOUSE_RELEASED)) |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2875 { |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2876 wp = mouse_find_win(&row, &col); |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2877 if (wp == NULL) |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2878 return IN_UNKNOWN; |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2879 winbar_click(wp, col); |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2880 } |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2881 return IN_OTHER_WIN | MOUSE_WINBAR; |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2882 } |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2883 #endif |
7 | 2884 if (flags & MOUSE_MAY_STOP_VIS) |
2885 { | |
2886 end_visual_mode(); | |
2887 redraw_curbuf_later(INVERTED); /* delete the inversion */ | |
2888 } | |
2889 #if defined(FEAT_CMDWIN) && defined(FEAT_CLIPBOARD) | |
2890 /* Continue a modeless selection in another window. */ | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2891 if (cmdwin_type != 0 && row < curwin->w_winrow) |
7 | 2892 return IN_OTHER_WIN; |
2893 #endif | |
2894 return IN_BUFFER; | |
2895 } | |
2896 | |
2897 prev_row = mouse_row; | |
2898 prev_col = mouse_col; | |
2899 | |
2900 if (flags & MOUSE_SETPOS) | |
2901 goto retnomove; /* ugly goto... */ | |
2902 | |
2903 #ifdef FEAT_FOLDING | |
2904 /* Remember the character under the mouse, it might be a '-' or '+' in the | |
2905 * fold column. */ | |
534 | 2906 if (row >= 0 && row < Rows && col >= 0 && col <= Columns |
2907 && ScreenLines != NULL) | |
7 | 2908 mouse_char = ScreenLines[LineOffset[row] + col]; |
2909 else | |
2910 mouse_char = ' '; | |
2911 #endif | |
2912 | |
2913 old_curwin = curwin; | |
2914 old_cursor = curwin->w_cursor; | |
2915 | |
2916 if (!(flags & MOUSE_FOCUS)) | |
2917 { | |
2918 if (row < 0 || col < 0) /* check if it makes sense */ | |
2919 return IN_UNKNOWN; | |
2920 | |
2921 /* find the window where the row is in */ | |
2922 wp = mouse_find_win(&row, &col); | |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
2923 if (wp == NULL) |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
2924 return IN_UNKNOWN; |
7 | 2925 dragwin = NULL; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2926 |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2927 #ifdef FEAT_MENU |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2928 if (row == -1) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2929 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2930 /* A click in the window toolbar does not enter another window or |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2931 * change Visual highlighting. */ |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2932 winbar_click(wp, col); |
12519
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2933 in_winbar = TRUE; |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2934 return IN_OTHER_WIN | MOUSE_WINBAR; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2935 } |
12519
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2936 in_winbar = FALSE; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2937 #endif |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2938 |
7 | 2939 /* |
2940 * winpos and height may change in win_enter()! | |
2941 */ | |
2942 if (row >= wp->w_height) /* In (or below) status line */ | |
2943 { | |
2944 on_status_line = row - wp->w_height + 1; | |
2945 dragwin = wp; | |
2946 } | |
2947 else | |
2948 on_status_line = 0; | |
2949 if (col >= wp->w_width) /* In separator line */ | |
2950 { | |
2951 on_sep_line = col - wp->w_width + 1; | |
2952 dragwin = wp; | |
2953 } | |
2954 else | |
2955 on_sep_line = 0; | |
2956 | |
2957 /* The rightmost character of the status line might be a vertical | |
2958 * separator character if there is no connecting window to the right. */ | |
2959 if (on_status_line && on_sep_line) | |
2960 { | |
2961 if (stl_connected(wp)) | |
2962 on_sep_line = 0; | |
2963 else | |
2964 on_status_line = 0; | |
2965 } | |
2966 | |
2967 /* Before jumping to another buffer, or moving the cursor for a left | |
2968 * click, stop Visual mode. */ | |
2969 if (VIsual_active | |
2970 && (wp->w_buffer != curwin->w_buffer | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12337
diff
changeset
|
2971 || (!on_status_line && !on_sep_line |
5735 | 2972 #ifdef FEAT_FOLDING |
7 | 2973 && ( |
5735 | 2974 # ifdef FEAT_RIGHTLEFT |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2975 wp->w_p_rl ? col < wp->w_width - wp->w_p_fdc : |
5735 | 2976 # endif |
7 | 2977 col >= wp->w_p_fdc |
5735 | 2978 # ifdef FEAT_CMDWIN |
7 | 2979 + (cmdwin_type == 0 && wp == curwin ? 0 : 1) |
5735 | 2980 # endif |
7 | 2981 ) |
5735 | 2982 #endif |
7 | 2983 && (flags & MOUSE_MAY_STOP_VIS)))) |
2984 { | |
2985 end_visual_mode(); | |
2986 redraw_curbuf_later(INVERTED); /* delete the inversion */ | |
2987 } | |
2988 #ifdef FEAT_CMDWIN | |
2989 if (cmdwin_type != 0 && wp != curwin) | |
2990 { | |
2991 /* A click outside the command-line window: Use modeless | |
2102
907cf09fbb32
updated for version 7.2.385
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
2992 * selection if possible. Allow dragging the status lines. */ |
7 | 2993 on_sep_line = 0; |
2994 # ifdef FEAT_CLIPBOARD | |
2995 if (on_status_line) | |
2996 return IN_STATUS_LINE; | |
2997 return IN_OTHER_WIN; | |
2998 # else | |
2999 row = 0; | |
3000 col += wp->w_wincol; | |
3001 wp = curwin; | |
3002 # endif | |
3003 } | |
3004 #endif | |
3005 /* Only change window focus when not clicking on or dragging the | |
3006 * status line. Do change focus when releasing the mouse button | |
3007 * (MOUSE_FOCUS was set above if we dragged first). */ | |
3008 if (dragwin == NULL || (flags & MOUSE_RELEASED)) | |
3009 win_enter(wp, TRUE); /* can make wp invalid! */ | |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
3010 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
3011 if (curwin != old_curwin) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
3012 { |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12337
diff
changeset
|
3013 #ifdef CHECK_DOUBLE_CLICK |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
3014 /* set topline, to be able to check for double click ourselves */ |
7 | 3015 set_mouse_topline(curwin); |
3016 #endif | |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
3017 #ifdef FEAT_TERMINAL |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
3018 /* when entering a terminal window may change state */ |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
3019 term_win_entered(); |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
3020 #endif |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
3021 } |
7 | 3022 if (on_status_line) /* In (or below) status line */ |
3023 { | |
3024 /* Don't use start_arrow() if we're in the same window */ | |
3025 if (curwin == old_curwin) | |
3026 return IN_STATUS_LINE; | |
3027 else | |
3028 return IN_STATUS_LINE | CURSOR_MOVED; | |
3029 } | |
3030 if (on_sep_line) /* In (or below) status line */ | |
3031 { | |
3032 /* Don't use start_arrow() if we're in the same window */ | |
3033 if (curwin == old_curwin) | |
3034 return IN_SEP_LINE; | |
3035 else | |
3036 return IN_SEP_LINE | CURSOR_MOVED; | |
3037 } | |
3038 | |
3039 curwin->w_cursor.lnum = curwin->w_topline; | |
3040 #ifdef FEAT_GUI | |
3041 /* remember topline, needed for double click */ | |
3042 gui_prev_topline = curwin->w_topline; | |
3043 # ifdef FEAT_DIFF | |
3044 gui_prev_topfill = curwin->w_topfill; | |
3045 # endif | |
3046 #endif | |
3047 } | |
3048 else if (on_status_line && which_button == MOUSE_LEFT) | |
3049 { | |
3050 if (dragwin != NULL) | |
3051 { | |
3052 /* Drag the status line */ | |
3053 count = row - dragwin->w_winrow - dragwin->w_height + 1 | |
3054 - on_status_line; | |
3055 win_drag_status_line(dragwin, count); | |
3056 did_drag |= count; | |
3057 } | |
3058 return IN_STATUS_LINE; /* Cursor didn't move */ | |
3059 } | |
3060 else if (on_sep_line && which_button == MOUSE_LEFT) | |
3061 { | |
3062 if (dragwin != NULL) | |
3063 { | |
3064 /* Drag the separator column */ | |
3065 count = col - dragwin->w_wincol - dragwin->w_width + 1 | |
3066 - on_sep_line; | |
3067 win_drag_vsep_line(dragwin, count); | |
3068 did_drag |= count; | |
3069 } | |
3070 return IN_SEP_LINE; /* Cursor didn't move */ | |
3071 } | |
12519
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
3072 #ifdef FEAT_MENU |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
3073 else if (in_winbar) |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
3074 { |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
3075 /* After a click on the window toolbar don't start Visual mode. */ |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
3076 return IN_OTHER_WIN | MOUSE_WINBAR; |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
3077 } |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
3078 #endif |
7 | 3079 else /* keep_window_focus must be TRUE */ |
3080 { | |
3081 /* before moving the cursor for a left click, stop Visual mode */ | |
3082 if (flags & MOUSE_MAY_STOP_VIS) | |
3083 { | |
3084 end_visual_mode(); | |
3085 redraw_curbuf_later(INVERTED); /* delete the inversion */ | |
3086 } | |
3087 | |
3088 #if defined(FEAT_CMDWIN) && defined(FEAT_CLIPBOARD) | |
3089 /* Continue a modeless selection in another window. */ | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
3090 if (cmdwin_type != 0 && row < curwin->w_winrow) |
7 | 3091 return IN_OTHER_WIN; |
3092 #endif | |
3093 | |
3094 row -= W_WINROW(curwin); | |
12513
3ca08bf99396
patch 8.0.1135: W_WINCOL() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
3095 col -= curwin->w_wincol; |
7 | 3096 |
3097 /* | |
3098 * When clicking beyond the end of the window, scroll the screen. | |
3099 * Scroll by however many rows outside the window we are. | |
3100 */ | |
3101 if (row < 0) | |
3102 { | |
3103 count = 0; | |
3104 for (first = TRUE; curwin->w_topline > 1; ) | |
3105 { | |
3106 #ifdef FEAT_DIFF | |
3107 if (curwin->w_topfill < diff_check(curwin, curwin->w_topline)) | |
3108 ++count; | |
3109 else | |
3110 #endif | |
3111 count += plines(curwin->w_topline - 1); | |
3112 if (!first && count > -row) | |
3113 break; | |
3114 first = FALSE; | |
3115 #ifdef FEAT_FOLDING | |
7009 | 3116 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
7 | 3117 #endif |
3118 #ifdef FEAT_DIFF | |
3119 if (curwin->w_topfill < diff_check(curwin, curwin->w_topline)) | |
3120 ++curwin->w_topfill; | |
3121 else | |
3122 #endif | |
3123 { | |
3124 --curwin->w_topline; | |
3125 #ifdef FEAT_DIFF | |
3126 curwin->w_topfill = 0; | |
3127 #endif | |
3128 } | |
3129 } | |
3130 #ifdef FEAT_DIFF | |
3131 check_topfill(curwin, FALSE); | |
3132 #endif | |
3133 curwin->w_valid &= | |
3134 ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); | |
3135 redraw_later(VALID); | |
3136 row = 0; | |
3137 } | |
3138 else if (row >= curwin->w_height) | |
3139 { | |
3140 count = 0; | |
3141 for (first = TRUE; curwin->w_topline < curbuf->b_ml.ml_line_count; ) | |
3142 { | |
3143 #ifdef FEAT_DIFF | |
3144 if (curwin->w_topfill > 0) | |
3145 ++count; | |
3146 else | |
3147 #endif | |
3148 count += plines(curwin->w_topline); | |
3149 if (!first && count > row - curwin->w_height + 1) | |
3150 break; | |
3151 first = FALSE; | |
3152 #ifdef FEAT_FOLDING | |
3153 if (hasFolding(curwin->w_topline, NULL, &curwin->w_topline) | |
3154 && curwin->w_topline == curbuf->b_ml.ml_line_count) | |
3155 break; | |
3156 #endif | |
3157 #ifdef FEAT_DIFF | |
3158 if (curwin->w_topfill > 0) | |
3159 --curwin->w_topfill; | |
3160 else | |
3161 #endif | |
3162 { | |
3163 ++curwin->w_topline; | |
3164 #ifdef FEAT_DIFF | |
3165 curwin->w_topfill = | |
3166 diff_check_fill(curwin, curwin->w_topline); | |
3167 #endif | |
3168 } | |
3169 } | |
3170 #ifdef FEAT_DIFF | |
3171 check_topfill(curwin, FALSE); | |
3172 #endif | |
3173 redraw_later(VALID); | |
3174 curwin->w_valid &= | |
3175 ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); | |
3176 row = curwin->w_height - 1; | |
3177 } | |
3178 else if (row == 0) | |
3179 { | |
3180 /* When dragging the mouse, while the text has been scrolled up as | |
3181 * far as it goes, moving the mouse in the top line should scroll | |
3182 * the text down (done later when recomputing w_topline). */ | |
1164 | 3183 if (mouse_dragging > 0 |
7 | 3184 && curwin->w_cursor.lnum |
3185 == curwin->w_buffer->b_ml.ml_line_count | |
3186 && curwin->w_cursor.lnum == curwin->w_topline) | |
3187 curwin->w_valid &= ~(VALID_TOPLINE); | |
3188 } | |
3189 } | |
3190 | |
3191 #ifdef FEAT_FOLDING | |
3192 /* Check for position outside of the fold column. */ | |
3193 if ( | |
3194 # ifdef FEAT_RIGHTLEFT | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
3195 curwin->w_p_rl ? col < curwin->w_width - curwin->w_p_fdc : |
7 | 3196 # endif |
3197 col >= curwin->w_p_fdc | |
3198 # ifdef FEAT_CMDWIN | |
3199 + (cmdwin_type == 0 ? 0 : 1) | |
3200 # endif | |
3201 ) | |
3202 mouse_char = ' '; | |
3203 #endif | |
3204 | |
3205 /* compute the position in the buffer line from the posn on the screen */ | |
3206 if (mouse_comp_pos(curwin, &row, &col, &curwin->w_cursor.lnum)) | |
3207 mouse_past_bottom = TRUE; | |
3208 | |
3209 /* Start Visual mode before coladvance(), for when 'sel' != "old" */ | |
3210 if ((flags & MOUSE_MAY_VIS) && !VIsual_active) | |
3211 { | |
3212 check_visual_highlight(); | |
3213 VIsual = old_cursor; | |
3214 VIsual_active = TRUE; | |
3215 VIsual_reselect = TRUE; | |
3216 /* if 'selectmode' contains "mouse", start Select mode */ | |
3217 may_start_select('o'); | |
3218 setmouse(); | |
642 | 3219 if (p_smd && msg_silent == 0) |
7 | 3220 redraw_cmdline = TRUE; /* show visual mode later */ |
3221 } | |
3222 | |
3223 curwin->w_curswant = col; | |
3224 curwin->w_set_curswant = FALSE; /* May still have been TRUE */ | |
3225 if (coladvance(col) == FAIL) /* Mouse click beyond end of line */ | |
3226 { | |
3227 if (inclusive != NULL) | |
3228 *inclusive = TRUE; | |
3229 mouse_past_eol = TRUE; | |
3230 } | |
3231 else if (inclusive != NULL) | |
3232 *inclusive = FALSE; | |
3233 | |
3234 count = IN_BUFFER; | |
3235 if (curwin != old_curwin || curwin->w_cursor.lnum != old_cursor.lnum | |
3236 || curwin->w_cursor.col != old_cursor.col) | |
3237 count |= CURSOR_MOVED; /* Cursor has moved */ | |
3238 | |
3239 #ifdef FEAT_FOLDING | |
3240 if (mouse_char == '+') | |
3241 count |= MOUSE_FOLD_OPEN; | |
3242 else if (mouse_char != ' ') | |
3243 count |= MOUSE_FOLD_CLOSE; | |
3244 #endif | |
3245 | |
3246 return count; | |
3247 } | |
3248 | |
3249 /* | |
3250 * Compute the position in the buffer line from the posn on the screen in | |
3251 * window "win". | |
3252 * Returns TRUE if the position is below the last line. | |
3253 */ | |
3254 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3255 mouse_comp_pos( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3256 win_T *win, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3257 int *rowp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3258 int *colp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3259 linenr_T *lnump) |
7 | 3260 { |
3261 int col = *colp; | |
3262 int row = *rowp; | |
3263 linenr_T lnum; | |
3264 int retval = FALSE; | |
3265 int off; | |
3266 int count; | |
3267 | |
3268 #ifdef FEAT_RIGHTLEFT | |
3269 if (win->w_p_rl) | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
3270 col = win->w_width - 1 - col; |
7 | 3271 #endif |
3272 | |
3273 lnum = win->w_topline; | |
3274 | |
3275 while (row > 0) | |
3276 { | |
3277 #ifdef FEAT_DIFF | |
3278 /* Don't include filler lines in "count" */ | |
237 | 3279 if (win->w_p_diff |
3280 # ifdef FEAT_FOLDING | |
3281 && !hasFoldingWin(win, lnum, NULL, NULL, TRUE, NULL) | |
3282 # endif | |
3283 ) | |
7 | 3284 { |
3285 if (lnum == win->w_topline) | |
3286 row -= win->w_topfill; | |
3287 else | |
3288 row -= diff_check_fill(win, lnum); | |
3289 count = plines_win_nofill(win, lnum, TRUE); | |
3290 } | |
3291 else | |
3292 #endif | |
3293 count = plines_win(win, lnum, TRUE); | |
3294 if (count > row) | |
3295 break; /* Position is in this buffer line. */ | |
3296 #ifdef FEAT_FOLDING | |
3297 (void)hasFoldingWin(win, lnum, NULL, &lnum, TRUE, NULL); | |
3298 #endif | |
3299 if (lnum == win->w_buffer->b_ml.ml_line_count) | |
3300 { | |
3301 retval = TRUE; | |
3302 break; /* past end of file */ | |
3303 } | |
3304 row -= count; | |
3305 ++lnum; | |
3306 } | |
3307 | |
3308 if (!retval) | |
3309 { | |
3310 /* Compute the column without wrapping. */ | |
3311 off = win_col_off(win) - win_col_off2(win); | |
3312 if (col < off) | |
3313 col = off; | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
3314 col += row * (win->w_width - off); |
7 | 3315 /* add skip column (for long wrapping line) */ |
3316 col += win->w_skipcol; | |
3317 } | |
3318 | |
3319 if (!win->w_p_wrap) | |
3320 col += win->w_leftcol; | |
3321 | |
3322 /* skip line number and fold column in front of the line */ | |
3323 col -= win_col_off(win); | |
3324 if (col < 0) | |
3325 { | |
3326 #ifdef FEAT_NETBEANS_INTG | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3327 netbeans_gutter_click(lnum); |
7 | 3328 #endif |
3329 col = 0; | |
3330 } | |
3331 | |
3332 *colp = col; | |
3333 *rowp = row; | |
3334 *lnump = lnum; | |
3335 return retval; | |
3336 } | |
3337 | |
3338 /* | |
3339 * Find the window at screen position "*rowp" and "*colp". The positions are | |
3340 * updated to become relative to the top-left of the window. | |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3341 * Returns NULL when something is wrong. |
7 | 3342 */ |
3343 win_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3344 mouse_find_win(int *rowp, int *colp UNUSED) |
7 | 3345 { |
3346 frame_T *fp; | |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3347 win_T *wp; |
7 | 3348 |
3349 fp = topframe; | |
667 | 3350 *rowp -= firstwin->w_winrow; |
7 | 3351 for (;;) |
3352 { | |
3353 if (fp->fr_layout == FR_LEAF) | |
3354 break; | |
3355 if (fp->fr_layout == FR_ROW) | |
3356 { | |
3357 for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next) | |
3358 { | |
3359 if (*colp < fp->fr_width) | |
3360 break; | |
3361 *colp -= fp->fr_width; | |
3362 } | |
3363 } | |
3364 else /* fr_layout == FR_COL */ | |
3365 { | |
3366 for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next) | |
3367 { | |
3368 if (*rowp < fp->fr_height) | |
3369 break; | |
3370 *rowp -= fp->fr_height; | |
3371 } | |
3372 } | |
3373 } | |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3374 /* When using a timer that closes a window the window might not actually |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3375 * exist. */ |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3376 FOR_ALL_WINDOWS(wp) |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3377 if (wp == fp->fr_win) |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
3378 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
3379 #ifdef FEAT_MENU |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
3380 *rowp -= wp->w_winbar_height; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
3381 #endif |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3382 return wp; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
3383 } |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3384 return NULL; |
7 | 3385 } |
3386 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
3387 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MAC) \ |
7 | 3388 || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \ |
13371
1a3f5759b61e
patch 8.0.1559: build failure without GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
3389 || defined(FEAT_GUI_PHOTON) || defined(FEAT_TERM_POPUP_MENU) \ |
1a3f5759b61e
patch 8.0.1559: build failure without GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
3390 || defined(PROTO) |
7 | 3391 /* |
3392 * Translate window coordinates to buffer position without any side effects | |
3393 */ | |
3394 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3395 get_fpos_of_mouse(pos_T *mpos) |
7 | 3396 { |
3397 win_T *wp; | |
3398 int row = mouse_row; | |
3399 int col = mouse_col; | |
3400 | |
3401 if (row < 0 || col < 0) /* check if it makes sense */ | |
3402 return IN_UNKNOWN; | |
3403 | |
3404 /* find the window where the row is in */ | |
3405 wp = mouse_find_win(&row, &col); | |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3406 if (wp == NULL) |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3407 return IN_UNKNOWN; |
7 | 3408 /* |
3409 * winpos and height may change in win_enter()! | |
3410 */ | |
3411 if (row >= wp->w_height) /* In (or below) status line */ | |
3412 return IN_STATUS_LINE; | |
3413 if (col >= wp->w_width) /* In vertical separator line */ | |
3414 return IN_SEP_LINE; | |
3415 | |
3416 if (wp != curwin) | |
3417 return IN_UNKNOWN; | |
3418 | |
3419 /* compute the position in the buffer line from the posn on the screen */ | |
3420 if (mouse_comp_pos(curwin, &row, &col, &mpos->lnum)) | |
3421 return IN_STATUS_LINE; /* past bottom */ | |
3422 | |
3423 mpos->col = vcol2col(wp, mpos->lnum, col); | |
3424 | |
3425 if (mpos->col > 0) | |
3426 --mpos->col; | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2428
diff
changeset
|
3427 mpos->coladd = 0; |
7 | 3428 return IN_BUFFER; |
3429 } | |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12831
diff
changeset
|
3430 #endif |
7 | 3431 |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12831
diff
changeset
|
3432 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MAC) \ |
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12831
diff
changeset
|
3433 || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \ |
13373
0802633a0b2d
patch 8.0.1560: build failure without GUI on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13371
diff
changeset
|
3434 || defined(FEAT_GUI_PHOTON) || defined(FEAT_BEVAL) \ |
0802633a0b2d
patch 8.0.1560: build failure without GUI on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13371
diff
changeset
|
3435 || defined(FEAT_TERM_POPUP_MENU) || defined(PROTO) |
7 | 3436 /* |
3437 * Convert a virtual (screen) column to a character column. | |
3438 * The first column is one. | |
3439 */ | |
3440 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3441 vcol2col(win_T *wp, linenr_T lnum, int vcol) |
7 | 3442 { |
3443 /* try to advance to the specified column */ | |
3444 int count = 0; | |
3445 char_u *ptr; | |
5995 | 3446 char_u *line; |
7 | 3447 |
5995 | 3448 line = ptr = ml_get_buf(wp->w_buffer, lnum, FALSE); |
3877 | 3449 while (count < vcol && *ptr != NUL) |
7 | 3450 { |
5995 | 3451 count += win_lbr_chartabsize(wp, line, ptr, count, NULL); |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3452 MB_PTR_ADV(ptr); |
7 | 3453 } |
5995 | 3454 return (int)(ptr - line); |
7 | 3455 } |
3456 #endif | |
3457 | |
3458 #endif /* FEAT_MOUSE */ | |
3459 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15665
diff
changeset
|
3460 #if defined(FEAT_GUI) || defined(MSWIN) || defined(PROTO) |
7 | 3461 /* |
3462 * Called when focus changed. Used for the GUI or for systems where this can | |
3463 * be done in the console (Win32). | |
3464 */ | |
3465 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3466 ui_focus_change( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3467 int in_focus) /* TRUE if focus gained. */ |
7 | 3468 { |
3469 static time_t last_time = (time_t)0; | |
3470 int need_redraw = FALSE; | |
3471 | |
3472 /* When activated: Check if any file was modified outside of Vim. | |
3473 * Only do this when not done within the last two seconds (could get | |
3474 * several events in a row). */ | |
3475 if (in_focus && last_time + 2 < time(NULL)) | |
3476 { | |
3477 need_redraw = check_timestamps( | |
3478 # ifdef FEAT_GUI | |
3479 gui.in_use | |
3480 # else | |
3481 FALSE | |
3482 # endif | |
3483 ); | |
3484 last_time = time(NULL); | |
3485 } | |
3486 | |
3487 /* | |
3488 * Fire the focus gained/lost autocommand. | |
3489 */ | |
3490 need_redraw |= apply_autocmds(in_focus ? EVENT_FOCUSGAINED | |
3491 : EVENT_FOCUSLOST, NULL, NULL, FALSE, curbuf); | |
3492 | |
3493 if (need_redraw) | |
3494 { | |
3495 /* Something was executed, make sure the cursor is put back where it | |
3496 * belongs. */ | |
3497 need_wait_return = FALSE; | |
3498 | |
3499 if (State & CMDLINE) | |
3500 redrawcmdline(); | |
3501 else if (State == HITRETURN || State == SETWSIZE || State == ASKMORE | |
3502 || State == EXTERNCMD || State == CONFIRM || exmode_active) | |
3503 repeat_message(); | |
3504 else if ((State & NORMAL) || (State & INSERT)) | |
3505 { | |
3506 if (must_redraw != 0) | |
3507 update_screen(0); | |
3508 setcursor(); | |
3509 } | |
3510 cursor_on(); /* redrawing may have switched it off */ | |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
3511 out_flush_cursor(FALSE, TRUE); |
7 | 3512 # ifdef FEAT_GUI |
3513 if (gui.in_use) | |
3514 gui_update_scrollbars(FALSE); | |
3515 # endif | |
3516 } | |
3517 #ifdef FEAT_TITLE | |
3518 /* File may have been changed from 'readonly' to 'noreadonly' */ | |
3519 if (need_maketitle) | |
3520 maketitle(); | |
3521 #endif | |
3522 } | |
3523 #endif | |
3524 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13373
diff
changeset
|
3525 #if defined(HAVE_INPUT_METHOD) || defined(PROTO) |
7 | 3526 /* |
3527 * Save current Input Method status to specified place. | |
3528 */ | |
3529 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3530 im_save_status(long *psave) |
7 | 3531 { |
3532 /* Don't save when 'imdisable' is set or "xic" is NULL, IM is always | |
3533 * disabled then (but might start later). | |
3534 * Also don't save when inside a mapping, vgetc_im_active has not been set | |
3535 * then. | |
3536 * And don't save when the keys were stuffed (e.g., for a "." command). | |
3537 * And don't save when the GUI is running but our window doesn't have | |
3538 * input focus (e.g., when a find dialog is open). */ | |
3539 if (!p_imdisable && KeyTyped && !KeyStuffed | |
3540 # ifdef FEAT_XIM | |
3541 && xic != NULL | |
3542 # endif | |
3543 # ifdef FEAT_GUI | |
3544 && (!gui.in_use || gui.in_focus) | |
3545 # endif | |
3546 ) | |
3547 { | |
3548 /* Do save when IM is on, or IM is off and saved status is on. */ | |
3549 if (vgetc_im_active) | |
3550 *psave = B_IMODE_IM; | |
3551 else if (*psave == B_IMODE_IM) | |
3552 *psave = B_IMODE_NONE; | |
3553 } | |
3554 } | |
3555 #endif |