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