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