Mercurial > vim
annotate src/gui_x11.c @ 14749:706a5bcea803
Added tag v8.1.0386 for changeset 00da090af0ab31989d5d831089ce3d760433e192
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 13 Sep 2018 20:45:06 +0200 |
parents | eb264a775071 |
children | 27b9a84395b5 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9939
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * GUI/Motif support by Robert Webb | |
5 * | |
6 * Do ":help uganda" in Vim to read copying and usage conditions. | |
7 * Do ":help credits" in Vim to see a list of people who contributed. | |
8 * See README.txt for an overview of the Vim source code. | |
9 */ | |
10 /* | |
11 * Common code for the Motif and Athena GUI. | |
12 * Not used for GTK. | |
13 */ | |
14 | |
10956
90af0c60d78d
patch 8.0.0367: types in include files may be inconsistent
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
15 #include "vim.h" |
90af0c60d78d
patch 8.0.0367: types in include files may be inconsistent
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
16 |
7 | 17 #include <X11/keysym.h> |
18 #include <X11/Xatom.h> | |
19 #include <X11/StringDefs.h> | |
20 #include <X11/Intrinsic.h> | |
21 #include <X11/Shell.h> | |
22 #include <X11/cursorfont.h> | |
23 | |
24 /* | |
25 * For Workshop XpmP.h is preferred, because it makes the signs drawn with a | |
26 * transparent background instead of black. | |
27 */ | |
28 #if defined(HAVE_XM_XPMP_H) && defined(FEAT_GUI_MOTIF) \ | |
29 && (!defined(HAVE_X11_XPM_H) || defined(FEAT_SUN_WORKSHOP)) | |
30 # include <Xm/XpmP.h> | |
31 #else | |
32 # ifdef HAVE_X11_XPM_H | |
33 # include <X11/xpm.h> | |
34 # endif | |
35 #endif | |
36 | |
37 #ifdef FEAT_XFONTSET | |
38 # ifdef X_LOCALE | |
39 # include <X11/Xlocale.h> | |
40 # else | |
41 # include <locale.h> | |
42 # endif | |
43 #endif | |
44 | |
45 #ifdef HAVE_X11_SUNKEYSYM_H | |
46 # include <X11/Sunkeysym.h> | |
47 #endif | |
48 | |
49 #ifdef HAVE_X11_XMU_EDITRES_H | |
50 # include <X11/Xmu/Editres.h> | |
51 #endif | |
52 | |
53 #define VIM_NAME "vim" | |
54 #define VIM_CLASS "Vim" | |
55 | |
56 /* Default resource values */ | |
57 #define DFLT_FONT "7x13" | |
58 #ifdef FONTSET_ALWAYS | |
59 # define DFLT_MENU_FONT XtDefaultFontSet | |
60 #else | |
61 # define DFLT_MENU_FONT XtDefaultFont | |
62 #endif | |
63 #define DFLT_TOOLTIP_FONT XtDefaultFontSet | |
64 | |
65 #ifdef FEAT_GUI_ATHENA | |
66 # define DFLT_MENU_BG_COLOR "gray77" | |
67 # define DFLT_MENU_FG_COLOR "black" | |
68 # define DFLT_SCROLL_BG_COLOR "gray60" | |
69 # define DFLT_SCROLL_FG_COLOR "gray77" | |
9634
86d470495333
commit https://github.com/vim/vim/commit/4658228262f491fcb582d531d4e8e5754b0d5e83
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
70 # define DFLT_TOOLTIP_BG_COLOR "#ffff91" |
86d470495333
commit https://github.com/vim/vim/commit/4658228262f491fcb582d531d4e8e5754b0d5e83
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
71 # define DFLT_TOOLTIP_FG_COLOR "#000000" |
7 | 72 #else |
73 /* use the default (CDE) colors */ | |
74 # define DFLT_MENU_BG_COLOR "" | |
75 # define DFLT_MENU_FG_COLOR "" | |
76 # define DFLT_SCROLL_BG_COLOR "" | |
77 # define DFLT_SCROLL_FG_COLOR "" | |
9634
86d470495333
commit https://github.com/vim/vim/commit/4658228262f491fcb582d531d4e8e5754b0d5e83
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
78 # define DFLT_TOOLTIP_BG_COLOR "#ffff91" |
86d470495333
commit https://github.com/vim/vim/commit/4658228262f491fcb582d531d4e8e5754b0d5e83
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
79 # define DFLT_TOOLTIP_FG_COLOR "#000000" |
7 | 80 #endif |
81 | |
82 Widget vimShell = (Widget)0; | |
83 | |
84 static Atom wm_atoms[2]; /* Window Manager Atoms */ | |
85 #define DELETE_WINDOW_IDX 0 /* index in wm_atoms[] for WM_DELETE_WINDOW */ | |
86 #define SAVE_YOURSELF_IDX 1 /* index in wm_atoms[] for WM_SAVE_YOURSELF */ | |
87 | |
88 #ifdef FEAT_XFONTSET | |
89 /* | |
90 * We either draw with a fontset (when current_fontset != NULL) or with a | |
91 * normal font (current_fontset == NULL, use gui.text_gc and gui.back_gc). | |
92 */ | |
93 static XFontSet current_fontset = NULL; | |
94 | |
95 #define XDrawString(dpy, win, gc, x, y, str, n) \ | |
96 do \ | |
97 { \ | |
98 if (current_fontset != NULL) \ | |
99 XmbDrawString(dpy, win, current_fontset, gc, x, y, str, n); \ | |
100 else \ | |
101 XDrawString(dpy, win, gc, x, y, str, n); \ | |
102 } while (0) | |
103 | |
104 #define XDrawString16(dpy, win, gc, x, y, str, n) \ | |
105 do \ | |
106 { \ | |
107 if (current_fontset != NULL) \ | |
108 XwcDrawString(dpy, win, current_fontset, gc, x, y, (wchar_t *)str, n); \ | |
109 else \ | |
717 | 110 XDrawString16(dpy, win, gc, x, y, (XChar2b *)str, n); \ |
111 } while (0) | |
112 | |
113 #define XDrawImageString16(dpy, win, gc, x, y, str, n) \ | |
114 do \ | |
115 { \ | |
116 if (current_fontset != NULL) \ | |
117 XwcDrawImageString(dpy, win, current_fontset, gc, x, y, (wchar_t *)str, n); \ | |
118 else \ | |
119 XDrawImageString16(dpy, win, gc, x, y, (XChar2b *)str, n); \ | |
7 | 120 } while (0) |
121 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
122 static int check_fontset_sanity(XFontSet fs); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
123 static int fontset_width(XFontSet fs); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
124 static int fontset_ascent(XFontSet fs); |
7 | 125 #endif |
126 | |
127 static guicolor_T prev_fg_color = INVALCOLOR; | |
128 static guicolor_T prev_bg_color = INVALCOLOR; | |
206 | 129 static guicolor_T prev_sp_color = INVALCOLOR; |
7 | 130 |
131 #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) | |
132 static XButtonPressedEvent last_mouse_event; | |
133 #endif | |
134 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
135 static void gui_x11_check_copy_area(void); |
7 | 136 #ifdef FEAT_CLIENTSERVER |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
137 static void gui_x11_send_event_handler(Widget, XtPointer, XEvent *, Boolean *); |
7 | 138 #endif |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
139 static void gui_x11_wm_protocol_handler(Widget, XtPointer, XEvent *, Boolean *); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
140 static Cursor gui_x11_create_blank_mouse(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
141 static void draw_curl(int row, int col, int cells); |
7 | 142 |
143 | |
144 /* | |
145 * Keycodes recognized by vim. | |
146 * NOTE: when changing this, the table in gui_gtk_x11.c probably needs the | |
147 * same change! | |
148 */ | |
149 static struct specialkey | |
150 { | |
151 KeySym key_sym; | |
152 char_u vim_code0; | |
153 char_u vim_code1; | |
154 } special_keys[] = | |
155 { | |
156 {XK_Up, 'k', 'u'}, | |
157 {XK_Down, 'k', 'd'}, | |
158 {XK_Left, 'k', 'l'}, | |
159 {XK_Right, 'k', 'r'}, | |
160 | |
161 {XK_F1, 'k', '1'}, | |
162 {XK_F2, 'k', '2'}, | |
163 {XK_F3, 'k', '3'}, | |
164 {XK_F4, 'k', '4'}, | |
165 {XK_F5, 'k', '5'}, | |
166 {XK_F6, 'k', '6'}, | |
167 {XK_F7, 'k', '7'}, | |
168 {XK_F8, 'k', '8'}, | |
169 {XK_F9, 'k', '9'}, | |
170 {XK_F10, 'k', ';'}, | |
171 | |
172 {XK_F11, 'F', '1'}, | |
173 {XK_F12, 'F', '2'}, | |
174 {XK_F13, 'F', '3'}, | |
175 {XK_F14, 'F', '4'}, | |
176 {XK_F15, 'F', '5'}, | |
177 {XK_F16, 'F', '6'}, | |
178 {XK_F17, 'F', '7'}, | |
179 {XK_F18, 'F', '8'}, | |
180 {XK_F19, 'F', '9'}, | |
181 {XK_F20, 'F', 'A'}, | |
182 | |
183 {XK_F21, 'F', 'B'}, | |
184 {XK_F22, 'F', 'C'}, | |
185 {XK_F23, 'F', 'D'}, | |
186 {XK_F24, 'F', 'E'}, | |
187 {XK_F25, 'F', 'F'}, | |
188 {XK_F26, 'F', 'G'}, | |
189 {XK_F27, 'F', 'H'}, | |
190 {XK_F28, 'F', 'I'}, | |
191 {XK_F29, 'F', 'J'}, | |
192 {XK_F30, 'F', 'K'}, | |
193 | |
194 {XK_F31, 'F', 'L'}, | |
195 {XK_F32, 'F', 'M'}, | |
196 {XK_F33, 'F', 'N'}, | |
197 {XK_F34, 'F', 'O'}, | |
198 {XK_F35, 'F', 'P'}, /* keysymdef.h defines up to F35 */ | |
199 #ifdef SunXK_F36 | |
200 {SunXK_F36, 'F', 'Q'}, | |
201 {SunXK_F37, 'F', 'R'}, | |
202 #endif | |
203 | |
204 {XK_Help, '%', '1'}, | |
205 {XK_Undo, '&', '8'}, | |
206 {XK_BackSpace, 'k', 'b'}, | |
207 {XK_Insert, 'k', 'I'}, | |
208 {XK_Delete, 'k', 'D'}, | |
209 {XK_Home, 'k', 'h'}, | |
210 {XK_End, '@', '7'}, | |
211 {XK_Prior, 'k', 'P'}, | |
212 {XK_Next, 'k', 'N'}, | |
213 {XK_Print, '%', '9'}, | |
214 | |
215 /* Keypad keys: */ | |
216 #ifdef XK_KP_Left | |
217 {XK_KP_Left, 'k', 'l'}, | |
218 {XK_KP_Right, 'k', 'r'}, | |
219 {XK_KP_Up, 'k', 'u'}, | |
220 {XK_KP_Down, 'k', 'd'}, | |
221 {XK_KP_Insert, KS_EXTRA, (char_u)KE_KINS}, | |
222 {XK_KP_Delete, KS_EXTRA, (char_u)KE_KDEL}, | |
223 {XK_KP_Home, 'K', '1'}, | |
224 {XK_KP_End, 'K', '4'}, | |
225 {XK_KP_Prior, 'K', '3'}, | |
226 {XK_KP_Next, 'K', '5'}, | |
227 | |
228 {XK_KP_Add, 'K', '6'}, | |
229 {XK_KP_Subtract, 'K', '7'}, | |
230 {XK_KP_Divide, 'K', '8'}, | |
231 {XK_KP_Multiply, 'K', '9'}, | |
232 {XK_KP_Enter, 'K', 'A'}, | |
233 {XK_KP_Decimal, 'K', 'B'}, | |
234 | |
235 {XK_KP_0, 'K', 'C'}, | |
236 {XK_KP_1, 'K', 'D'}, | |
237 {XK_KP_2, 'K', 'E'}, | |
238 {XK_KP_3, 'K', 'F'}, | |
239 {XK_KP_4, 'K', 'G'}, | |
240 {XK_KP_5, 'K', 'H'}, | |
241 {XK_KP_6, 'K', 'I'}, | |
242 {XK_KP_7, 'K', 'J'}, | |
243 {XK_KP_8, 'K', 'K'}, | |
244 {XK_KP_9, 'K', 'L'}, | |
245 #endif | |
246 | |
247 /* End of list marker: */ | |
248 {(KeySym)0, 0, 0} | |
249 }; | |
250 | |
251 #define XtNboldFont "boldFont" | |
252 #define XtCBoldFont "BoldFont" | |
253 #define XtNitalicFont "italicFont" | |
254 #define XtCItalicFont "ItalicFont" | |
255 #define XtNboldItalicFont "boldItalicFont" | |
256 #define XtCBoldItalicFont "BoldItalicFont" | |
257 #define XtNscrollbarWidth "scrollbarWidth" | |
258 #define XtCScrollbarWidth "ScrollbarWidth" | |
259 #define XtNmenuHeight "menuHeight" | |
260 #define XtCMenuHeight "MenuHeight" | |
261 #define XtNmenuFont "menuFont" | |
262 #define XtCMenuFont "MenuFont" | |
263 #define XtNmenuFontSet "menuFontSet" | |
264 #define XtCMenuFontSet "MenuFontSet" | |
265 | |
266 | |
267 /* Resources for setting the foreground and background colors of menus */ | |
268 #define XtNmenuBackground "menuBackground" | |
269 #define XtCMenuBackground "MenuBackground" | |
270 #define XtNmenuForeground "menuForeground" | |
271 #define XtCMenuForeground "MenuForeground" | |
272 | |
273 /* Resources for setting the foreground and background colors of scrollbars */ | |
274 #define XtNscrollBackground "scrollBackground" | |
275 #define XtCScrollBackground "ScrollBackground" | |
276 #define XtNscrollForeground "scrollForeground" | |
277 #define XtCScrollForeground "ScrollForeground" | |
278 | |
279 /* Resources for setting the foreground and background colors of tooltip */ | |
280 #define XtNtooltipBackground "tooltipBackground" | |
281 #define XtCTooltipBackground "TooltipBackground" | |
282 #define XtNtooltipForeground "tooltipForeground" | |
283 #define XtCTooltipForeground "TooltipForeground" | |
284 #define XtNtooltipFont "tooltipFont" | |
285 #define XtCTooltipFont "TooltipFont" | |
286 | |
287 /* | |
288 * X Resources: | |
289 */ | |
290 static XtResource vim_resources[] = | |
291 { | |
292 { | |
293 XtNforeground, | |
294 XtCForeground, | |
295 XtRPixel, | |
296 sizeof(Pixel), | |
297 XtOffsetOf(gui_T, def_norm_pixel), | |
298 XtRString, | |
299 XtDefaultForeground | |
300 }, | |
301 { | |
302 XtNbackground, | |
303 XtCBackground, | |
304 XtRPixel, | |
305 sizeof(Pixel), | |
306 XtOffsetOf(gui_T, def_back_pixel), | |
307 XtRString, | |
308 XtDefaultBackground | |
309 }, | |
310 { | |
311 XtNfont, | |
312 XtCFont, | |
313 XtRString, | |
314 sizeof(String *), | |
315 XtOffsetOf(gui_T, rsrc_font_name), | |
316 XtRImmediate, | |
317 XtDefaultFont | |
318 }, | |
319 { | |
320 XtNboldFont, | |
321 XtCBoldFont, | |
322 XtRString, | |
323 sizeof(String *), | |
324 XtOffsetOf(gui_T, rsrc_bold_font_name), | |
325 XtRImmediate, | |
326 "" | |
327 }, | |
328 { | |
329 XtNitalicFont, | |
330 XtCItalicFont, | |
331 XtRString, | |
332 sizeof(String *), | |
333 XtOffsetOf(gui_T, rsrc_ital_font_name), | |
334 XtRImmediate, | |
335 "" | |
336 }, | |
337 { | |
338 XtNboldItalicFont, | |
339 XtCBoldItalicFont, | |
340 XtRString, | |
341 sizeof(String *), | |
342 XtOffsetOf(gui_T, rsrc_boldital_font_name), | |
343 XtRImmediate, | |
344 "" | |
345 }, | |
346 { | |
347 XtNgeometry, | |
348 XtCGeometry, | |
349 XtRString, | |
350 sizeof(String *), | |
351 XtOffsetOf(gui_T, geom), | |
352 XtRImmediate, | |
353 "" | |
354 }, | |
355 { | |
356 XtNreverseVideo, | |
357 XtCReverseVideo, | |
358 XtRBool, | |
359 sizeof(Bool), | |
360 XtOffsetOf(gui_T, rsrc_rev_video), | |
361 XtRImmediate, | |
362 (XtPointer)False | |
363 }, | |
364 { | |
365 XtNborderWidth, | |
366 XtCBorderWidth, | |
367 XtRInt, | |
368 sizeof(int), | |
369 XtOffsetOf(gui_T, border_width), | |
370 XtRImmediate, | |
371 (XtPointer)2 | |
372 }, | |
373 { | |
374 XtNscrollbarWidth, | |
375 XtCScrollbarWidth, | |
376 XtRInt, | |
377 sizeof(int), | |
378 XtOffsetOf(gui_T, scrollbar_width), | |
379 XtRImmediate, | |
380 (XtPointer)SB_DEFAULT_WIDTH | |
381 }, | |
382 #ifdef FEAT_MENU | |
383 # ifdef FEAT_GUI_ATHENA /* with Motif the height is always computed */ | |
384 { | |
385 XtNmenuHeight, | |
386 XtCMenuHeight, | |
387 XtRInt, | |
388 sizeof(int), | |
389 XtOffsetOf(gui_T, menu_height), | |
390 XtRImmediate, | |
391 (XtPointer)MENU_DEFAULT_HEIGHT /* Should figure out at run time */ | |
392 }, | |
393 # endif | |
394 { | |
395 # ifdef FONTSET_ALWAYS | |
396 XtNmenuFontSet, | |
397 XtCMenuFontSet, | |
398 #else | |
399 XtNmenuFont, | |
400 XtCMenuFont, | |
401 #endif | |
402 XtRString, | |
403 sizeof(char *), | |
404 XtOffsetOf(gui_T, rsrc_menu_font_name), | |
405 XtRString, | |
406 DFLT_MENU_FONT | |
407 }, | |
408 #endif | |
409 { | |
410 XtNmenuForeground, | |
411 XtCMenuForeground, | |
412 XtRString, | |
413 sizeof(char *), | |
414 XtOffsetOf(gui_T, rsrc_menu_fg_name), | |
415 XtRString, | |
416 DFLT_MENU_FG_COLOR | |
417 }, | |
418 { | |
419 XtNmenuBackground, | |
420 XtCMenuBackground, | |
421 XtRString, | |
422 sizeof(char *), | |
423 XtOffsetOf(gui_T, rsrc_menu_bg_name), | |
424 XtRString, | |
425 DFLT_MENU_BG_COLOR | |
426 }, | |
427 { | |
428 XtNscrollForeground, | |
429 XtCScrollForeground, | |
430 XtRString, | |
431 sizeof(char *), | |
432 XtOffsetOf(gui_T, rsrc_scroll_fg_name), | |
433 XtRString, | |
434 DFLT_SCROLL_FG_COLOR | |
435 }, | |
436 { | |
437 XtNscrollBackground, | |
438 XtCScrollBackground, | |
439 XtRString, | |
440 sizeof(char *), | |
441 XtOffsetOf(gui_T, rsrc_scroll_bg_name), | |
442 XtRString, | |
443 DFLT_SCROLL_BG_COLOR | |
444 }, | |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
445 #ifdef FEAT_BEVAL_GUI |
7 | 446 { |
447 XtNtooltipForeground, | |
448 XtCTooltipForeground, | |
449 XtRString, | |
450 sizeof(char *), | |
451 XtOffsetOf(gui_T, rsrc_tooltip_fg_name), | |
452 XtRString, | |
453 DFLT_TOOLTIP_FG_COLOR | |
454 }, | |
455 { | |
456 XtNtooltipBackground, | |
457 XtCTooltipBackground, | |
458 XtRString, | |
459 sizeof(char *), | |
460 XtOffsetOf(gui_T, rsrc_tooltip_bg_name), | |
461 XtRString, | |
462 DFLT_TOOLTIP_BG_COLOR | |
463 }, | |
464 { | |
465 XtNtooltipFont, | |
466 XtCTooltipFont, | |
467 XtRString, | |
468 sizeof(char *), | |
469 XtOffsetOf(gui_T, rsrc_tooltip_font_name), | |
470 XtRString, | |
471 DFLT_TOOLTIP_FONT | |
472 }, | |
473 /* This one isn't really needed, keep for Sun Workshop? */ | |
474 { | |
475 "balloonEvalFontSet", | |
476 XtCFontSet, | |
477 XtRFontSet, | |
478 sizeof(XFontSet), | |
479 XtOffsetOf(gui_T, tooltip_fontset), | |
480 XtRImmediate, | |
481 (XtPointer)NOFONTSET | |
482 }, | |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
483 #endif /* FEAT_BEVAL_GUI */ |
7 | 484 #ifdef FEAT_XIM |
485 { | |
486 "preeditType", | |
487 "PreeditType", | |
488 XtRString, | |
489 sizeof(char*), | |
490 XtOffsetOf(gui_T, rsrc_preedit_type_name), | |
491 XtRString, | |
492 (XtPointer)"OverTheSpot,OffTheSpot,Root" | |
493 }, | |
494 { | |
495 "inputMethod", | |
496 "InputMethod", | |
497 XtRString, | |
498 sizeof(char*), | |
499 XtOffsetOf(gui_T, rsrc_input_method), | |
500 XtRString, | |
501 NULL | |
502 }, | |
503 #endif /* FEAT_XIM */ | |
504 }; | |
505 | |
506 /* | |
507 * This table holds all the X GUI command line options allowed. This includes | |
508 * the standard ones so that we can skip them when vim is started without the | |
509 * GUI (but the GUI might start up later). | |
510 * When changing this, also update doc/vim_gui.txt and the usage message!!! | |
511 */ | |
512 static XrmOptionDescRec cmdline_options[] = | |
513 { | |
514 /* We handle these options ourselves */ | |
515 {"-bg", ".background", XrmoptionSepArg, NULL}, | |
516 {"-background", ".background", XrmoptionSepArg, NULL}, | |
517 {"-fg", ".foreground", XrmoptionSepArg, NULL}, | |
518 {"-foreground", ".foreground", XrmoptionSepArg, NULL}, | |
519 {"-fn", ".font", XrmoptionSepArg, NULL}, | |
520 {"-font", ".font", XrmoptionSepArg, NULL}, | |
521 {"-boldfont", ".boldFont", XrmoptionSepArg, NULL}, | |
522 {"-italicfont", ".italicFont", XrmoptionSepArg, NULL}, | |
523 {"-geom", ".geometry", XrmoptionSepArg, NULL}, | |
524 {"-geometry", ".geometry", XrmoptionSepArg, NULL}, | |
525 {"-reverse", "*reverseVideo", XrmoptionNoArg, "True"}, | |
526 {"-rv", "*reverseVideo", XrmoptionNoArg, "True"}, | |
527 {"+reverse", "*reverseVideo", XrmoptionNoArg, "False"}, | |
528 {"+rv", "*reverseVideo", XrmoptionNoArg, "False"}, | |
529 {"-display", ".display", XrmoptionSepArg, NULL}, | |
557 | 530 {"-iconic", ".iconic", XrmoptionNoArg, "True"}, |
7 | 531 {"-name", ".name", XrmoptionSepArg, NULL}, |
532 {"-bw", ".borderWidth", XrmoptionSepArg, NULL}, | |
533 {"-borderwidth", ".borderWidth", XrmoptionSepArg, NULL}, | |
534 {"-sw", ".scrollbarWidth", XrmoptionSepArg, NULL}, | |
535 {"-scrollbarwidth", ".scrollbarWidth", XrmoptionSepArg, NULL}, | |
536 {"-mh", ".menuHeight", XrmoptionSepArg, NULL}, | |
537 {"-menuheight", ".menuHeight", XrmoptionSepArg, NULL}, | |
538 #ifdef FONTSET_ALWAYS | |
539 {"-mf", ".menuFontSet", XrmoptionSepArg, NULL}, | |
540 {"-menufont", ".menuFontSet", XrmoptionSepArg, NULL}, | |
541 {"-menufontset", ".menuFontSet", XrmoptionSepArg, NULL}, | |
542 #else | |
543 {"-mf", ".menuFont", XrmoptionSepArg, NULL}, | |
544 {"-menufont", ".menuFont", XrmoptionSepArg, NULL}, | |
545 #endif | |
546 {"-xrm", NULL, XrmoptionResArg, NULL} | |
547 }; | |
548 | |
549 static int gui_argc = 0; | |
550 static char **gui_argv = NULL; | |
551 | |
552 /* | |
553 * Call-back routines. | |
554 */ | |
555 | |
556 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
557 gui_x11_timer_cb( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
558 XtPointer timed_out, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
559 XtIntervalId *interval_id UNUSED) |
7 | 560 { |
561 *((int *)timed_out) = TRUE; | |
562 } | |
563 | |
12257
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
564 #ifdef FEAT_JOB_CHANNEL |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
565 static void |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
566 channel_poll_cb( |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
567 XtPointer client_data, |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
568 XtIntervalId *interval_id UNUSED) |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
569 { |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
570 XtIntervalId *channel_timer = (XtIntervalId *)client_data; |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
571 |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
572 /* Using an event handler for a channel that may be disconnected does |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
573 * not work, it hangs. Instead poll for messages. */ |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
574 channel_handle_events(TRUE); |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
575 parse_queued_messages(); |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
576 |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
577 /* repeat */ |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
578 *channel_timer = XtAppAddTimeOut(app_context, (long_u)20, |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
579 channel_poll_cb, client_data); |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
580 } |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
581 #endif |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
582 |
7 | 583 static void |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
584 gui_x11_visibility_cb( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
585 Widget w UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
586 XtPointer dud UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
587 XEvent *event, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
588 Boolean *dum UNUSED) |
7 | 589 { |
590 if (event->type != VisibilityNotify) | |
591 return; | |
592 | |
593 gui.visibility = event->xvisibility.state; | |
594 | |
595 /* | |
596 * When we do an XCopyArea(), and the window is partially obscured, we want | |
597 * to receive an event to tell us whether it worked or not. | |
598 */ | |
599 XSetGraphicsExposures(gui.dpy, gui.text_gc, | |
600 gui.visibility != VisibilityUnobscured); | |
601 | |
602 /* This is needed for when redrawing is slow. */ | |
603 gui_mch_update(); | |
604 } | |
605 | |
606 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
607 gui_x11_expose_cb( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
608 Widget w UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
609 XtPointer dud UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
610 XEvent *event, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
611 Boolean *dum UNUSED) |
7 | 612 { |
613 XExposeEvent *gevent; | |
614 int new_x; | |
615 | |
616 if (event->type != Expose) | |
617 return; | |
618 | |
619 out_flush(); /* make sure all output has been processed */ | |
620 | |
621 gevent = (XExposeEvent *)event; | |
622 gui_redraw(gevent->x, gevent->y, gevent->width, gevent->height); | |
623 | |
624 new_x = FILL_X(0); | |
625 | |
626 /* Clear the border areas if needed */ | |
627 if (gevent->x < new_x) | |
628 XClearArea(gui.dpy, gui.wid, 0, 0, new_x, 0, False); | |
629 if (gevent->y < FILL_Y(0)) | |
630 XClearArea(gui.dpy, gui.wid, 0, 0, 0, FILL_Y(0), False); | |
631 if (gevent->x > FILL_X(Columns)) | |
632 XClearArea(gui.dpy, gui.wid, FILL_X((int)Columns), 0, 0, 0, False); | |
633 if (gevent->y > FILL_Y(Rows)) | |
634 XClearArea(gui.dpy, gui.wid, 0, FILL_Y((int)Rows), 0, 0, False); | |
635 | |
636 /* This is needed for when redrawing is slow. */ | |
637 gui_mch_update(); | |
638 } | |
639 | |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
1887
diff
changeset
|
640 #if ((defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)) \ |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
1887
diff
changeset
|
641 && defined(FEAT_GUI_MOTIF)) || defined(PROTO) |
7 | 642 /* |
445 | 643 * This function fills in the XRectangle object with the current x,y |
644 * coordinates and height, width so that an XtVaSetValues to the same shell of | |
1226 | 645 * those resources will restore the window to its former position and |
445 | 646 * dimensions. |
7 | 647 * |
445 | 648 * Note: This function may fail, in which case the XRectangle will be |
649 * unchanged. Be sure to have the XRectangle set with the proper values for a | |
650 * failed condition prior to calling this function. | |
7 | 651 */ |
652 static void | |
653 shellRectangle(Widget shell, XRectangle *r) | |
654 { | |
655 Window rootw, shellw, child, parentw; | |
656 int absx, absy; | |
657 XWindowAttributes a; | |
658 Window *children; | |
659 unsigned int childrenCount; | |
660 | |
661 shellw = XtWindow(shell); | |
662 if (shellw == 0) | |
663 return; | |
664 for (;;) | |
665 { | |
666 XQueryTree(XtDisplay(shell), shellw, &rootw, &parentw, | |
667 &children, &childrenCount); | |
668 XFree(children); | |
669 if (parentw == rootw) | |
670 break; | |
671 shellw = parentw; | |
672 } | |
673 XGetWindowAttributes(XtDisplay(shell), shellw, &a); | |
674 XTranslateCoordinates(XtDisplay(shell), shellw, a.root, 0, 0, | |
675 &absx, &absy, &child); | |
676 r->x = absx; | |
677 r->y = absy; | |
678 XtVaGetValues(shell, XmNheight, &r->height, XmNwidth, &r->width, NULL); | |
679 } | |
680 #endif | |
681 | |
682 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
683 gui_x11_resize_window_cb( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
684 Widget w UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
685 XtPointer dud UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
686 XEvent *event, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
687 Boolean *dum UNUSED) |
7 | 688 { |
689 static int lastWidth, lastHeight; | |
690 | |
691 if (event->type != ConfigureNotify) | |
692 return; | |
693 | |
694 if (event->xconfigure.width != lastWidth | |
695 || event->xconfigure.height != lastHeight) | |
696 { | |
697 lastWidth = event->xconfigure.width; | |
698 lastHeight = event->xconfigure.height; | |
699 gui_resize_shell(event->xconfigure.width, event->xconfigure.height | |
700 #ifdef FEAT_XIM | |
701 - xim_get_status_area_height() | |
702 #endif | |
703 ); | |
704 } | |
705 #ifdef FEAT_SUN_WORKSHOP | |
706 if (usingSunWorkShop) | |
707 { | |
708 XRectangle rec; | |
709 | |
710 shellRectangle(w, &rec); | |
711 workshop_frame_moved(rec.x, rec.y, rec.width, rec.height); | |
712 } | |
713 #endif | |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
1887
diff
changeset
|
714 #if defined(FEAT_NETBEANS_INTG) && defined(FEAT_GUI_MOTIF) |
2210 | 715 if (netbeans_active()) |
7 | 716 { |
717 XRectangle rec; | |
718 | |
719 shellRectangle(w, &rec); | |
720 netbeans_frame_moved(rec.x, rec.y); | |
721 } | |
722 #endif | |
723 #ifdef FEAT_XIM | |
724 xim_set_preedit(); | |
725 #endif | |
726 } | |
727 | |
728 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
729 gui_x11_focus_change_cb( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
730 Widget w UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
731 XtPointer data UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
732 XEvent *event, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
733 Boolean *dum UNUSED) |
7 | 734 { |
735 gui_focus_change(event->type == FocusIn); | |
736 } | |
737 | |
738 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
739 gui_x11_enter_cb( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
740 Widget w UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
741 XtPointer data UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
742 XEvent *event UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
743 Boolean *dum UNUSED) |
7 | 744 { |
745 gui_focus_change(TRUE); | |
746 } | |
747 | |
748 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
749 gui_x11_leave_cb( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
750 Widget w UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
751 XtPointer data UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
752 XEvent *event UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
753 Boolean *dum UNUSED) |
7 | 754 { |
755 gui_focus_change(FALSE); | |
756 } | |
757 | |
758 #if defined(X_HAVE_UTF8_STRING) && defined(FEAT_MBYTE) | |
759 # if X_HAVE_UTF8_STRING | |
760 # define USE_UTF8LOOKUP | |
761 # endif | |
762 #endif | |
763 | |
764 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
765 gui_x11_key_hit_cb( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
766 Widget w UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
767 XtPointer dud UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
768 XEvent *event, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
769 Boolean *dum UNUSED) |
7 | 770 { |
771 XKeyPressedEvent *ev_press; | |
772 #ifdef FEAT_XIM | |
773 char_u string2[256]; | |
774 char_u string_shortbuf[256]; | |
775 char_u *string = string_shortbuf; | |
776 Boolean string_alloced = False; | |
777 Status status; | |
778 #else | |
779 char_u string[4], string2[3]; | |
780 #endif | |
781 KeySym key_sym, key_sym2; | |
782 int len, len2; | |
783 int i; | |
784 int modifiers; | |
785 int key; | |
786 | |
787 ev_press = (XKeyPressedEvent *)event; | |
788 | |
789 #ifdef FEAT_XIM | |
790 if (xic) | |
791 { | |
792 # ifdef USE_UTF8LOOKUP | |
793 /* XFree86 4.0.2 or newer: Be able to get UTF-8 characters even when | |
794 * the locale isn't utf-8. */ | |
795 if (enc_utf8) | |
796 len = Xutf8LookupString(xic, ev_press, (char *)string, | |
797 sizeof(string_shortbuf), &key_sym, &status); | |
798 else | |
799 # endif | |
800 len = XmbLookupString(xic, ev_press, (char *)string, | |
801 sizeof(string_shortbuf), &key_sym, &status); | |
802 if (status == XBufferOverflow) | |
803 { | |
804 string = (char_u *)XtMalloc(len + 1); | |
805 string_alloced = True; | |
806 # ifdef USE_UTF8LOOKUP | |
807 /* XFree86 4.0.2 or newer: Be able to get UTF-8 characters even | |
808 * when the locale isn't utf-8. */ | |
809 if (enc_utf8) | |
810 len = Xutf8LookupString(xic, ev_press, (char *)string, | |
811 len, &key_sym, &status); | |
812 else | |
813 # endif | |
814 len = XmbLookupString(xic, ev_press, (char *)string, | |
815 len, &key_sym, &status); | |
816 } | |
817 if (status == XLookupNone || status == XLookupChars) | |
818 key_sym = XK_VoidSymbol; | |
819 | |
820 # ifdef FEAT_MBYTE | |
821 /* Do conversion from 'termencoding' to 'encoding'. When using | |
822 * Xutf8LookupString() it has already been done. */ | |
823 if (len > 0 && input_conv.vc_type != CONV_NONE | |
824 # ifdef USE_UTF8LOOKUP | |
825 && !enc_utf8 | |
826 # endif | |
827 ) | |
828 { | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13152
diff
changeset
|
829 int maxlen = len * 4 + 40; /* guessed */ |
7 | 830 char_u *p = (char_u *)XtMalloc(maxlen); |
831 | |
832 mch_memmove(p, string, len); | |
833 if (string_alloced) | |
834 XtFree((char *)string); | |
835 string = p; | |
836 string_alloced = True; | |
837 len = convert_input(p, len, maxlen); | |
838 } | |
839 # endif | |
840 | |
841 /* Translate CSI to K_CSI, otherwise it could be recognized as the | |
842 * start of a special key. */ | |
843 for (i = 0; i < len; ++i) | |
844 if (string[i] == CSI) | |
845 { | |
846 char_u *p = (char_u *)XtMalloc(len + 3); | |
847 | |
848 mch_memmove(p, string, i + 1); | |
849 p[i + 1] = KS_EXTRA; | |
850 p[i + 2] = (int)KE_CSI; | |
851 mch_memmove(p + i + 3, string + i + 1, len - i); | |
852 if (string_alloced) | |
853 XtFree((char *)string); | |
854 string = p; | |
855 string_alloced = True; | |
856 i += 2; | |
857 len += 2; | |
858 } | |
859 } | |
860 else | |
861 #endif | |
862 len = XLookupString(ev_press, (char *)string, sizeof(string), | |
863 &key_sym, NULL); | |
864 | |
865 #ifdef SunXK_F36 | |
866 /* | |
867 * These keys have bogus lookup strings, and trapping them here is | |
868 * easier than trying to XRebindKeysym() on them with every possible | |
869 * combination of modifiers. | |
870 */ | |
871 if (key_sym == SunXK_F36 || key_sym == SunXK_F37) | |
872 len = 0; | |
873 #endif | |
874 | |
875 #ifdef FEAT_HANGULIN | |
876 if ((key_sym == XK_space) && (ev_press->state & ShiftMask)) | |
877 { | |
878 hangul_input_state_toggle(); | |
879 goto theend; | |
880 } | |
881 #endif | |
882 | |
883 if (key_sym == XK_space) | |
884 string[0] = ' '; /* Otherwise Ctrl-Space doesn't work */ | |
885 | |
886 /* | |
887 * Only on some machines ^_ requires Ctrl+Shift+minus. For consistency, | |
888 * allow just Ctrl+minus too. | |
889 */ | |
890 if (key_sym == XK_minus && (ev_press->state & ControlMask)) | |
891 string[0] = Ctrl__; | |
892 | |
893 #ifdef XK_ISO_Left_Tab | |
894 /* why do we get XK_ISO_Left_Tab instead of XK_Tab for shift-tab? */ | |
895 if (key_sym == XK_ISO_Left_Tab) | |
896 { | |
897 key_sym = XK_Tab; | |
898 string[0] = TAB; | |
899 len = 1; | |
900 } | |
901 #endif | |
902 | |
903 /* Check for Alt/Meta key (Mod1Mask), but not for a BS, DEL or character | |
904 * that already has the 8th bit set. And not when using a double-byte | |
905 * encoding, setting the 8th bit may make it the lead byte of a | |
906 * double-byte character. */ | |
907 if (len == 1 | |
908 && (ev_press->state & Mod1Mask) | |
909 && !(key_sym == XK_BackSpace || key_sym == XK_Delete) | |
910 && (string[0] & 0x80) == 0 | |
911 #ifdef FEAT_MBYTE | |
912 && !enc_dbcs | |
913 #endif | |
914 ) | |
915 { | |
916 #if defined(FEAT_MENU) && defined(FEAT_GUI_MOTIF) | |
917 /* Ignore ALT keys when they are used for the menu only */ | |
918 if (gui.menu_is_active | |
919 && (p_wak[0] == 'y' | |
920 || (p_wak[0] == 'm' && gui_is_menu_shortcut(string[0])))) | |
921 goto theend; | |
922 #endif | |
923 /* | |
924 * Before we set the 8th bit, check to make sure the user doesn't | |
925 * already have a mapping defined for this sequence. We determine this | |
926 * by checking to see if the input would be the same without the | |
927 * Alt/Meta key. | |
928 * Don't do this for <S-M-Tab>, that should become K_S_TAB with ALT. | |
929 */ | |
930 ev_press->state &= ~Mod1Mask; | |
931 len2 = XLookupString(ev_press, (char *)string2, sizeof(string2), | |
932 &key_sym2, NULL); | |
933 if (key_sym2 == XK_space) | |
934 string2[0] = ' '; /* Otherwise Meta-Ctrl-Space doesn't work */ | |
935 if ( len2 == 1 | |
936 && string[0] == string2[0] | |
937 && !(key_sym == XK_Tab && (ev_press->state & ShiftMask))) | |
938 { | |
939 string[0] |= 0x80; | |
940 #ifdef FEAT_MBYTE | |
941 if (enc_utf8) /* convert to utf-8 */ | |
942 { | |
943 string[1] = string[0] & 0xbf; | |
944 string[0] = ((unsigned)string[0] >> 6) + 0xc0; | |
945 if (string[1] == CSI) | |
946 { | |
947 string[2] = KS_EXTRA; | |
948 string[3] = (int)KE_CSI; | |
949 len = 4; | |
950 } | |
951 else | |
952 len = 2; | |
953 } | |
954 #endif | |
955 } | |
956 else | |
957 ev_press->state |= Mod1Mask; | |
958 } | |
959 | |
960 if (len == 1 && string[0] == CSI) | |
961 { | |
962 string[1] = KS_EXTRA; | |
963 string[2] = (int)KE_CSI; | |
964 len = -3; | |
965 } | |
966 | |
967 /* Check for special keys. Also do this when len == 1 (key has an ASCII | |
968 * value) to detect backspace, delete and keypad keys. */ | |
969 if (len == 0 || len == 1) | |
970 { | |
971 for (i = 0; special_keys[i].key_sym != (KeySym)0; i++) | |
972 { | |
973 if (special_keys[i].key_sym == key_sym) | |
974 { | |
975 string[0] = CSI; | |
976 string[1] = special_keys[i].vim_code0; | |
977 string[2] = special_keys[i].vim_code1; | |
978 len = -3; | |
979 break; | |
980 } | |
981 } | |
982 } | |
983 | |
984 /* Unrecognised key is ignored. */ | |
985 if (len == 0) | |
986 goto theend; | |
987 | |
988 /* Special keys (and a few others) may have modifiers. Also when using a | |
989 * double-byte encoding (can't set the 8th bit). */ | |
990 if (len == -3 || key_sym == XK_space || key_sym == XK_Tab | |
991 || key_sym == XK_Return || key_sym == XK_Linefeed | |
992 || key_sym == XK_Escape | |
993 #ifdef FEAT_MBYTE | |
994 || (enc_dbcs && len == 1 && (ev_press->state & Mod1Mask)) | |
995 #endif | |
996 ) | |
997 { | |
998 modifiers = 0; | |
999 if (ev_press->state & ShiftMask) | |
1000 modifiers |= MOD_MASK_SHIFT; | |
1001 if (ev_press->state & ControlMask) | |
1002 modifiers |= MOD_MASK_CTRL; | |
1003 if (ev_press->state & Mod1Mask) | |
1004 modifiers |= MOD_MASK_ALT; | |
179 | 1005 if (ev_press->state & Mod4Mask) |
1006 modifiers |= MOD_MASK_META; | |
7 | 1007 |
1008 /* | |
1009 * For some keys a shift modifier is translated into another key | |
1010 * code. | |
1011 */ | |
1012 if (len == -3) | |
1013 key = TO_SPECIAL(string[1], string[2]); | |
1014 else | |
1015 key = string[0]; | |
1016 key = simplify_key(key, &modifiers); | |
1017 if (key == CSI) | |
1018 key = K_CSI; | |
1019 if (IS_SPECIAL(key)) | |
1020 { | |
1021 string[0] = CSI; | |
1022 string[1] = K_SECOND(key); | |
1023 string[2] = K_THIRD(key); | |
1024 len = 3; | |
1025 } | |
1026 else | |
1027 { | |
1028 string[0] = key; | |
1029 len = 1; | |
1030 } | |
1031 | |
1032 if (modifiers != 0) | |
1033 { | |
1034 string2[0] = CSI; | |
1035 string2[1] = KS_MODIFIER; | |
1036 string2[2] = modifiers; | |
1037 add_to_input_buf(string2, 3); | |
1038 } | |
1039 } | |
1040 | |
1041 if (len == 1 && ((string[0] == Ctrl_C && ctrl_c_interrupts) | |
1042 #ifdef UNIX | |
1043 || (intr_char != 0 && string[0] == intr_char) | |
1044 #endif | |
1045 )) | |
1046 { | |
1047 trash_input_buf(); | |
1048 got_int = TRUE; | |
1049 } | |
1050 | |
1051 add_to_input_buf(string, len); | |
1052 | |
1053 /* | |
1054 * blank out the pointer if necessary | |
1055 */ | |
1056 if (p_mh) | |
1057 gui_mch_mousehide(TRUE); | |
1058 | |
1059 #if defined(FEAT_BEVAL_TIP) | |
1060 { | |
1061 BalloonEval *be; | |
1062 | |
1063 if ((be = gui_mch_currently_showing_beval()) != NULL) | |
1064 gui_mch_unpost_balloon(be); | |
1065 } | |
1066 #endif | |
1067 theend: | |
1068 {} /* some compilers need a statement here */ | |
1069 #ifdef FEAT_XIM | |
1070 if (string_alloced) | |
1071 XtFree((char *)string); | |
1072 #endif | |
1073 } | |
1074 | |
1075 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1076 gui_x11_mouse_cb( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1077 Widget w UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1078 XtPointer dud UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1079 XEvent *event, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1080 Boolean *dum UNUSED) |
7 | 1081 { |
1082 static XtIntervalId timer = (XtIntervalId)0; | |
1083 static int timed_out = TRUE; | |
1084 | |
1085 int button; | |
1086 int repeated_click = FALSE; | |
1087 int x, y; | |
1088 int_u x_modifiers; | |
1089 int_u vim_modifiers; | |
1090 | |
1091 if (event->type == MotionNotify) | |
1092 { | |
1093 /* Get the latest position, avoids lagging behind on a drag. */ | |
1094 x = event->xmotion.x; | |
1095 y = event->xmotion.y; | |
1096 x_modifiers = event->xmotion.state; | |
1097 button = (x_modifiers & (Button1Mask | Button2Mask | Button3Mask)) | |
1098 ? MOUSE_DRAG : ' '; | |
1099 | |
1100 /* | |
1101 * if our pointer is currently hidden, then we should show it. | |
1102 */ | |
1103 gui_mch_mousehide(FALSE); | |
1104 | |
1105 if (button != MOUSE_DRAG) /* just moving the rodent */ | |
1106 { | |
1107 #ifdef FEAT_MENU | |
1108 if (dud) /* moved in vimForm */ | |
1109 y -= gui.menu_height; | |
1110 #endif | |
1111 gui_mouse_moved(x, y); | |
1112 return; | |
1113 } | |
1114 } | |
1115 else | |
1116 { | |
1117 x = event->xbutton.x; | |
1118 y = event->xbutton.y; | |
1119 if (event->type == ButtonPress) | |
1120 { | |
1121 /* Handle multiple clicks */ | |
1122 if (!timed_out) | |
1123 { | |
1124 XtRemoveTimeOut(timer); | |
1125 repeated_click = TRUE; | |
1126 } | |
1127 timed_out = FALSE; | |
1128 timer = XtAppAddTimeOut(app_context, (long_u)p_mouset, | |
1129 gui_x11_timer_cb, &timed_out); | |
1130 switch (event->xbutton.button) | |
1131 { | |
7260
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1132 /* keep in sync with gui_gtk_x11.c */ |
7 | 1133 case Button1: button = MOUSE_LEFT; break; |
1134 case Button2: button = MOUSE_MIDDLE; break; | |
1135 case Button3: button = MOUSE_RIGHT; break; | |
1136 case Button4: button = MOUSE_4; break; | |
1137 case Button5: button = MOUSE_5; break; | |
7260
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1138 case 6: button = MOUSE_7; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1139 case 7: button = MOUSE_6; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1140 case 8: button = MOUSE_X1; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1141 case 9: button = MOUSE_X2; break; |
7 | 1142 default: |
1143 return; /* Unknown button */ | |
1144 } | |
1145 } | |
1146 else if (event->type == ButtonRelease) | |
1147 button = MOUSE_RELEASE; | |
1148 else | |
1149 return; /* Unknown mouse event type */ | |
1150 | |
1151 x_modifiers = event->xbutton.state; | |
1152 #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) | |
1153 last_mouse_event = event->xbutton; | |
1154 #endif | |
1155 } | |
1156 | |
1157 vim_modifiers = 0x0; | |
1158 if (x_modifiers & ShiftMask) | |
1159 vim_modifiers |= MOUSE_SHIFT; | |
1160 if (x_modifiers & ControlMask) | |
1161 vim_modifiers |= MOUSE_CTRL; | |
1162 if (x_modifiers & Mod1Mask) /* Alt or Meta key */ | |
1163 vim_modifiers |= MOUSE_ALT; | |
1164 | |
1165 gui_send_mouse_event(button, x, y, repeated_click, vim_modifiers); | |
1166 } | |
1167 | |
1168 /* | |
1169 * End of call-back routines | |
1170 */ | |
1171 | |
1172 /* | |
1173 * Parse the GUI related command-line arguments. Any arguments used are | |
1174 * deleted from argv, and *argc is decremented accordingly. This is called | |
1175 * when vim is started, whether or not the GUI has been started. | |
1176 */ | |
1177 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1178 gui_mch_prepare(int *argc, char **argv) |
7 | 1179 { |
1180 int arg; | |
1181 int i; | |
1182 | |
1183 /* | |
1184 * Move all the entries in argv which are relevant to X into gui_argv. | |
1185 */ | |
1186 gui_argc = 0; | |
1187 gui_argv = (char **)lalloc((long_u)(*argc * sizeof(char *)), FALSE); | |
1188 if (gui_argv == NULL) | |
1189 return; | |
1190 gui_argv[gui_argc++] = argv[0]; | |
1191 arg = 1; | |
1192 while (arg < *argc) | |
1193 { | |
1194 /* Look for argv[arg] in cmdline_options[] table */ | |
1887 | 1195 for (i = 0; i < (int)XtNumber(cmdline_options); i++) |
7 | 1196 if (strcmp(argv[arg], cmdline_options[i].option) == 0) |
1197 break; | |
1198 | |
1887 | 1199 if (i < (int)XtNumber(cmdline_options)) |
7 | 1200 { |
1201 /* Remember finding "-rv" or "-reverse" */ | |
1202 if (strcmp("-rv", argv[arg]) == 0 | |
1203 || strcmp("-reverse", argv[arg]) == 0) | |
1204 found_reverse_arg = TRUE; | |
1205 else if ((strcmp("-fn", argv[arg]) == 0 | |
1206 || strcmp("-font", argv[arg]) == 0) | |
1207 && arg + 1 < *argc) | |
1208 font_argument = argv[arg + 1]; | |
1209 | |
1210 /* Found match in table, so move it into gui_argv */ | |
1211 gui_argv[gui_argc++] = argv[arg]; | |
1212 if (--*argc > arg) | |
1213 { | |
1214 mch_memmove(&argv[arg], &argv[arg + 1], (*argc - arg) | |
1215 * sizeof(char *)); | |
1216 if (cmdline_options[i].argKind != XrmoptionNoArg) | |
1217 { | |
1218 /* Move the options argument as well */ | |
1219 gui_argv[gui_argc++] = argv[arg]; | |
1220 if (--*argc > arg) | |
1221 mch_memmove(&argv[arg], &argv[arg + 1], (*argc - arg) | |
1222 * sizeof(char *)); | |
1223 } | |
1224 } | |
1225 argv[*argc] = NULL; | |
1226 } | |
1227 else | |
1228 #ifdef FEAT_SUN_WORKSHOP | |
1229 if (strcmp("-ws", argv[arg]) == 0) | |
1230 { | |
1231 usingSunWorkShop++; | |
1232 p_acd = TRUE; | |
1233 gui.dofork = FALSE; /* don't fork() when starting GUI */ | |
1234 mch_memmove(&argv[arg], &argv[arg + 1], | |
1235 (--*argc - arg) * sizeof(char *)); | |
1236 argv[*argc] = NULL; | |
1237 # ifdef WSDEBUG | |
1238 wsdebug_wait(WT_ENV | WT_WAIT | WT_STOP, "SPRO_GVIM_WAIT", 20); | |
1239 wsdebug_log_init("SPRO_GVIM_DEBUG", "SPRO_GVIM_DLEVEL"); | |
1240 # endif | |
1241 } | |
1242 else | |
1243 #endif | |
1244 #ifdef FEAT_NETBEANS_INTG | |
1245 if (strncmp("-nb", argv[arg], 3) == 0) | |
1246 { | |
1247 gui.dofork = FALSE; /* don't fork() when starting GUI */ | |
1248 netbeansArg = argv[arg]; | |
1249 mch_memmove(&argv[arg], &argv[arg + 1], | |
1250 (--*argc - arg) * sizeof(char *)); | |
1251 argv[*argc] = NULL; | |
1252 } | |
1253 else | |
1254 #endif | |
1255 arg++; | |
1256 } | |
1257 } | |
1258 | |
1259 #ifndef XtSpecificationRelease | |
1260 # define CARDINAL (Cardinal *) | |
1261 #else | |
1262 # if XtSpecificationRelease == 4 | |
1263 # define CARDINAL (Cardinal *) | |
1264 # else | |
1265 # define CARDINAL (int *) | |
1266 # endif | |
1267 #endif | |
1268 | |
1269 /* | |
1270 * Check if the GUI can be started. Called before gvimrc is sourced. | |
1271 * Return OK or FAIL. | |
1272 */ | |
1273 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1274 gui_mch_init_check(void) |
7 | 1275 { |
1276 #ifdef FEAT_XIM | |
1277 XtSetLanguageProc(NULL, NULL, NULL); | |
1278 #endif | |
1279 open_app_context(); | |
1280 if (app_context != NULL) | |
1281 gui.dpy = XtOpenDisplay(app_context, 0, VIM_NAME, VIM_CLASS, | |
51 | 1282 cmdline_options, XtNumber(cmdline_options), |
1283 CARDINAL &gui_argc, gui_argv); | |
7 | 1284 |
13925
eb264a775071
patch 8.0.1833: X11: ":echo 3.14" gives E806
Christian Brabandt <cb@256bit.org>
parents:
13858
diff
changeset
|
1285 # if defined(FEAT_FLOAT) && defined(LC_NUMERIC) |
eb264a775071
patch 8.0.1833: X11: ":echo 3.14" gives E806
Christian Brabandt <cb@256bit.org>
parents:
13858
diff
changeset
|
1286 { |
eb264a775071
patch 8.0.1833: X11: ":echo 3.14" gives E806
Christian Brabandt <cb@256bit.org>
parents:
13858
diff
changeset
|
1287 /* The call to XtOpenDisplay() may have set the locale from the |
eb264a775071
patch 8.0.1833: X11: ":echo 3.14" gives E806
Christian Brabandt <cb@256bit.org>
parents:
13858
diff
changeset
|
1288 * environment. Set LC_NUMERIC to "C" to make sure that strtod() uses a |
eb264a775071
patch 8.0.1833: X11: ":echo 3.14" gives E806
Christian Brabandt <cb@256bit.org>
parents:
13858
diff
changeset
|
1289 * decimal point, not a comma. */ |
eb264a775071
patch 8.0.1833: X11: ":echo 3.14" gives E806
Christian Brabandt <cb@256bit.org>
parents:
13858
diff
changeset
|
1290 char *p = setlocale(LC_NUMERIC, NULL); |
eb264a775071
patch 8.0.1833: X11: ":echo 3.14" gives E806
Christian Brabandt <cb@256bit.org>
parents:
13858
diff
changeset
|
1291 |
eb264a775071
patch 8.0.1833: X11: ":echo 3.14" gives E806
Christian Brabandt <cb@256bit.org>
parents:
13858
diff
changeset
|
1292 if (p == NULL || strcmp(p, "C") != 0) |
eb264a775071
patch 8.0.1833: X11: ":echo 3.14" gives E806
Christian Brabandt <cb@256bit.org>
parents:
13858
diff
changeset
|
1293 setlocale(LC_NUMERIC, "C"); |
eb264a775071
patch 8.0.1833: X11: ":echo 3.14" gives E806
Christian Brabandt <cb@256bit.org>
parents:
13858
diff
changeset
|
1294 } |
eb264a775071
patch 8.0.1833: X11: ":echo 3.14" gives E806
Christian Brabandt <cb@256bit.org>
parents:
13858
diff
changeset
|
1295 # endif |
7 | 1296 if (app_context == NULL || gui.dpy == NULL) |
1297 { | |
1298 gui.dying = TRUE; | |
1299 EMSG(_(e_opendisp)); | |
1300 return FAIL; | |
1301 } | |
1302 return OK; | |
1303 } | |
1304 | |
1305 | |
1306 #ifdef USE_XSMP | |
1307 /* | |
1308 * Handle XSMP processing, de-registering the attachment upon error | |
1309 */ | |
1310 static XtInputId _xsmp_xtinputid; | |
1311 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
1312 static void local_xsmp_handle_requests(XtPointer c, int *s, XtInputId *i); |
7 | 1313 |
1314 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1315 local_xsmp_handle_requests( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1316 XtPointer c UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1317 int *s UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1318 XtInputId *i UNUSED) |
7 | 1319 { |
1320 if (xsmp_handle_requests() == FAIL) | |
1321 XtRemoveInput(_xsmp_xtinputid); | |
1322 } | |
1323 #endif | |
1324 | |
1325 | |
1326 /* | |
1327 * Initialise the X GUI. Create all the windows, set up all the call-backs etc. | |
1328 * Returns OK for success, FAIL when the GUI can't be started. | |
1329 */ | |
1330 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1331 gui_mch_init(void) |
7 | 1332 { |
1333 XtGCMask gc_mask; | |
1334 XGCValues gc_vals; | |
1335 int x, y, mask; | |
1336 unsigned w, h; | |
1337 | |
1338 #if 0 | |
1339 /* Uncomment this to enable synchronous mode for debugging */ | |
1340 XSynchronize(gui.dpy, True); | |
1341 #endif | |
1342 | |
1343 vimShell = XtVaAppCreateShell(VIM_NAME, VIM_CLASS, | |
1344 applicationShellWidgetClass, gui.dpy, NULL); | |
1345 | |
1346 /* | |
1347 * Get the application resources | |
1348 */ | |
1349 XtVaGetApplicationResources(vimShell, (XtPointer)&gui, | |
1350 vim_resources, XtNumber(vim_resources), NULL); | |
1351 | |
1352 gui.scrollbar_height = gui.scrollbar_width; | |
1353 | |
1354 /* | |
1355 * Get the colors ourselves. Using the automatic conversion doesn't | |
1356 * handle looking for approximate colors. | |
1357 */ | |
1358 /* NOTE: These next few lines are an exact duplicate of gui_athena.c's | |
1359 * gui_mch_def_colors(). Why? | |
1360 */ | |
1361 gui.menu_fg_pixel = gui_get_color((char_u *)gui.rsrc_menu_fg_name); | |
1362 gui.menu_bg_pixel = gui_get_color((char_u *)gui.rsrc_menu_bg_name); | |
1363 gui.scroll_fg_pixel = gui_get_color((char_u *)gui.rsrc_scroll_fg_name); | |
1364 gui.scroll_bg_pixel = gui_get_color((char_u *)gui.rsrc_scroll_bg_name); | |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
1365 #ifdef FEAT_BEVAL_GUI |
7 | 1366 gui.tooltip_fg_pixel = gui_get_color((char_u *)gui.rsrc_tooltip_fg_name); |
1367 gui.tooltip_bg_pixel = gui_get_color((char_u *)gui.rsrc_tooltip_bg_name); | |
1368 #endif | |
1369 | |
1370 #if defined(FEAT_MENU) && defined(FEAT_GUI_ATHENA) | |
1371 /* If the menu height was set, don't change it at runtime */ | |
1372 if (gui.menu_height != MENU_DEFAULT_HEIGHT) | |
1373 gui.menu_height_fixed = TRUE; | |
1374 #endif | |
1375 | |
1376 /* Set default foreground and background colours */ | |
1377 gui.norm_pixel = gui.def_norm_pixel; | |
1378 gui.back_pixel = gui.def_back_pixel; | |
1379 | |
1380 /* Check if reverse video needs to be applied (on Sun it's done by X) */ | |
1381 if (gui.rsrc_rev_video && gui_get_lightness(gui.back_pixel) | |
1382 > gui_get_lightness(gui.norm_pixel)) | |
1383 { | |
1384 gui.norm_pixel = gui.def_back_pixel; | |
1385 gui.back_pixel = gui.def_norm_pixel; | |
1386 gui.def_norm_pixel = gui.norm_pixel; | |
1387 gui.def_back_pixel = gui.back_pixel; | |
1388 } | |
1389 | |
1390 /* Get the colors from the "Normal", "Tooltip", "Scrollbar" and "Menu" | |
1391 * group (set in syntax.c or in a vimrc file) */ | |
1392 set_normal_colors(); | |
1393 | |
1394 /* | |
1395 * Check that none of the colors are the same as the background color | |
1396 */ | |
1397 gui_check_colors(); | |
1398 | |
1399 /* | |
1400 * Set up the GCs. The font attributes will be set in gui_init_font(). | |
1401 */ | |
1402 gc_mask = GCForeground | GCBackground; | |
1403 gc_vals.foreground = gui.norm_pixel; | |
1404 gc_vals.background = gui.back_pixel; | |
1405 gui.text_gc = XtGetGC(vimShell, gc_mask, &gc_vals); | |
1406 | |
1407 gc_vals.foreground = gui.back_pixel; | |
1408 gc_vals.background = gui.norm_pixel; | |
1409 gui.back_gc = XtGetGC(vimShell, gc_mask, &gc_vals); | |
1410 | |
1411 gc_mask |= GCFunction; | |
1412 gc_vals.foreground = gui.norm_pixel ^ gui.back_pixel; | |
1413 gc_vals.background = gui.norm_pixel ^ gui.back_pixel; | |
1414 gc_vals.function = GXxor; | |
1415 gui.invert_gc = XtGetGC(vimShell, gc_mask, &gc_vals); | |
1416 | |
1417 gui.visibility = VisibilityUnobscured; | |
1418 x11_setup_atoms(gui.dpy); | |
1419 | |
1420 if (gui_win_x != -1 && gui_win_y != -1) | |
1421 gui_mch_set_winpos(gui_win_x, gui_win_y); | |
1422 | |
1423 /* Now adapt the supplied(?) geometry-settings */ | |
1424 /* Added by Kjetil Jacobsen <kjetilja@stud.cs.uit.no> */ | |
1425 if (gui.geom != NULL && *gui.geom != NUL) | |
1426 { | |
1427 mask = XParseGeometry((char *)gui.geom, &x, &y, &w, &h); | |
1428 if (mask & WidthValue) | |
1429 Columns = w; | |
1430 if (mask & HeightValue) | |
857 | 1431 { |
1887 | 1432 if (p_window > (long)h - 1 || !option_was_set((char_u *)"window")) |
857 | 1433 p_window = h - 1; |
7 | 1434 Rows = h; |
857 | 1435 } |
5086
6ddc1785c4ff
updated for version 7.3.1286
Bram Moolenaar <bram@vim.org>
parents:
4885
diff
changeset
|
1436 limit_screen_size(); |
7 | 1437 /* |
1438 * Set the (x,y) position of the main window only if specified in the | |
1439 * users geometry, so we get good defaults when they don't. This needs | |
1440 * to be done before the shell is popped up. | |
1441 */ | |
1442 if (mask & (XValue|YValue)) | |
1443 XtVaSetValues(vimShell, XtNgeometry, gui.geom, NULL); | |
1444 } | |
1445 | |
1446 gui_x11_create_widgets(); | |
1447 | |
1448 /* | |
1449 * Add an icon to Vim (Marcel Douben: 11 May 1998). | |
1450 */ | |
1451 if (vim_strchr(p_go, GO_ICON) != NULL) | |
1452 { | |
1453 #ifndef HAVE_XPM | |
1454 # include "vim_icon.xbm" | |
1455 # include "vim_mask.xbm" | |
1456 | |
1457 Arg arg[2]; | |
1458 | |
1459 XtSetArg(arg[0], XtNiconPixmap, | |
1460 XCreateBitmapFromData(gui.dpy, | |
1461 DefaultRootWindow(gui.dpy), | |
1462 (char *)vim_icon_bits, | |
1463 vim_icon_width, | |
1464 vim_icon_height)); | |
1465 XtSetArg(arg[1], XtNiconMask, | |
1466 XCreateBitmapFromData(gui.dpy, | |
1467 DefaultRootWindow(gui.dpy), | |
1468 (char *)vim_mask_icon_bits, | |
1469 vim_mask_icon_width, | |
1470 vim_mask_icon_height)); | |
1471 XtSetValues(vimShell, arg, (Cardinal)2); | |
1472 #else | |
1473 /* Use Pixmaps, looking much nicer. */ | |
1474 | |
1475 /* If you get an error message here, you still need to unpack the runtime | |
1476 * archive! */ | |
1477 # ifdef magick | |
1478 # undef magick | |
1479 # endif | |
1480 # define magick vim32x32 | |
1481 # include "../runtime/vim32x32.xpm" | |
1482 # undef magick | |
1483 # define magick vim16x16 | |
1484 # include "../runtime/vim16x16.xpm" | |
1485 # undef magick | |
1486 # define magick vim48x48 | |
1487 # include "../runtime/vim48x48.xpm" | |
1488 # undef magick | |
1489 | |
1490 static Pixmap icon = 0; | |
1491 static Pixmap icon_mask = 0; | |
1492 static char **magick = vim32x32; | |
1493 Window root_window; | |
1494 XIconSize *size; | |
1495 int number_sizes; | |
1496 Display *dsp; | |
1497 Screen *scr; | |
1498 XpmAttributes attr; | |
1499 Colormap cmap; | |
1500 | |
1501 /* | |
1502 * Adjust the icon to the preferences of the actual window manager. | |
1503 */ | |
1504 root_window = XRootWindowOfScreen(XtScreen(vimShell)); | |
1505 if (XGetIconSizes(XtDisplay(vimShell), root_window, | |
1506 &size, &number_sizes) != 0) | |
1507 { | |
1508 if (number_sizes > 0) | |
1509 { | |
5196
ba9a11fe2563
updated for version 7.4a.024
Bram Moolenaar <bram@vim.org>
parents:
5086
diff
changeset
|
1510 if (size->max_height >= 48 && size->max_width >= 48) |
7 | 1511 magick = vim48x48; |
5196
ba9a11fe2563
updated for version 7.4a.024
Bram Moolenaar <bram@vim.org>
parents:
5086
diff
changeset
|
1512 else if (size->max_height >= 32 && size->max_width >= 32) |
7 | 1513 magick = vim32x32; |
5196
ba9a11fe2563
updated for version 7.4a.024
Bram Moolenaar <bram@vim.org>
parents:
5086
diff
changeset
|
1514 else if (size->max_height >= 16 && size->max_width >= 16) |
7 | 1515 magick = vim16x16; |
1516 } | |
1517 } | |
1518 | |
1519 dsp = XtDisplay(vimShell); | |
1520 scr = XtScreen(vimShell); | |
1521 | |
1522 cmap = DefaultColormap(dsp, DefaultScreen(dsp)); | |
1523 XtVaSetValues(vimShell, XtNcolormap, cmap, NULL); | |
1524 | |
1525 attr.valuemask = 0L; | |
1526 attr.valuemask = XpmCloseness | XpmReturnPixels | XpmColormap | XpmDepth; | |
1527 attr.closeness = 65535; /* accuracy isn't crucial */ | |
1528 attr.colormap = cmap; | |
1529 attr.depth = DefaultDepthOfScreen(scr); | |
1530 | |
1531 if (!icon) | |
1605 | 1532 { |
7 | 1533 XpmCreatePixmapFromData(dsp, root_window, magick, &icon, |
1534 &icon_mask, &attr); | |
1605 | 1535 XpmFreeAttributes(&attr); |
1536 } | |
7 | 1537 |
1538 # ifdef FEAT_GUI_ATHENA | |
1539 XtVaSetValues(vimShell, XtNiconPixmap, icon, XtNiconMask, icon_mask, NULL); | |
1540 # else | |
1541 XtVaSetValues(vimShell, XmNiconPixmap, icon, XmNiconMask, icon_mask, NULL); | |
1542 # endif | |
1543 #endif | |
1544 } | |
1545 | |
1546 if (gui.color_approx) | |
1547 EMSG(_("Vim E458: Cannot allocate colormap entry, some colors may be incorrect")); | |
1548 | |
1549 #ifdef FEAT_SUN_WORKSHOP | |
1550 if (usingSunWorkShop) | |
1551 workshop_connect(app_context); | |
1552 #endif | |
1553 | |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
1554 #ifdef FEAT_BEVAL_GUI |
7 | 1555 gui_init_tooltip_font(); |
1556 #endif | |
1557 #ifdef FEAT_MENU | |
1558 gui_init_menu_font(); | |
1559 #endif | |
1560 | |
1561 #ifdef USE_XSMP | |
1562 /* Attach listener on ICE connection */ | |
1563 if (-1 != xsmp_icefd) | |
1564 _xsmp_xtinputid = XtAppAddInput(app_context, xsmp_icefd, | |
1565 (XtPointer)XtInputReadMask, local_xsmp_handle_requests, NULL); | |
1566 #endif | |
1567 | |
1568 return OK; | |
1569 } | |
1570 | |
1571 /* | |
1572 * Called when starting the GUI fails after calling gui_mch_init(). | |
1573 */ | |
1574 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1575 gui_mch_uninit(void) |
7 | 1576 { |
1577 gui_x11_destroy_widgets(); | |
1578 XtCloseDisplay(gui.dpy); | |
1579 gui.dpy = NULL; | |
1580 vimShell = (Widget)0; | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13152
diff
changeset
|
1581 VIM_CLEAR(gui_argv); |
7 | 1582 } |
1583 | |
1584 /* | |
1585 * Called when the foreground or background color has been changed. | |
1586 */ | |
1587 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1588 gui_mch_new_colors(void) |
7 | 1589 { |
1590 long_u gc_mask; | |
1591 XGCValues gc_vals; | |
1592 | |
1593 gc_mask = GCForeground | GCBackground; | |
1594 gc_vals.foreground = gui.norm_pixel; | |
1595 gc_vals.background = gui.back_pixel; | |
1596 if (gui.text_gc != NULL) | |
1597 XChangeGC(gui.dpy, gui.text_gc, gc_mask, &gc_vals); | |
1598 | |
1599 gc_vals.foreground = gui.back_pixel; | |
1600 gc_vals.background = gui.norm_pixel; | |
1601 if (gui.back_gc != NULL) | |
1602 XChangeGC(gui.dpy, gui.back_gc, gc_mask, &gc_vals); | |
1603 | |
1604 gc_mask |= GCFunction; | |
1605 gc_vals.foreground = gui.norm_pixel ^ gui.back_pixel; | |
1606 gc_vals.background = gui.norm_pixel ^ gui.back_pixel; | |
1607 gc_vals.function = GXxor; | |
1608 if (gui.invert_gc != NULL) | |
1609 XChangeGC(gui.dpy, gui.invert_gc, gc_mask, &gc_vals); | |
1610 | |
1611 gui_x11_set_back_color(); | |
1612 } | |
1613 | |
1614 /* | |
1615 * Open the GUI window which was created by a call to gui_mch_init(). | |
1616 */ | |
1617 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1618 gui_mch_open(void) |
7 | 1619 { |
1620 /* Actually open the window */ | |
557 | 1621 XtRealizeWidget(vimShell); |
1622 XtManageChild(XtNameToWidget(vimShell, "*vimForm")); | |
7 | 1623 |
1624 gui.wid = gui_x11_get_wid(); | |
1625 gui.blank_pointer = gui_x11_create_blank_mouse(); | |
1626 | |
1627 /* | |
1628 * Add a callback for the Close item on the window managers menu, and the | |
1629 * save-yourself event. | |
1630 */ | |
1631 wm_atoms[SAVE_YOURSELF_IDX] = | |
1632 XInternAtom(gui.dpy, "WM_SAVE_YOURSELF", False); | |
1633 wm_atoms[DELETE_WINDOW_IDX] = | |
1634 XInternAtom(gui.dpy, "WM_DELETE_WINDOW", False); | |
1635 XSetWMProtocols(gui.dpy, XtWindow(vimShell), wm_atoms, 2); | |
1636 XtAddEventHandler(vimShell, NoEventMask, True, gui_x11_wm_protocol_handler, | |
1637 NULL); | |
1638 #ifdef HAVE_X11_XMU_EDITRES_H | |
1639 /* | |
1640 * Enable editres protocol (see "man editres"). | |
1641 * Usually will need to add -lXmu to the linker line as well. | |
1642 */ | |
1643 XtAddEventHandler(vimShell, (EventMask)0, True, _XEditResCheckMessages, | |
1644 (XtPointer)NULL); | |
1645 #endif | |
1646 | |
1647 #ifdef FEAT_CLIENTSERVER | |
1648 if (serverName == NULL && serverDelayedStartName != NULL) | |
1649 { | |
1650 /* This is a :gui command in a plain vim with no previous server */ | |
1651 commWindow = XtWindow(vimShell); | |
1652 (void)serverRegisterName(gui.dpy, serverDelayedStartName); | |
1653 } | |
1654 else | |
1655 { | |
1656 /* | |
1657 * Cannot handle "widget-less" windows with XtProcessEvent() we'll | |
1658 * have to change the "server" registration to that of the main window | |
1659 * If we have not registered a name yet, remember the window | |
1660 */ | |
1661 serverChangeRegisteredWindow(gui.dpy, XtWindow(vimShell)); | |
1662 } | |
1663 XtAddEventHandler(vimShell, PropertyChangeMask, False, | |
1664 gui_x11_send_event_handler, NULL); | |
1665 #endif | |
1666 | |
1667 | |
1668 #if defined(FEAT_MENU) && defined(FEAT_GUI_ATHENA) | |
1669 /* The Athena GUI needs this again after opening the window */ | |
1670 gui_position_menu(); | |
1671 # ifdef FEAT_TOOLBAR | |
1672 gui_mch_set_toolbar_pos(0, gui.menu_height, gui.menu_width, | |
1673 gui.toolbar_height); | |
1674 # endif | |
1675 #endif | |
1676 | |
1677 /* Get the colors for the highlight groups (gui_check_colors() might have | |
1678 * changed them) */ | |
1679 highlight_gui_started(); /* re-init colors and fonts */ | |
1680 | |
1681 #ifdef FEAT_HANGULIN | |
1682 hangul_keyboard_set(); | |
1683 #endif | |
1684 #ifdef FEAT_XIM | |
1685 xim_init(); | |
1686 #endif | |
1687 #ifdef FEAT_SUN_WORKSHOP | |
1688 workshop_postinit(); | |
1689 #endif | |
1690 | |
1691 return OK; | |
1692 } | |
1693 | |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
1694 #if defined(FEAT_BEVAL_GUI) || defined(PROTO) |
7 | 1695 /* |
1696 * Convert the tooltip fontset name to an XFontSet. | |
1697 */ | |
1698 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1699 gui_init_tooltip_font(void) |
7 | 1700 { |
1701 XrmValue from, to; | |
1702 | |
1703 from.addr = (char *)gui.rsrc_tooltip_font_name; | |
1704 from.size = strlen(from.addr); | |
1705 to.addr = (XtPointer)&gui.tooltip_fontset; | |
1706 to.size = sizeof(XFontSet); | |
1707 | |
1708 if (XtConvertAndStore(vimShell, XtRString, &from, XtRFontSet, &to) == False) | |
1709 { | |
1710 /* Failed. What to do? */ | |
1711 } | |
1712 } | |
1713 #endif | |
1714 | |
1715 #if defined(FEAT_MENU) || defined(PROTO) | |
1716 /* Convert the menu font/fontset name to an XFontStruct/XFontset */ | |
1717 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1718 gui_init_menu_font(void) |
7 | 1719 { |
1720 XrmValue from, to; | |
1721 | |
1722 #ifdef FONTSET_ALWAYS | |
1723 from.addr = (char *)gui.rsrc_menu_font_name; | |
1724 from.size = strlen(from.addr); | |
1725 to.addr = (XtPointer)&gui.menu_fontset; | |
1726 to.size = sizeof(GuiFontset); | |
1727 | |
1728 if (XtConvertAndStore(vimShell, XtRString, &from, XtRFontSet, &to) == False) | |
1729 { | |
1730 /* Failed. What to do? */ | |
1731 } | |
1732 #else | |
1733 from.addr = (char *)gui.rsrc_menu_font_name; | |
1734 from.size = strlen(from.addr); | |
1735 to.addr = (XtPointer)&gui.menu_font; | |
1736 to.size = sizeof(GuiFont); | |
1737 | |
1738 if (XtConvertAndStore(vimShell, XtRString, &from, XtRFontStruct, &to) == False) | |
1739 { | |
1740 /* Failed. What to do? */ | |
1741 } | |
1742 #endif | |
1743 } | |
1744 #endif | |
1745 | |
1746 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1747 gui_mch_exit(int rc UNUSED) |
7 | 1748 { |
1749 #if 0 | |
1750 /* Lesstif gives an error message here, and so does Solaris. The man page | |
1751 * says that this isn't needed when exiting, so just skip it. */ | |
1752 XtCloseDisplay(gui.dpy); | |
1753 #endif | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13152
diff
changeset
|
1754 VIM_CLEAR(gui_argv); |
7 | 1755 } |
1756 | |
1757 /* | |
1758 * Get the position of the top left corner of the window. | |
1759 */ | |
1760 int | |
7825
7898da204b98
commit https://github.com/vim/vim/commit/02fdaeaa697fb5af4ba7fee6e209b3c2c825bb4f
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
1761 gui_mch_get_winpos(int *x, int *y) |
7 | 1762 { |
1763 Dimension xpos, ypos; | |
1764 | |
1765 XtVaGetValues(vimShell, | |
1766 XtNx, &xpos, | |
1767 XtNy, &ypos, | |
1768 NULL); | |
1769 *x = xpos; | |
1770 *y = ypos; | |
1771 return OK; | |
1772 } | |
1773 | |
1774 /* | |
1775 * Set the position of the top left corner of the window to the given | |
1776 * coordinates. | |
1777 */ | |
1778 void | |
7825
7898da204b98
commit https://github.com/vim/vim/commit/02fdaeaa697fb5af4ba7fee6e209b3c2c825bb4f
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
1779 gui_mch_set_winpos(int x, int y) |
7 | 1780 { |
1781 XtVaSetValues(vimShell, | |
1782 XtNx, x, | |
1783 XtNy, y, | |
1784 NULL); | |
1785 } | |
1786 | |
1787 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1788 gui_mch_set_shellsize( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1789 int width, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1790 int height, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1791 int min_width, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1792 int min_height, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1793 int base_width, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1794 int base_height, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1795 int direction UNUSED) |
7 | 1796 { |
51 | 1797 #ifdef FEAT_XIM |
1798 height += xim_get_status_area_height(), | |
1799 #endif | |
7 | 1800 XtVaSetValues(vimShell, |
1801 XtNwidthInc, gui.char_width, | |
1802 XtNheightInc, gui.char_height, | |
1803 #if defined(XtSpecificationRelease) && XtSpecificationRelease >= 4 | |
1804 XtNbaseWidth, base_width, | |
1805 XtNbaseHeight, base_height, | |
1806 #endif | |
1807 XtNminWidth, min_width, | |
1808 XtNminHeight, min_height, | |
1809 XtNwidth, width, | |
1810 XtNheight, height, | |
1811 NULL); | |
1812 } | |
1813 | |
1814 /* | |
445 | 1815 * Allow 10 pixels for horizontal borders, 'guiheadroom' for vertical borders. |
7 | 1816 * Is there no way in X to find out how wide the borders really are? |
1817 */ | |
1818 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1819 gui_mch_get_screen_dimensions( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1820 int *screen_w, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1821 int *screen_h) |
7 | 1822 { |
1823 *screen_w = DisplayWidth(gui.dpy, DefaultScreen(gui.dpy)) - 10; | |
1824 *screen_h = DisplayHeight(gui.dpy, DefaultScreen(gui.dpy)) - p_ghr; | |
1825 } | |
1826 | |
1827 /* | |
1828 * Initialise vim to use the font "font_name". If it's NULL, pick a default | |
1829 * font. | |
1830 * If "fontset" is TRUE, load the "font_name" as a fontset. | |
1831 * Return FAIL if the font could not be loaded, OK otherwise. | |
1832 */ | |
1833 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1834 gui_mch_init_font( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1835 char_u *font_name, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1836 int do_fontset UNUSED) |
7 | 1837 { |
1838 XFontStruct *font = NULL; | |
1839 | |
1840 #ifdef FEAT_XFONTSET | |
1841 XFontSet fontset = NULL; | |
46 | 1842 #endif |
1843 | |
1844 #ifdef FEAT_GUI_MOTIF | |
1845 /* A font name equal "*" is indicating, that we should activate the font | |
1846 * selection dialogue to get a new font name. So let us do it here. */ | |
1847 if (font_name != NULL && STRCMP(font_name, "*") == 0) | |
1848 font_name = gui_xm_select_font(hl_get_font_name()); | |
1849 #endif | |
1850 | |
1851 #ifdef FEAT_XFONTSET | |
7 | 1852 if (do_fontset) |
1853 { | |
1854 /* If 'guifontset' is set, VIM treats all font specifications as if | |
1855 * they were fontsets, and 'guifontset' becomes the default. */ | |
1856 if (font_name != NULL) | |
1857 { | |
1858 fontset = (XFontSet)gui_mch_get_fontset(font_name, FALSE, TRUE); | |
1859 if (fontset == NULL) | |
1860 return FAIL; | |
1861 } | |
1862 } | |
1863 else | |
1864 #endif | |
1865 { | |
1866 if (font_name == NULL) | |
1867 { | |
1868 /* | |
1869 * If none of the fonts in 'font' could be loaded, try the one set | |
1870 * in the X resource, and finally just try using DFLT_FONT, which | |
1871 * will hopefully always be there. | |
1872 */ | |
1873 font_name = gui.rsrc_font_name; | |
1874 font = (XFontStruct *)gui_mch_get_font(font_name, FALSE); | |
1875 if (font == NULL) | |
1876 font_name = (char_u *)DFLT_FONT; | |
1877 } | |
1878 if (font == NULL) | |
1879 font = (XFontStruct *)gui_mch_get_font(font_name, FALSE); | |
1880 if (font == NULL) | |
1881 return FAIL; | |
1882 } | |
1883 | |
1884 gui_mch_free_font(gui.norm_font); | |
1885 #ifdef FEAT_XFONTSET | |
1886 gui_mch_free_fontset(gui.fontset); | |
1887 | |
1888 if (fontset != NULL) | |
1889 { | |
1890 gui.norm_font = NOFONT; | |
1891 gui.fontset = (GuiFontset)fontset; | |
1892 gui.char_width = fontset_width(fontset); | |
1893 gui.char_height = fontset_height(fontset) + p_linespace; | |
1894 gui.char_ascent = fontset_ascent(fontset) + p_linespace / 2; | |
1895 } | |
1896 else | |
1897 #endif | |
1898 { | |
1899 gui.norm_font = (GuiFont)font; | |
1900 #ifdef FEAT_XFONTSET | |
1901 gui.fontset = NOFONTSET; | |
1902 #endif | |
1903 gui.char_width = font->max_bounds.width; | |
1904 gui.char_height = font->ascent + font->descent + p_linespace; | |
1905 gui.char_ascent = font->ascent + p_linespace / 2; | |
1906 } | |
1907 | |
1908 hl_set_font_name(font_name); | |
1909 | |
1910 /* | |
1911 * Try to load other fonts for bold, italic, and bold-italic. | |
1912 * We should also try to work out what font to use for these when they are | |
1913 * not specified by X resources, but we don't yet. | |
1914 */ | |
1915 if (font_name == gui.rsrc_font_name) | |
1916 { | |
1917 if (gui.bold_font == NOFONT | |
1918 && gui.rsrc_bold_font_name != NULL | |
1919 && *gui.rsrc_bold_font_name != NUL) | |
1920 gui.bold_font = gui_mch_get_font(gui.rsrc_bold_font_name, FALSE); | |
1921 if (gui.ital_font == NOFONT | |
1922 && gui.rsrc_ital_font_name != NULL | |
1923 && *gui.rsrc_ital_font_name != NUL) | |
1924 gui.ital_font = gui_mch_get_font(gui.rsrc_ital_font_name, FALSE); | |
1925 if (gui.boldital_font == NOFONT | |
1926 && gui.rsrc_boldital_font_name != NULL | |
1927 && *gui.rsrc_boldital_font_name != NUL) | |
1928 gui.boldital_font = gui_mch_get_font(gui.rsrc_boldital_font_name, | |
1929 FALSE); | |
1930 } | |
1931 else | |
1932 { | |
1933 /* When not using the font specified by the resources, also don't use | |
1934 * the bold/italic fonts, otherwise setting 'guifont' will look very | |
1935 * strange. */ | |
1936 if (gui.bold_font != NOFONT) | |
1937 { | |
1938 XFreeFont(gui.dpy, (XFontStruct *)gui.bold_font); | |
1939 gui.bold_font = NOFONT; | |
1940 } | |
1941 if (gui.ital_font != NOFONT) | |
1942 { | |
1943 XFreeFont(gui.dpy, (XFontStruct *)gui.ital_font); | |
1944 gui.ital_font = NOFONT; | |
1945 } | |
1946 if (gui.boldital_font != NOFONT) | |
1947 { | |
1948 XFreeFont(gui.dpy, (XFontStruct *)gui.boldital_font); | |
1949 gui.boldital_font = NOFONT; | |
1950 } | |
1951 } | |
1952 | |
46 | 1953 #ifdef FEAT_GUI_MOTIF |
1954 gui_motif_synch_fonts(); | |
1955 #endif | |
1956 | |
7 | 1957 return OK; |
1958 } | |
1959 | |
1960 /* | |
1961 * Get a font structure for highlighting. | |
1962 */ | |
1963 GuiFont | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1964 gui_mch_get_font(char_u *name, int giveErrorIfMissing) |
7 | 1965 { |
1966 XFontStruct *font; | |
1967 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13152
diff
changeset
|
1968 if (!gui.in_use || name == NULL) /* can't do this when GUI not running */ |
7 | 1969 return NOFONT; |
1970 | |
1971 font = XLoadQueryFont(gui.dpy, (char *)name); | |
1972 | |
1973 if (font == NULL) | |
1974 { | |
1975 if (giveErrorIfMissing) | |
1976 EMSG2(_(e_font), name); | |
1977 return NOFONT; | |
1978 } | |
1979 | |
1980 #ifdef DEBUG | |
1981 printf("Font Information for '%s':\n", name); | |
1982 printf(" w = %d, h = %d, ascent = %d, descent = %d\n", | |
1983 font->max_bounds.width, font->ascent + font->descent, | |
1984 font->ascent, font->descent); | |
1985 printf(" max ascent = %d, max descent = %d, max h = %d\n", | |
1986 font->max_bounds.ascent, font->max_bounds.descent, | |
1987 font->max_bounds.ascent + font->max_bounds.descent); | |
1988 printf(" min lbearing = %d, min rbearing = %d\n", | |
1989 font->min_bounds.lbearing, font->min_bounds.rbearing); | |
1990 printf(" max lbearing = %d, max rbearing = %d\n", | |
1991 font->max_bounds.lbearing, font->max_bounds.rbearing); | |
1992 printf(" leftink = %d, rightink = %d\n", | |
1993 (font->min_bounds.lbearing < 0), | |
1994 (font->max_bounds.rbearing > font->max_bounds.width)); | |
1995 printf("\n"); | |
1996 #endif | |
1997 | |
1998 if (font->max_bounds.width != font->min_bounds.width) | |
1999 { | |
2000 EMSG2(_(e_fontwidth), name); | |
2001 XFreeFont(gui.dpy, font); | |
2002 return NOFONT; | |
2003 } | |
2004 return (GuiFont)font; | |
2005 } | |
2006 | |
46 | 2007 #if defined(FEAT_EVAL) || defined(PROTO) |
38 | 2008 /* |
2009 * Return the name of font "font" in allocated memory. | |
2010 */ | |
2011 char_u * | |
11119
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2012 gui_mch_get_fontname(GuiFont font, char_u *name) |
38 | 2013 { |
11119
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2014 char_u *ret = NULL; |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2015 |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2016 if (name != NULL && font == NULL) |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2017 { |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2018 /* In this case, there's no way other than doing this. */ |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2019 ret = vim_strsave(name); |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2020 } |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2021 else if (font != NULL) |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2022 { |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2023 /* In this case, try to retrieve the XLFD corresponding to 'font'->fid; |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2024 * if failed, use 'name' unless it's NULL. */ |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2025 unsigned long value = 0L; |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2026 |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2027 if (XGetFontProperty(font, XA_FONT, &value)) |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2028 { |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2029 char *xa_font_name = NULL; |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2030 |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2031 xa_font_name = XGetAtomName(gui.dpy, value); |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2032 if (xa_font_name != NULL) |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2033 { |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2034 ret = vim_strsave((char_u *)xa_font_name); |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2035 XFree(xa_font_name); |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2036 } |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2037 else if (name != NULL) |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2038 ret = vim_strsave(name); |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2039 } |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2040 else if (name != NULL) |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2041 ret = vim_strsave(name); |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2042 } |
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
10956
diff
changeset
|
2043 return ret; |
38 | 2044 } |
46 | 2045 #endif |
38 | 2046 |
445 | 2047 /* |
2048 * Adjust gui.char_height (after 'linespace' was changed). | |
2049 */ | |
7 | 2050 int |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2051 gui_mch_adjust_charheight(void) |
7 | 2052 { |
2053 #ifdef FEAT_XFONTSET | |
2054 if (gui.fontset != NOFONTSET) | |
2055 { | |
2056 gui.char_height = fontset_height((XFontSet)gui.fontset) + p_linespace; | |
2057 gui.char_ascent = fontset_ascent((XFontSet)gui.fontset) | |
2058 + p_linespace / 2; | |
2059 } | |
2060 else | |
2061 #endif | |
2062 { | |
2063 XFontStruct *font = (XFontStruct *)gui.norm_font; | |
2064 | |
2065 gui.char_height = font->ascent + font->descent + p_linespace; | |
2066 gui.char_ascent = font->ascent + p_linespace / 2; | |
2067 } | |
2068 return OK; | |
2069 } | |
2070 | |
2071 /* | |
2072 * Set the current text font. | |
2073 */ | |
2074 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2075 gui_mch_set_font(GuiFont font) |
7 | 2076 { |
2077 static Font prev_font = (Font)-1; | |
2078 Font fid = ((XFontStruct *)font)->fid; | |
2079 | |
2080 if (fid != prev_font) | |
2081 { | |
2082 XSetFont(gui.dpy, gui.text_gc, fid); | |
2083 XSetFont(gui.dpy, gui.back_gc, fid); | |
2084 prev_font = fid; | |
2085 gui.char_ascent = ((XFontStruct *)font)->ascent + p_linespace / 2; | |
2086 } | |
2087 #ifdef FEAT_XFONTSET | |
2088 current_fontset = (XFontSet)NULL; | |
2089 #endif | |
2090 } | |
2091 | |
2092 #if defined(FEAT_XFONTSET) || defined(PROTO) | |
2093 /* | |
2094 * Set the current text fontset. | |
2095 * Adjust the ascent, in case it's different. | |
2096 */ | |
2097 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2098 gui_mch_set_fontset(GuiFontset fontset) |
7 | 2099 { |
2100 current_fontset = (XFontSet)fontset; | |
2101 gui.char_ascent = fontset_ascent(current_fontset) + p_linespace / 2; | |
2102 } | |
2103 #endif | |
2104 | |
2105 /* | |
2106 * If a font is not going to be used, free its structure. | |
2107 */ | |
2108 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2109 gui_mch_free_font(GuiFont font) |
7 | 2110 { |
2111 if (font != NOFONT) | |
2112 XFreeFont(gui.dpy, (XFontStruct *)font); | |
2113 } | |
2114 | |
2115 #if defined(FEAT_XFONTSET) || defined(PROTO) | |
2116 /* | |
2117 * If a fontset is not going to be used, free its structure. | |
2118 */ | |
2119 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2120 gui_mch_free_fontset(GuiFontset fontset) |
7 | 2121 { |
2122 if (fontset != NOFONTSET) | |
2123 XFreeFontSet(gui.dpy, (XFontSet)fontset); | |
2124 } | |
2125 | |
2126 /* | |
2127 * Load the fontset "name". | |
2128 * Return a reference to the fontset, or NOFONTSET when failing. | |
2129 */ | |
2130 GuiFontset | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2131 gui_mch_get_fontset( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2132 char_u *name, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2133 int giveErrorIfMissing, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2134 int fixed_width) |
7 | 2135 { |
2136 XFontSet fontset; | |
2137 char **missing, *def_str; | |
2138 int num_missing; | |
2139 | |
2140 if (!gui.in_use || name == NULL) | |
2141 return NOFONTSET; | |
2142 | |
2143 fontset = XCreateFontSet(gui.dpy, (char *)name, &missing, &num_missing, | |
2144 &def_str); | |
2145 if (num_missing > 0) | |
2146 { | |
2147 int i; | |
2148 | |
2149 if (giveErrorIfMissing) | |
2150 { | |
2151 EMSG2(_("E250: Fonts for the following charsets are missing in fontset %s:"), name); | |
2152 for (i = 0; i < num_missing; i++) | |
2153 EMSG2("%s", missing[i]); | |
2154 } | |
2155 XFreeStringList(missing); | |
2156 } | |
2157 | |
2158 if (fontset == NULL) | |
2159 { | |
2160 if (giveErrorIfMissing) | |
2161 EMSG2(_(e_fontset), name); | |
2162 return NOFONTSET; | |
2163 } | |
2164 | |
2165 if (fixed_width && check_fontset_sanity(fontset) == FAIL) | |
2166 { | |
2167 XFreeFontSet(gui.dpy, fontset); | |
2168 return NOFONTSET; | |
2169 } | |
2170 return (GuiFontset)fontset; | |
2171 } | |
2172 | |
2173 /* | |
2174 * Check if fontset "fs" is fixed width. | |
2175 */ | |
2176 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2177 check_fontset_sanity(XFontSet fs) |
7 | 2178 { |
2179 XFontStruct **xfs; | |
2180 char **font_name; | |
2181 int fn; | |
2182 char *base_name; | |
2183 int i; | |
2184 int min_width; | |
2185 int min_font_idx = 0; | |
2186 | |
2187 base_name = XBaseFontNameListOfFontSet(fs); | |
2188 fn = XFontsOfFontSet(fs, &xfs, &font_name); | |
2189 for (i = 0; i < fn; i++) | |
2190 { | |
2191 if (xfs[i]->max_bounds.width != xfs[i]->min_bounds.width) | |
2192 { | |
2193 EMSG2(_("E252: Fontset name: %s"), base_name); | |
2194 EMSG2(_("Font '%s' is not fixed-width"), font_name[i]); | |
2195 return FAIL; | |
2196 } | |
2197 } | |
2198 /* scan base font width */ | |
2199 min_width = 32767; | |
2200 for (i = 0; i < fn; i++) | |
2201 { | |
2202 if (xfs[i]->max_bounds.width<min_width) | |
2203 { | |
2204 min_width = xfs[i]->max_bounds.width; | |
2205 min_font_idx = i; | |
2206 } | |
2207 } | |
2208 for (i = 0; i < fn; i++) | |
2209 { | |
2210 if ( xfs[i]->max_bounds.width != 2 * min_width | |
2211 && xfs[i]->max_bounds.width != min_width) | |
2212 { | |
4885
6f7ed9b799a3
updated for version 7.3.1188
Bram Moolenaar <bram@vim.org>
parents:
2638
diff
changeset
|
2213 EMSG2(_("E253: Fontset name: %s"), base_name); |
6f7ed9b799a3
updated for version 7.3.1188
Bram Moolenaar <bram@vim.org>
parents:
2638
diff
changeset
|
2214 EMSG2(_("Font0: %s"), font_name[min_font_idx]); |
6f7ed9b799a3
updated for version 7.3.1188
Bram Moolenaar <bram@vim.org>
parents:
2638
diff
changeset
|
2215 EMSG2(_("Font1: %s"), font_name[i]); |
6f7ed9b799a3
updated for version 7.3.1188
Bram Moolenaar <bram@vim.org>
parents:
2638
diff
changeset
|
2216 EMSGN(_("Font%ld width is not twice that of font0"), i); |
6f7ed9b799a3
updated for version 7.3.1188
Bram Moolenaar <bram@vim.org>
parents:
2638
diff
changeset
|
2217 EMSGN(_("Font0 width: %ld"), xfs[min_font_idx]->max_bounds.width); |
6f7ed9b799a3
updated for version 7.3.1188
Bram Moolenaar <bram@vim.org>
parents:
2638
diff
changeset
|
2218 EMSGN(_("Font1 width: %ld"), xfs[i]->max_bounds.width); |
7 | 2219 return FAIL; |
2220 } | |
2221 } | |
2222 /* it seems ok. Good Luck!! */ | |
2223 return OK; | |
2224 } | |
2225 | |
2226 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2227 fontset_width(XFontSet fs) |
7 | 2228 { |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2229 return XmbTextEscapement(fs, "Vim", 3) / 3; |
7 | 2230 } |
2231 | |
2232 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2233 fontset_height( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2234 XFontSet fs) |
7 | 2235 { |
2236 XFontSetExtents *extents; | |
2237 | |
2238 extents = XExtentsOfFontSet(fs); | |
2239 return extents->max_logical_extent.height; | |
2240 } | |
2241 | |
2242 #if (defined(FONTSET_ALWAYS) && defined(FEAT_GUI_ATHENA) \ | |
2243 && defined(FEAT_MENU)) || defined(PROTO) | |
2244 /* | |
2245 * Returns the bounding box height around the actual glyph image of all | |
2246 * characters in all fonts of the fontset. | |
2247 */ | |
2248 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2249 fontset_height2(XFontSet fs) |
7 | 2250 { |
2251 XFontSetExtents *extents; | |
2252 | |
2253 extents = XExtentsOfFontSet(fs); | |
2254 return extents->max_ink_extent.height; | |
2255 } | |
2256 #endif | |
2257 | |
2258 /* NOT USED YET | |
2259 static int | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7825
diff
changeset
|
2260 fontset_descent(XFontSet fs) |
7 | 2261 { |
2262 XFontSetExtents *extents; | |
2263 | |
2264 extents = XExtentsOfFontSet (fs); | |
2265 return extents->max_logical_extent.height + extents->max_logical_extent.y; | |
2266 } | |
2267 */ | |
2268 | |
2269 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2270 fontset_ascent(XFontSet fs) |
7 | 2271 { |
2272 XFontSetExtents *extents; | |
2273 | |
2274 extents = XExtentsOfFontSet(fs); | |
2275 return -extents->max_logical_extent.y; | |
2276 } | |
2277 | |
2278 #endif /* FEAT_XFONTSET */ | |
2279 | |
2280 /* | |
2281 * Return the Pixel value (color) for the given color name. | |
2282 * Return INVALCOLOR for error. | |
2283 */ | |
2284 guicolor_T | |
9634
86d470495333
commit https://github.com/vim/vim/commit/4658228262f491fcb582d531d4e8e5754b0d5e83
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
2285 gui_mch_get_color(char_u *name) |
7 | 2286 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13152
diff
changeset
|
2287 guicolor_T requested; |
7 | 2288 |
2289 /* can't do this when GUI not running */ | |
9634
86d470495333
commit https://github.com/vim/vim/commit/4658228262f491fcb582d531d4e8e5754b0d5e83
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
2290 if (!gui.in_use || name == NULL || *name == NUL) |
86d470495333
commit https://github.com/vim/vim/commit/4658228262f491fcb582d531d4e8e5754b0d5e83
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
2291 return INVALCOLOR; |
86d470495333
commit https://github.com/vim/vim/commit/4658228262f491fcb582d531d4e8e5754b0d5e83
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
2292 |
86d470495333
commit https://github.com/vim/vim/commit/4658228262f491fcb582d531d4e8e5754b0d5e83
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
2293 requested = gui_get_color_cmn(name); |
86d470495333
commit https://github.com/vim/vim/commit/4658228262f491fcb582d531d4e8e5754b0d5e83
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
2294 if (requested == INVALCOLOR) |
7 | 2295 return INVALCOLOR; |
2296 | |
11745
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
2297 return gui_mch_get_rgb_color( |
9634
86d470495333
commit https://github.com/vim/vim/commit/4658228262f491fcb582d531d4e8e5754b0d5e83
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
2298 (requested & 0xff0000) >> 16, |
86d470495333
commit https://github.com/vim/vim/commit/4658228262f491fcb582d531d4e8e5754b0d5e83
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
2299 (requested & 0xff00) >> 8, |
86d470495333
commit https://github.com/vim/vim/commit/4658228262f491fcb582d531d4e8e5754b0d5e83
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
2300 requested & 0xff); |
11745
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
2301 } |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
2302 |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
2303 /* |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
2304 * Return the Pixel value (color) for the given RGB values. |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
2305 * Return INVALCOLOR for error. |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
2306 */ |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
2307 guicolor_T |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
2308 gui_mch_get_rgb_color(int r, int g, int b) |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
2309 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13152
diff
changeset
|
2310 XColor available; |
11770
0aa1910a3dfa
patch 8.0.0767: build failure with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
11745
diff
changeset
|
2311 Colormap colormap; |
11745
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
2312 |
13858
245c053021d3
patch 8.0.1800: X11: getting color is slow
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2313 /* Using XParseColor() is very slow, put rgb in XColor directly. |
245c053021d3
patch 8.0.1800: X11: getting color is slow
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2314 |
245c053021d3
patch 8.0.1800: X11: getting color is slow
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2315 char spec[8]; // space enough to hold "#RRGGBB" |
11745
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
2316 vim_snprintf(spec, sizeof(spec), "#%.2x%.2x%.2x", r, g, b); |
9634
86d470495333
commit https://github.com/vim/vim/commit/4658228262f491fcb582d531d4e8e5754b0d5e83
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
2317 if (XParseColor(gui.dpy, colormap, (char *)spec, &available) != 0 |
86d470495333
commit https://github.com/vim/vim/commit/4658228262f491fcb582d531d4e8e5754b0d5e83
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
2318 && XAllocColor(gui.dpy, colormap, &available) != 0) |
86d470495333
commit https://github.com/vim/vim/commit/4658228262f491fcb582d531d4e8e5754b0d5e83
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
2319 return (guicolor_T)available.pixel; |
13858
245c053021d3
patch 8.0.1800: X11: getting color is slow
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2320 */ |
245c053021d3
patch 8.0.1800: X11: getting color is slow
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2321 colormap = DefaultColormap(gui.dpy, DefaultScreen(gui.dpy)); |
245c053021d3
patch 8.0.1800: X11: getting color is slow
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2322 vim_memset(&available, 0, sizeof(XColor)); |
245c053021d3
patch 8.0.1800: X11: getting color is slow
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2323 available.red = r << 8; |
245c053021d3
patch 8.0.1800: X11: getting color is slow
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2324 available.green = g << 8; |
245c053021d3
patch 8.0.1800: X11: getting color is slow
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2325 available.blue = b << 8; |
245c053021d3
patch 8.0.1800: X11: getting color is slow
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2326 if (XAllocColor(gui.dpy, colormap, &available) != 0) |
245c053021d3
patch 8.0.1800: X11: getting color is slow
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2327 return (guicolor_T)available.pixel; |
7 | 2328 |
2329 return INVALCOLOR; | |
2330 } | |
2331 | |
2332 /* | |
206 | 2333 * Set the current text foreground color. |
2334 */ | |
7 | 2335 void |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2336 gui_mch_set_fg_color(guicolor_T color) |
7 | 2337 { |
2338 if (color != prev_fg_color) | |
2339 { | |
2340 XSetForeground(gui.dpy, gui.text_gc, (Pixel)color); | |
2341 prev_fg_color = color; | |
2342 } | |
2343 } | |
2344 | |
2345 /* | |
2346 * Set the current text background color. | |
2347 */ | |
2348 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2349 gui_mch_set_bg_color(guicolor_T color) |
7 | 2350 { |
2351 if (color != prev_bg_color) | |
2352 { | |
2353 XSetBackground(gui.dpy, gui.text_gc, (Pixel)color); | |
2354 prev_bg_color = color; | |
2355 } | |
2356 } | |
2357 | |
2358 /* | |
206 | 2359 * Set the current text special color. |
2360 */ | |
2361 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2362 gui_mch_set_sp_color(guicolor_T color) |
206 | 2363 { |
2364 prev_sp_color = color; | |
2365 } | |
2366 | |
2367 /* | |
7 | 2368 * create a mouse pointer that is blank |
2369 */ | |
2370 static Cursor | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2371 gui_x11_create_blank_mouse(void) |
7 | 2372 { |
2373 Pixmap blank_pixmap = XCreatePixmap(gui.dpy, gui.wid, 1, 1, 1); | |
2374 GC gc = XCreateGC(gui.dpy, blank_pixmap, (unsigned long)0, (XGCValues*)0); | |
2375 XDrawPoint(gui.dpy, blank_pixmap, gc, 0, 0); | |
2376 XFreeGC(gui.dpy, gc); | |
2377 return XCreatePixmapCursor(gui.dpy, blank_pixmap, blank_pixmap, | |
2378 (XColor*)&gui.norm_pixel, (XColor*)&gui.norm_pixel, 0, 0); | |
2379 } | |
2380 | |
206 | 2381 /* |
2382 * Draw a curled line at the bottom of the character cell. | |
2383 */ | |
2384 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2385 draw_curl(int row, int col, int cells) |
206 | 2386 { |
2387 int i; | |
2388 int offset; | |
1887 | 2389 static const int val[8] = {1, 0, 0, 0, 1, 2, 2, 2 }; |
206 | 2390 |
2391 XSetForeground(gui.dpy, gui.text_gc, prev_sp_color); | |
2392 for (i = FILL_X(col); i < FILL_X(col + cells); ++i) | |
2393 { | |
2394 offset = val[i % 8]; | |
2395 XDrawPoint(gui.dpy, gui.wid, gui.text_gc, i, | |
2396 FILL_Y(row + 1) - 1 - offset); | |
2397 } | |
2398 XSetForeground(gui.dpy, gui.text_gc, prev_fg_color); | |
2399 } | |
2400 | |
7 | 2401 void |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2402 gui_mch_draw_string( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2403 int row, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2404 int col, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2405 char_u *s, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2406 int len, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2407 int flags) |
7 | 2408 { |
2409 int cells = len; | |
2410 #ifdef FEAT_MBYTE | |
717 | 2411 static void *buf = NULL; |
7 | 2412 static int buflen = 0; |
2413 char_u *p; | |
2414 int wlen = 0; | |
2415 int c; | |
2416 | |
2417 if (enc_utf8) | |
2418 { | |
2419 /* Convert UTF-8 byte sequence to 16 bit characters for the X | |
2420 * functions. Need a buffer for the 16 bit characters. Keep it | |
2421 * between calls, because allocating it each time is slow. */ | |
2422 if (buflen < len) | |
2423 { | |
2424 XtFree((char *)buf); | |
717 | 2425 buf = (void *)XtMalloc(len * (sizeof(XChar2b) < sizeof(wchar_t) |
2426 ? sizeof(wchar_t) : sizeof(XChar2b))); | |
7 | 2427 buflen = len; |
2428 } | |
2429 p = s; | |
2430 cells = 0; | |
2431 while (p < s + len) | |
2432 { | |
2433 c = utf_ptr2char(p); | |
717 | 2434 # ifdef FEAT_XFONTSET |
2435 if (current_fontset != NULL) | |
2436 { | |
1887 | 2437 # ifdef SMALL_WCHAR_T |
2438 if (c >= 0x10000) | |
717 | 2439 c = 0xbf; /* show chars > 0xffff as ? */ |
1887 | 2440 # endif |
717 | 2441 ((wchar_t *)buf)[wlen] = c; |
2442 } | |
2443 else | |
2444 # endif | |
2445 { | |
2446 if (c >= 0x10000) | |
2447 c = 0xbf; /* show chars > 0xffff as ? */ | |
2448 ((XChar2b *)buf)[wlen].byte1 = (unsigned)c >> 8; | |
2449 ((XChar2b *)buf)[wlen].byte2 = c; | |
2450 } | |
7 | 2451 ++wlen; |
2452 cells += utf_char2cells(c); | |
474 | 2453 p += utf_ptr2len(p); |
7 | 2454 } |
2455 } | |
2456 else if (has_mbyte) | |
2457 { | |
2458 cells = 0; | |
2459 for (p = s; p < s + len; ) | |
2460 { | |
2461 cells += ptr2cells(p); | |
474 | 2462 p += (*mb_ptr2len)(p); |
7 | 2463 } |
2464 } | |
2465 | |
2466 #endif | |
2467 | |
2468 #ifdef FEAT_XFONTSET | |
2469 if (current_fontset != NULL) | |
2470 { | |
2471 /* Setup a clip rectangle to avoid spilling over in the next or | |
2472 * previous line. This is apparently needed for some fonts which are | |
2473 * used in a fontset. */ | |
2474 XRectangle clip; | |
2475 | |
2476 clip.x = 0; | |
2477 clip.y = 0; | |
2478 clip.height = gui.char_height; | |
2479 clip.width = gui.char_width * cells + 1; | |
2480 XSetClipRectangles(gui.dpy, gui.text_gc, FILL_X(col), FILL_Y(row), | |
2481 &clip, 1, Unsorted); | |
2482 } | |
2483 #endif | |
2484 | |
2485 if (flags & DRAW_TRANSP) | |
2486 { | |
2487 #ifdef FEAT_MBYTE | |
2488 if (enc_utf8) | |
2489 XDrawString16(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col), | |
2490 TEXT_Y(row), buf, wlen); | |
2491 else | |
2492 #endif | |
2493 XDrawString(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col), | |
2494 TEXT_Y(row), (char *)s, len); | |
2495 } | |
2496 else if (p_linespace != 0 | |
2497 #ifdef FEAT_XFONTSET | |
2498 || current_fontset != NULL | |
2499 #endif | |
2500 ) | |
2501 { | |
2502 XSetForeground(gui.dpy, gui.text_gc, prev_bg_color); | |
2503 XFillRectangle(gui.dpy, gui.wid, gui.text_gc, FILL_X(col), | |
2504 FILL_Y(row), gui.char_width * cells, gui.char_height); | |
2505 XSetForeground(gui.dpy, gui.text_gc, prev_fg_color); | |
206 | 2506 |
7 | 2507 #ifdef FEAT_MBYTE |
2508 if (enc_utf8) | |
2509 XDrawString16(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col), | |
2510 TEXT_Y(row), buf, wlen); | |
2511 else | |
2512 #endif | |
2513 XDrawString(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col), | |
2514 TEXT_Y(row), (char *)s, len); | |
2515 } | |
2516 else | |
2517 { | |
2518 /* XmbDrawImageString has bug, don't use it for fontset. */ | |
2519 #ifdef FEAT_MBYTE | |
2520 if (enc_utf8) | |
2521 XDrawImageString16(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col), | |
2522 TEXT_Y(row), buf, wlen); | |
2523 else | |
2524 #endif | |
2525 XDrawImageString(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col), | |
2526 TEXT_Y(row), (char *)s, len); | |
2527 } | |
2528 | |
2529 /* Bold trick: draw the text again with a one-pixel offset. */ | |
2530 if (flags & DRAW_BOLD) | |
2531 { | |
2532 #ifdef FEAT_MBYTE | |
2533 if (enc_utf8) | |
2534 XDrawString16(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col) + 1, | |
2535 TEXT_Y(row), buf, wlen); | |
2536 else | |
2537 #endif | |
2538 XDrawString(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col) + 1, | |
2539 TEXT_Y(row), (char *)s, len); | |
2540 } | |
2541 | |
206 | 2542 /* Undercurl: draw curl at the bottom of the character cell. */ |
2543 if (flags & DRAW_UNDERC) | |
2544 draw_curl(row, col, cells); | |
2545 | |
7 | 2546 /* Underline: draw a line at the bottom of the character cell. */ |
2547 if (flags & DRAW_UNDERL) | |
206 | 2548 { |
2549 int y = FILL_Y(row + 1) - 1; | |
2550 | |
2551 /* When p_linespace is 0, overwrite the bottom row of pixels. | |
2552 * Otherwise put the line just below the character. */ | |
2553 if (p_linespace > 1) | |
2554 y -= p_linespace - 1; | |
7 | 2555 XDrawLine(gui.dpy, gui.wid, gui.text_gc, FILL_X(col), |
206 | 2556 y, FILL_X(col + cells) - 1, y); |
2557 } | |
7 | 2558 |
12317
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12257
diff
changeset
|
2559 if (flags & DRAW_STRIKE) |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12257
diff
changeset
|
2560 { |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12257
diff
changeset
|
2561 int y = FILL_Y(row + 1) - gui.char_height/2; |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12257
diff
changeset
|
2562 |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12257
diff
changeset
|
2563 XSetForeground(gui.dpy, gui.text_gc, prev_sp_color); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12257
diff
changeset
|
2564 XDrawLine(gui.dpy, gui.wid, gui.text_gc, FILL_X(col), |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12257
diff
changeset
|
2565 y, FILL_X(col + cells) - 1, y); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12257
diff
changeset
|
2566 XSetForeground(gui.dpy, gui.text_gc, prev_fg_color); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12257
diff
changeset
|
2567 } |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12257
diff
changeset
|
2568 |
7 | 2569 #ifdef FEAT_XFONTSET |
2570 if (current_fontset != NULL) | |
2571 XSetClipMask(gui.dpy, gui.text_gc, None); | |
2572 #endif | |
2573 } | |
2574 | |
2575 /* | |
2576 * Return OK if the key with the termcap name "name" is supported. | |
2577 */ | |
2578 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2579 gui_mch_haskey(char_u *name) |
7 | 2580 { |
2581 int i; | |
2582 | |
2583 for (i = 0; special_keys[i].key_sym != (KeySym)0; i++) | |
2584 if (name[0] == special_keys[i].vim_code0 && | |
2585 name[1] == special_keys[i].vim_code1) | |
2586 return OK; | |
2587 return FAIL; | |
2588 } | |
2589 | |
2590 /* | |
2591 * Return the text window-id and display. Only required for X-based GUI's | |
2592 */ | |
2593 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2594 gui_get_x11_windis(Window *win, Display **dis) |
7 | 2595 { |
2596 *win = XtWindow(vimShell); | |
2597 *dis = gui.dpy; | |
2598 return OK; | |
2599 } | |
2600 | |
2601 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2602 gui_mch_beep(void) |
7 | 2603 { |
2604 XBell(gui.dpy, 0); | |
2605 } | |
2606 | |
2607 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2608 gui_mch_flash(int msec) |
7 | 2609 { |
2610 /* Do a visual beep by reversing the foreground and background colors */ | |
2611 XFillRectangle(gui.dpy, gui.wid, gui.invert_gc, 0, 0, | |
2612 FILL_X((int)Columns) + gui.border_offset, | |
2613 FILL_Y((int)Rows) + gui.border_offset); | |
2614 XSync(gui.dpy, False); | |
2615 ui_delay((long)msec, TRUE); /* wait for a few msec */ | |
2616 XFillRectangle(gui.dpy, gui.wid, gui.invert_gc, 0, 0, | |
2617 FILL_X((int)Columns) + gui.border_offset, | |
2618 FILL_Y((int)Rows) + gui.border_offset); | |
2619 } | |
2620 | |
2621 /* | |
2622 * Invert a rectangle from row r, column c, for nr rows and nc columns. | |
2623 */ | |
2624 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2625 gui_mch_invert_rectangle( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2626 int r, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2627 int c, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2628 int nr, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2629 int nc) |
7 | 2630 { |
2631 XFillRectangle(gui.dpy, gui.wid, gui.invert_gc, | |
2632 FILL_X(c), FILL_Y(r), (nc) * gui.char_width, (nr) * gui.char_height); | |
2633 } | |
2634 | |
2635 /* | |
2636 * Iconify the GUI window. | |
2637 */ | |
2638 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2639 gui_mch_iconify(void) |
7 | 2640 { |
2641 XIconifyWindow(gui.dpy, XtWindow(vimShell), DefaultScreen(gui.dpy)); | |
2642 } | |
2643 | |
2644 #if defined(FEAT_EVAL) || defined(PROTO) | |
2645 /* | |
2646 * Bring the Vim window to the foreground. | |
2647 */ | |
2648 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2649 gui_mch_set_foreground(void) |
7 | 2650 { |
2651 XMapRaised(gui.dpy, XtWindow(vimShell)); | |
2652 } | |
2653 #endif | |
2654 | |
2655 /* | |
2656 * Draw a cursor without focus. | |
2657 */ | |
2658 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2659 gui_mch_draw_hollow_cursor(guicolor_T color) |
7 | 2660 { |
2661 int w = 1; | |
2662 | |
2663 #ifdef FEAT_MBYTE | |
2664 if (mb_lefthalve(gui.row, gui.col)) | |
2665 w = 2; | |
2666 #endif | |
2667 gui_mch_set_fg_color(color); | |
2668 XDrawRectangle(gui.dpy, gui.wid, gui.text_gc, FILL_X(gui.col), | |
2669 FILL_Y(gui.row), w * gui.char_width - 1, gui.char_height - 1); | |
2670 } | |
2671 | |
2672 /* | |
2673 * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using | |
2674 * color "color". | |
2675 */ | |
2676 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2677 gui_mch_draw_part_cursor(int w, int h, guicolor_T color) |
7 | 2678 { |
2679 gui_mch_set_fg_color(color); | |
2680 | |
2681 XFillRectangle(gui.dpy, gui.wid, gui.text_gc, | |
2682 #ifdef FEAT_RIGHTLEFT | |
2683 /* vertical line should be on the right of current point */ | |
2684 CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w : | |
2685 #endif | |
2686 FILL_X(gui.col), | |
2687 FILL_Y(gui.row) + gui.char_height - h, | |
2688 w, h); | |
2689 } | |
2690 | |
2691 /* | |
2692 * Catch up with any queued X events. This may put keyboard input into the | |
2693 * input buffer, call resize call-backs, trigger timers etc. If there is | |
2694 * nothing in the X event queue (& no timers pending), then we return | |
2695 * immediately. | |
2696 */ | |
2697 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2698 gui_mch_update(void) |
7 | 2699 { |
2700 XtInputMask mask, desired; | |
2701 | |
2702 #ifdef ALT_X_INPUT | |
2703 if (suppress_alternate_input) | |
2704 desired = (XtIMXEvent | XtIMTimer); | |
2705 else | |
2706 #endif | |
2707 desired = (XtIMAll); | |
2708 while ((mask = XtAppPending(app_context)) && (mask & desired) | |
2709 && !vim_is_input_buf_full()) | |
2710 XtAppProcessEvent(app_context, desired); | |
2711 } | |
2712 | |
2713 /* | |
2714 * GUI input routine called by gui_wait_for_chars(). Waits for a character | |
2715 * from the keyboard. | |
2716 * wtime == -1 Wait forever. | |
2717 * wtime == 0 This should never happen. | |
2718 * wtime > 0 Wait wtime milliseconds for a character. | |
2719 * Returns OK if a character was found to be available within the given time, | |
2720 * or FAIL otherwise. | |
2721 */ | |
2722 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2723 gui_mch_wait_for_chars(long wtime) |
7 | 2724 { |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
2725 int focus; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
2726 int retval = FAIL; |
7 | 2727 |
2728 /* | |
2729 * Make this static, in case gui_x11_timer_cb is called after leaving | |
2730 * this function (otherwise a random value on the stack may be changed). | |
2731 */ | |
2732 static int timed_out; | |
2733 XtIntervalId timer = (XtIntervalId)0; | |
2734 XtInputMask desired; | |
12257
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
2735 #ifdef FEAT_JOB_CHANNEL |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
2736 XtIntervalId channel_timer = (XtIntervalId)0; |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
2737 #endif |
7 | 2738 |
2739 timed_out = FALSE; | |
2740 | |
2741 if (wtime > 0) | |
2742 timer = XtAppAddTimeOut(app_context, (long_u)wtime, gui_x11_timer_cb, | |
2743 &timed_out); | |
12257
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
2744 #ifdef FEAT_JOB_CHANNEL |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
2745 /* If there is a channel with the keep_open flag we need to poll for input |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
2746 * on them. */ |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
2747 if (channel_any_keep_open()) |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
2748 channel_timer = XtAppAddTimeOut(app_context, (long_u)20, |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
2749 channel_poll_cb, (XtPointer)&channel_timer); |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
2750 #endif |
7 | 2751 |
2752 focus = gui.in_focus; | |
2753 #ifdef ALT_X_INPUT | |
2754 if (suppress_alternate_input) | |
2755 desired = (XtIMXEvent | XtIMTimer); | |
2756 else | |
2757 #endif | |
2758 desired = (XtIMAll); | |
2759 while (!timed_out) | |
2760 { | |
2761 /* Stop or start blinking when focus changes */ | |
2762 if (gui.in_focus != focus) | |
2763 { | |
2764 if (gui.in_focus) | |
2765 gui_mch_start_blink(); | |
2766 else | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
2767 gui_mch_stop_blink(TRUE); |
7 | 2768 focus = gui.in_focus; |
2769 } | |
2770 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
5196
diff
changeset
|
2771 #ifdef MESSAGE_QUEUE |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
2772 # ifdef FEAT_TIMERS |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
2773 did_add_timer = FALSE; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
2774 # endif |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
5196
diff
changeset
|
2775 parse_queued_messages(); |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
2776 # ifdef FEAT_TIMERS |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
2777 if (did_add_timer) |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
2778 /* Need to recompute the waiting time. */ |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
2779 break; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
2780 # endif |
2638 | 2781 #endif |
2782 | |
7 | 2783 /* |
2784 * Don't use gui_mch_update() because then we will spin-lock until a | |
2785 * char arrives, instead we use XtAppProcessEvent() to hang until an | |
2786 * event arrives. No need to check for input_buf_full because we are | |
2787 * returning as soon as it contains a single char. Note that | |
2788 * XtAppNextEvent() may not be used because it will not return after a | |
2789 * timer event has arrived -- webb | |
2790 */ | |
2791 XtAppProcessEvent(app_context, desired); | |
2792 | |
2793 if (input_available()) | |
2794 { | |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
2795 retval = OK; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
2796 break; |
7 | 2797 } |
2798 } | |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
2799 |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
2800 if (timer != (XtIntervalId)0 && !timed_out) |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
2801 XtRemoveTimeOut(timer); |
12257
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
2802 #ifdef FEAT_JOB_CHANNEL |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
2803 if (channel_timer != (XtIntervalId)0) |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
2804 XtRemoveTimeOut(channel_timer); |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
2805 #endif |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
2806 |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
2807 return retval; |
7 | 2808 } |
2809 | |
2810 /* | |
2811 * Output routines. | |
2812 */ | |
2813 | |
2814 /* Flush any output to the screen */ | |
2815 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2816 gui_mch_flush(void) |
7 | 2817 { |
2818 XFlush(gui.dpy); | |
2819 } | |
2820 | |
2821 /* | |
2822 * Clear a rectangular region of the screen from text pos (row1, col1) to | |
2823 * (row2, col2) inclusive. | |
2824 */ | |
2825 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2826 gui_mch_clear_block( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2827 int row1, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2828 int col1, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2829 int row2, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2830 int col2) |
7 | 2831 { |
2832 int x; | |
2833 | |
2834 x = FILL_X(col1); | |
2835 | |
2836 /* Clear one extra pixel at the far right, for when bold characters have | |
2837 * spilled over to the next column. */ | |
2838 XFillRectangle(gui.dpy, gui.wid, gui.back_gc, x, FILL_Y(row1), | |
2839 (col2 - col1 + 1) * gui.char_width + (col2 == Columns - 1), | |
2840 (row2 - row1 + 1) * gui.char_height); | |
2841 } | |
2842 | |
2843 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2844 gui_mch_clear_all(void) |
7 | 2845 { |
2846 XClearArea(gui.dpy, gui.wid, 0, 0, 0, 0, False); | |
2847 } | |
2848 | |
2849 /* | |
2850 * Delete the given number of lines from the given row, scrolling up any | |
2851 * text further down within the scroll region. | |
2852 */ | |
2853 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2854 gui_mch_delete_lines(int row, int num_lines) |
7 | 2855 { |
2856 if (gui.visibility == VisibilityFullyObscured) | |
2857 return; /* Can't see the window */ | |
2858 | |
2859 /* copy one extra pixel at the far right, for when bold has spilled | |
2860 * over */ | |
2861 XCopyArea(gui.dpy, gui.wid, gui.wid, gui.text_gc, | |
2862 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), | |
2863 gui.char_width * (gui.scroll_region_right - gui.scroll_region_left + 1) | |
2864 + (gui.scroll_region_right == Columns - 1), | |
2865 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1), | |
2866 FILL_X(gui.scroll_region_left), FILL_Y(row)); | |
2867 | |
2868 gui_clear_block(gui.scroll_region_bot - num_lines + 1, | |
2869 gui.scroll_region_left, | |
2870 gui.scroll_region_bot, gui.scroll_region_right); | |
2871 gui_x11_check_copy_area(); | |
2872 } | |
2873 | |
2874 /* | |
2875 * Insert the given number of lines before the given row, scrolling down any | |
2876 * following text within the scroll region. | |
2877 */ | |
2878 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2879 gui_mch_insert_lines(int row, int num_lines) |
7 | 2880 { |
2881 if (gui.visibility == VisibilityFullyObscured) | |
2882 return; /* Can't see the window */ | |
2883 | |
2884 /* copy one extra pixel at the far right, for when bold has spilled | |
2885 * over */ | |
2886 XCopyArea(gui.dpy, gui.wid, gui.wid, gui.text_gc, | |
2887 FILL_X(gui.scroll_region_left), FILL_Y(row), | |
2888 gui.char_width * (gui.scroll_region_right - gui.scroll_region_left + 1) | |
2889 + (gui.scroll_region_right == Columns - 1), | |
2890 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1), | |
2891 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines)); | |
2892 | |
2893 gui_clear_block(row, gui.scroll_region_left, | |
2894 row + num_lines - 1, gui.scroll_region_right); | |
2895 gui_x11_check_copy_area(); | |
2896 } | |
2897 | |
2898 /* | |
2899 * Update the region revealed by scrolling up/down. | |
2900 */ | |
2901 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2902 gui_x11_check_copy_area(void) |
7 | 2903 { |
2904 XEvent event; | |
2905 XGraphicsExposeEvent *gevent; | |
2906 | |
2907 if (gui.visibility != VisibilityPartiallyObscured) | |
2908 return; | |
2909 | |
2910 XFlush(gui.dpy); | |
2911 | |
2912 /* Wait to check whether the scroll worked or not */ | |
2913 for (;;) | |
2914 { | |
2915 if (XCheckTypedEvent(gui.dpy, NoExpose, &event)) | |
2916 return; /* The scroll worked. */ | |
2917 | |
2918 if (XCheckTypedEvent(gui.dpy, GraphicsExpose, &event)) | |
2919 { | |
2920 gevent = (XGraphicsExposeEvent *)&event; | |
2921 gui_redraw(gevent->x, gevent->y, gevent->width, gevent->height); | |
2922 if (gevent->count == 0) | |
2923 return; /* This was the last expose event */ | |
2924 } | |
2925 XSync(gui.dpy, False); | |
2926 } | |
2927 } | |
2928 | |
2929 /* | |
2930 * X Selection stuff, for cutting and pasting text to other windows. | |
2931 */ | |
2932 | |
2933 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2934 clip_mch_lose_selection(VimClipboard *cbd) |
7 | 2935 { |
2936 clip_x11_lose_selection(vimShell, cbd); | |
2937 } | |
2938 | |
2939 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2940 clip_mch_own_selection(VimClipboard *cbd) |
7 | 2941 { |
2942 return clip_x11_own_selection(vimShell, cbd); | |
2943 } | |
2944 | |
2945 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2946 clip_mch_request_selection(VimClipboard *cbd) |
7 | 2947 { |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2948 clip_x11_request_selection(vimShell, gui.dpy, cbd); |
7 | 2949 } |
2950 | |
2951 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2952 clip_mch_set_selection( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2953 VimClipboard *cbd) |
7 | 2954 { |
2955 clip_x11_set_selection(cbd); | |
2956 } | |
2957 | |
2958 #if defined(FEAT_MENU) || defined(PROTO) | |
2959 /* | |
2960 * Menu stuff. | |
2961 */ | |
2962 | |
2963 /* | |
2964 * Make a menu either grey or not grey. | |
2965 */ | |
2966 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2967 gui_mch_menu_grey(vimmenu_T *menu, int grey) |
7 | 2968 { |
2969 if (menu->id != (Widget)0) | |
2970 { | |
2971 gui_mch_menu_hidden(menu, False); | |
2972 if (grey | |
2973 #ifdef FEAT_GUI_MOTIF | |
2974 || !menu->sensitive | |
2975 #endif | |
2976 ) | |
2977 XtSetSensitive(menu->id, False); | |
2978 else | |
2979 XtSetSensitive(menu->id, True); | |
2980 } | |
2981 } | |
2982 | |
2983 /* | |
2984 * Make menu item hidden or not hidden | |
2985 */ | |
2986 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2987 gui_mch_menu_hidden(vimmenu_T *menu, int hidden) |
7 | 2988 { |
2989 if (menu->id != (Widget)0) | |
2990 { | |
2991 if (hidden) | |
2992 XtUnmanageChild(menu->id); | |
2993 else | |
2994 XtManageChild(menu->id); | |
2995 } | |
2996 } | |
2997 | |
2998 /* | |
2999 * This is called after setting all the menus to grey/hidden or not. | |
3000 */ | |
3001 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3002 gui_mch_draw_menubar(void) |
7 | 3003 { |
3004 /* Nothing to do in X */ | |
3005 } | |
3006 | |
3007 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3008 gui_x11_menu_cb( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3009 Widget w UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3010 XtPointer client_data, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3011 XtPointer call_data UNUSED) |
7 | 3012 { |
3013 gui_menu_cb((vimmenu_T *)client_data); | |
3014 } | |
3015 | |
3016 #endif /* FEAT_MENU */ | |
3017 | |
3018 | |
3019 | |
3020 /* | |
3021 * Function called when window closed. Works like ":qa". | |
3022 * Should put up a requester! | |
3023 */ | |
3024 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3025 gui_x11_wm_protocol_handler( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3026 Widget w UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3027 XtPointer client_data UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3028 XEvent *event, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3029 Boolean *dum UNUSED) |
7 | 3030 { |
3031 /* | |
3032 * Only deal with Client messages. | |
3033 */ | |
3034 if (event->type != ClientMessage) | |
3035 return; | |
3036 | |
3037 /* | |
3038 * The WM_SAVE_YOURSELF event arrives when the window manager wants to | |
3039 * exit. That can be cancelled though, thus Vim shouldn't exit here. | |
3040 * Just sync our swap files. | |
3041 */ | |
1887 | 3042 if ((Atom)((XClientMessageEvent *)event)->data.l[0] == |
7 | 3043 wm_atoms[SAVE_YOURSELF_IDX]) |
3044 { | |
3045 out_flush(); | |
3046 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
3047 | |
3048 /* Set the window's WM_COMMAND property, to let the window manager | |
3049 * know we are done saving ourselves. We don't want to be restarted, | |
3050 * thus set argv to NULL. */ | |
3051 XSetCommand(gui.dpy, XtWindow(vimShell), NULL, 0); | |
3052 return; | |
3053 } | |
3054 | |
1887 | 3055 if ((Atom)((XClientMessageEvent *)event)->data.l[0] != |
7 | 3056 wm_atoms[DELETE_WINDOW_IDX]) |
3057 return; | |
3058 | |
3059 gui_shell_closed(); | |
3060 } | |
3061 | |
3062 #ifdef FEAT_CLIENTSERVER | |
3063 /* | |
3064 * Function called when property changed. Check for incoming commands | |
3065 */ | |
3066 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3067 gui_x11_send_event_handler( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3068 Widget w UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3069 XtPointer client_data UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3070 XEvent *event, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3071 Boolean *dum UNUSED) |
7 | 3072 { |
3073 XPropertyEvent *e = (XPropertyEvent *) event; | |
3074 | |
3075 if (e->type == PropertyNotify && e->window == commWindow | |
3076 && e->atom == commProperty && e->state == PropertyNewValue) | |
3077 { | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
5196
diff
changeset
|
3078 serverEventProc(gui.dpy, event, 0); |
7 | 3079 } |
3080 } | |
3081 #endif | |
3082 | |
3083 /* | |
3084 * Cursor blink functions. | |
3085 * | |
3086 * This is a simple state machine: | |
3087 * BLINK_NONE not blinking at all | |
3088 * BLINK_OFF blinking, cursor is not shown | |
3089 * BLINK_ON blinking, cursor is shown | |
3090 */ | |
3091 | |
3092 #define BLINK_NONE 0 | |
3093 #define BLINK_OFF 1 | |
3094 #define BLINK_ON 2 | |
3095 | |
3096 static int blink_state = BLINK_NONE; | |
3097 static long_u blink_waittime = 700; | |
3098 static long_u blink_ontime = 400; | |
3099 static long_u blink_offtime = 250; | |
3100 static XtIntervalId blink_timer = (XtIntervalId)0; | |
3101 | |
9213
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
3102 int |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
3103 gui_mch_is_blinking(void) |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
3104 { |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
3105 return blink_state != BLINK_NONE; |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
3106 } |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
3107 |
9428
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
3108 int |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
3109 gui_mch_is_blink_off(void) |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
3110 { |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
3111 return blink_state == BLINK_OFF; |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
3112 } |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
3113 |
7 | 3114 void |
7825
7898da204b98
commit https://github.com/vim/vim/commit/02fdaeaa697fb5af4ba7fee6e209b3c2c825bb4f
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
3115 gui_mch_set_blinking(long waittime, long on, long off) |
7 | 3116 { |
3117 blink_waittime = waittime; | |
3118 blink_ontime = on; | |
3119 blink_offtime = off; | |
3120 } | |
3121 | |
3122 /* | |
3123 * Stop the cursor blinking. Show the cursor if it wasn't shown. | |
3124 */ | |
3125 void | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
3126 gui_mch_stop_blink(int may_call_gui_update_cursor) |
7 | 3127 { |
3128 if (blink_timer != (XtIntervalId)0) | |
3129 { | |
3130 XtRemoveTimeOut(blink_timer); | |
3131 blink_timer = (XtIntervalId)0; | |
3132 } | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
3133 if (blink_state == BLINK_OFF && may_call_gui_update_cursor) |
7 | 3134 gui_update_cursor(TRUE, FALSE); |
3135 blink_state = BLINK_NONE; | |
3136 } | |
3137 | |
3138 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3139 gui_x11_blink_cb( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3140 XtPointer timed_out UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3141 XtIntervalId *interval_id UNUSED) |
7 | 3142 { |
3143 if (blink_state == BLINK_ON) | |
3144 { | |
3145 gui_undraw_cursor(); | |
3146 blink_state = BLINK_OFF; | |
3147 blink_timer = XtAppAddTimeOut(app_context, blink_offtime, | |
3148 gui_x11_blink_cb, NULL); | |
3149 } | |
3150 else | |
3151 { | |
3152 gui_update_cursor(TRUE, FALSE); | |
3153 blink_state = BLINK_ON; | |
3154 blink_timer = XtAppAddTimeOut(app_context, blink_ontime, | |
3155 gui_x11_blink_cb, NULL); | |
3156 } | |
3157 } | |
3158 | |
3159 /* | |
12257
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
3160 * Start the cursor blinking. If it was already blinking, this restarts the |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
3161 * waiting time and shows the cursor. |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
3162 */ |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
3163 void |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
3164 gui_mch_start_blink(void) |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
3165 { |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
3166 if (blink_timer != (XtIntervalId)0) |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
3167 XtRemoveTimeOut(blink_timer); |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
3168 /* Only switch blinking on if none of the times is zero */ |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
3169 if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus) |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
3170 { |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
3171 blink_timer = XtAppAddTimeOut(app_context, blink_waittime, |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
3172 gui_x11_blink_cb, NULL); |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
3173 blink_state = BLINK_ON; |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
3174 gui_update_cursor(TRUE, FALSE); |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
3175 } |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
3176 } |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
3177 |
519e4e6bbc28
patch 8.0.1008: slow updating of terminal window in Motif
Christian Brabandt <cb@256bit.org>
parents:
11770
diff
changeset
|
3178 /* |
7 | 3179 * Return the RGB value of a pixel as a long. |
3180 */ | |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9634
diff
changeset
|
3181 guicolor_T |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3182 gui_mch_get_rgb(guicolor_T pixel) |
7 | 3183 { |
3184 XColor xc; | |
3185 Colormap colormap; | |
3186 | |
3187 colormap = DefaultColormap(gui.dpy, XDefaultScreen(gui.dpy)); | |
3188 xc.pixel = pixel; | |
3189 XQueryColor(gui.dpy, colormap, &xc); | |
3190 | |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9634
diff
changeset
|
3191 return (guicolor_T)(((xc.red & 0xff00) << 8) + (xc.green & 0xff00) |
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9634
diff
changeset
|
3192 + ((unsigned)xc.blue >> 8)); |
7 | 3193 } |
3194 | |
3195 /* | |
3196 * Add the callback functions. | |
3197 */ | |
3198 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3199 gui_x11_callbacks(Widget textArea, Widget vimForm) |
7 | 3200 { |
3201 XtAddEventHandler(textArea, VisibilityChangeMask, FALSE, | |
3202 gui_x11_visibility_cb, (XtPointer)0); | |
3203 | |
3204 XtAddEventHandler(textArea, ExposureMask, FALSE, gui_x11_expose_cb, | |
3205 (XtPointer)0); | |
3206 | |
3207 XtAddEventHandler(vimShell, StructureNotifyMask, FALSE, | |
3208 gui_x11_resize_window_cb, (XtPointer)0); | |
3209 | |
3210 XtAddEventHandler(vimShell, FocusChangeMask, FALSE, gui_x11_focus_change_cb, | |
3211 (XtPointer)0); | |
3212 /* | |
3213 * Only install these enter/leave callbacks when 'p' in 'guioptions'. | |
3214 * Only needed for some window managers. | |
3215 */ | |
3216 if (vim_strchr(p_go, GO_POINTER) != NULL) | |
3217 { | |
3218 XtAddEventHandler(vimShell, LeaveWindowMask, FALSE, gui_x11_leave_cb, | |
3219 (XtPointer)0); | |
3220 XtAddEventHandler(textArea, LeaveWindowMask, FALSE, gui_x11_leave_cb, | |
3221 (XtPointer)0); | |
3222 XtAddEventHandler(textArea, EnterWindowMask, FALSE, gui_x11_enter_cb, | |
3223 (XtPointer)0); | |
3224 XtAddEventHandler(vimShell, EnterWindowMask, FALSE, gui_x11_enter_cb, | |
3225 (XtPointer)0); | |
3226 } | |
3227 | |
3228 XtAddEventHandler(vimForm, KeyPressMask, FALSE, gui_x11_key_hit_cb, | |
3229 (XtPointer)0); | |
3230 XtAddEventHandler(textArea, KeyPressMask, FALSE, gui_x11_key_hit_cb, | |
3231 (XtPointer)0); | |
3232 | |
3233 /* get pointer moved events from scrollbar, needed for 'mousefocus' */ | |
3234 XtAddEventHandler(vimForm, PointerMotionMask, | |
3235 FALSE, gui_x11_mouse_cb, (XtPointer)1); | |
3236 XtAddEventHandler(textArea, ButtonPressMask | ButtonReleaseMask | | |
3237 ButtonMotionMask | PointerMotionMask, | |
3238 FALSE, gui_x11_mouse_cb, (XtPointer)0); | |
3239 } | |
3240 | |
3241 /* | |
88 | 3242 * Get current mouse coordinates in text window. |
7 | 3243 */ |
88 | 3244 void |
3245 gui_mch_getmouse(int *x, int *y) | |
7 | 3246 { |
3247 int rootx, rooty, winx, winy; | |
3248 Window root, child; | |
3249 unsigned int mask; | |
3250 | |
3251 if (gui.wid && XQueryPointer(gui.dpy, gui.wid, &root, &child, | |
88 | 3252 &rootx, &rooty, &winx, &winy, &mask)) { |
3253 *x = winx; | |
3254 *y = winy; | |
3255 } else { | |
3256 *x = -1; | |
3257 *y = -1; | |
3258 } | |
7 | 3259 } |
3260 | |
3261 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3262 gui_mch_setmouse(int x, int y) |
7 | 3263 { |
3264 if (gui.wid) | |
3265 XWarpPointer(gui.dpy, (Window)0, gui.wid, 0, 0, 0, 0, x, y); | |
3266 } | |
3267 | |
3268 #if (defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU)) || defined(PROTO) | |
3269 XButtonPressedEvent * | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3270 gui_x11_get_last_mouse_event(void) |
7 | 3271 { |
3272 return &last_mouse_event; | |
3273 } | |
3274 #endif | |
3275 | |
3276 #if defined(FEAT_SIGN_ICONS) || defined(PROTO) | |
3277 | |
3278 /* Signs are currently always 2 chars wide. Hopefully the font is big enough | |
3279 * to provide room for the bitmap! */ | |
3280 # define SIGN_WIDTH (gui.char_width * 2) | |
3281 | |
3282 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3283 gui_mch_drawsign(int row, int col, int typenr) |
7 | 3284 { |
3285 XImage *sign; | |
3286 | |
3287 if (gui.in_use && (sign = (XImage *)sign_get_image(typenr)) != NULL) | |
3288 { | |
3289 XClearArea(gui.dpy, gui.wid, TEXT_X(col), TEXT_Y(row) - sign->height, | |
3290 SIGN_WIDTH, gui.char_height, FALSE); | |
3291 XPutImage(gui.dpy, gui.wid, gui.text_gc, sign, 0, 0, | |
3292 TEXT_X(col) + (SIGN_WIDTH - sign->width) / 2, | |
3293 TEXT_Y(row) - sign->height, | |
3294 sign->width, sign->height); | |
3295 } | |
3296 } | |
3297 | |
3298 void * | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3299 gui_mch_register_sign(char_u *signfile) |
7 | 3300 { |
3301 XpmAttributes attrs; | |
1827 | 3302 XImage *sign = NULL; |
7 | 3303 int status; |
3304 | |
3305 /* | |
3306 * Setup the color substitution table. | |
3307 */ | |
3308 if (signfile[0] != NUL && signfile[0] != '-') | |
3309 { | |
1827 | 3310 XpmColorSymbol color[5] = |
7 | 3311 { |
1827 | 3312 {"none", NULL, 0}, |
3313 {"iconColor1", NULL, 0}, | |
3314 {"bottomShadowColor", NULL, 0}, | |
3315 {"topShadowColor", NULL, 0}, | |
3316 {"selectColor", NULL, 0} | |
3317 }; | |
3318 attrs.valuemask = XpmColorSymbols; | |
3319 attrs.numsymbols = 2; | |
3320 attrs.colorsymbols = color; | |
3321 attrs.colorsymbols[0].pixel = gui.back_pixel; | |
3322 attrs.colorsymbols[1].pixel = gui.norm_pixel; | |
3323 status = XpmReadFileToImage(gui.dpy, (char *)signfile, | |
7 | 3324 &sign, NULL, &attrs); |
1827 | 3325 if (status == 0) |
3326 { | |
3327 /* Sign width is fixed at two columns now. | |
3328 if (sign->width > gui.sign_width) | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
3329 gui.sign_width = sign->width + 8; */ |
7 | 3330 } |
1827 | 3331 else |
3332 EMSG(_(e_signdata)); | |
7 | 3333 } |
3334 | |
3335 return (void *)sign; | |
3336 } | |
3337 | |
3338 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3339 gui_mch_destroy_sign(void *sign) |
7 | 3340 { |
1827 | 3341 XDestroyImage((XImage*)sign); |
7 | 3342 } |
3343 #endif | |
3344 | |
3345 | |
3346 #ifdef FEAT_MOUSESHAPE | |
3347 /* The last set mouse pointer shape is remembered, to be used when it goes | |
3348 * from hidden to not hidden. */ | |
3349 static int last_shape = 0; | |
3350 #endif | |
3351 | |
3352 /* | |
3353 * Use the blank mouse pointer or not. | |
3354 */ | |
3355 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3356 gui_mch_mousehide( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3357 int hide) /* TRUE = use blank ptr, FALSE = use parent ptr */ |
7 | 3358 { |
3359 if (gui.pointer_hidden != hide) | |
3360 { | |
3361 gui.pointer_hidden = hide; | |
3362 if (hide) | |
3363 XDefineCursor(gui.dpy, gui.wid, gui.blank_pointer); | |
3364 else | |
3365 #ifdef FEAT_MOUSESHAPE | |
3366 mch_set_mouse_shape(last_shape); | |
3367 #else | |
3368 XUndefineCursor(gui.dpy, gui.wid); | |
3369 #endif | |
3370 } | |
3371 } | |
3372 | |
3373 #if defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
3374 | |
3375 /* Table for shape IDs. Keep in sync with the mshape_names[] table in | |
3376 * misc2.c! */ | |
3377 static int mshape_ids[] = | |
3378 { | |
3379 XC_left_ptr, /* arrow */ | |
3380 0, /* blank */ | |
3381 XC_xterm, /* beam */ | |
3382 XC_sb_v_double_arrow, /* updown */ | |
3383 XC_sizing, /* udsizing */ | |
3384 XC_sb_h_double_arrow, /* leftright */ | |
3385 XC_sizing, /* lrsizing */ | |
3386 XC_watch, /* busy */ | |
3387 XC_X_cursor, /* no */ | |
3388 XC_crosshair, /* crosshair */ | |
3389 XC_hand1, /* hand1 */ | |
3390 XC_hand2, /* hand2 */ | |
3391 XC_pencil, /* pencil */ | |
3392 XC_question_arrow, /* question */ | |
3393 XC_right_ptr, /* right-arrow */ | |
3394 XC_center_ptr, /* up-arrow */ | |
3395 XC_left_ptr /* last one */ | |
3396 }; | |
3397 | |
3398 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3399 mch_set_mouse_shape(int shape) |
7 | 3400 { |
3401 int id; | |
3402 | |
3403 if (!gui.in_use) | |
3404 return; | |
3405 | |
3406 if (shape == MSHAPE_HIDE || gui.pointer_hidden) | |
3407 XDefineCursor(gui.dpy, gui.wid, gui.blank_pointer); | |
3408 else | |
3409 { | |
3410 if (shape >= MSHAPE_NUMBERED) | |
3411 { | |
3412 id = shape - MSHAPE_NUMBERED; | |
3413 if (id >= XC_num_glyphs) | |
3414 id = XC_left_ptr; | |
3415 else | |
3416 id &= ~1; /* they are always even (why?) */ | |
3417 } | |
3418 else | |
3419 id = mshape_ids[shape]; | |
3420 | |
3421 XDefineCursor(gui.dpy, gui.wid, XCreateFontCursor(gui.dpy, id)); | |
3422 } | |
3423 if (shape != MSHAPE_HIDE) | |
3424 last_shape = shape; | |
3425 } | |
3426 #endif | |
3427 | |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
3428 #if (defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL_GUI)) || defined(PROTO) |
7 | 3429 /* |
3430 * Set the balloon-eval used for the tooltip of a toolbar menu item. | |
3431 * The check for a non-toolbar item was added, because there is a crash when | |
3432 * passing a normal menu item here. Can't explain that, but better avoid it. | |
3433 */ | |
3434 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3435 gui_mch_menu_set_tip(vimmenu_T *menu) |
7 | 3436 { |
3437 if (menu->id != NULL && menu->parent != NULL | |
3438 && menu_is_toolbar(menu->parent->name)) | |
3439 { | |
3440 /* Always destroy and create the balloon, in case the string was | |
3441 * changed. */ | |
3442 if (menu->tip != NULL) | |
3443 { | |
3444 gui_mch_destroy_beval_area(menu->tip); | |
3445 menu->tip = NULL; | |
3446 } | |
3447 if (menu->strings[MENU_INDEX_TIP] != NULL) | |
3448 menu->tip = gui_mch_create_beval_area( | |
3449 menu->id, | |
3450 menu->strings[MENU_INDEX_TIP], | |
3451 NULL, | |
3452 NULL); | |
3453 } | |
3454 } | |
3455 #endif |