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