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