Mercurial > vim
annotate src/gui_gtk_x11.c @ 8390:2230c0da23bd v7.4.1487
commit https://github.com/vim/vim/commit/6300317b15eb33409f652c603fb402417fe4eed7
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Mar 4 22:19:21 2016 +0100
patch 7.4.1487
Problem: For WIN32 isinf() is defined as a macro.
Solution: Define it as an inline function. (ZyX)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 04 Mar 2016 22:30:05 +0100 |
parents | 6a4c11fa1aa3 |
children | 1e58a938aafc |
rev | line source |
---|---|
7 | 1 /* vi:set ts=8 sts=4 sw=4: |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * Porting to GTK+ was done by: | |
12 * | |
70 | 13 * (C) 1998,1999,2000 by Marcin Dalecki <martin@dalecki.de> |
7 | 14 * |
15 * With GREAT support and continuous encouragements by Andy Kahn and of | |
16 * course Bram Moolenaar! | |
17 * | |
18 * Support for GTK+ 2 was added by: | |
19 * | |
20 * (C) 2002,2003 Jason Hildebrand <jason@peaceworks.ca> | |
21 * Daniel Elstner <daniel.elstner@gmx.net> | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
22 * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
23 * Support for GTK+ 3 was added by: |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
24 * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
25 * 2016 Kazunobu Kuriyama <kazunobu.kuriyama@gmail.com> |
7 | 26 */ |
27 | |
28 #include "vim.h" | |
7380
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
29 #ifdef USE_GRESOURCE |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
30 #include "auto/gui_gtk_gresources.h" |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
31 #endif |
1666 | 32 |
7 | 33 #ifdef FEAT_GUI_GNOME |
34 /* Gnome redefines _() and N_(). Grrr... */ | |
35 # ifdef _ | |
36 # undef _ | |
37 # endif | |
38 # ifdef N_ | |
39 # undef N_ | |
40 # endif | |
41 # ifdef textdomain | |
42 # undef textdomain | |
43 # endif | |
44 # ifdef bindtextdomain | |
45 # undef bindtextdomain | |
46 # endif | |
1286 | 47 # ifdef bind_textdomain_codeset |
48 # undef bind_textdomain_codeset | |
1226 | 49 # endif |
7 | 50 # if defined(FEAT_GETTEXT) && !defined(ENABLE_NLS) |
51 # define ENABLE_NLS /* so the texts in the dialog boxes are translated */ | |
52 # endif | |
53 # include <gnome.h> | |
54 # include "version.h" | |
798 | 55 /* missing prototype in bonobo-dock-item.h */ |
56 extern void bonobo_dock_item_set_behavior(BonoboDockItem *dock_item, BonoboDockItemBehavior beh); | |
7 | 57 #endif |
58 | |
59 #if !defined(FEAT_GUI_GTK) && defined(PROTO) | |
60 /* When generating prototypes we don't want syntax errors. */ | |
61 # define GdkAtom int | |
62 # define GdkEventExpose int | |
63 # define GdkEventFocus int | |
64 # define GdkEventVisibility int | |
65 # define GdkEventProperty int | |
66 # define GtkContainer int | |
67 # define GtkTargetEntry int | |
68 # define GtkType int | |
69 # define GtkWidget int | |
70 # define gint int | |
71 # define gpointer int | |
72 # define guint int | |
73 # define GdkEventKey int | |
74 # define GdkEventSelection int | |
75 # define GtkSelectionData int | |
76 # define GdkEventMotion int | |
77 # define GdkEventButton int | |
78 # define GdkDragContext int | |
79 # define GdkEventConfigure int | |
80 # define GdkEventClient int | |
81 #else | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
82 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
83 # include <gdk/gdkkeysyms-compat.h> |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
84 # include <gtk/gtkx.h> |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
85 # else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
86 # include <gdk/gdkkeysyms.h> |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
87 # endif |
7 | 88 # include <gdk/gdk.h> |
89 # ifdef WIN3264 | |
90 # include <gdk/gdkwin32.h> | |
91 # else | |
92 # include <gdk/gdkx.h> | |
93 # endif | |
94 # include <gtk/gtk.h> | |
95 # include "gui_gtk_f.h" | |
96 #endif | |
97 | |
98 #ifdef HAVE_X11_SUNKEYSYM_H | |
99 # include <X11/Sunkeysym.h> | |
2714 | 100 #endif |
101 | |
7 | 102 /* |
103 * Easy-to-use macro for multihead support. | |
104 */ | |
105 #ifdef HAVE_GTK_MULTIHEAD | |
106 # define GET_X_ATOM(atom) gdk_x11_atom_to_xatom_for_display( \ | |
107 gtk_widget_get_display(gui.mainwin), atom) | |
108 #else | |
109 # define GET_X_ATOM(atom) ((Atom)(atom)) | |
110 #endif | |
111 | |
112 /* Selection type distinguishers */ | |
113 enum | |
114 { | |
115 TARGET_TYPE_NONE, | |
116 TARGET_UTF8_STRING, | |
117 TARGET_STRING, | |
118 TARGET_COMPOUND_TEXT, | |
1904 | 119 TARGET_HTML, |
7 | 120 TARGET_TEXT, |
121 TARGET_TEXT_URI_LIST, | |
122 TARGET_TEXT_PLAIN, | |
123 TARGET_VIM, | |
124 TARGET_VIMENC | |
125 }; | |
126 | |
127 /* | |
128 * Table of selection targets supported by Vim. | |
129 * Note: Order matters, preferred types should come first. | |
130 */ | |
131 static const GtkTargetEntry selection_targets[] = | |
132 { | |
133 {VIMENC_ATOM_NAME, 0, TARGET_VIMENC}, | |
134 {VIM_ATOM_NAME, 0, TARGET_VIM}, | |
1904 | 135 {"text/html", 0, TARGET_HTML}, |
7 | 136 {"UTF8_STRING", 0, TARGET_UTF8_STRING}, |
137 {"COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT}, | |
138 {"TEXT", 0, TARGET_TEXT}, | |
139 {"STRING", 0, TARGET_STRING} | |
140 }; | |
141 #define N_SELECTION_TARGETS (sizeof(selection_targets) / sizeof(selection_targets[0])) | |
142 | |
143 #ifdef FEAT_DND | |
144 /* | |
145 * Table of DnD targets supported by Vim. | |
146 * Note: Order matters, preferred types should come first. | |
147 */ | |
148 static const GtkTargetEntry dnd_targets[] = | |
149 { | |
150 {"text/uri-list", 0, TARGET_TEXT_URI_LIST}, | |
1904 | 151 {"text/html", 0, TARGET_HTML}, |
7 | 152 {"UTF8_STRING", 0, TARGET_UTF8_STRING}, |
153 {"STRING", 0, TARGET_STRING}, | |
154 {"text/plain", 0, TARGET_TEXT_PLAIN} | |
155 }; | |
156 # define N_DND_TARGETS (sizeof(dnd_targets) / sizeof(dnd_targets[0])) | |
157 #endif | |
158 | |
159 | |
160 /* | |
161 * "Monospace" is a standard font alias that should be present | |
162 * on all proper Pango/fontconfig installations. | |
163 */ | |
164 # define DEFAULT_FONT "Monospace 10" | |
165 | |
166 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
167 /* | |
168 * Atoms used to communicate save-yourself from the X11 session manager. There | |
169 * is no need to move them into the GUI struct, since they should be constant. | |
170 */ | |
171 static GdkAtom wm_protocols_atom = GDK_NONE; | |
172 static GdkAtom save_yourself_atom = GDK_NONE; | |
173 #endif | |
174 | |
175 /* | |
176 * Atoms used to control/reference X11 selections. | |
177 */ | |
1904 | 178 static GdkAtom html_atom = GDK_NONE; |
7 | 179 static GdkAtom utf8_string_atom = GDK_NONE; |
180 static GdkAtom vim_atom = GDK_NONE; /* Vim's own special selection format */ | |
181 static GdkAtom vimenc_atom = GDK_NONE; /* Vim's extended selection format */ | |
182 | |
183 /* | |
184 * Keycodes recognized by vim. | |
185 * NOTE: when changing this, the table in gui_x11.c probably needs the same | |
186 * change! | |
187 */ | |
188 static struct special_key | |
189 { | |
190 guint key_sym; | |
191 char_u code0; | |
192 char_u code1; | |
193 } | |
194 const special_keys[] = | |
195 { | |
196 {GDK_Up, 'k', 'u'}, | |
197 {GDK_Down, 'k', 'd'}, | |
198 {GDK_Left, 'k', 'l'}, | |
199 {GDK_Right, 'k', 'r'}, | |
200 {GDK_F1, 'k', '1'}, | |
201 {GDK_F2, 'k', '2'}, | |
202 {GDK_F3, 'k', '3'}, | |
203 {GDK_F4, 'k', '4'}, | |
204 {GDK_F5, 'k', '5'}, | |
205 {GDK_F6, 'k', '6'}, | |
206 {GDK_F7, 'k', '7'}, | |
207 {GDK_F8, 'k', '8'}, | |
208 {GDK_F9, 'k', '9'}, | |
209 {GDK_F10, 'k', ';'}, | |
210 {GDK_F11, 'F', '1'}, | |
211 {GDK_F12, 'F', '2'}, | |
212 {GDK_F13, 'F', '3'}, | |
213 {GDK_F14, 'F', '4'}, | |
214 {GDK_F15, 'F', '5'}, | |
215 {GDK_F16, 'F', '6'}, | |
216 {GDK_F17, 'F', '7'}, | |
217 {GDK_F18, 'F', '8'}, | |
218 {GDK_F19, 'F', '9'}, | |
219 {GDK_F20, 'F', 'A'}, | |
220 {GDK_F21, 'F', 'B'}, | |
221 {GDK_Pause, 'F', 'B'}, /* Pause == F21 according to netbeans.txt */ | |
222 {GDK_F22, 'F', 'C'}, | |
223 {GDK_F23, 'F', 'D'}, | |
224 {GDK_F24, 'F', 'E'}, | |
225 {GDK_F25, 'F', 'F'}, | |
226 {GDK_F26, 'F', 'G'}, | |
227 {GDK_F27, 'F', 'H'}, | |
228 {GDK_F28, 'F', 'I'}, | |
229 {GDK_F29, 'F', 'J'}, | |
230 {GDK_F30, 'F', 'K'}, | |
231 {GDK_F31, 'F', 'L'}, | |
232 {GDK_F32, 'F', 'M'}, | |
233 {GDK_F33, 'F', 'N'}, | |
234 {GDK_F34, 'F', 'O'}, | |
235 {GDK_F35, 'F', 'P'}, | |
236 #ifdef SunXK_F36 | |
237 {SunXK_F36, 'F', 'Q'}, | |
238 {SunXK_F37, 'F', 'R'}, | |
239 #endif | |
240 {GDK_Help, '%', '1'}, | |
241 {GDK_Undo, '&', '8'}, | |
242 {GDK_BackSpace, 'k', 'b'}, | |
243 {GDK_Insert, 'k', 'I'}, | |
244 {GDK_Delete, 'k', 'D'}, | |
245 {GDK_3270_BackTab, 'k', 'B'}, | |
246 {GDK_Clear, 'k', 'C'}, | |
247 {GDK_Home, 'k', 'h'}, | |
248 {GDK_End, '@', '7'}, | |
249 {GDK_Prior, 'k', 'P'}, | |
250 {GDK_Next, 'k', 'N'}, | |
251 {GDK_Print, '%', '9'}, | |
252 /* Keypad keys: */ | |
253 {GDK_KP_Left, 'k', 'l'}, | |
254 {GDK_KP_Right, 'k', 'r'}, | |
255 {GDK_KP_Up, 'k', 'u'}, | |
256 {GDK_KP_Down, 'k', 'd'}, | |
257 {GDK_KP_Insert, KS_EXTRA, (char_u)KE_KINS}, | |
258 {GDK_KP_Delete, KS_EXTRA, (char_u)KE_KDEL}, | |
259 {GDK_KP_Home, 'K', '1'}, | |
260 {GDK_KP_End, 'K', '4'}, | |
261 {GDK_KP_Prior, 'K', '3'}, /* page up */ | |
262 {GDK_KP_Next, 'K', '5'}, /* page down */ | |
263 | |
264 {GDK_KP_Add, 'K', '6'}, | |
265 {GDK_KP_Subtract, 'K', '7'}, | |
266 {GDK_KP_Divide, 'K', '8'}, | |
267 {GDK_KP_Multiply, 'K', '9'}, | |
268 {GDK_KP_Enter, 'K', 'A'}, | |
269 {GDK_KP_Decimal, 'K', 'B'}, | |
270 | |
271 {GDK_KP_0, 'K', 'C'}, | |
272 {GDK_KP_1, 'K', 'D'}, | |
273 {GDK_KP_2, 'K', 'E'}, | |
274 {GDK_KP_3, 'K', 'F'}, | |
275 {GDK_KP_4, 'K', 'G'}, | |
276 {GDK_KP_5, 'K', 'H'}, | |
277 {GDK_KP_6, 'K', 'I'}, | |
278 {GDK_KP_7, 'K', 'J'}, | |
279 {GDK_KP_8, 'K', 'K'}, | |
280 {GDK_KP_9, 'K', 'L'}, | |
281 | |
282 /* End of list marker: */ | |
283 {0, 0, 0} | |
284 }; | |
285 | |
286 /* | |
287 * Flags for command line options table below. | |
288 */ | |
289 #define ARG_FONT 1 | |
290 #define ARG_GEOMETRY 2 | |
291 #define ARG_REVERSE 3 | |
292 #define ARG_NOREVERSE 4 | |
293 #define ARG_BACKGROUND 5 | |
294 #define ARG_FOREGROUND 6 | |
295 #define ARG_ICONIC 7 | |
296 #define ARG_ROLE 8 | |
297 #define ARG_NETBEANS 9 | |
298 #define ARG_XRM 10 /* ignored */ | |
299 #define ARG_MENUFONT 11 /* ignored */ | |
300 #define ARG_INDEX_MASK 0x00ff | |
301 #define ARG_HAS_VALUE 0x0100 /* a value is expected after the argument */ | |
302 #define ARG_NEEDS_GUI 0x0200 /* need to initialize the GUI for this */ | |
303 #define ARG_FOR_GTK 0x0400 /* argument is handled by GTK+ or GNOME */ | |
304 #define ARG_COMPAT_LONG 0x0800 /* accept -foo but substitute with --foo */ | |
305 #define ARG_KEEP 0x1000 /* don't remove argument from argv[] */ | |
306 | |
307 /* | |
308 * This table holds all the X GUI command line options allowed. This includes | |
309 * the standard ones so that we can skip them when Vim is started without the | |
310 * GUI (but the GUI might start up later). | |
311 * | |
312 * When changing this, also update doc/gui_x11.txt and the usage message!!! | |
313 */ | |
314 typedef struct | |
315 { | |
316 const char *name; | |
317 unsigned int flags; | |
318 } | |
319 cmdline_option_T; | |
320 | |
321 static const cmdline_option_T cmdline_options[] = | |
322 { | |
323 /* We handle these options ourselves */ | |
324 {"-fn", ARG_FONT|ARG_HAS_VALUE}, | |
325 {"-font", ARG_FONT|ARG_HAS_VALUE}, | |
326 {"-geom", ARG_GEOMETRY|ARG_HAS_VALUE}, | |
327 {"-geometry", ARG_GEOMETRY|ARG_HAS_VALUE}, | |
328 {"-rv", ARG_REVERSE}, | |
329 {"-reverse", ARG_REVERSE}, | |
330 {"+rv", ARG_NOREVERSE}, | |
331 {"+reverse", ARG_NOREVERSE}, | |
332 {"-bg", ARG_BACKGROUND|ARG_HAS_VALUE}, | |
333 {"-background", ARG_BACKGROUND|ARG_HAS_VALUE}, | |
334 {"-fg", ARG_FOREGROUND|ARG_HAS_VALUE}, | |
335 {"-foreground", ARG_FOREGROUND|ARG_HAS_VALUE}, | |
336 {"-iconic", ARG_ICONIC}, | |
337 {"--role", ARG_ROLE|ARG_HAS_VALUE}, | |
338 #ifdef FEAT_NETBEANS_INTG | |
339 {"-nb", ARG_NETBEANS}, /* non-standard value format */ | |
340 {"-xrm", ARG_XRM|ARG_HAS_VALUE}, /* not implemented */ | |
341 {"-mf", ARG_MENUFONT|ARG_HAS_VALUE}, /* not implemented */ | |
342 {"-menufont", ARG_MENUFONT|ARG_HAS_VALUE}, /* not implemented */ | |
343 #endif | |
344 /* Arguments handled by GTK (and GNOME) internally. */ | |
345 {"--g-fatal-warnings", ARG_FOR_GTK}, | |
346 {"--gdk-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
347 {"--gdk-no-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
348 {"--gtk-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
349 {"--gtk-no-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
350 {"--gtk-module", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
351 {"--sync", ARG_FOR_GTK}, | |
352 {"--display", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
353 {"--name", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
354 {"--class", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
355 {"--screen", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
356 {"--gxid-host", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
357 {"--gxid-port", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
358 #ifdef FEAT_GUI_GNOME | |
359 {"--load-modules", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
360 {"--sm-client-id", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
361 {"--sm-config-prefix", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
362 {"--sm-disable", ARG_FOR_GTK}, | |
363 {"--oaf-ior-fd", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
364 {"--oaf-activate-iid", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
365 {"--oaf-private", ARG_FOR_GTK}, | |
366 {"--enable-sound", ARG_FOR_GTK}, | |
367 {"--disable-sound", ARG_FOR_GTK}, | |
368 {"--espeaker", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
369 {"-?", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
370 {"--help", ARG_FOR_GTK|ARG_NEEDS_GUI|ARG_KEEP}, | |
371 {"--usage", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
372 # if 0 /* conflicts with Vim's own --version argument */ | |
373 {"--version", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
374 # endif | |
375 {"--disable-crash-dialog", ARG_FOR_GTK}, | |
376 #endif | |
377 {NULL, 0} | |
378 }; | |
379 | |
380 static int gui_argc = 0; | |
381 static char **gui_argv = NULL; | |
382 | |
383 static const char *role_argument = NULL; | |
384 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
385 static const char *restart_command = NULL; | |
1898 | 386 static char *abs_restart_command = NULL; |
7 | 387 #endif |
388 static int found_iconic_arg = FALSE; | |
389 | |
390 #ifdef FEAT_GUI_GNOME | |
391 /* | |
392 * Can't use Gnome if --socketid given | |
393 */ | |
394 static int using_gnome = 0; | |
395 #else | |
396 # define using_gnome 0 | |
397 #endif | |
398 | |
399 /* | |
400 * Parse the GUI related command-line arguments. Any arguments used are | |
401 * deleted from argv, and *argc is decremented accordingly. This is called | |
402 * when vim is started, whether or not the GUI has been started. | |
403 */ | |
404 void | |
405 gui_mch_prepare(int *argc, char **argv) | |
406 { | |
407 const cmdline_option_T *option; | |
408 int i = 0; | |
409 int len = 0; | |
410 | |
411 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
412 /* | |
413 * Determine the command used to invoke Vim, to be passed as restart | |
414 * command to the session manager. If argv[0] contains any directory | |
415 * components try building an absolute path, otherwise leave it as is. | |
416 */ | |
417 restart_command = argv[0]; | |
418 | |
419 if (strchr(argv[0], G_DIR_SEPARATOR) != NULL) | |
420 { | |
421 char_u buf[MAXPATHL]; | |
422 | |
423 if (mch_FullName((char_u *)argv[0], buf, (int)sizeof(buf), TRUE) == OK) | |
1898 | 424 { |
425 abs_restart_command = (char *)vim_strsave(buf); | |
426 restart_command = abs_restart_command; | |
427 } | |
7 | 428 } |
429 #endif | |
430 | |
431 /* | |
432 * Move all the entries in argv which are relevant to GTK+ and GNOME | |
433 * into gui_argv. Freed later in gui_mch_init(). | |
434 */ | |
435 gui_argc = 0; | |
436 gui_argv = (char **)alloc((unsigned)((*argc + 1) * sizeof(char *))); | |
437 | |
438 g_return_if_fail(gui_argv != NULL); | |
439 | |
440 gui_argv[gui_argc++] = argv[i++]; | |
441 | |
442 while (i < *argc) | |
443 { | |
444 /* Don't waste CPU cycles on non-option arguments. */ | |
445 if (argv[i][0] != '-' && argv[i][0] != '+') | |
446 { | |
447 ++i; | |
448 continue; | |
449 } | |
450 | |
451 /* Look for argv[i] in cmdline_options[] table. */ | |
452 for (option = &cmdline_options[0]; option->name != NULL; ++option) | |
453 { | |
454 len = strlen(option->name); | |
455 | |
456 if (strncmp(argv[i], option->name, len) == 0) | |
457 { | |
458 if (argv[i][len] == '\0') | |
459 break; | |
460 /* allow --foo=bar style */ | |
461 if (argv[i][len] == '=' && (option->flags & ARG_HAS_VALUE)) | |
462 break; | |
463 #ifdef FEAT_NETBEANS_INTG | |
464 /* darn, -nb has non-standard syntax */ | |
465 if (vim_strchr((char_u *)":=", argv[i][len]) != NULL | |
466 && (option->flags & ARG_INDEX_MASK) == ARG_NETBEANS) | |
467 break; | |
468 #endif | |
469 } | |
470 else if ((option->flags & ARG_COMPAT_LONG) | |
471 && strcmp(argv[i], option->name + 1) == 0) | |
472 { | |
473 /* Replace the standard X arguments "-name" and "-display" | |
474 * with their GNU-style long option counterparts. */ | |
475 argv[i] = (char *)option->name; | |
476 break; | |
477 } | |
478 } | |
479 if (option->name == NULL) /* no match */ | |
480 { | |
481 ++i; | |
482 continue; | |
483 } | |
484 | |
485 if (option->flags & ARG_FOR_GTK) | |
486 { | |
487 /* Move the argument into gui_argv, which | |
488 * will later be passed to gtk_init_check() */ | |
489 gui_argv[gui_argc++] = argv[i]; | |
490 } | |
491 else | |
492 { | |
493 char *value = NULL; | |
494 | |
495 /* Extract the option's value if there is one. | |
496 * Accept both "--foo bar" and "--foo=bar" style. */ | |
497 if (option->flags & ARG_HAS_VALUE) | |
498 { | |
499 if (argv[i][len] == '=') | |
500 value = &argv[i][len + 1]; | |
501 else if (i + 1 < *argc && strcmp(argv[i + 1], "--") != 0) | |
502 value = argv[i + 1]; | |
503 } | |
504 | |
505 /* Check for options handled by Vim itself */ | |
506 switch (option->flags & ARG_INDEX_MASK) | |
507 { | |
508 case ARG_REVERSE: | |
509 found_reverse_arg = TRUE; | |
510 break; | |
511 case ARG_NOREVERSE: | |
512 found_reverse_arg = FALSE; | |
513 break; | |
514 case ARG_FONT: | |
515 font_argument = value; | |
516 break; | |
517 case ARG_GEOMETRY: | |
518 if (value != NULL) | |
519 gui.geom = vim_strsave((char_u *)value); | |
520 break; | |
521 case ARG_BACKGROUND: | |
522 background_argument = value; | |
523 break; | |
524 case ARG_FOREGROUND: | |
525 foreground_argument = value; | |
526 break; | |
527 case ARG_ICONIC: | |
528 found_iconic_arg = TRUE; | |
529 break; | |
530 case ARG_ROLE: | |
531 role_argument = value; /* used later in gui_mch_open() */ | |
532 break; | |
533 #ifdef FEAT_NETBEANS_INTG | |
534 case ARG_NETBEANS: | |
535 gui.dofork = FALSE; /* don't fork() when starting GUI */ | |
536 netbeansArg = argv[i]; | |
537 break; | |
538 #endif | |
539 default: | |
540 break; | |
541 } | |
542 } | |
543 | |
544 /* These arguments make gnome_program_init() print a message and exit. | |
545 * Must start the GUI for this, otherwise ":gui" will exit later! */ | |
546 if (option->flags & ARG_NEEDS_GUI) | |
547 gui.starting = TRUE; | |
548 | |
549 if (option->flags & ARG_KEEP) | |
550 ++i; | |
551 else | |
552 { | |
553 /* Remove the flag from the argument vector. */ | |
554 if (--*argc > i) | |
555 { | |
556 int n_strip = 1; | |
557 | |
558 /* Move the argument's value as well, if there is one. */ | |
559 if ((option->flags & ARG_HAS_VALUE) | |
560 && argv[i][len] != '=' | |
561 && strcmp(argv[i + 1], "--") != 0) | |
562 { | |
563 ++n_strip; | |
564 --*argc; | |
565 if (option->flags & ARG_FOR_GTK) | |
566 gui_argv[gui_argc++] = argv[i + 1]; | |
567 } | |
568 | |
569 if (*argc > i) | |
570 mch_memmove(&argv[i], &argv[i + n_strip], | |
571 (*argc - i) * sizeof(char *)); | |
572 } | |
573 argv[*argc] = NULL; | |
574 } | |
575 } | |
576 | |
577 gui_argv[gui_argc] = NULL; | |
578 } | |
579 | |
359 | 580 #if defined(EXITFREE) || defined(PROTO) |
581 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
582 gui_mch_free_all(void) |
359 | 583 { |
584 vim_free(gui_argv); | |
1898 | 585 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) |
586 vim_free(abs_restart_command); | |
587 #endif | |
359 | 588 } |
589 #endif | |
590 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
591 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 592 /* |
593 * This should be maybe completely removed. | |
594 * Doesn't seem possible, since check_copy_area() relies on | |
595 * this information. --danielk | |
596 */ | |
597 static gint | |
1884 | 598 visibility_event(GtkWidget *widget UNUSED, |
599 GdkEventVisibility *event, | |
600 gpointer data UNUSED) | |
7 | 601 { |
602 gui.visibility = event->state; | |
603 /* | |
604 * When we do an gdk_window_copy_area(), and the window is partially | |
605 * obscured, we want to receive an event to tell us whether it worked | |
606 * or not. | |
607 */ | |
608 if (gui.text_gc != NULL) | |
609 gdk_gc_set_exposures(gui.text_gc, | |
610 gui.visibility != GDK_VISIBILITY_UNOBSCURED); | |
611 return FALSE; | |
612 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
613 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 614 |
615 /* | |
616 * Redraw the corresponding portions of the screen. | |
617 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
618 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
619 static gboolean is_key_pressed = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
620 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
621 static gboolean gui_gtk_is_blink_on(void); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
622 static gboolean gui_gtk_is_no_blink(void); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
623 static void gui_gtk_window_clear(GdkWindow *win); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
624 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
625 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
626 gui_gtk3_redraw(int x, int y, int width, int height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
627 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
628 gui_redraw_block(Y_2_ROW(y), X_2_COL(x), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
629 Y_2_ROW(y + height - 1), X_2_COL(x + width - 1), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
630 GUI_MON_NOCLEAR); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
631 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
632 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
633 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
634 gui_gtk3_update_cursor(cairo_t *cr) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
635 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
636 if (gui.row == gui.cursor_row) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
637 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
638 gui.by_signal = TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
639 gui_update_cursor(TRUE, TRUE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
640 gui.by_signal = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
641 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
642 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
643 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
644 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
645 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
646 gui_gtk3_should_draw_cursor(void) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
647 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
648 unsigned int cond = 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
649 cond |= gui_gtk_is_blink_on(); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
650 cond |= is_key_pressed; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
651 cond |= gui.in_focus == FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
652 cond |= gui_gtk_is_no_blink(); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
653 return cond; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
654 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
655 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
656 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
657 draw_event(GtkWidget *widget, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
658 cairo_t *cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
659 gpointer user_data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
660 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
661 /* Skip this when the GUI isn't set up yet, will redraw later. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
662 if (gui.starting) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
663 return FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
664 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
665 out_flush(); /* make sure all output has been processed */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
666 /* for GTK+ 3, may induce other draw events. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
667 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
668 cairo_set_source_surface(cr, gui.surface, 0, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
669 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
670 /* Draw the window without the cursor. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
671 gui.by_signal = TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
672 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
673 cairo_rectangle_list_t *list = NULL; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
674 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
675 gui_gtk_window_clear(gtk_widget_get_window(widget)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
676 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
677 list = cairo_copy_clip_rectangle_list(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
678 if (list->status != CAIRO_STATUS_CLIP_NOT_REPRESENTABLE) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
679 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
680 int i; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
681 for (i = 0; i < list->num_rectangles; i++) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
682 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
683 const cairo_rectangle_t rect = list->rectangles[i]; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
684 gui_gtk3_redraw(rect.x, rect.y, rect.width, rect.height); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
685 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
686 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
687 cairo_rectangle_list_destroy(list); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
688 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
689 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
690 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
691 gui.by_signal = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
692 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
693 /* Add the cursor to the window if necessary.*/ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
694 if (gui_gtk3_should_draw_cursor()) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
695 gui_gtk3_update_cursor(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
696 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
697 return FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
698 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
699 #else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 700 static gint |
1884 | 701 expose_event(GtkWidget *widget UNUSED, |
702 GdkEventExpose *event, | |
703 gpointer data UNUSED) | |
7 | 704 { |
705 /* Skip this when the GUI isn't set up yet, will redraw later. */ | |
706 if (gui.starting) | |
707 return FALSE; | |
708 | |
709 out_flush(); /* make sure all output has been processed */ | |
710 gui_redraw(event->area.x, event->area.y, | |
711 event->area.width, event->area.height); | |
712 | |
713 /* Clear the border areas if needed */ | |
714 if (event->area.x < FILL_X(0)) | |
715 gdk_window_clear_area(gui.drawarea->window, 0, 0, FILL_X(0), 0); | |
716 if (event->area.y < FILL_Y(0)) | |
717 gdk_window_clear_area(gui.drawarea->window, 0, 0, 0, FILL_Y(0)); | |
718 if (event->area.x > FILL_X(Columns)) | |
719 gdk_window_clear_area(gui.drawarea->window, | |
720 FILL_X((int)Columns), 0, 0, 0); | |
721 if (event->area.y > FILL_Y(Rows)) | |
722 gdk_window_clear_area(gui.drawarea->window, 0, FILL_Y((int)Rows), 0, 0); | |
723 | |
724 return FALSE; | |
725 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
726 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 727 |
728 #ifdef FEAT_CLIENTSERVER | |
729 /* | |
730 * Handle changes to the "Comm" property | |
731 */ | |
732 static gint | |
1884 | 733 property_event(GtkWidget *widget, |
734 GdkEventProperty *event, | |
735 gpointer data UNUSED) | |
7 | 736 { |
737 if (event->type == GDK_PROPERTY_NOTIFY | |
738 && event->state == (int)GDK_PROPERTY_NEW_VALUE | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
739 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
740 && GDK_WINDOW_XID(event->window) == commWindow |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
741 # else |
7 | 742 && GDK_WINDOW_XWINDOW(event->window) == commWindow |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
743 # endif |
7 | 744 && GET_X_ATOM(event->atom) == commProperty) |
745 { | |
746 XEvent xev; | |
747 | |
748 /* Translate to XLib */ | |
749 xev.xproperty.type = PropertyNotify; | |
750 xev.xproperty.atom = commProperty; | |
751 xev.xproperty.window = commWindow; | |
752 xev.xproperty.state = PropertyNewValue; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
753 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
754 serverEventProc(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(widget)), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
755 &xev, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
756 # else |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
757 serverEventProc(GDK_WINDOW_XDISPLAY(widget->window), &xev, 0); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
758 # endif |
7 | 759 } |
760 return FALSE; | |
761 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
762 #endif /* defined(FEAT_CLIENTSERVER) */ |
7 | 763 |
764 | |
765 /**************************************************************************** | |
766 * Focus handlers: | |
767 */ | |
768 | |
769 | |
770 /* | |
771 * This is a simple state machine: | |
772 * BLINK_NONE not blinking at all | |
773 * BLINK_OFF blinking, cursor is not shown | |
774 * BLINK_ON blinking, cursor is shown | |
775 */ | |
776 | |
777 #define BLINK_NONE 0 | |
778 #define BLINK_OFF 1 | |
779 #define BLINK_ON 2 | |
780 | |
781 static int blink_state = BLINK_NONE; | |
782 static long_u blink_waittime = 700; | |
783 static long_u blink_ontime = 400; | |
784 static long_u blink_offtime = 250; | |
785 static guint blink_timer = 0; | |
786 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
787 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
788 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
789 gui_gtk_is_blink_on(void) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
790 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
791 return blink_state == BLINK_ON; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
792 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
793 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
794 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
795 gui_gtk_is_no_blink(void) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
796 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
797 return blink_waittime == 0 || blink_ontime == 0 || blink_offtime == 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
798 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
799 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
800 |
7 | 801 void |
802 gui_mch_set_blinking(long waittime, long on, long off) | |
803 { | |
804 blink_waittime = waittime; | |
805 blink_ontime = on; | |
806 blink_offtime = off; | |
807 } | |
808 | |
809 /* | |
810 * Stop the cursor blinking. Show the cursor if it wasn't shown. | |
811 */ | |
812 void | |
813 gui_mch_stop_blink(void) | |
814 { | |
815 if (blink_timer) | |
816 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
817 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
818 g_source_remove(blink_timer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
819 #else |
7 | 820 gtk_timeout_remove(blink_timer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
821 #endif |
7 | 822 blink_timer = 0; |
823 } | |
824 if (blink_state == BLINK_OFF) | |
825 gui_update_cursor(TRUE, FALSE); | |
826 blink_state = BLINK_NONE; | |
827 } | |
828 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
829 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
830 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
831 #else |
7 | 832 static gint |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
833 #endif |
1884 | 834 blink_cb(gpointer data UNUSED) |
7 | 835 { |
836 if (blink_state == BLINK_ON) | |
837 { | |
838 gui_undraw_cursor(); | |
839 blink_state = BLINK_OFF; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
840 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
841 blink_timer = g_timeout_add((guint)blink_offtime, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
842 (GSourceFunc) blink_cb, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
843 #else |
7 | 844 blink_timer = gtk_timeout_add((guint32)blink_offtime, |
845 (GtkFunction) blink_cb, NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
846 #endif |
7 | 847 } |
848 else | |
849 { | |
850 gui_update_cursor(TRUE, FALSE); | |
851 blink_state = BLINK_ON; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
852 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
853 blink_timer = g_timeout_add((guint)blink_ontime, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
854 (GSourceFunc) blink_cb, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
855 #else |
7 | 856 blink_timer = gtk_timeout_add((guint32)blink_ontime, |
857 (GtkFunction) blink_cb, NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
858 #endif |
7 | 859 } |
860 | |
861 return FALSE; /* don't happen again */ | |
862 } | |
863 | |
864 /* | |
865 * Start the cursor blinking. If it was already blinking, this restarts the | |
866 * waiting time and shows the cursor. | |
867 */ | |
868 void | |
869 gui_mch_start_blink(void) | |
870 { | |
871 if (blink_timer) | |
5818 | 872 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
873 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
874 g_source_remove(blink_timer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
875 #else |
7 | 876 gtk_timeout_remove(blink_timer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
877 #endif |
5818 | 878 blink_timer = 0; |
879 } | |
7 | 880 /* Only switch blinking on if none of the times is zero */ |
881 if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus) | |
882 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
883 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
884 blink_timer = g_timeout_add((guint)blink_waittime, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
885 (GSourceFunc) blink_cb, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
886 #else |
7 | 887 blink_timer = gtk_timeout_add((guint32)blink_waittime, |
888 (GtkFunction) blink_cb, NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
889 #endif |
7 | 890 blink_state = BLINK_ON; |
891 gui_update_cursor(TRUE, FALSE); | |
892 } | |
893 } | |
894 | |
895 static gint | |
1884 | 896 enter_notify_event(GtkWidget *widget UNUSED, |
897 GdkEventCrossing *event UNUSED, | |
898 gpointer data UNUSED) | |
7 | 899 { |
900 if (blink_state == BLINK_NONE) | |
901 gui_mch_start_blink(); | |
902 | |
903 /* make sure keyboard input goes there */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
904 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
905 if (gtk_socket_id == 0 || !gtk_widget_has_focus(gui.drawarea)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
906 #else |
7 | 907 if (gtk_socket_id == 0 || !GTK_WIDGET_HAS_FOCUS(gui.drawarea)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
908 #endif |
7 | 909 gtk_widget_grab_focus(gui.drawarea); |
910 | |
911 return FALSE; | |
912 } | |
913 | |
914 static gint | |
1884 | 915 leave_notify_event(GtkWidget *widget UNUSED, |
916 GdkEventCrossing *event UNUSED, | |
917 gpointer data UNUSED) | |
7 | 918 { |
919 if (blink_state != BLINK_NONE) | |
920 gui_mch_stop_blink(); | |
921 | |
922 return FALSE; | |
923 } | |
924 | |
925 static gint | |
1884 | 926 focus_in_event(GtkWidget *widget, |
927 GdkEventFocus *event UNUSED, | |
928 gpointer data UNUSED) | |
7 | 929 { |
930 gui_focus_change(TRUE); | |
931 | |
932 if (blink_state == BLINK_NONE) | |
933 gui_mch_start_blink(); | |
934 | |
1380 | 935 /* make sure keyboard input goes to the draw area (if this is focus for a |
936 * window) */ | |
791 | 937 if (widget != gui.drawarea) |
856 | 938 gtk_widget_grab_focus(gui.drawarea); |
7 | 939 |
940 return TRUE; | |
941 } | |
942 | |
943 static gint | |
1884 | 944 focus_out_event(GtkWidget *widget UNUSED, |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2301
diff
changeset
|
945 GdkEventFocus *event UNUSED, |
1884 | 946 gpointer data UNUSED) |
7 | 947 { |
948 gui_focus_change(FALSE); | |
949 | |
950 if (blink_state != BLINK_NONE) | |
951 gui_mch_stop_blink(); | |
952 | |
953 return TRUE; | |
954 } | |
955 | |
956 | |
957 /* | |
958 * Translate a GDK key value to UTF-8 independently of the current locale. | |
959 * The output is written to string, which must have room for at least 6 bytes | |
960 * plus the NUL terminator. Returns the length in bytes. | |
961 * | |
962 * This function is used in the GTK+ 2 GUI only. The GTK+ 1 code makes use | |
963 * of GdkEventKey::string instead. But event->string is evil; see here why: | |
964 * http://developer.gnome.org/doc/API/2.0/gdk/gdk-Event-Structures.html#GdkEventKey | |
965 */ | |
966 static int | |
967 keyval_to_string(unsigned int keyval, unsigned int state, char_u *string) | |
968 { | |
969 int len; | |
970 guint32 uc; | |
971 | |
972 uc = gdk_keyval_to_unicode(keyval); | |
973 if (uc != 0) | |
974 { | |
975 /* Check for CTRL-foo */ | |
976 if ((state & GDK_CONTROL_MASK) && uc >= 0x20 && uc < 0x80) | |
977 { | |
978 /* These mappings look arbitrary at the first glance, but in fact | |
979 * resemble quite exactly the behaviour of the GTK+ 1.2 GUI on my | |
980 * machine. The only difference is BS vs. DEL for CTRL-8 (makes | |
981 * more sense and is consistent with usual terminal behaviour). */ | |
982 if (uc >= '@') | |
983 string[0] = uc & 0x1F; | |
984 else if (uc == '2') | |
985 string[0] = NUL; | |
986 else if (uc >= '3' && uc <= '7') | |
987 string[0] = uc ^ 0x28; | |
988 else if (uc == '8') | |
989 string[0] = BS; | |
990 else if (uc == '?') | |
991 string[0] = DEL; | |
992 else | |
993 string[0] = uc; | |
994 len = 1; | |
995 } | |
996 else | |
997 { | |
998 /* Translate a normal key to UTF-8. This doesn't work for dead | |
999 * keys of course, you _have_ to use an input method for that. */ | |
1000 len = utf_char2bytes((int)uc, string); | |
1001 } | |
1002 } | |
1003 else | |
1004 { | |
1005 /* Translate keys which are represented by ASCII control codes in Vim. | |
1006 * There are only a few of those; most control keys are translated to | |
1007 * special terminal-like control sequences. */ | |
1008 len = 1; | |
1009 switch (keyval) | |
1010 { | |
1011 case GDK_Tab: case GDK_KP_Tab: case GDK_ISO_Left_Tab: | |
1012 string[0] = TAB; | |
1013 break; | |
1014 case GDK_Linefeed: | |
1015 string[0] = NL; | |
1016 break; | |
1017 case GDK_Return: case GDK_ISO_Enter: case GDK_3270_Enter: | |
1018 string[0] = CAR; | |
1019 break; | |
1020 case GDK_Escape: | |
1021 string[0] = ESC; | |
1022 break; | |
1023 default: | |
1024 len = 0; | |
1025 break; | |
1026 } | |
1027 } | |
1028 string[len] = NUL; | |
1029 | |
1030 return len; | |
1031 } | |
1032 | |
179 | 1033 static int |
1034 modifiers_gdk2vim(guint state) | |
1035 { | |
1036 int modifiers = 0; | |
1037 | |
1038 if (state & GDK_SHIFT_MASK) | |
1039 modifiers |= MOD_MASK_SHIFT; | |
1040 if (state & GDK_CONTROL_MASK) | |
1041 modifiers |= MOD_MASK_CTRL; | |
1042 if (state & GDK_MOD1_MASK) | |
1043 modifiers |= MOD_MASK_ALT; | |
2550
7c1f73452ea6
Fix #ifdef for GDK_SUPER_MASK.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
1044 #if GTK_CHECK_VERSION(2,10,0) |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1045 if (state & GDK_SUPER_MASK) |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1046 modifiers |= MOD_MASK_META; |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1047 #endif |
179 | 1048 if (state & GDK_MOD4_MASK) |
1049 modifiers |= MOD_MASK_META; | |
1050 | |
1051 return modifiers; | |
1052 } | |
1053 | |
1054 static int | |
1055 modifiers_gdk2mouse(guint state) | |
1056 { | |
1057 int modifiers = 0; | |
1058 | |
1059 if (state & GDK_SHIFT_MASK) | |
1060 modifiers |= MOUSE_SHIFT; | |
1061 if (state & GDK_CONTROL_MASK) | |
1062 modifiers |= MOUSE_CTRL; | |
1063 if (state & GDK_MOD1_MASK) | |
1064 modifiers |= MOUSE_ALT; | |
1065 | |
1066 return modifiers; | |
1067 } | |
1068 | |
7 | 1069 /* |
1070 * Main keyboard handler: | |
1071 */ | |
1072 static gint | |
1884 | 1073 key_press_event(GtkWidget *widget UNUSED, |
1074 GdkEventKey *event, | |
1075 gpointer data UNUSED) | |
7 | 1076 { |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1077 /* For GTK+ 2 we know for sure how large the string might get. |
7 | 1078 * (That is, up to 6 bytes + NUL + CSI escapes + safety measure.) */ |
1079 char_u string[32], string2[32]; | |
1080 guint key_sym; | |
1081 int len; | |
1082 int i; | |
1083 int modifiers; | |
1084 int key; | |
1085 guint state; | |
1086 char_u *s, *d; | |
1087 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1088 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1089 is_key_pressed = TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1090 gui_mch_stop_blink(); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1091 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1092 |
2923 | 1093 gui.event_time = event->time; |
7 | 1094 key_sym = event->keyval; |
1095 state = event->state; | |
1096 | |
1097 #ifdef FEAT_XIM | |
1098 if (xim_queue_key_press_event(event, TRUE)) | |
1099 return TRUE; | |
1100 #endif | |
1101 | |
1102 #ifdef FEAT_HANGULIN | |
1103 if (key_sym == GDK_space && (state & GDK_SHIFT_MASK)) | |
1104 { | |
1105 hangul_input_state_toggle(); | |
1106 return TRUE; | |
1107 } | |
1108 #endif | |
1109 | |
1110 #ifdef SunXK_F36 | |
1111 /* | |
1112 * These keys have bogus lookup strings, and trapping them here is | |
1113 * easier than trying to XRebindKeysym() on them with every possible | |
1114 * combination of modifiers. | |
1115 */ | |
1116 if (key_sym == SunXK_F36 || key_sym == SunXK_F37) | |
1117 len = 0; | |
1118 else | |
1119 #endif | |
1120 { | |
1121 len = keyval_to_string(key_sym, state, string2); | |
1122 | |
1123 /* Careful: convert_input() doesn't handle the NUL character. | |
1124 * No need to convert pure ASCII anyway, thus the len > 1 check. */ | |
1125 if (len > 1 && input_conv.vc_type != CONV_NONE) | |
1126 len = convert_input(string2, len, sizeof(string2)); | |
1127 | |
1128 s = string2; | |
1129 d = string; | |
1130 for (i = 0; i < len; ++i) | |
1131 { | |
1132 *d++ = s[i]; | |
1133 if (d[-1] == CSI && d + 2 < string + sizeof(string)) | |
1134 { | |
1135 /* Turn CSI into K_CSI. */ | |
1136 *d++ = KS_EXTRA; | |
1137 *d++ = (int)KE_CSI; | |
1138 } | |
1139 } | |
1140 len = d - string; | |
1141 } | |
1142 | |
1143 /* Shift-Tab results in Left_Tab, but we want <S-Tab> */ | |
1144 if (key_sym == GDK_ISO_Left_Tab) | |
1145 { | |
1146 key_sym = GDK_Tab; | |
1147 state |= GDK_SHIFT_MASK; | |
1148 } | |
1149 | |
1150 #ifdef FEAT_MENU | |
1151 /* If there is a menu and 'wak' is "yes", or 'wak' is "menu" and the key | |
1152 * is a menu shortcut, we ignore everything with the ALT modifier. */ | |
1153 if ((state & GDK_MOD1_MASK) | |
1154 && gui.menu_is_active | |
1155 && (*p_wak == 'y' | |
1156 || (*p_wak == 'm' | |
1157 && len == 1 | |
1158 && gui_is_menu_shortcut(string[0])))) | |
1159 /* For GTK2 we return false to signify that we haven't handled the | |
1160 * keypress, so that gtk will handle the mnemonic or accelerator. */ | |
1161 return FALSE; | |
1162 #endif | |
1163 | |
1164 /* Check for Alt/Meta key (Mod1Mask), but not for a BS, DEL or character | |
1165 * that already has the 8th bit set. | |
1166 * Don't do this for <S-M-Tab>, that should become K_S_TAB with ALT. | |
1167 * Don't do this for double-byte encodings, it turns the char into a lead | |
1168 * byte. */ | |
1169 if (len == 1 | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1170 && ((state & GDK_MOD1_MASK) |
2571
42bdbc2bbb59
Fix #ifdef for GDK_SUPER_MASK. (Stephan Schulz)
Bram Moolenaar <bram@vim.org>
parents:
2550
diff
changeset
|
1171 #if GTK_CHECK_VERSION(2,10,0) |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1172 || (state & GDK_SUPER_MASK) |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1173 #endif |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1174 ) |
7 | 1175 && !(key_sym == GDK_BackSpace || key_sym == GDK_Delete) |
1176 && (string[0] & 0x80) == 0 | |
1177 && !(key_sym == GDK_Tab && (state & GDK_SHIFT_MASK)) | |
1178 && !enc_dbcs | |
1179 ) | |
1180 { | |
1181 string[0] |= 0x80; | |
1182 state &= ~GDK_MOD1_MASK; /* don't use it again */ | |
1183 if (enc_utf8) /* convert to utf-8 */ | |
1184 { | |
1185 string[1] = string[0] & 0xbf; | |
1186 string[0] = ((unsigned)string[0] >> 6) + 0xc0; | |
1187 if (string[1] == CSI) | |
1188 { | |
1189 string[2] = KS_EXTRA; | |
1190 string[3] = (int)KE_CSI; | |
1191 len = 4; | |
1192 } | |
1193 else | |
1194 len = 2; | |
1195 } | |
1196 } | |
1197 | |
1198 /* Check for special keys. Also do this when len == 1 (key has an ASCII | |
1199 * value) to detect backspace, delete and keypad keys. */ | |
1200 if (len == 0 || len == 1) | |
1201 { | |
1202 for (i = 0; special_keys[i].key_sym != 0; i++) | |
1203 { | |
1204 if (special_keys[i].key_sym == key_sym) | |
1205 { | |
1206 string[0] = CSI; | |
1207 string[1] = special_keys[i].code0; | |
1208 string[2] = special_keys[i].code1; | |
1209 len = -3; | |
1210 break; | |
1211 } | |
1212 } | |
1213 } | |
1214 | |
1215 if (len == 0) /* Unrecognized key */ | |
1216 return TRUE; | |
1217 | |
1218 /* Special keys (and a few others) may have modifiers. Also when using a | |
1219 * double-byte encoding (can't set the 8th bit). */ | |
1220 if (len == -3 || key_sym == GDK_space || key_sym == GDK_Tab | |
1221 || key_sym == GDK_Return || key_sym == GDK_Linefeed | |
1222 || key_sym == GDK_Escape || key_sym == GDK_KP_Tab | |
1223 || key_sym == GDK_ISO_Enter || key_sym == GDK_3270_Enter | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1224 || (enc_dbcs && len == 1 && ((state & GDK_MOD1_MASK) |
2571
42bdbc2bbb59
Fix #ifdef for GDK_SUPER_MASK. (Stephan Schulz)
Bram Moolenaar <bram@vim.org>
parents:
2550
diff
changeset
|
1225 #if GTK_CHECK_VERSION(2,10,0) |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1226 || (state & GDK_SUPER_MASK) |
7 | 1227 #endif |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1228 ))) |
7 | 1229 { |
179 | 1230 modifiers = modifiers_gdk2vim(state); |
7 | 1231 |
1232 /* | |
1233 * For some keys a shift modifier is translated into another key | |
1234 * code. | |
1235 */ | |
1236 if (len == -3) | |
1237 key = TO_SPECIAL(string[1], string[2]); | |
1238 else | |
1239 key = string[0]; | |
1240 | |
1241 key = simplify_key(key, &modifiers); | |
1242 if (key == CSI) | |
1243 key = K_CSI; | |
1244 if (IS_SPECIAL(key)) | |
1245 { | |
1246 string[0] = CSI; | |
1247 string[1] = K_SECOND(key); | |
1248 string[2] = K_THIRD(key); | |
1249 len = 3; | |
1250 } | |
1251 else | |
1252 { | |
1253 string[0] = key; | |
1254 len = 1; | |
1255 } | |
1256 | |
1257 if (modifiers != 0) | |
1258 { | |
1259 string2[0] = CSI; | |
1260 string2[1] = KS_MODIFIER; | |
1261 string2[2] = modifiers; | |
1262 add_to_input_buf(string2, 3); | |
1263 } | |
1264 } | |
1265 | |
1266 if (len == 1 && ((string[0] == Ctrl_C && ctrl_c_interrupts) | |
1267 || (string[0] == intr_char && intr_char != Ctrl_C))) | |
1268 { | |
1269 trash_input_buf(); | |
1270 got_int = TRUE; | |
1271 } | |
1272 | |
1273 add_to_input_buf(string, len); | |
1274 | |
1275 /* blank out the pointer if necessary */ | |
1276 if (p_mh) | |
1277 gui_mch_mousehide(TRUE); | |
1278 | |
1279 return TRUE; | |
1280 } | |
1281 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1282 #if defined(FEAT_XIM) || GTK_CHECK_VERSION(3,0,0) |
7 | 1283 static gboolean |
1884 | 1284 key_release_event(GtkWidget *widget UNUSED, |
1285 GdkEventKey *event, | |
1286 gpointer data UNUSED) | |
7 | 1287 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1288 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1289 is_key_pressed = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1290 gui_mch_start_blink(); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1291 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1292 # if defined(FEAT_XIM) |
2923 | 1293 gui.event_time = event->time; |
7 | 1294 /* |
1295 * GTK+ 2 input methods may do fancy stuff on key release events too. | |
1296 * With the default IM for instance, you can enter any UCS code point | |
1297 * by holding down CTRL-SHIFT and typing hexadecimal digits. | |
1298 */ | |
1299 return xim_queue_key_press_event(event, FALSE); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1300 # else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1301 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1302 # endif |
7 | 1303 } |
1304 #endif | |
1305 | |
1306 | |
1307 /**************************************************************************** | |
1308 * Selection handlers: | |
1309 */ | |
1310 | |
1311 static gint | |
1884 | 1312 selection_clear_event(GtkWidget *widget UNUSED, |
7 | 1313 GdkEventSelection *event, |
1884 | 1314 gpointer user_data UNUSED) |
7 | 1315 { |
1316 if (event->selection == clip_plus.gtk_sel_atom) | |
1317 clip_lose_selection(&clip_plus); | |
1318 else | |
1319 clip_lose_selection(&clip_star); | |
1320 | |
1321 return TRUE; | |
1322 } | |
1323 | |
1324 #define RS_NONE 0 /* selection_received_cb() not called yet */ | |
1325 #define RS_OK 1 /* selection_received_cb() called and OK */ | |
1326 #define RS_FAIL 2 /* selection_received_cb() called and failed */ | |
1327 static int received_selection = RS_NONE; | |
1328 | |
1329 static void | |
1884 | 1330 selection_received_cb(GtkWidget *widget UNUSED, |
7 | 1331 GtkSelectionData *data, |
1884 | 1332 guint time_ UNUSED, |
1333 gpointer user_data UNUSED) | |
7 | 1334 { |
1335 VimClipboard *cbd; | |
1336 char_u *text; | |
1337 char_u *tmpbuf = NULL; | |
1338 guchar *tmpbuf_utf8 = NULL; | |
1339 int len; | |
2896 | 1340 int motion_type = MAUTO; |
7 | 1341 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1342 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1343 if (gtk_selection_data_get_selection(data) == clip_plus.gtk_sel_atom) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1344 #else |
7 | 1345 if (data->selection == clip_plus.gtk_sel_atom) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1346 #endif |
7 | 1347 cbd = &clip_plus; |
1348 else | |
1349 cbd = &clip_star; | |
1350 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1351 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1352 text = (char_u *)gtk_selection_data_get_data(data); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1353 len = gtk_selection_data_get_length(data); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1354 #else |
7 | 1355 text = (char_u *)data->data; |
1356 len = data->length; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1357 #endif |
7 | 1358 |
1359 if (text == NULL || len <= 0) | |
1360 { | |
1361 received_selection = RS_FAIL; | |
1362 /* clip_free_selection(cbd); ??? */ | |
1363 | |
1364 return; | |
1365 } | |
1366 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1367 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1368 if (gtk_selection_data_get_data_type(data) == vim_atom) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1369 #else |
7 | 1370 if (data->type == vim_atom) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1371 #endif |
7 | 1372 { |
1373 motion_type = *text++; | |
1374 --len; | |
1375 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1376 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1377 else if (gtk_selection_data_get_data_type(data) == vimenc_atom) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1378 #else |
7 | 1379 else if (data->type == vimenc_atom) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1380 #endif |
7 | 1381 { |
1382 char_u *enc; | |
1383 vimconv_T conv; | |
1384 | |
1385 motion_type = *text++; | |
1386 --len; | |
1387 | |
1388 enc = text; | |
1389 text += STRLEN(text) + 1; | |
1390 len -= text - enc; | |
1391 | |
1392 /* If the encoding of the text is different from 'encoding', attempt | |
1393 * converting it. */ | |
1394 conv.vc_type = CONV_NONE; | |
1395 convert_setup(&conv, enc, p_enc); | |
1396 if (conv.vc_type != CONV_NONE) | |
1397 { | |
1398 tmpbuf = string_convert(&conv, text, &len); | |
1399 if (tmpbuf != NULL) | |
1400 text = tmpbuf; | |
1401 convert_setup(&conv, NULL, NULL); | |
1402 } | |
1403 } | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1404 |
7 | 1405 /* gtk_selection_data_get_text() handles all the nasty details |
1406 * and targets and encodings etc. This rocks so hard. */ | |
1407 else | |
1408 { | |
1409 tmpbuf_utf8 = gtk_selection_data_get_text(data); | |
1410 if (tmpbuf_utf8 != NULL) | |
1411 { | |
1412 len = STRLEN(tmpbuf_utf8); | |
1413 if (input_conv.vc_type != CONV_NONE) | |
1414 { | |
1415 tmpbuf = string_convert(&input_conv, tmpbuf_utf8, &len); | |
1416 if (tmpbuf != NULL) | |
1417 text = tmpbuf; | |
1418 } | |
1419 else | |
1420 text = tmpbuf_utf8; | |
1421 } | |
1904 | 1422 else if (len >= 2 && text[0] == 0xff && text[1] == 0xfe) |
1423 { | |
1424 vimconv_T conv; | |
1425 | |
1426 /* UTF-16, we get this for HTML */ | |
1427 conv.vc_type = CONV_NONE; | |
1428 convert_setup_ext(&conv, (char_u *)"utf-16le", FALSE, p_enc, TRUE); | |
1429 | |
1430 if (conv.vc_type != CONV_NONE) | |
1431 { | |
1432 text += 2; | |
1433 len -= 2; | |
1434 tmpbuf = string_convert(&conv, text, &len); | |
1435 convert_setup(&conv, NULL, NULL); | |
1436 } | |
1437 if (tmpbuf != NULL) | |
1438 text = tmpbuf; | |
1439 } | |
7 | 1440 } |
1441 | |
4352 | 1442 /* Chop off any trailing NUL bytes. OpenOffice sends these. */ |
2183 | 1443 while (len > 0 && text[len - 1] == NUL) |
1444 --len; | |
1445 | |
7 | 1446 clip_yank_selection(motion_type, text, (long)len, cbd); |
1447 received_selection = RS_OK; | |
1448 vim_free(tmpbuf); | |
1449 g_free(tmpbuf_utf8); | |
1450 } | |
1451 | |
1452 /* | |
1453 * Prepare our selection data for passing it to the external selection | |
1454 * client. | |
1455 */ | |
1456 static void | |
1884 | 1457 selection_get_cb(GtkWidget *widget UNUSED, |
7 | 1458 GtkSelectionData *selection_data, |
1459 guint info, | |
1884 | 1460 guint time_ UNUSED, |
1461 gpointer user_data UNUSED) | |
7 | 1462 { |
1463 char_u *string; | |
1464 char_u *tmpbuf; | |
1465 long_u tmplen; | |
1466 int length; | |
1467 int motion_type; | |
1468 GdkAtom type; | |
1469 VimClipboard *cbd; | |
1470 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1471 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1472 if (gtk_selection_data_get_selection(selection_data) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1473 == clip_plus.gtk_sel_atom) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1474 #else |
7 | 1475 if (selection_data->selection == clip_plus.gtk_sel_atom) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1476 #endif |
7 | 1477 cbd = &clip_plus; |
1478 else | |
1479 cbd = &clip_star; | |
1480 | |
1481 if (!cbd->owned) | |
1482 return; /* Shouldn't ever happen */ | |
1483 | |
1484 if (info != (guint)TARGET_STRING | |
1904 | 1485 && (!clip_html || info != (guint)TARGET_HTML) |
7 | 1486 && info != (guint)TARGET_UTF8_STRING |
1487 && info != (guint)TARGET_VIMENC | |
1488 && info != (guint)TARGET_VIM | |
1489 && info != (guint)TARGET_COMPOUND_TEXT | |
1490 && info != (guint)TARGET_TEXT) | |
1491 return; | |
1492 | |
1493 /* get the selection from the '*'/'+' register */ | |
1494 clip_get_selection(cbd); | |
1495 | |
1496 motion_type = clip_convert_selection(&string, &tmplen, cbd); | |
1497 if (motion_type < 0 || string == NULL) | |
1498 return; | |
1499 /* Due to int arguments we can't handle more than G_MAXINT. Also | |
1500 * reserve one extra byte for NUL or the motion type; just in case. | |
1501 * (Not that pasting 2G of text is ever going to work, but... ;-) */ | |
1502 length = MIN(tmplen, (long_u)(G_MAXINT - 1)); | |
1503 | |
1504 if (info == (guint)TARGET_VIM) | |
1505 { | |
1506 tmpbuf = alloc((unsigned)length + 1); | |
1507 if (tmpbuf != NULL) | |
1508 { | |
1509 tmpbuf[0] = motion_type; | |
1510 mch_memmove(tmpbuf + 1, string, (size_t)length); | |
1511 } | |
1512 /* For our own format, the first byte contains the motion type */ | |
1513 ++length; | |
1514 vim_free(string); | |
1515 string = tmpbuf; | |
1516 type = vim_atom; | |
1517 } | |
1518 | |
1904 | 1519 else if (info == (guint)TARGET_HTML) |
1520 { | |
1521 vimconv_T conv; | |
1522 | |
1523 /* Since we get utf-16, we probably should set it as well. */ | |
1524 conv.vc_type = CONV_NONE; | |
1525 convert_setup_ext(&conv, p_enc, TRUE, (char_u *)"utf-16le", FALSE); | |
1526 if (conv.vc_type != CONV_NONE) | |
1527 { | |
1528 tmpbuf = string_convert(&conv, string, &length); | |
1529 convert_setup(&conv, NULL, NULL); | |
1530 vim_free(string); | |
1531 string = tmpbuf; | |
1532 } | |
1533 | |
1534 /* Prepend the BOM: "fffe" */ | |
1535 if (string != NULL) | |
1536 { | |
1537 tmpbuf = alloc(length + 2); | |
1538 tmpbuf[0] = 0xff; | |
1539 tmpbuf[1] = 0xfe; | |
1540 mch_memmove(tmpbuf + 2, string, (size_t)length); | |
1541 vim_free(string); | |
1542 string = tmpbuf; | |
1543 length += 2; | |
1544 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1545 #if !GTK_CHECK_VERSION(3,0,0) |
8301
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
1546 /* Looks redundant even for GTK2 because these values are |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1547 * overwritten by gtk_selection_data_set() that follows. */ |
1904 | 1548 selection_data->type = selection_data->target; |
1549 selection_data->format = 16; /* 16 bits per char */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1550 #endif |
1904 | 1551 gtk_selection_data_set(selection_data, html_atom, 16, |
1552 string, length); | |
1553 vim_free(string); | |
1554 } | |
1555 return; | |
1556 } | |
7 | 1557 else if (info == (guint)TARGET_VIMENC) |
1558 { | |
1559 int l = STRLEN(p_enc); | |
1560 | |
1561 /* contents: motion_type 'encoding' NUL text */ | |
1562 tmpbuf = alloc((unsigned)length + l + 2); | |
1563 if (tmpbuf != NULL) | |
1564 { | |
1565 tmpbuf[0] = motion_type; | |
1566 STRCPY(tmpbuf + 1, p_enc); | |
1567 mch_memmove(tmpbuf + l + 2, string, (size_t)length); | |
1568 } | |
1569 length += l + 2; | |
1570 vim_free(string); | |
1571 string = tmpbuf; | |
1572 type = vimenc_atom; | |
1573 } | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1574 |
7 | 1575 /* gtk_selection_data_set_text() handles everything for us. This is |
1576 * so easy and simple and cool, it'd be insane not to use it. */ | |
1577 else | |
1578 { | |
1579 if (output_conv.vc_type != CONV_NONE) | |
1580 { | |
1581 tmpbuf = string_convert(&output_conv, string, &length); | |
1582 vim_free(string); | |
1583 if (tmpbuf == NULL) | |
1584 return; | |
1585 string = tmpbuf; | |
1586 } | |
1587 /* Validate the string to avoid runtime warnings */ | |
1588 if (g_utf8_validate((const char *)string, (gssize)length, NULL)) | |
1589 { | |
1590 gtk_selection_data_set_text(selection_data, | |
1591 (const char *)string, length); | |
1592 } | |
1593 vim_free(string); | |
1594 return; | |
1595 } | |
1596 | |
1597 if (string != NULL) | |
1598 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1599 #if !GTK_CHECK_VERSION(3,0,0) |
8301
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
1600 /* Looks redundant even for GTK2 because these values are |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1601 * overwritten by gtk_selection_data_set() that follows. */ |
7 | 1602 selection_data->type = selection_data->target; |
1603 selection_data->format = 8; /* 8 bits per char */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1604 #endif |
7 | 1605 gtk_selection_data_set(selection_data, type, 8, string, length); |
1606 vim_free(string); | |
1607 } | |
1608 } | |
1609 | |
1610 /* | |
3518 | 1611 * Check if the GUI can be started. Called before gvimrc is sourced and |
1612 * before fork(). | |
1613 * Return OK or FAIL. | |
1614 */ | |
1615 int | |
1616 gui_mch_early_init_check(void) | |
1617 { | |
1618 char_u *p; | |
1619 | |
1620 /* Guess that when $DISPLAY isn't set the GUI can't start. */ | |
1621 p = mch_getenv((char_u *)"DISPLAY"); | |
1622 if (p == NULL || *p == NUL) | |
1623 { | |
1624 gui.dying = TRUE; | |
1625 EMSG(_((char *)e_opendisp)); | |
1626 return FAIL; | |
1627 } | |
1628 return OK; | |
1629 } | |
1630 | |
1631 /* | |
1632 * Check if the GUI can be started. Called before gvimrc is sourced but after | |
1633 * fork(). | |
7 | 1634 * Return OK or FAIL. |
1635 */ | |
1636 int | |
1637 gui_mch_init_check(void) | |
1638 { | |
7679
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1639 #ifdef USE_GRESOURCE |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1640 static int res_registered = FALSE; |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1641 |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1642 if (!res_registered) |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1643 { |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1644 /* Call this function in the GUI process; otherwise, the resources |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1645 * won't be available. Don't call it twice. */ |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1646 res_registered = TRUE; |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1647 gui_gtk_register_resource(); |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1648 } |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1649 #endif |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1650 |
7 | 1651 #ifdef FEAT_GUI_GNOME |
1652 if (gtk_socket_id == 0) | |
1653 using_gnome = 1; | |
1654 #endif | |
1655 | |
4474 | 1656 /* This defaults to argv[0], but we want it to match the name of the |
1657 * shipped gvim.desktop so that Vim's windows can be associated with this | |
1658 * file. */ | |
1659 g_set_prgname("gvim"); | |
1660 | |
7 | 1661 /* Don't use gtk_init() or gnome_init(), it exits on failure. */ |
1662 if (!gtk_init_check(&gui_argc, &gui_argv)) | |
1663 { | |
1664 gui.dying = TRUE; | |
1666 | 1665 EMSG(_((char *)e_opendisp)); |
7 | 1666 return FAIL; |
1667 } | |
1668 | |
1669 return OK; | |
1670 } | |
1671 | |
1672 | |
1673 /**************************************************************************** | |
1674 * Mouse handling callbacks | |
1675 */ | |
1676 | |
1677 | |
1678 static guint mouse_click_timer = 0; | |
1679 static int mouse_timed_out = TRUE; | |
1680 | |
1681 /* | |
1682 * Timer used to recognize multiple clicks of the mouse button | |
1683 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1684 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1685 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1686 #else |
7 | 1687 static gint |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1688 #endif |
7 | 1689 mouse_click_timer_cb(gpointer data) |
1690 { | |
1691 /* we don't use this information currently */ | |
1692 int *timed_out = (int *) data; | |
1693 | |
1694 *timed_out = TRUE; | |
1695 return FALSE; /* don't happen again */ | |
1696 } | |
1697 | |
1698 static guint motion_repeat_timer = 0; | |
1699 static int motion_repeat_offset = FALSE; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1700 #ifdef GTK_DEST_DEFAULT_ALL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1701 static gboolean motion_repeat_timer_cb(gpointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1702 #else |
7 | 1703 static gint motion_repeat_timer_cb(gpointer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1704 #endif |
7 | 1705 |
1706 static void | |
1707 process_motion_notify(int x, int y, GdkModifierType state) | |
1708 { | |
1709 int button; | |
1710 int_u vim_modifiers; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1711 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1712 GtkAllocation allocation; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1713 #endif |
7 | 1714 |
1715 button = (state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | | |
1716 GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | | |
1717 GDK_BUTTON5_MASK)) | |
1718 ? MOUSE_DRAG : ' '; | |
1719 | |
1720 /* If our pointer is currently hidden, then we should show it. */ | |
1721 gui_mch_mousehide(FALSE); | |
1722 | |
1723 /* Just moving the rodent above the drawing area without any button | |
1724 * being pressed. */ | |
1725 if (button != MOUSE_DRAG) | |
1726 { | |
1727 gui_mouse_moved(x, y); | |
1728 return; | |
1729 } | |
1730 | |
1731 /* translate modifier coding between the main engine and GTK */ | |
179 | 1732 vim_modifiers = modifiers_gdk2mouse(state); |
7 | 1733 |
1226 | 1734 /* inform the editor engine about the occurrence of this event */ |
7 | 1735 gui_send_mouse_event(button, x, y, FALSE, vim_modifiers); |
1736 | |
1737 /* | |
1738 * Auto repeat timer handling. | |
1739 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1740 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1741 gtk_widget_get_allocation(gui.drawarea, &allocation); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1742 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1743 if (x < 0 || y < 0 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1744 || x >= allocation.width |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1745 || y >= allocation.height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1746 #else |
7 | 1747 if (x < 0 || y < 0 |
1748 || x >= gui.drawarea->allocation.width | |
1749 || y >= gui.drawarea->allocation.height) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1750 #endif |
7 | 1751 { |
1752 | |
1753 int dx; | |
1754 int dy; | |
1755 int offshoot; | |
1756 int delay = 10; | |
1757 | |
1758 /* Calculate the maximal distance of the cursor from the drawing area. | |
1759 * (offshoot can't become negative here!). | |
1760 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1761 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1762 dx = x < 0 ? -x : x - allocation.width; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1763 dy = y < 0 ? -y : y - allocation.height; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1764 #else |
7 | 1765 dx = x < 0 ? -x : x - gui.drawarea->allocation.width; |
1766 dy = y < 0 ? -y : y - gui.drawarea->allocation.height; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1767 #endif |
7 | 1768 |
1769 offshoot = dx > dy ? dx : dy; | |
1770 | |
1884 | 1771 /* Make a linearly decaying timer delay with a threshold of 5 at a |
7 | 1772 * distance of 127 pixels from the main window. |
1773 * | |
1774 * One could think endlessly about the most ergonomic variant here. | |
1775 * For example it could make sense to calculate the distance from the | |
1776 * drags start instead... | |
1777 * | |
1778 * Maybe a parabolic interpolation would suite us better here too... | |
1779 */ | |
1780 if (offshoot > 127) | |
1781 { | |
1782 /* 5 appears to be somehow near to my perceptual limits :-). */ | |
1783 delay = 5; | |
1784 } | |
1785 else | |
1786 { | |
1787 delay = (130 * (127 - offshoot)) / 127 + 5; | |
1788 } | |
1789 | |
1790 /* shoot again */ | |
1791 if (!motion_repeat_timer) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1792 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1793 motion_repeat_timer = g_timeout_add((guint)delay, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1794 motion_repeat_timer_cb, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1795 #else |
7 | 1796 motion_repeat_timer = gtk_timeout_add((guint32)delay, |
1797 motion_repeat_timer_cb, NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1798 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1799 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1800 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1801 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1802 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1803 static GdkDevice * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1804 gui_gtk_get_pointer_device(GtkWidget *widget) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1805 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1806 GdkWindow * const win = gtk_widget_get_window(widget); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1807 GdkDisplay * const dpy = gdk_window_get_display(win); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1808 GdkDeviceManager * const mngr = gdk_display_get_device_manager(dpy); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1809 return gdk_device_manager_get_client_pointer(mngr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1810 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1811 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1812 static GdkWindow * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1813 gui_gtk_get_pointer(GtkWidget *widget, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1814 gint *x, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1815 gint *y, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1816 GdkModifierType *state) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1817 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1818 GdkWindow * const win = gtk_widget_get_window(widget); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1819 GdkDevice * const dev = gui_gtk_get_pointer_device(widget); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1820 return gdk_window_get_device_position(win, dev , x, y, state); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1821 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1822 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1823 static GdkWindow * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1824 gui_gtk_window_at_position(GtkWidget *widget, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1825 gint *x, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1826 gint *y) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1827 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1828 GdkDevice * const dev = gui_gtk_get_pointer_device(widget); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1829 return gdk_device_get_window_at_position(dev, x, y); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1830 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1831 #endif |
7 | 1832 |
1833 /* | |
1834 * Timer used to recognize multiple clicks of the mouse button. | |
1835 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1836 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1837 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1838 #else |
7 | 1839 static gint |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1840 #endif |
1884 | 1841 motion_repeat_timer_cb(gpointer data UNUSED) |
7 | 1842 { |
1843 int x; | |
1844 int y; | |
1845 GdkModifierType state; | |
1846 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1847 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1848 gui_gtk_get_pointer(gui.drawarea, &x, &y, &state); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1849 #else |
7 | 1850 gdk_window_get_pointer(gui.drawarea->window, &x, &y, &state); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1851 #endif |
7 | 1852 |
1853 if (!(state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | | |
1854 GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | | |
1855 GDK_BUTTON5_MASK))) | |
1856 { | |
1857 motion_repeat_timer = 0; | |
1858 return FALSE; | |
1859 } | |
1860 | |
1861 /* If there already is a mouse click in the input buffer, wait another | |
1862 * time (otherwise we would create a backlog of clicks) */ | |
1863 if (vim_used_in_input_buf() > 10) | |
1864 return TRUE; | |
1865 | |
1866 motion_repeat_timer = 0; | |
1867 | |
1868 /* | |
1869 * Fake a motion event. | |
1870 * Trick: Pretend the mouse moved to the next character on every other | |
1871 * event, otherwise drag events will be discarded, because they are still | |
1872 * in the same character. | |
1873 */ | |
1874 if (motion_repeat_offset) | |
1875 x += gui.char_width; | |
1876 | |
1877 motion_repeat_offset = !motion_repeat_offset; | |
1878 process_motion_notify(x, y, state); | |
1879 | |
1880 /* Don't happen again. We will get reinstalled in the synthetic event | |
1881 * if needed -- thus repeating should still work. */ | |
1882 return FALSE; | |
1883 } | |
1884 | |
1885 static gint | |
1884 | 1886 motion_notify_event(GtkWidget *widget, |
1887 GdkEventMotion *event, | |
1888 gpointer data UNUSED) | |
7 | 1889 { |
1890 if (event->is_hint) | |
1891 { | |
1892 int x; | |
1893 int y; | |
1894 GdkModifierType state; | |
1895 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1896 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1897 gui_gtk_get_pointer(widget, &x, &y, &state); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1898 #else |
7 | 1899 gdk_window_get_pointer(widget->window, &x, &y, &state); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1900 #endif |
7 | 1901 process_motion_notify(x, y, state); |
1902 } | |
1903 else | |
1904 { | |
1905 process_motion_notify((int)event->x, (int)event->y, | |
1906 (GdkModifierType)event->state); | |
1907 } | |
1908 | |
1909 return TRUE; /* handled */ | |
1910 } | |
1911 | |
1912 | |
1913 /* | |
1914 * Mouse button handling. Note please that we are capturing multiple click's | |
1915 * by our own timeout mechanism instead of the one provided by GTK+ itself. | |
1916 * This is due to the way the generic VIM code is recognizing multiple clicks. | |
1917 */ | |
1918 static gint | |
1884 | 1919 button_press_event(GtkWidget *widget, |
1920 GdkEventButton *event, | |
1921 gpointer data UNUSED) | |
7 | 1922 { |
1923 int button; | |
1924 int repeated_click = FALSE; | |
1925 int x, y; | |
1926 int_u vim_modifiers; | |
1927 | |
2923 | 1928 gui.event_time = event->time; |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2254
diff
changeset
|
1929 |
7 | 1930 /* Make sure we have focus now we've been selected */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1931 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1932 if (gtk_socket_id != 0 && !gtk_widget_has_focus(widget)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1933 #else |
7 | 1934 if (gtk_socket_id != 0 && !GTK_WIDGET_HAS_FOCUS(widget)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1935 #endif |
7 | 1936 gtk_widget_grab_focus(widget); |
1937 | |
1938 /* | |
1939 * Don't let additional events about multiple clicks send by GTK to us | |
1940 * after the initial button press event confuse us. | |
1941 */ | |
1942 if (event->type != GDK_BUTTON_PRESS) | |
1943 return FALSE; | |
1944 | |
1945 x = event->x; | |
1946 y = event->y; | |
1947 | |
1948 /* Handle multiple clicks */ | |
1949 if (!mouse_timed_out && mouse_click_timer) | |
1950 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1951 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1952 g_source_remove(mouse_click_timer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1953 #else |
7 | 1954 gtk_timeout_remove(mouse_click_timer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1955 #endif |
7 | 1956 mouse_click_timer = 0; |
1957 repeated_click = TRUE; | |
1958 } | |
1959 | |
1960 mouse_timed_out = FALSE; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1961 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1962 mouse_click_timer = g_timeout_add((guint)p_mouset, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1963 mouse_click_timer_cb, &mouse_timed_out); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1964 #else |
7 | 1965 mouse_click_timer = gtk_timeout_add((guint32)p_mouset, |
1966 mouse_click_timer_cb, &mouse_timed_out); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1967 #endif |
7 | 1968 |
1969 switch (event->button) | |
1970 { | |
7260
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1971 /* Keep in sync with gui_x11.c. |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1972 * Buttons 4-7 are handled in scroll_event() */ |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1973 case 1: button = MOUSE_LEFT; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1974 case 2: button = MOUSE_MIDDLE; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1975 case 3: button = MOUSE_RIGHT; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1976 case 8: button = MOUSE_X1; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1977 case 9: button = MOUSE_X2; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1978 default: |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1979 return FALSE; /* Unknown button */ |
7 | 1980 } |
1981 | |
1982 #ifdef FEAT_XIM | |
1983 /* cancel any preediting */ | |
1984 if (im_is_preediting()) | |
1985 xim_reset(); | |
1986 #endif | |
1987 | |
179 | 1988 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 1989 |
1990 gui_send_mouse_event(button, x, y, repeated_click, vim_modifiers); | |
1991 | |
1992 return TRUE; | |
1993 } | |
1994 | |
1995 /* | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1996 * GTK+ 2 abstracts scrolling via the GdkEventScroll. |
7 | 1997 */ |
1998 static gboolean | |
1884 | 1999 scroll_event(GtkWidget *widget, |
2000 GdkEventScroll *event, | |
2001 gpointer data UNUSED) | |
7 | 2002 { |
2003 int button; | |
179 | 2004 int_u vim_modifiers; |
7 | 2005 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2006 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2007 if (gtk_socket_id != 0 && !gtk_widget_has_focus(widget)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2008 #else |
7 | 2009 if (gtk_socket_id != 0 && !GTK_WIDGET_HAS_FOCUS(widget)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2010 #endif |
7 | 2011 gtk_widget_grab_focus(widget); |
2012 | |
2013 switch (event->direction) | |
2014 { | |
2015 case GDK_SCROLL_UP: | |
2016 button = MOUSE_4; | |
2017 break; | |
2018 case GDK_SCROLL_DOWN: | |
2019 button = MOUSE_5; | |
2020 break; | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2021 case GDK_SCROLL_LEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2022 button = MOUSE_7; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2023 break; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2024 case GDK_SCROLL_RIGHT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2025 button = MOUSE_6; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2026 break; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2027 default: /* This shouldn't happen */ |
7 | 2028 return FALSE; |
2029 } | |
2030 | |
2031 # ifdef FEAT_XIM | |
2032 /* cancel any preediting */ | |
2033 if (im_is_preediting()) | |
2034 xim_reset(); | |
2035 # endif | |
2036 | |
179 | 2037 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 2038 |
2039 gui_send_mouse_event(button, (int)event->x, (int)event->y, | |
2040 FALSE, vim_modifiers); | |
2041 | |
2042 return TRUE; | |
2043 } | |
2044 | |
2045 | |
2046 static gint | |
1884 | 2047 button_release_event(GtkWidget *widget UNUSED, |
2048 GdkEventButton *event, | |
2049 gpointer data UNUSED) | |
7 | 2050 { |
2051 int x, y; | |
2052 int_u vim_modifiers; | |
2053 | |
2923 | 2054 gui.event_time = event->time; |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2254
diff
changeset
|
2055 |
7 | 2056 /* Remove any motion "machine gun" timers used for automatic further |
2057 extension of allocation areas if outside of the applications window | |
2058 area .*/ | |
2059 if (motion_repeat_timer) | |
2060 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2061 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2062 g_source_remove(motion_repeat_timer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2063 #else |
7 | 2064 gtk_timeout_remove(motion_repeat_timer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2065 #endif |
7 | 2066 motion_repeat_timer = 0; |
2067 } | |
2068 | |
2069 x = event->x; | |
2070 y = event->y; | |
2071 | |
179 | 2072 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 2073 |
2074 gui_send_mouse_event(MOUSE_RELEASE, x, y, FALSE, vim_modifiers); | |
2075 | |
2076 return TRUE; | |
2077 } | |
2078 | |
2079 | |
2080 #ifdef FEAT_DND | |
2081 /**************************************************************************** | |
2082 * Drag aNd Drop support handlers. | |
2083 */ | |
2084 | |
2085 /* | |
2086 * Count how many items there may be and separate them with a NUL. | |
2087 * Apparently the items are separated with \r\n. This is not documented, | |
2088 * thus be careful not to go past the end. Also allow separation with | |
2089 * NUL characters. | |
2090 */ | |
2091 static int | |
2092 count_and_decode_uri_list(char_u *out, char_u *raw, int len) | |
2093 { | |
2094 int i; | |
2095 char_u *p = out; | |
2096 int count = 0; | |
2097 | |
2098 for (i = 0; i < len; ++i) | |
2099 { | |
2100 if (raw[i] == NUL || raw[i] == '\n' || raw[i] == '\r') | |
2101 { | |
2102 if (p > out && p[-1] != NUL) | |
2103 { | |
2104 ++count; | |
2105 *p++ = NUL; | |
2106 } | |
2107 } | |
2108 else if (raw[i] == '%' && i + 2 < len && hexhex2nr(raw + i + 1) > 0) | |
2109 { | |
2110 *p++ = hexhex2nr(raw + i + 1); | |
2111 i += 2; | |
2112 } | |
2113 else | |
2114 *p++ = raw[i]; | |
2115 } | |
2116 if (p > out && p[-1] != NUL) | |
2117 { | |
2118 *p = NUL; /* last item didn't have \r or \n */ | |
2119 ++count; | |
2120 } | |
2121 return count; | |
2122 } | |
2123 | |
2124 /* | |
2125 * Parse NUL separated "src" strings. Make it an array "outlist" form. On | |
2126 * this process, URI which protocol is not "file:" are removed. Return | |
2127 * length of array (less than "max"). | |
2128 */ | |
2129 static int | |
2130 filter_uri_list(char_u **outlist, int max, char_u *src) | |
2131 { | |
2132 int i, j; | |
2133 | |
2134 for (i = j = 0; i < max; ++i) | |
2135 { | |
2136 outlist[i] = NULL; | |
2137 if (STRNCMP(src, "file:", 5) == 0) | |
2138 { | |
2139 src += 5; | |
2140 if (STRNCMP(src, "//localhost", 11) == 0) | |
2141 src += 11; | |
2142 while (src[0] == '/' && src[1] == '/') | |
2143 ++src; | |
2144 outlist[j++] = vim_strsave(src); | |
2145 } | |
2146 src += STRLEN(src) + 1; | |
2147 } | |
2148 return j; | |
2149 } | |
2150 | |
2151 static char_u ** | |
2152 parse_uri_list(int *count, char_u *data, int len) | |
2153 { | |
2154 int n = 0; | |
2155 char_u *tmp = NULL; | |
2156 char_u **array = NULL;; | |
2157 | |
2158 if (data != NULL && len > 0 && (tmp = (char_u *)alloc(len + 1)) != NULL) | |
2159 { | |
2160 n = count_and_decode_uri_list(tmp, data, len); | |
2161 if (n > 0 && (array = (char_u **)alloc(n * sizeof(char_u *))) != NULL) | |
2162 n = filter_uri_list(array, n, tmp); | |
2163 } | |
2164 vim_free(tmp); | |
2165 *count = n; | |
2166 return array; | |
2167 } | |
2168 | |
2169 static void | |
2170 drag_handle_uri_list(GdkDragContext *context, | |
2171 GtkSelectionData *data, | |
2172 guint time_, | |
2173 GdkModifierType state, | |
2174 gint x, | |
2175 gint y) | |
2176 { | |
2177 char_u **fnames; | |
2178 int nfiles = 0; | |
2179 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2180 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2181 fnames = parse_uri_list(&nfiles, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2182 (char_u *)gtk_selection_data_get_data(data), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2183 gtk_selection_data_get_length(data)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2184 # else |
7 | 2185 fnames = parse_uri_list(&nfiles, data->data, data->length); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2186 # endif |
7 | 2187 |
2188 if (fnames != NULL && nfiles > 0) | |
2189 { | |
179 | 2190 int_u modifiers; |
7 | 2191 |
2192 gtk_drag_finish(context, TRUE, FALSE, time_); /* accept */ | |
2193 | |
179 | 2194 modifiers = modifiers_gdk2mouse(state); |
7 | 2195 |
2196 gui_handle_drop(x, y, modifiers, fnames, nfiles); | |
2197 } | |
840 | 2198 else |
2199 vim_free(fnames); | |
7 | 2200 } |
2201 | |
2202 static void | |
2203 drag_handle_text(GdkDragContext *context, | |
2204 GtkSelectionData *data, | |
2205 guint time_, | |
2206 GdkModifierType state) | |
2207 { | |
2208 char_u dropkey[6] = {CSI, KS_MODIFIER, 0, CSI, KS_EXTRA, (char_u)KE_DROP}; | |
2209 char_u *text; | |
2210 int len; | |
2211 char_u *tmpbuf = NULL; | |
2212 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2213 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2214 text = (char_u *)gtk_selection_data_get_data(data); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2215 len = gtk_selection_data_get_length(data); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2216 # else |
7 | 2217 text = data->data; |
2218 len = data->length; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2219 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2220 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2221 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2222 if (gtk_selection_data_get_data_type(data) == utf8_string_atom) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2223 # else |
7 | 2224 if (data->type == utf8_string_atom) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2225 # endif |
7 | 2226 { |
2227 if (input_conv.vc_type != CONV_NONE) | |
2228 tmpbuf = string_convert(&input_conv, text, &len); | |
2229 if (tmpbuf != NULL) | |
2230 text = tmpbuf; | |
2231 } | |
2232 | |
2233 dnd_yank_drag_data(text, (long)len); | |
2234 gtk_drag_finish(context, TRUE, FALSE, time_); /* accept */ | |
2235 vim_free(tmpbuf); | |
2236 | |
179 | 2237 dropkey[2] = modifiers_gdk2vim(state); |
7 | 2238 |
2239 if (dropkey[2] != 0) | |
2240 add_to_input_buf(dropkey, (int)sizeof(dropkey)); | |
2241 else | |
2242 add_to_input_buf(dropkey + 3, (int)(sizeof(dropkey) - 3)); | |
2243 } | |
2244 | |
2245 /* | |
2246 * DND receiver. | |
2247 */ | |
2248 static void | |
2249 drag_data_received_cb(GtkWidget *widget, | |
2250 GdkDragContext *context, | |
2251 gint x, | |
2252 gint y, | |
2253 GtkSelectionData *data, | |
2254 guint info, | |
2255 guint time_, | |
1884 | 2256 gpointer user_data UNUSED) |
7 | 2257 { |
2258 GdkModifierType state; | |
2259 | |
2260 /* Guard against trash */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2261 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2262 const guchar * const data_data = gtk_selection_data_get_data(data); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2263 const gint data_length = gtk_selection_data_get_length(data); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2264 const gint data_format = gtk_selection_data_get_format(data); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2265 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2266 if (data_data == NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2267 || data_length <= 0 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2268 || data_format != 8 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2269 || data_data[data_length] != '\0') |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2270 # else |
7 | 2271 if (data->data == NULL |
2272 || data->length <= 0 | |
2273 || data->format != 8 | |
2274 || data->data[data->length] != '\0') | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2275 # endif |
7 | 2276 { |
2277 gtk_drag_finish(context, FALSE, FALSE, time_); | |
2278 return; | |
2279 } | |
2280 | |
2281 /* Get the current modifier state for proper distinguishment between | |
2282 * different operations later. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2283 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2284 gui_gtk_get_pointer(widget, NULL, NULL, &state); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2285 # else |
7 | 2286 gdk_window_get_pointer(widget->window, NULL, NULL, &state); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2287 # endif |
7 | 2288 |
2289 /* Not sure about the role of "text/plain" here... */ | |
2290 if (info == (guint)TARGET_TEXT_URI_LIST) | |
2291 drag_handle_uri_list(context, data, time_, state, x, y); | |
2292 else | |
2293 drag_handle_text(context, data, time_, state); | |
2294 | |
2295 } | |
2296 #endif /* FEAT_DND */ | |
2297 | |
2298 | |
2299 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
2300 /* | |
2301 * GnomeClient interact callback. Check for unsaved buffers that cannot | |
2302 * be abandoned and pop up a dialog asking the user for confirmation if | |
2303 * necessary. | |
2304 */ | |
2305 static void | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2306 sm_client_check_changed_any(GnomeClient *client UNUSED, |
7 | 2307 gint key, |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2308 GnomeDialogType type UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2309 gpointer data UNUSED) |
7 | 2310 { |
2311 cmdmod_T save_cmdmod; | |
2312 gboolean shutdown_cancelled; | |
2313 | |
2314 save_cmdmod = cmdmod; | |
2315 | |
2316 # ifdef FEAT_BROWSE | |
2317 cmdmod.browse = TRUE; | |
2318 # endif | |
2319 # if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
2320 cmdmod.confirm = TRUE; | |
2321 # endif | |
2322 /* | |
2323 * If there are changed buffers, present the user with | |
2324 * a dialog if possible, otherwise give an error message. | |
2325 */ | |
7469
15eefe1b0dad
commit https://github.com/vim/vim/commit/027387f70c671f62e3e08e0bdd09ec05b0232735
Christian Brabandt <cb@256bit.org>
parents:
7380
diff
changeset
|
2326 shutdown_cancelled = check_changed_any(FALSE, FALSE); |
7 | 2327 |
2328 exiting = FALSE; | |
2329 cmdmod = save_cmdmod; | |
2330 setcursor(); /* position the cursor */ | |
2331 out_flush(); | |
2332 /* | |
2333 * If the user hit the [Cancel] button the whole shutdown | |
2334 * will be cancelled. Wow, quite powerful feature (: | |
2335 */ | |
2336 gnome_interaction_key_return(key, shutdown_cancelled); | |
2337 } | |
2338 | |
2339 /* | |
2340 * Generate a script that can be used to restore the current editing session. | |
2341 * Save the value of v:this_session before running :mksession in order to make | |
2342 * automagic session save fully transparent. Return TRUE on success. | |
2343 */ | |
2344 static int | |
2345 write_session_file(char_u *filename) | |
2346 { | |
2347 char_u *escaped_filename; | |
2348 char *mksession_cmdline; | |
2349 unsigned int save_ssop_flags; | |
2350 int failed; | |
2351 | |
2352 /* | |
2353 * Build an ex command line to create a script that restores the current | |
2354 * session if executed. Escape the filename to avoid nasty surprises. | |
2355 */ | |
2356 escaped_filename = vim_strsave_escaped(filename, escape_chars); | |
2357 if (escaped_filename == NULL) | |
2358 return FALSE; | |
1296 | 2359 mksession_cmdline = g_strconcat("mksession ", (char *)escaped_filename, |
2360 NULL); | |
7 | 2361 vim_free(escaped_filename); |
1296 | 2362 |
7 | 2363 /* |
2364 * Use a reasonable hardcoded set of 'sessionoptions' flags to avoid | |
2365 * unpredictable effects when the session is saved automatically. Also, | |
2366 * we definitely need SSOP_GLOBALS to be able to restore v:this_session. | |
2367 * Don't use SSOP_BUFFERS to prevent the buffer list from becoming | |
2368 * enormously large if the GNOME session feature is used regularly. | |
2369 */ | |
2370 save_ssop_flags = ssop_flags; | |
2371 ssop_flags = (SSOP_BLANK|SSOP_CURDIR|SSOP_FOLDS|SSOP_GLOBALS | |
1296 | 2372 |SSOP_HELP|SSOP_OPTIONS|SSOP_WINSIZE|SSOP_TABPAGES); |
7 | 2373 |
2374 do_cmdline_cmd((char_u *)"let Save_VV_this_session = v:this_session"); | |
2375 failed = (do_cmdline_cmd((char_u *)mksession_cmdline) == FAIL); | |
2376 do_cmdline_cmd((char_u *)"let v:this_session = Save_VV_this_session"); | |
150 | 2377 do_unlet((char_u *)"Save_VV_this_session", TRUE); |
7 | 2378 |
2379 ssop_flags = save_ssop_flags; | |
2380 g_free(mksession_cmdline); | |
5905 | 2381 |
7 | 2382 /* |
2383 * Reopen the file and append a command to restore v:this_session, | |
2384 * as if this save never happened. This is to avoid conflicts with | |
2385 * the user's own sessions. FIXME: It's probably less hackish to add | |
2386 * a "stealth" flag to 'sessionoptions' -- gotta ask Bram. | |
2387 */ | |
2388 if (!failed) | |
2389 { | |
2390 FILE *fd; | |
2391 | |
2392 fd = open_exfile(filename, TRUE, APPENDBIN); | |
2393 | |
2394 failed = (fd == NULL | |
2395 || put_line(fd, "let v:this_session = Save_VV_this_session") == FAIL | |
2396 || put_line(fd, "unlet Save_VV_this_session") == FAIL); | |
2397 | |
2398 if (fd != NULL && fclose(fd) != 0) | |
2399 failed = TRUE; | |
2400 | |
2401 if (failed) | |
2402 mch_remove(filename); | |
2403 } | |
2404 | |
2405 return !failed; | |
2406 } | |
2407 | |
2408 /* | |
2409 * "save_yourself" signal handler. Initiate an interaction to ask the user | |
2410 * for confirmation if necessary. Save the current editing session and tell | |
2411 * the session manager how to restart Vim. | |
2412 */ | |
2413 static gboolean | |
2414 sm_client_save_yourself(GnomeClient *client, | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2415 gint phase UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2416 GnomeSaveStyle save_style UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2417 gboolean shutdown UNUSED, |
7 | 2418 GnomeInteractStyle interact_style, |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2419 gboolean fast UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2420 gpointer data UNUSED) |
7 | 2421 { |
2422 static const char suffix[] = "-session.vim"; | |
2423 char *session_file; | |
2424 unsigned int len; | |
2425 gboolean success; | |
2426 | |
2427 /* Always request an interaction if possible. check_changed_any() | |
2428 * won't actually show a dialog unless any buffers have been modified. | |
2429 * There doesn't seem to be an obvious way to check that without | |
2430 * automatically firing the dialog. Anyway, it works just fine. */ | |
2431 if (interact_style == GNOME_INTERACT_ANY) | |
2432 gnome_client_request_interaction(client, GNOME_DIALOG_NORMAL, | |
2433 &sm_client_check_changed_any, | |
2434 NULL); | |
2435 out_flush(); | |
2436 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
2437 | |
2438 /* The path is unique for each session save. We do neither know nor care | |
2439 * which session script will actually be used later. This decision is in | |
2440 * the domain of the session manager. */ | |
2441 session_file = gnome_config_get_real_path( | |
2442 gnome_client_get_config_prefix(client)); | |
2443 len = strlen(session_file); | |
2444 | |
2445 if (len > 0 && session_file[len-1] == G_DIR_SEPARATOR) | |
2446 --len; /* get rid of the superfluous trailing '/' */ | |
2447 | |
2448 session_file = g_renew(char, session_file, len + sizeof(suffix)); | |
2449 memcpy(session_file + len, suffix, sizeof(suffix)); | |
2450 | |
2451 success = write_session_file((char_u *)session_file); | |
2452 | |
2453 if (success) | |
2454 { | |
2455 const char *argv[8]; | |
2456 int i; | |
2457 | |
2458 /* Tell the session manager how to wipe out the stored session data. | |
2459 * This isn't as dangerous as it looks, don't worry :) session_file | |
2460 * is a unique absolute filename. Usually it'll be something like | |
2461 * `/home/user/.gnome2/vim-XXXXXX-session.vim'. */ | |
2462 i = 0; | |
2463 argv[i++] = "rm"; | |
2464 argv[i++] = session_file; | |
2465 argv[i] = NULL; | |
2466 | |
2467 gnome_client_set_discard_command(client, i, (char **)argv); | |
2468 | |
2469 /* Tell the session manager how to restore the just saved session. | |
2470 * This is easily done thanks to Vim's -S option. Pass the -f flag | |
2471 * since there's no need to fork -- it might even cause confusion. | |
2472 * Also pass the window role to give the WM something to match on. | |
2473 * The role is set in gui_mch_open(), thus should _never_ be NULL. */ | |
2474 i = 0; | |
2475 argv[i++] = restart_command; | |
2476 argv[i++] = "-f"; | |
2477 argv[i++] = "-g"; | |
2478 argv[i++] = "--role"; | |
2479 argv[i++] = gtk_window_get_role(GTK_WINDOW(gui.mainwin)); | |
2480 argv[i++] = "-S"; | |
2481 argv[i++] = session_file; | |
2482 argv[i] = NULL; | |
2483 | |
2484 gnome_client_set_restart_command(client, i, (char **)argv); | |
2485 gnome_client_set_clone_command(client, 0, NULL); | |
2486 } | |
2487 | |
2488 g_free(session_file); | |
2489 | |
2490 return success; | |
2491 } | |
2492 | |
2493 /* | |
2494 * Called when the session manager wants us to die. There isn't much to save | |
2495 * here since "save_yourself" has been emitted before (unless serious trouble | |
2496 * is happening). | |
2497 */ | |
2498 static void | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2499 sm_client_die(GnomeClient *client UNUSED, gpointer data UNUSED) |
7 | 2500 { |
2501 /* Don't write messages to the GUI anymore */ | |
2502 full_screen = FALSE; | |
2503 | |
1666 | 2504 vim_strncpy(IObuff, (char_u *) |
419 | 2505 _("Vim: Received \"die\" request from session manager\n"), |
1666 | 2506 IOSIZE - 1); |
7 | 2507 preserve_exit(); |
2508 } | |
2509 | |
2510 /* | |
2511 * Connect our signal handlers to be notified on session save and shutdown. | |
2512 */ | |
2513 static void | |
2514 setup_save_yourself(void) | |
2515 { | |
2516 GnomeClient *client; | |
2517 | |
2518 client = gnome_master_client(); | |
2519 | |
2520 if (client != NULL) | |
2521 { | |
2522 /* Must use the deprecated gtk_signal_connect() for compatibility | |
2523 * with GNOME 1. Arrgh, zombies! */ | |
2524 gtk_signal_connect(GTK_OBJECT(client), "save_yourself", | |
2525 GTK_SIGNAL_FUNC(&sm_client_save_yourself), NULL); | |
2526 gtk_signal_connect(GTK_OBJECT(client), "die", | |
2527 GTK_SIGNAL_FUNC(&sm_client_die), NULL); | |
2528 } | |
2529 } | |
2530 | |
2531 #else /* !(FEAT_GUI_GNOME && FEAT_SESSION) */ | |
2532 | |
2533 # ifdef USE_XSMP | |
2534 /* | |
2535 * GTK tells us that XSMP needs attention | |
2536 */ | |
2537 static gboolean | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2538 local_xsmp_handle_requests( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2539 GIOChannel *source UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2540 GIOCondition condition, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2541 gpointer data) |
7 | 2542 { |
2543 if (condition == G_IO_IN) | |
2544 { | |
2545 /* Do stuff; maybe close connection */ | |
2546 if (xsmp_handle_requests() == FAIL) | |
2547 g_io_channel_unref((GIOChannel *)data); | |
2548 return TRUE; | |
2549 } | |
2550 /* Error */ | |
2551 g_io_channel_unref((GIOChannel *)data); | |
2552 xsmp_close(); | |
2553 return TRUE; | |
2554 } | |
2555 # endif /* USE_XSMP */ | |
2556 | |
2557 /* | |
2558 * Setup the WM_PROTOCOLS to indicate we want the WM_SAVE_YOURSELF event. | |
2559 * This is an ugly use of X functions. GTK doesn't offer an alternative. | |
2560 */ | |
2561 static void | |
2562 setup_save_yourself(void) | |
2563 { | |
2564 Atom *existing_atoms = NULL; | |
2565 int count = 0; | |
2566 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2567 # ifdef USE_XSMP |
7 | 2568 if (xsmp_icefd != -1) |
2569 { | |
2570 /* | |
2571 * Use XSMP is preference to legacy WM_SAVE_YOURSELF; | |
2572 * set up GTK IO monitor | |
2573 */ | |
2574 GIOChannel *g_io = g_io_channel_unix_new(xsmp_icefd); | |
2575 | |
2576 g_io_add_watch(g_io, G_IO_IN | G_IO_ERR | G_IO_HUP, | |
2577 local_xsmp_handle_requests, (gpointer)g_io); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2578 g_io_channel_unref(g_io); |
7 | 2579 } |
2580 else | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2581 # endif |
7 | 2582 { |
2583 /* Fall back to old method */ | |
2584 | |
2585 /* first get the existing value */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2586 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2587 GdkWindow * const mainwin_win = gtk_widget_get_window(gui.mainwin); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2588 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2589 if (XGetWMProtocols(GDK_WINDOW_XDISPLAY(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2590 GDK_WINDOW_XID(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2591 &existing_atoms, &count)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2592 # else |
7 | 2593 if (XGetWMProtocols(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2594 GDK_WINDOW_XWINDOW(gui.mainwin->window), | |
2595 &existing_atoms, &count)) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2596 # endif |
7 | 2597 { |
2598 Atom *new_atoms; | |
2599 Atom save_yourself_xatom; | |
2600 int i; | |
2601 | |
2602 save_yourself_xatom = GET_X_ATOM(save_yourself_atom); | |
2603 | |
2604 /* check if WM_SAVE_YOURSELF isn't there yet */ | |
2605 for (i = 0; i < count; ++i) | |
2606 if (existing_atoms[i] == save_yourself_xatom) | |
2607 break; | |
2608 | |
2609 if (i == count) | |
2610 { | |
2611 /* allocate an Atoms array which is one item longer */ | |
2612 new_atoms = (Atom *)alloc((unsigned)((count + 1) | |
2613 * sizeof(Atom))); | |
2614 if (new_atoms != NULL) | |
2615 { | |
2616 memcpy(new_atoms, existing_atoms, count * sizeof(Atom)); | |
2617 new_atoms[count] = save_yourself_xatom; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2618 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2619 XSetWMProtocols(GDK_WINDOW_XDISPLAY(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2620 GDK_WINDOW_XID(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2621 # else |
7 | 2622 XSetWMProtocols(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2623 GDK_WINDOW_XWINDOW(gui.mainwin->window), | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2624 # endif |
7 | 2625 new_atoms, count + 1); |
2626 vim_free(new_atoms); | |
2627 } | |
2628 } | |
2629 XFree(existing_atoms); | |
2630 } | |
2631 } | |
2632 } | |
2633 | |
2634 /* | |
2635 * Installing a global event filter seems to be the only way to catch | |
2636 * client messages of type WM_PROTOCOLS without overriding GDK's own | |
2637 * client message event filter. Well, that's still better than trying | |
2638 * to guess what the GDK filter had done if it had been invoked instead | |
2639 * | |
2640 * GTK2_FIXME: This doesn't seem to work. For some reason we never | |
2641 * receive WM_SAVE_YOURSELF even though everything is set up correctly. | |
2642 * I have the nasty feeling modern session managers just don't send this | |
2643 * deprecated message anymore. Addition: confirmed by several people. | |
2644 * | |
2645 * The GNOME session support is much cooler anyway. Unlike this ugly | |
2646 * WM_SAVE_YOURSELF hack it actually stores the session... And yes, | |
2647 * it should work with KDE as well. | |
2648 */ | |
2649 static GdkFilterReturn | |
1884 | 2650 global_event_filter(GdkXEvent *xev, |
2651 GdkEvent *event UNUSED, | |
2652 gpointer data UNUSED) | |
7 | 2653 { |
2654 XEvent *xevent = (XEvent *)xev; | |
2655 | |
2656 if (xevent != NULL | |
2657 && xevent->type == ClientMessage | |
2658 && xevent->xclient.message_type == GET_X_ATOM(wm_protocols_atom) | |
1884 | 2659 && (long_u)xevent->xclient.data.l[0] |
2660 == GET_X_ATOM(save_yourself_atom)) | |
7 | 2661 { |
2662 out_flush(); | |
2663 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
2664 /* | |
2665 * Set the window's WM_COMMAND property, to let the window manager | |
2666 * know we are done saving ourselves. We don't want to be | |
2667 * restarted, thus set argv to NULL. | |
2668 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2669 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2670 XSetCommand(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.mainwin)), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2671 GDK_WINDOW_XID(gtk_widget_get_window(gui.mainwin)), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2672 # else |
7 | 2673 XSetCommand(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2674 GDK_WINDOW_XWINDOW(gui.mainwin->window), | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2675 # endif |
7 | 2676 NULL, 0); |
2677 return GDK_FILTER_REMOVE; | |
2678 } | |
2679 | |
2680 return GDK_FILTER_CONTINUE; | |
2681 } | |
2682 #endif /* !(FEAT_GUI_GNOME && FEAT_SESSION) */ | |
2683 | |
2684 | |
2685 /* | |
2686 * Setup the window icon & xcmdsrv comm after the main window has been realized. | |
2687 */ | |
2688 static void | |
1884 | 2689 mainwin_realize(GtkWidget *widget UNUSED, gpointer data UNUSED) |
7 | 2690 { |
2691 /* If you get an error message here, you still need to unpack the runtime | |
2692 * archive! */ | |
2693 #ifdef magick | |
2694 # undef magick | |
2695 #endif | |
2696 /* A bit hackish, but avoids casting later and allows optimization */ | |
2697 # define static static const | |
2698 #define magick vim32x32 | |
2699 #include "../runtime/vim32x32.xpm" | |
2700 #undef magick | |
2701 #define magick vim16x16 | |
2702 #include "../runtime/vim16x16.xpm" | |
2703 #undef magick | |
2704 #define magick vim48x48 | |
2705 #include "../runtime/vim48x48.xpm" | |
2706 #undef magick | |
2707 # undef static | |
2708 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2709 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2710 GdkWindow * const mainwin_win = gtk_widget_get_window(gui.mainwin); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2711 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2712 |
7 | 2713 /* When started with "--echo-wid" argument, write window ID on stdout. */ |
2714 if (echo_wid_arg) | |
2715 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2716 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2717 printf("WID: %ld\n", (long)GDK_WINDOW_XID(mainwin_win)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2718 #else |
7 | 2719 printf("WID: %ld\n", (long)GDK_WINDOW_XWINDOW(gui.mainwin->window)); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2720 #endif |
7 | 2721 fflush(stdout); |
2722 } | |
2723 | |
2724 if (vim_strchr(p_go, GO_ICON) != NULL) | |
2725 { | |
2726 /* | |
2727 * Add an icon to the main window. For fun and convenience of the user. | |
2728 */ | |
2729 GList *icons = NULL; | |
2730 | |
2731 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim16x16)); | |
2732 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim32x32)); | |
2733 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim48x48)); | |
2734 | |
2735 gtk_window_set_icon_list(GTK_WINDOW(gui.mainwin), icons); | |
2736 | |
2737 g_list_foreach(icons, (GFunc)&g_object_unref, NULL); | |
2738 g_list_free(icons); | |
2739 } | |
2740 | |
2741 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
2742 /* Register a handler for WM_SAVE_YOURSELF with GDK's low-level X I/F */ | |
2743 gdk_window_add_filter(NULL, &global_event_filter, NULL); | |
2744 #endif | |
2745 /* Setup to indicate to the window manager that we want to catch the | |
2746 * WM_SAVE_YOURSELF event. For GNOME, this connects to the session | |
2747 * manager instead. */ | |
2748 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
2749 if (using_gnome) | |
2750 #endif | |
2751 setup_save_yourself(); | |
2752 | |
2753 #ifdef FEAT_CLIENTSERVER | |
2754 if (serverName == NULL && serverDelayedStartName != NULL) | |
2755 { | |
2756 /* This is a :gui command in a plain vim with no previous server */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2757 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2758 commWindow = GDK_WINDOW_XID(mainwin_win); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2759 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2760 (void)serverRegisterName(GDK_WINDOW_XDISPLAY(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2761 serverDelayedStartName); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2762 # else |
7 | 2763 commWindow = GDK_WINDOW_XWINDOW(gui.mainwin->window); |
2764 | |
2765 (void)serverRegisterName(GDK_WINDOW_XDISPLAY(gui.mainwin->window), | |
2766 serverDelayedStartName); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2767 # endif |
7 | 2768 } |
2769 else | |
2770 { | |
2771 /* | |
2772 * Cannot handle "XLib-only" windows with gtk event routines, we'll | |
2773 * have to change the "server" registration to that of the main window | |
2774 * If we have not registered a name yet, remember the window | |
2775 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2776 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2777 serverChangeRegisteredWindow(GDK_WINDOW_XDISPLAY(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2778 GDK_WINDOW_XID(mainwin_win)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2779 # else |
7 | 2780 serverChangeRegisteredWindow(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2781 GDK_WINDOW_XWINDOW(gui.mainwin->window)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2782 # endif |
7 | 2783 } |
2784 gtk_widget_add_events(gui.mainwin, GDK_PROPERTY_CHANGE_MASK); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2785 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2786 g_signal_connect(G_OBJECT(gui.mainwin), "property-notify-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2787 G_CALLBACK(property_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2788 # else |
7 | 2789 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "property_notify_event", |
2790 GTK_SIGNAL_FUNC(property_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2791 # endif |
7 | 2792 #endif |
2793 } | |
2794 | |
2795 static GdkCursor * | |
2796 create_blank_pointer(void) | |
2797 { | |
2798 GdkWindow *root_window = NULL; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2799 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2800 GdkPixbuf *blank_mask; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2801 #else |
7 | 2802 GdkPixmap *blank_mask; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2803 #endif |
7 | 2804 GdkCursor *cursor; |
2805 GdkColor color = { 0, 0, 0, 0 }; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2806 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 2807 char blank_data[] = { 0x0 }; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2808 #endif |
7 | 2809 |
2810 #ifdef HAVE_GTK_MULTIHEAD | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2811 # if GTK_CHECK_VERSION(3,12,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2812 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2813 GdkWindow * const win = gtk_widget_get_window(gui.mainwin); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2814 GdkScreen * const scrn = gdk_window_get_screen(win); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2815 root_window = gdk_screen_get_root_window(scrn); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2816 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2817 # else |
7 | 2818 root_window = gtk_widget_get_root_window(gui.mainwin); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2819 # endif |
7 | 2820 #endif |
2821 | |
2822 /* Create a pseudo blank pointer, which is in fact one pixel by one pixel | |
2823 * in size. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2824 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2825 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2826 cairo_surface_t *surf; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2827 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2828 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2829 surf = cairo_image_surface_create(CAIRO_FORMAT_A1, 1, 1); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2830 cr = cairo_create(surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2831 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2832 cairo_set_source_rgb(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2833 color.red / 65535.0, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2834 color.green / 65535.0, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2835 color.blue / 65535.0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2836 cairo_rectangle(cr, 0, 0, 1, 1); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2837 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2838 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2839 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2840 blank_mask = gdk_pixbuf_get_from_surface(surf, 0, 0, 1, 1); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2841 cairo_surface_destroy(surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2842 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2843 cursor = gdk_cursor_new_from_pixbuf(gdk_window_get_display(root_window), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2844 blank_mask, 0, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2845 g_object_unref(blank_mask); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2846 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2847 #else |
7 | 2848 blank_mask = gdk_bitmap_create_from_data(root_window, blank_data, 1, 1); |
2849 cursor = gdk_cursor_new_from_pixmap(blank_mask, blank_mask, | |
2850 &color, &color, 0, 0); | |
2851 gdk_bitmap_unref(blank_mask); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2852 #endif |
7 | 2853 |
2854 return cursor; | |
2855 } | |
2856 | |
2857 #ifdef HAVE_GTK_MULTIHEAD | |
2858 static void | |
2859 mainwin_screen_changed_cb(GtkWidget *widget, | |
1884 | 2860 GdkScreen *previous_screen UNUSED, |
2861 gpointer data UNUSED) | |
7 | 2862 { |
2863 if (!gtk_widget_has_screen(widget)) | |
2864 return; | |
2865 | |
2866 /* | |
1226 | 2867 * Recreate the invisible mouse cursor. |
7 | 2868 */ |
2869 if (gui.blank_pointer != NULL) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2870 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2871 g_object_unref(G_OBJECT(gui.blank_pointer)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2872 # else |
7 | 2873 gdk_cursor_unref(gui.blank_pointer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2874 # endif |
7 | 2875 |
2876 gui.blank_pointer = create_blank_pointer(); | |
2877 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2878 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2879 if (gui.pointer_hidden && gtk_widget_get_window(gui.drawarea) != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2880 gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2881 gui.blank_pointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2882 # else |
7 | 2883 if (gui.pointer_hidden && gui.drawarea->window != NULL) |
2884 gdk_window_set_cursor(gui.drawarea->window, gui.blank_pointer); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2885 # endif |
7 | 2886 |
2887 /* | |
2888 * Create a new PangoContext for this screen, and initialize it | |
2889 * with the current font if necessary. | |
2890 */ | |
2891 if (gui.text_context != NULL) | |
2892 g_object_unref(gui.text_context); | |
2893 | |
2894 gui.text_context = gtk_widget_create_pango_context(widget); | |
2895 pango_context_set_base_dir(gui.text_context, PANGO_DIRECTION_LTR); | |
2896 | |
2897 if (gui.norm_font != NULL) | |
2898 { | |
38 | 2899 gui_mch_init_font(p_guifont, FALSE); |
814 | 2900 gui_set_shellsize(FALSE, FALSE, RESIZE_BOTH); |
7 | 2901 } |
2902 } | |
2903 #endif /* HAVE_GTK_MULTIHEAD */ | |
2904 | |
2905 /* | |
2906 * After the drawing area comes up, we calculate all colors and create the | |
2907 * dummy blank cursor. | |
2908 * | |
2909 * Don't try to set any VIM scrollbar sizes anywhere here. I'm relying on the | |
2910 * fact that the main VIM engine doesn't take them into account anywhere. | |
2911 */ | |
2912 static void | |
1884 | 2913 drawarea_realize_cb(GtkWidget *widget, gpointer data UNUSED) |
7 | 2914 { |
2915 GtkWidget *sbar; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2916 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2917 GtkAllocation allocation; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2918 #endif |
7 | 2919 |
2920 #ifdef FEAT_XIM | |
2921 xim_init(); | |
2922 #endif | |
2923 gui_mch_new_colors(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2924 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2925 gui.surface = gdk_window_create_similar_surface( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2926 gtk_widget_get_window(widget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2927 CAIRO_CONTENT_COLOR_ALPHA, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2928 gtk_widget_get_allocated_width(widget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2929 gtk_widget_get_allocated_height(widget)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2930 #else |
7 | 2931 gui.text_gc = gdk_gc_new(gui.drawarea->window); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2932 #endif |
7 | 2933 |
2934 gui.blank_pointer = create_blank_pointer(); | |
2935 if (gui.pointer_hidden) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2936 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2937 gdk_window_set_cursor(gtk_widget_get_window(widget), gui.blank_pointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2938 #else |
7 | 2939 gdk_window_set_cursor(widget->window, gui.blank_pointer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2940 #endif |
7 | 2941 |
2942 /* get the actual size of the scrollbars, if they are realized */ | |
2943 sbar = firstwin->w_scrollbars[SBAR_LEFT].id; | |
2944 if (!sbar || (!gui.which_scrollbars[SBAR_LEFT] | |
2945 && firstwin->w_scrollbars[SBAR_RIGHT].id)) | |
2946 sbar = firstwin->w_scrollbars[SBAR_RIGHT].id; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2947 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2948 gtk_widget_get_allocation(sbar, &allocation); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2949 if (sbar && gtk_widget_get_realized(sbar) && allocation.width) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2950 gui.scrollbar_width = allocation.width; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2951 #else |
7 | 2952 if (sbar && GTK_WIDGET_REALIZED(sbar) && sbar->allocation.width) |
2953 gui.scrollbar_width = sbar->allocation.width; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2954 #endif |
7 | 2955 |
2956 sbar = gui.bottom_sbar.id; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2957 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2958 if (sbar && gtk_widget_get_realized(sbar) && allocation.height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2959 gui.scrollbar_height = allocation.height; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2960 #else |
7 | 2961 if (sbar && GTK_WIDGET_REALIZED(sbar) && sbar->allocation.height) |
2962 gui.scrollbar_height = sbar->allocation.height; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2963 #endif |
7 | 2964 } |
2965 | |
2966 /* | |
2967 * Properly clean up on shutdown. | |
2968 */ | |
2969 static void | |
1884 | 2970 drawarea_unrealize_cb(GtkWidget *widget UNUSED, gpointer data UNUSED) |
7 | 2971 { |
2972 /* Don't write messages to the GUI anymore */ | |
2973 full_screen = FALSE; | |
2974 | |
2975 #ifdef FEAT_XIM | |
2976 im_shutdown(); | |
2977 #endif | |
2978 if (gui.ascii_glyphs != NULL) | |
2979 { | |
2980 pango_glyph_string_free(gui.ascii_glyphs); | |
2981 gui.ascii_glyphs = NULL; | |
2982 } | |
2983 if (gui.ascii_font != NULL) | |
2984 { | |
2985 g_object_unref(gui.ascii_font); | |
2986 gui.ascii_font = NULL; | |
2987 } | |
2988 g_object_unref(gui.text_context); | |
2989 gui.text_context = NULL; | |
2990 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2991 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2992 if (gui.surface != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2993 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2994 cairo_surface_destroy(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2995 gui.surface = NULL; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2996 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2997 #else |
7 | 2998 g_object_unref(gui.text_gc); |
2999 gui.text_gc = NULL; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3000 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3001 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3002 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3003 g_object_unref(G_OBJECT(gui.blank_pointer)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3004 #else |
7 | 3005 gdk_cursor_unref(gui.blank_pointer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3006 #endif |
7 | 3007 gui.blank_pointer = NULL; |
3008 } | |
3009 | |
3010 static void | |
1884 | 3011 drawarea_style_set_cb(GtkWidget *widget UNUSED, |
3012 GtkStyle *previous_style UNUSED, | |
3013 gpointer data UNUSED) | |
7 | 3014 { |
3015 gui_mch_new_colors(); | |
3016 } | |
3017 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3018 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3019 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3020 drawarea_configure_event_cb(GtkWidget *widget, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3021 GdkEventConfigure *event, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3022 gpointer data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3023 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3024 static int cur_width = 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3025 static int cur_height = 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3026 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3027 g_return_val_if_fail(event |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3028 && event->width >= 1 && event->height >= 1, TRUE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3029 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3030 if (event->width == cur_width && event->height == cur_height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3031 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3032 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3033 cur_width = event->width; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3034 cur_height = event->height; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3035 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3036 if (gui.surface != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3037 cairo_surface_destroy(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3038 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3039 gui.surface = gdk_window_create_similar_surface( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3040 gtk_widget_get_window(widget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3041 CAIRO_CONTENT_COLOR_ALPHA, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3042 event->width, event->height); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3043 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3044 gtk_widget_queue_draw(widget); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3045 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3046 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3047 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3048 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3049 |
7 | 3050 /* |
3051 * Callback routine for the "delete_event" signal on the toplevel window. | |
3052 * Tries to vim gracefully, or refuses to exit with changed buffers. | |
3053 */ | |
3054 static gint | |
1884 | 3055 delete_event_cb(GtkWidget *widget UNUSED, |
3056 GdkEventAny *event UNUSED, | |
3057 gpointer data UNUSED) | |
7 | 3058 { |
3059 gui_shell_closed(); | |
3060 return TRUE; | |
3061 } | |
3062 | |
685 | 3063 #if defined(FEAT_MENU) || defined(FEAT_TOOLBAR) || defined(FEAT_GUI_TABLINE) |
3064 static int | |
3065 get_item_dimensions(GtkWidget *widget, GtkOrientation orientation) | |
3066 { | |
3067 GtkOrientation item_orientation = GTK_ORIENTATION_HORIZONTAL; | |
3068 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3069 # ifdef FEAT_GUI_GNOME |
685 | 3070 if (using_gnome && widget != NULL) |
3071 { | |
856 | 3072 GtkWidget *parent; |
685 | 3073 BonoboDockItem *dockitem; |
3074 | |
791 | 3075 parent = gtk_widget_get_parent(widget); |
856 | 3076 if (G_TYPE_FROM_INSTANCE(parent) == BONOBO_TYPE_DOCK_ITEM) |
3077 { | |
3078 /* Only menu & toolbar are dock items. Could tabline be? | |
3079 * Seem to be only the 2 defined in GNOME */ | |
3080 widget = parent; | |
3081 dockitem = BONOBO_DOCK_ITEM(widget); | |
3082 | |
3083 if (dockitem == NULL || dockitem->is_floating) | |
3084 return 0; | |
3085 item_orientation = bonobo_dock_item_get_orientation(dockitem); | |
3086 } | |
685 | 3087 } |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3088 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3089 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3090 if (widget != NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3091 && item_orientation == orientation |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3092 && gtk_widget_get_realized(widget) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3093 && gtk_widget_get_visible(widget)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3094 # else |
685 | 3095 if (widget != NULL |
3096 && item_orientation == orientation | |
3097 && GTK_WIDGET_REALIZED(widget) | |
3098 && GTK_WIDGET_VISIBLE(widget)) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3099 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3100 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3101 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3102 GtkAllocation allocation; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3103 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3104 gtk_widget_get_allocation(widget, &allocation); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3105 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3106 if (orientation == GTK_ORIENTATION_HORIZONTAL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3107 return allocation.height; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3108 else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3109 return allocation.width; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3110 # else |
685 | 3111 if (orientation == GTK_ORIENTATION_HORIZONTAL) |
3112 return widget->allocation.height; | |
3113 else | |
3114 return widget->allocation.width; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3115 # endif |
685 | 3116 } |
3117 return 0; | |
3118 } | |
3119 #endif | |
3120 | |
3121 static int | |
3122 get_menu_tool_width(void) | |
3123 { | |
3124 int width = 0; | |
3125 | |
3126 #ifdef FEAT_GUI_GNOME /* these are never vertical without GNOME */ | |
3127 # ifdef FEAT_MENU | |
3128 width += get_item_dimensions(gui.menubar, GTK_ORIENTATION_VERTICAL); | |
3129 # endif | |
3130 # ifdef FEAT_TOOLBAR | |
3131 width += get_item_dimensions(gui.toolbar, GTK_ORIENTATION_VERTICAL); | |
3132 # endif | |
3133 # ifdef FEAT_GUI_TABLINE | |
782 | 3134 if (gui.tabline != NULL) |
3135 width += get_item_dimensions(gui.tabline, GTK_ORIENTATION_VERTICAL); | |
685 | 3136 # endif |
3137 #endif | |
3138 | |
3139 return width; | |
3140 } | |
3141 | |
3142 static int | |
3143 get_menu_tool_height(void) | |
3144 { | |
3145 int height = 0; | |
3146 | |
3147 #ifdef FEAT_MENU | |
3148 height += get_item_dimensions(gui.menubar, GTK_ORIENTATION_HORIZONTAL); | |
3149 #endif | |
3150 #ifdef FEAT_TOOLBAR | |
3151 height += get_item_dimensions(gui.toolbar, GTK_ORIENTATION_HORIZONTAL); | |
3152 #endif | |
3153 #ifdef FEAT_GUI_TABLINE | |
782 | 3154 if (gui.tabline != NULL) |
3155 height += get_item_dimensions(gui.tabline, GTK_ORIENTATION_HORIZONTAL); | |
685 | 3156 #endif |
3157 | |
3158 return height; | |
3159 } | |
3160 | |
791 | 3161 /* This controls whether we can set the real window hints at |
3162 * start-up when in a GtkPlug. | |
3163 * 0 = normal processing (default) | |
3164 * 1 = init. hints set, no-one's tried to reset since last check | |
3165 * 2 = init. hints set, attempt made to change hints | |
3166 */ | |
3167 static int init_window_hints_state = 0; | |
3168 | |
685 | 3169 static void |
791 | 3170 update_window_manager_hints(int force_width, int force_height) |
685 | 3171 { |
3172 static int old_width = 0; | |
3173 static int old_height = 0; | |
791 | 3174 static int old_min_width = 0; |
3175 static int old_min_height = 0; | |
685 | 3176 static int old_char_width = 0; |
3177 static int old_char_height = 0; | |
3178 | |
3179 int width; | |
3180 int height; | |
791 | 3181 int min_width; |
3182 int min_height; | |
3183 | |
3184 /* At start-up, don't try to set the hints until the initial | |
3185 * values have been used (those that dictate our initial size) | |
1884 | 3186 * Let forced (i.e., correct) values through always. |
791 | 3187 */ |
3188 if (!(force_width && force_height) && init_window_hints_state > 0) | |
3189 { | |
856 | 3190 /* Don't do it! */ |
3191 init_window_hints_state = 2; | |
3192 return; | |
791 | 3193 } |
685 | 3194 |
3195 /* This also needs to be done when the main window isn't there yet, | |
3196 * otherwise the hints don't work. */ | |
3197 width = gui_get_base_width(); | |
3198 height = gui_get_base_height(); | |
3199 # ifdef FEAT_MENU | |
3200 height += tabline_height() * gui.char_height; | |
3201 # endif | |
3202 width += get_menu_tool_width(); | |
3203 height += get_menu_tool_height(); | |
3204 | |
791 | 3205 /* GtkSockets use GtkPlug's [gui,mainwin] min-size hints to determine |
1226 | 3206 * their actual widget size. When we set our size ourselves (e.g., |
791 | 3207 * 'set columns=' or init. -geom) we briefly set the min. to the size |
3208 * we wish to be instead of the legitimate minimum so that we actually | |
3209 * resize correctly. | |
3210 */ | |
3211 if (force_width && force_height) | |
3212 { | |
856 | 3213 min_width = force_width; |
3214 min_height = force_height; | |
791 | 3215 } |
3216 else | |
3217 { | |
856 | 3218 min_width = width + MIN_COLUMNS * gui.char_width; |
3219 min_height = height + MIN_LINES * gui.char_height; | |
791 | 3220 } |
3221 | |
685 | 3222 /* Avoid an expose event when the size didn't change. */ |
3223 if (width != old_width | |
3224 || height != old_height | |
856 | 3225 || min_width != old_min_width |
791 | 3226 || min_height != old_min_height |
685 | 3227 || gui.char_width != old_char_width |
3228 || gui.char_height != old_char_height) | |
3229 { | |
3230 GdkGeometry geometry; | |
3231 GdkWindowHints geometry_mask; | |
3232 | |
3233 geometry.width_inc = gui.char_width; | |
3234 geometry.height_inc = gui.char_height; | |
3235 geometry.base_width = width; | |
3236 geometry.base_height = height; | |
856 | 3237 geometry.min_width = min_width; |
3238 geometry.min_height = min_height; | |
685 | 3239 geometry_mask = GDK_HINT_BASE_SIZE|GDK_HINT_RESIZE_INC |
3240 |GDK_HINT_MIN_SIZE; | |
3241 /* Using gui.formwin as geometry widget doesn't work as expected | |
3242 * with GTK+ 2 -- dunno why. Presumably all the resizing hacks | |
3243 * in Vim confuse GTK+. */ | |
3244 gtk_window_set_geometry_hints(GTK_WINDOW(gui.mainwin), gui.mainwin, | |
3245 &geometry, geometry_mask); | |
856 | 3246 old_width = width; |
3247 old_height = height; | |
3248 old_min_width = min_width; | |
3249 old_min_height = min_height; | |
3250 old_char_width = gui.char_width; | |
3251 old_char_height = gui.char_height; | |
685 | 3252 } |
3253 } | |
3254 | |
7 | 3255 #ifdef FEAT_TOOLBAR |
3256 | |
3257 /* | |
3258 * This extra effort wouldn't be necessary if we only used stock icons in the | |
3259 * toolbar, as we do for all builtin icons. But user-defined toolbar icons | |
3260 * shouldn't be treated differently, thus we do need this. | |
3261 */ | |
3262 static void | |
3263 icon_size_changed_foreach(GtkWidget *widget, gpointer user_data) | |
3264 { | |
3265 if (GTK_IS_IMAGE(widget)) | |
3266 { | |
3267 GtkImage *image = (GtkImage *)widget; | |
3268 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3269 # if GTK_CHECK_VERSION(3,10,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3270 if (gtk_image_get_storage_type(image) == GTK_IMAGE_ICON_NAME) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3271 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3272 const GtkIconSize icon_size = GPOINTER_TO_INT(user_data); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3273 const gchar *icon_name; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3274 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3275 gtk_image_get_icon_name(image, &icon_name, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3276 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3277 gtk_image_set_from_icon_name(image, icon_name, icon_size); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3278 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3279 # else |
7 | 3280 /* User-defined icons are stored in a GtkIconSet */ |
3281 if (gtk_image_get_storage_type(image) == GTK_IMAGE_ICON_SET) | |
3282 { | |
3283 GtkIconSet *icon_set; | |
3284 GtkIconSize icon_size; | |
3285 | |
3286 gtk_image_get_icon_set(image, &icon_set, &icon_size); | |
3287 icon_size = (GtkIconSize)(long)user_data; | |
3288 | |
3289 gtk_icon_set_ref(icon_set); | |
3290 gtk_image_set_from_icon_set(image, icon_set, icon_size); | |
3291 gtk_icon_set_unref(icon_set); | |
3292 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3293 # endif |
7 | 3294 } |
3295 else if (GTK_IS_CONTAINER(widget)) | |
3296 { | |
3297 gtk_container_foreach((GtkContainer *)widget, | |
3298 &icon_size_changed_foreach, | |
3299 user_data); | |
3300 } | |
3301 } | |
3302 | |
3303 static void | |
3304 set_toolbar_style(GtkToolbar *toolbar) | |
3305 { | |
3306 GtkToolbarStyle style; | |
3307 GtkIconSize size; | |
3308 GtkIconSize oldsize; | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3309 |
7 | 3310 if ((toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS | TOOLBAR_HORIZ)) |
3311 == (TOOLBAR_TEXT | TOOLBAR_ICONS | TOOLBAR_HORIZ)) | |
3312 style = GTK_TOOLBAR_BOTH_HORIZ; | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3313 else if ((toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS)) |
7 | 3314 == (TOOLBAR_TEXT | TOOLBAR_ICONS)) |
3315 style = GTK_TOOLBAR_BOTH; | |
3316 else if (toolbar_flags & TOOLBAR_TEXT) | |
3317 style = GTK_TOOLBAR_TEXT; | |
3318 else | |
3319 style = GTK_TOOLBAR_ICONS; | |
3320 | |
3321 gtk_toolbar_set_style(toolbar, style); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3322 # if !GTK_CHECK_VERSION(3,0,0) |
7 | 3323 gtk_toolbar_set_tooltips(toolbar, (toolbar_flags & TOOLBAR_TOOLTIPS) != 0); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3324 # endif |
7 | 3325 |
3326 switch (tbis_flags) | |
3327 { | |
3328 case TBIS_TINY: size = GTK_ICON_SIZE_MENU; break; | |
3329 case TBIS_SMALL: size = GTK_ICON_SIZE_SMALL_TOOLBAR; break; | |
3330 case TBIS_MEDIUM: size = GTK_ICON_SIZE_BUTTON; break; | |
3331 case TBIS_LARGE: size = GTK_ICON_SIZE_LARGE_TOOLBAR; break; | |
3332 default: size = GTK_ICON_SIZE_INVALID; break; | |
3333 } | |
3334 oldsize = gtk_toolbar_get_icon_size(toolbar); | |
3335 | |
3336 if (size == GTK_ICON_SIZE_INVALID) | |
3337 { | |
3338 /* Let global user preferences decide the icon size. */ | |
3339 gtk_toolbar_unset_icon_size(toolbar); | |
3340 size = gtk_toolbar_get_icon_size(toolbar); | |
3341 } | |
3342 if (size != oldsize) | |
3343 { | |
3344 gtk_container_foreach(GTK_CONTAINER(toolbar), | |
3345 &icon_size_changed_foreach, | |
3346 GINT_TO_POINTER((int)size)); | |
3347 } | |
3348 gtk_toolbar_set_icon_size(toolbar, size); | |
3349 } | |
3350 | |
3351 #endif /* FEAT_TOOLBAR */ | |
3352 | |
685 | 3353 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
3354 static int ignore_tabline_evt = FALSE; | |
689 | 3355 static GtkWidget *tabline_menu; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3356 # if !GTK_CHECK_VERSION(3,0,0) |
846 | 3357 static GtkTooltips *tabline_tooltip; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3358 # endif |
689 | 3359 static int clicked_page; /* page clicked in tab line */ |
3360 | |
3361 /* | |
3362 * Handle selecting an item in the tab line popup menu. | |
3363 */ | |
3364 static void | |
1884 | 3365 tabline_menu_handler(GtkMenuItem *item UNUSED, gpointer user_data) |
689 | 3366 { |
3367 /* Add the string cmd into input buffer */ | |
824 | 3368 send_tabline_menu_event(clicked_page, (int)(long)user_data); |
689 | 3369 } |
3370 | |
851 | 3371 static void |
3372 add_tabline_menu_item(GtkWidget *menu, char_u *text, int resp) | |
3373 { | |
3374 GtkWidget *item; | |
3375 char_u *utf_text; | |
3376 | |
3377 utf_text = CONVERT_TO_UTF8(text); | |
3378 item = gtk_menu_item_new_with_label((const char *)utf_text); | |
3379 gtk_widget_show(item); | |
3380 CONVERT_TO_UTF8_FREE(utf_text); | |
3381 | |
3382 gtk_container_add(GTK_CONTAINER(menu), item); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3383 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3384 g_signal_connect(G_OBJECT(item), "activate", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3385 G_CALLBACK(tabline_menu_handler), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3386 GINT_TO_POINTER(resp)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3387 # else |
851 | 3388 gtk_signal_connect(GTK_OBJECT(item), "activate", |
3389 GTK_SIGNAL_FUNC(tabline_menu_handler), | |
1660 | 3390 (gpointer)(long)resp); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3391 # endif |
851 | 3392 } |
3393 | |
689 | 3394 /* |
3395 * Create a menu for the tab line. | |
3396 */ | |
3397 static GtkWidget * | |
3398 create_tabline_menu(void) | |
3399 { | |
851 | 3400 GtkWidget *menu; |
689 | 3401 |
3402 menu = gtk_menu_new(); | |
6819 | 3403 if (first_tabpage->tp_next != NULL) |
3404 add_tabline_menu_item(menu, (char_u *)_("Close tab"), | |
3405 TABLINE_MENU_CLOSE); | |
851 | 3406 add_tabline_menu_item(menu, (char_u *)_("New tab"), TABLINE_MENU_NEW); |
3407 add_tabline_menu_item(menu, (char_u *)_("Open Tab..."), TABLINE_MENU_OPEN); | |
689 | 3408 |
3409 return menu; | |
3410 } | |
3411 | |
3412 static gboolean | |
3413 on_tabline_menu(GtkWidget *widget, GdkEvent *event) | |
3414 { | |
3415 /* Was this button press event ? */ | |
3416 if (event->type == GDK_BUTTON_PRESS) | |
3417 { | |
3418 GdkEventButton *bevent = (GdkEventButton *)event; | |
3419 int x = bevent->x; | |
851 | 3420 int y = bevent->y; |
3421 GtkWidget *tabwidget; | |
3422 GdkWindow *tabwin; | |
689 | 3423 |
844 | 3424 /* When ignoring events return TRUE so that the selected page doesn't |
3425 * change. */ | |
3426 if (hold_gui_events | |
3427 # ifdef FEAT_CMDWIN | |
3428 || cmdwin_type != 0 | |
3429 # endif | |
3430 ) | |
3431 return TRUE; | |
3432 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3433 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3434 tabwin = gui_gtk_window_at_position(gui.mainwin, &x, &y); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3435 # else |
851 | 3436 tabwin = gdk_window_at_pointer(&x, &y); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3437 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3438 |
851 | 3439 gdk_window_get_user_data(tabwin, (gpointer)&tabwidget); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3440 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3441 clicked_page = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(tabwidget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3442 "tab_num")); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3443 # else |
851 | 3444 clicked_page = (int)(long)gtk_object_get_user_data( |
3445 GTK_OBJECT(tabwidget)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3446 # endif |
689 | 3447 |
3448 /* If the event was generated for 3rd button popup the menu. */ | |
3449 if (bevent->button == 3) | |
3450 { | |
3451 gtk_menu_popup(GTK_MENU(widget), NULL, NULL, NULL, NULL, | |
3452 bevent->button, bevent->time); | |
3453 /* We handled the event. */ | |
3454 return TRUE; | |
3455 } | |
868 | 3456 else if (bevent->button == 1) |
693 | 3457 { |
868 | 3458 if (clicked_page == 0) |
3459 { | |
1394 | 3460 /* Click after all tabs moves to next tab page. When "x" is |
3461 * small guess it's the left button. */ | |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
3462 send_tabline_event(x < 50 ? -1 : 0); |
868 | 3463 } |
693 | 3464 } |
689 | 3465 } |
844 | 3466 |
689 | 3467 /* We didn't handle the event. */ |
3468 return FALSE; | |
3469 } | |
685 | 3470 |
3471 /* | |
3472 * Handle selecting one of the tabs. | |
3473 */ | |
3474 static void | |
3475 on_select_tab( | |
1884 | 3476 GtkNotebook *notebook UNUSED, |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3477 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3478 gpointer *page UNUSED, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3479 # else |
1884 | 3480 GtkNotebookPage *page UNUSED, |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3481 # endif |
944 | 3482 gint idx, |
1884 | 3483 gpointer data UNUSED) |
685 | 3484 { |
3485 if (!ignore_tabline_evt) | |
693 | 3486 { |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
3487 send_tabline_event(idx + 1); |
693 | 3488 } |
685 | 3489 } |
3490 | |
3491 /* | |
3492 * Show or hide the tabline. | |
3493 */ | |
3494 void | |
3495 gui_mch_show_tabline(int showit) | |
3496 { | |
3497 if (gui.tabline == NULL) | |
3498 return; | |
3499 | |
3500 if (!showit != !gtk_notebook_get_show_tabs(GTK_NOTEBOOK(gui.tabline))) | |
3501 { | |
708 | 3502 /* Note: this may cause a resize event */ |
685 | 3503 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gui.tabline), showit); |
791 | 3504 update_window_manager_hints(0, 0); |
868 | 3505 if (showit) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3506 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3507 gtk_widget_set_can_focus(GTK_WIDGET(gui.tabline), FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3508 # else |
868 | 3509 GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(gui.tabline), GTK_CAN_FOCUS); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3510 # endif |
868 | 3511 } |
3512 | |
3513 gui_mch_update(); | |
685 | 3514 } |
3515 | |
3516 /* | |
708 | 3517 * Return TRUE when tabline is displayed. |
3518 */ | |
3519 int | |
3520 gui_mch_showing_tabline(void) | |
3521 { | |
3522 return gui.tabline != NULL | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3523 && gtk_notebook_get_show_tabs(GTK_NOTEBOOK(gui.tabline)); |
708 | 3524 } |
3525 | |
3526 /* | |
685 | 3527 * Update the labels of the tabline. |
3528 */ | |
3529 void | |
3530 gui_mch_update_tabline(void) | |
3531 { | |
3532 GtkWidget *page; | |
846 | 3533 GtkWidget *event_box; |
685 | 3534 GtkWidget *label; |
3535 tabpage_T *tp; | |
3536 int nr = 0; | |
851 | 3537 int tab_num; |
685 | 3538 int curtabidx = 0; |
836 | 3539 char_u *labeltext; |
685 | 3540 |
3541 if (gui.tabline == NULL) | |
3542 return; | |
3543 | |
3544 ignore_tabline_evt = TRUE; | |
3545 | |
3546 /* Add a label for each tab page. They all contain the same text area. */ | |
3547 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr) | |
3548 { | |
3549 if (tp == curtab) | |
3550 curtabidx = nr; | |
3551 | |
851 | 3552 tab_num = nr + 1; |
3553 | |
685 | 3554 page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr); |
3555 if (page == NULL) | |
3556 { | |
3557 /* Add notebook page */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3558 # if GTK_CHECK_VERSION(3,2,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3559 page = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3560 gtk_box_set_homogeneous(GTK_BOX(page), FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3561 # else |
685 | 3562 page = gtk_vbox_new(FALSE, 0); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3563 # endif |
685 | 3564 gtk_widget_show(page); |
846 | 3565 event_box = gtk_event_box_new(); |
3566 gtk_widget_show(event_box); | |
685 | 3567 label = gtk_label_new("-Empty-"); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3568 # if !GTK_CHECK_VERSION(3,14,0) |
851 | 3569 gtk_misc_set_padding(GTK_MISC(label), 2, 2); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3570 # endif |
846 | 3571 gtk_container_add(GTK_CONTAINER(event_box), label); |
685 | 3572 gtk_widget_show(label); |
3573 gtk_notebook_insert_page(GTK_NOTEBOOK(gui.tabline), | |
3574 page, | |
846 | 3575 event_box, |
685 | 3576 nr++); |
3577 } | |
3578 | |
846 | 3579 event_box = gtk_notebook_get_tab_label(GTK_NOTEBOOK(gui.tabline), page); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3580 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3581 g_object_set_data(G_OBJECT(event_box), "tab_num", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3582 GINT_TO_POINTER(tab_num)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3583 # else |
1660 | 3584 gtk_object_set_user_data(GTK_OBJECT(event_box), |
3585 (gpointer)(long)tab_num); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3586 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3587 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3588 label = gtk_bin_get_child(GTK_BIN(event_box)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3589 # else |
846 | 3590 label = GTK_BIN(event_box)->child; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3591 # endif |
839 | 3592 get_tabline_label(tp, FALSE); |
836 | 3593 labeltext = CONVERT_TO_UTF8(NameBuff); |
846 | 3594 gtk_label_set_text(GTK_LABEL(label), (const char *)labeltext); |
836 | 3595 CONVERT_TO_UTF8_FREE(labeltext); |
846 | 3596 |
3597 get_tabline_label(tp, TRUE); | |
3598 labeltext = CONVERT_TO_UTF8(NameBuff); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3599 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3600 gtk_widget_set_tooltip_text(event_box, (const gchar *)labeltext); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3601 # else |
846 | 3602 gtk_tooltips_set_tip(GTK_TOOLTIPS(tabline_tooltip), event_box, |
3603 (const char *)labeltext, NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3604 # endif |
846 | 3605 CONVERT_TO_UTF8_FREE(labeltext); |
685 | 3606 } |
3607 | |
3608 /* Remove any old labels. */ | |
3609 while (gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr) != NULL) | |
3610 gtk_notebook_remove_page(GTK_NOTEBOOK(gui.tabline), nr); | |
3611 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3612 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3613 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(gui.tabline)) != curtabidx) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3614 gtk_notebook_set_current_page(GTK_NOTEBOOK(gui.tabline), curtabidx); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3615 # else |
685 | 3616 if (gtk_notebook_current_page(GTK_NOTEBOOK(gui.tabline)) != curtabidx) |
856 | 3617 gtk_notebook_set_page(GTK_NOTEBOOK(gui.tabline), curtabidx); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3618 # endif |
685 | 3619 |
851 | 3620 /* Make sure everything is in place before drawing text. */ |
3621 gui_mch_update(); | |
3622 | |
685 | 3623 ignore_tabline_evt = FALSE; |
3624 } | |
3625 | |
3626 /* | |
3627 * Set the current tab to "nr". First tab is 1. | |
3628 */ | |
3629 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
3630 gui_mch_set_curtab(int nr) |
685 | 3631 { |
3632 if (gui.tabline == NULL) | |
3633 return; | |
3634 | |
3635 ignore_tabline_evt = TRUE; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3636 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3637 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(gui.tabline)) != nr - 1) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3638 gtk_notebook_set_current_page(GTK_NOTEBOOK(gui.tabline), nr - 1); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3639 # else |
685 | 3640 if (gtk_notebook_current_page(GTK_NOTEBOOK(gui.tabline)) != nr - 1) |
856 | 3641 gtk_notebook_set_page(GTK_NOTEBOOK(gui.tabline), nr - 1); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3642 # endif |
685 | 3643 ignore_tabline_evt = FALSE; |
3644 } | |
3645 | |
3646 #endif /* FEAT_GUI_TABLINE */ | |
3647 | |
7 | 3648 /* |
2183 | 3649 * Add selection targets for PRIMARY and CLIPBOARD selections. |
3650 */ | |
3651 void | |
3652 gui_gtk_set_selection_targets(void) | |
3653 { | |
3654 int i, j = 0; | |
3655 int n_targets = N_SELECTION_TARGETS; | |
3656 GtkTargetEntry targets[N_SELECTION_TARGETS]; | |
3657 | |
3658 for (i = 0; i < (int)N_SELECTION_TARGETS; ++i) | |
3659 { | |
3518 | 3660 /* OpenOffice tries to use TARGET_HTML and fails when we don't |
2183 | 3661 * return something, instead of trying another target. Therefore only |
3662 * offer TARGET_HTML when it works. */ | |
3663 if (!clip_html && selection_targets[i].info == TARGET_HTML) | |
3664 n_targets--; | |
3665 else | |
3666 targets[j++] = selection_targets[i]; | |
3667 } | |
3668 | |
3669 gtk_selection_clear_targets(gui.drawarea, (GdkAtom)GDK_SELECTION_PRIMARY); | |
3670 gtk_selection_clear_targets(gui.drawarea, (GdkAtom)clip_plus.gtk_sel_atom); | |
3671 gtk_selection_add_targets(gui.drawarea, | |
3672 (GdkAtom)GDK_SELECTION_PRIMARY, | |
3673 targets, n_targets); | |
3674 gtk_selection_add_targets(gui.drawarea, | |
3675 (GdkAtom)clip_plus.gtk_sel_atom, | |
3676 targets, n_targets); | |
3677 } | |
3678 | |
3679 /* | |
3680 * Set up for receiving DND items. | |
3681 */ | |
3682 void | |
3683 gui_gtk_set_dnd_targets(void) | |
3684 { | |
3685 int i, j = 0; | |
3686 int n_targets = N_DND_TARGETS; | |
3687 GtkTargetEntry targets[N_DND_TARGETS]; | |
3688 | |
3689 for (i = 0; i < (int)N_DND_TARGETS; ++i) | |
3690 { | |
3154 | 3691 if (!clip_html && dnd_targets[i].info == TARGET_HTML) |
2183 | 3692 n_targets--; |
3693 else | |
3694 targets[j++] = dnd_targets[i]; | |
3695 } | |
3696 | |
3697 gtk_drag_dest_unset(gui.drawarea); | |
3698 gtk_drag_dest_set(gui.drawarea, | |
3699 GTK_DEST_DEFAULT_ALL, | |
3700 targets, n_targets, | |
2718 | 3701 GDK_ACTION_COPY | GDK_ACTION_MOVE); |
2183 | 3702 } |
3703 | |
3704 /* | |
7 | 3705 * Initialize the GUI. Create all the windows, set up all the callbacks etc. |
3706 * Returns OK for success, FAIL when the GUI can't be started. | |
3707 */ | |
3708 int | |
3709 gui_mch_init(void) | |
3710 { | |
3711 GtkWidget *vbox; | |
3712 | |
3713 #ifdef FEAT_GUI_GNOME | |
3714 /* Initialize the GNOME libraries. gnome_program_init()/gnome_init() | |
3715 * exits on failure, but that's a non-issue because we already called | |
3716 * gtk_init_check() in gui_mch_init_check(). */ | |
3717 if (using_gnome) | |
4045 | 3718 { |
7 | 3719 gnome_program_init(VIMPACKAGE, VIM_VERSION_SHORT, |
3720 LIBGNOMEUI_MODULE, gui_argc, gui_argv, NULL); | |
4045 | 3721 # if defined(FEAT_FLOAT) && defined(LC_NUMERIC) |
5854 | 3722 { |
3723 char *p = setlocale(LC_NUMERIC, NULL); | |
3724 | |
3725 /* Make sure strtod() uses a decimal point, not a comma. Gnome | |
3726 * init may change it. */ | |
3727 if (p == NULL || strcmp(p, "C") != 0) | |
3728 setlocale(LC_NUMERIC, "C"); | |
3729 } | |
4045 | 3730 # endif |
3731 } | |
7 | 3732 #endif |
3733 vim_free(gui_argv); | |
3734 gui_argv = NULL; | |
3735 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3736 #if GLIB_CHECK_VERSION(2,1,3) |
7 | 3737 /* Set the human-readable application name */ |
3738 g_set_application_name("Vim"); | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3739 #endif |
7 | 3740 /* |
3741 * Force UTF-8 output no matter what the value of 'encoding' is. | |
3742 * did_set_string_option() in option.c prohibits changing 'termencoding' | |
3743 * to something else than UTF-8 if the GUI is in use. | |
3744 */ | |
3745 set_option_value((char_u *)"termencoding", 0L, (char_u *)"utf-8", 0); | |
3746 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3747 #ifdef FEAT_TOOLBAR |
7 | 3748 gui_gtk_register_stock_icons(); |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3749 #endif |
7 | 3750 /* FIXME: Need to install the classic icons and a gtkrc.classic file. |
3751 * The hard part is deciding install locations and the Makefile magic. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3752 #if !GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3753 # if 0 |
7 | 3754 gtk_rc_parse("gtkrc"); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3755 # endif |
7 | 3756 #endif |
3757 | |
3758 /* Initialize values */ | |
3759 gui.border_width = 2; | |
3760 gui.scrollbar_width = SB_DEFAULT_WIDTH; | |
3761 gui.scrollbar_height = SB_DEFAULT_WIDTH; | |
136 | 3762 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
7 | 3763 gui.fgcolor = g_new0(GdkColor, 1); |
136 | 3764 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
7 | 3765 gui.bgcolor = g_new0(GdkColor, 1); |
207 | 3766 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
3767 gui.spcolor = g_new0(GdkColor, 1); | |
7 | 3768 |
3769 /* Initialise atoms */ | |
1904 | 3770 html_atom = gdk_atom_intern("text/html", FALSE); |
7 | 3771 utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE); |
3772 | |
3773 /* Set default foreground and background colors. */ | |
3774 gui.norm_pixel = gui.def_norm_pixel; | |
3775 gui.back_pixel = gui.def_back_pixel; | |
3776 | |
3777 if (gtk_socket_id != 0) | |
3778 { | |
3779 GtkWidget *plug; | |
3780 | |
3781 /* Use GtkSocket from another app. */ | |
3782 #ifdef HAVE_GTK_MULTIHEAD | |
3783 plug = gtk_plug_new_for_display(gdk_display_get_default(), | |
3784 gtk_socket_id); | |
3785 #else | |
3786 plug = gtk_plug_new(gtk_socket_id); | |
3787 #endif | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3788 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3789 if (plug != NULL && gtk_plug_get_socket_window(GTK_PLUG(plug)) != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3790 #else |
7 | 3791 if (plug != NULL && GTK_PLUG(plug)->socket_window != NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3792 #endif |
7 | 3793 { |
3794 gui.mainwin = plug; | |
3795 } | |
3796 else | |
3797 { | |
3798 g_warning("Connection to GTK+ socket (ID %u) failed", | |
3799 (unsigned int)gtk_socket_id); | |
3800 /* Pretend we never wanted it if it failed (get own window) */ | |
3801 gtk_socket_id = 0; | |
3802 } | |
3803 } | |
3804 | |
3805 if (gtk_socket_id == 0) | |
3806 { | |
3807 #ifdef FEAT_GUI_GNOME | |
3808 if (using_gnome) | |
3809 { | |
3810 gui.mainwin = gnome_app_new("Vim", NULL); | |
3811 # ifdef USE_XSMP | |
3812 /* Use the GNOME save-yourself functionality now. */ | |
3813 xsmp_close(); | |
3814 # endif | |
3815 } | |
3816 else | |
3817 #endif | |
3818 gui.mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
3819 } | |
3820 | |
3821 gtk_widget_set_name(gui.mainwin, "vim-main-window"); | |
3822 | |
3823 /* Create the PangoContext used for drawing all text. */ | |
3824 gui.text_context = gtk_widget_create_pango_context(gui.mainwin); | |
3825 pango_context_set_base_dir(gui.text_context, PANGO_DIRECTION_LTR); | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3826 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3827 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3828 gtk_container_set_border_width(GTK_CONTAINER(gui.mainwin), 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3829 #else |
7 | 3830 gtk_container_border_width(GTK_CONTAINER(gui.mainwin), 0); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3831 #endif |
7 | 3832 gtk_widget_add_events(gui.mainwin, GDK_VISIBILITY_NOTIFY_MASK); |
3833 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3834 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3835 g_signal_connect(G_OBJECT(gui.mainwin), "delete-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3836 G_CALLBACK(&delete_event_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3837 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3838 g_signal_connect(G_OBJECT(gui.mainwin), "realize", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3839 G_CALLBACK(&mainwin_realize), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3840 #else |
7 | 3841 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "delete_event", |
3842 GTK_SIGNAL_FUNC(&delete_event_cb), NULL); | |
3843 | |
3844 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "realize", | |
3845 GTK_SIGNAL_FUNC(&mainwin_realize), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3846 #endif |
7 | 3847 #ifdef HAVE_GTK_MULTIHEAD |
3848 g_signal_connect(G_OBJECT(gui.mainwin), "screen_changed", | |
3849 G_CALLBACK(&mainwin_screen_changed_cb), NULL); | |
3850 #endif | |
3851 gui.accel_group = gtk_accel_group_new(); | |
3852 gtk_window_add_accel_group(GTK_WINDOW(gui.mainwin), gui.accel_group); | |
3853 | |
685 | 3854 /* A vertical box holds the menubar, toolbar and main text window. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3855 #if GTK_CHECK_VERSION(3,2,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3856 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3857 gtk_box_set_homogeneous(GTK_BOX(vbox), FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3858 #else |
7 | 3859 vbox = gtk_vbox_new(FALSE, 0); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3860 #endif |
7 | 3861 |
3862 #ifdef FEAT_GUI_GNOME | |
3863 if (using_gnome) | |
3864 { | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3865 # if defined(FEAT_MENU) |
7 | 3866 /* automagically restore menubar/toolbar placement */ |
3867 gnome_app_enable_layout_config(GNOME_APP(gui.mainwin), TRUE); | |
3868 # endif | |
3869 gnome_app_set_contents(GNOME_APP(gui.mainwin), vbox); | |
3870 } | |
3871 else | |
3872 #endif | |
3873 { | |
3874 gtk_container_add(GTK_CONTAINER(gui.mainwin), vbox); | |
3875 gtk_widget_show(vbox); | |
3876 } | |
3877 | |
3878 #ifdef FEAT_MENU | |
3879 /* | |
3880 * Create the menubar and handle | |
3881 */ | |
3882 gui.menubar = gtk_menu_bar_new(); | |
3883 gtk_widget_set_name(gui.menubar, "vim-menubar"); | |
3884 | |
36 | 3885 /* Avoid that GTK takes <F10> away from us. */ |
3886 { | |
3887 GtkSettings *gtk_settings; | |
3888 | |
3889 gtk_settings = gtk_settings_get_for_screen(gdk_screen_get_default()); | |
3890 g_object_set(gtk_settings, "gtk-menu-bar-accel", NULL, NULL); | |
3891 } | |
3892 | |
3893 | |
7 | 3894 # ifdef FEAT_GUI_GNOME |
3895 if (using_gnome) | |
3896 { | |
3897 BonoboDockItem *dockitem; | |
3898 | |
3899 gnome_app_set_menus(GNOME_APP(gui.mainwin), GTK_MENU_BAR(gui.menubar)); | |
3900 dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), | |
3901 GNOME_APP_MENUBAR_NAME); | |
798 | 3902 /* We don't want the menu to float. */ |
3903 bonobo_dock_item_set_behavior(dockitem, | |
3904 bonobo_dock_item_get_behavior(dockitem) | |
3905 | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); | |
7 | 3906 gui.menubar_h = GTK_WIDGET(dockitem); |
3907 } | |
3908 else | |
3909 # endif /* FEAT_GUI_GNOME */ | |
3910 { | |
827 | 3911 /* Always show the menubar, otherwise <F10> doesn't work. It may be |
3912 * disabled in gui_init() later. */ | |
3913 gtk_widget_show(gui.menubar); | |
7 | 3914 gtk_box_pack_start(GTK_BOX(vbox), gui.menubar, FALSE, FALSE, 0); |
3915 } | |
3916 #endif /* FEAT_MENU */ | |
3917 | |
3918 #ifdef FEAT_TOOLBAR | |
3919 /* | |
3920 * Create the toolbar and handle | |
3921 */ | |
3922 /* some aesthetics on the toolbar */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3923 # ifdef USE_GTK3 |
8301
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
3924 /* TODO: Add GTK+ 3 code here using GtkCssProvider if necessary. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3925 /* N.B. Since the default value of GtkToolbar::button-relief is |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3926 * GTK_RELIEF_NONE, there's no need to specify that, probably. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3927 # else |
7 | 3928 gtk_rc_parse_string( |
3929 "style \"vim-toolbar-style\" {\n" | |
3930 " GtkToolbar::button_relief = GTK_RELIEF_NONE\n" | |
3931 "}\n" | |
3932 "widget \"*.vim-toolbar\" style \"vim-toolbar-style\"\n"); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3933 # endif |
7 | 3934 gui.toolbar = gtk_toolbar_new(); |
3935 gtk_widget_set_name(gui.toolbar, "vim-toolbar"); | |
3936 set_toolbar_style(GTK_TOOLBAR(gui.toolbar)); | |
3937 | |
3938 # ifdef FEAT_GUI_GNOME | |
3939 if (using_gnome) | |
3940 { | |
3941 BonoboDockItem *dockitem; | |
3942 | |
3943 gnome_app_set_toolbar(GNOME_APP(gui.mainwin), GTK_TOOLBAR(gui.toolbar)); | |
3944 dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), | |
3945 GNOME_APP_TOOLBAR_NAME); | |
3946 gui.toolbar_h = GTK_WIDGET(dockitem); | |
795 | 3947 /* When the toolbar is floating it gets stuck. So long as that isn't |
798 | 3948 * fixed let's disallow floating. */ |
795 | 3949 bonobo_dock_item_set_behavior(dockitem, |
798 | 3950 bonobo_dock_item_get_behavior(dockitem) |
3951 | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); | |
7 | 3952 gtk_container_set_border_width(GTK_CONTAINER(gui.toolbar), 0); |
3953 } | |
3954 else | |
3955 # endif /* FEAT_GUI_GNOME */ | |
3956 { | |
3957 if (vim_strchr(p_go, GO_TOOLBAR) != NULL | |
3958 && (toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS))) | |
3959 gtk_widget_show(gui.toolbar); | |
3960 gtk_box_pack_start(GTK_BOX(vbox), gui.toolbar, FALSE, FALSE, 0); | |
3961 } | |
3962 #endif /* FEAT_TOOLBAR */ | |
3963 | |
685 | 3964 #ifdef FEAT_GUI_TABLINE |
782 | 3965 /* |
3966 * Use a Notebook for the tab pages labels. The labels are hidden by | |
3967 * default. | |
3968 */ | |
791 | 3969 gui.tabline = gtk_notebook_new(); |
3970 gtk_widget_show(gui.tabline); | |
3971 gtk_box_pack_start(GTK_BOX(vbox), gui.tabline, FALSE, FALSE, 0); | |
3972 gtk_notebook_set_show_border(GTK_NOTEBOOK(gui.tabline), FALSE); | |
3973 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gui.tabline), FALSE); | |
841 | 3974 gtk_notebook_set_scrollable(GTK_NOTEBOOK(gui.tabline), TRUE); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3975 # if !GTK_CHECK_VERSION(3,0,0) |
868 | 3976 gtk_notebook_set_tab_border(GTK_NOTEBOOK(gui.tabline), FALSE); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3977 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3978 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3979 # if !GTK_CHECK_VERSION(3,0,0) |
846 | 3980 tabline_tooltip = gtk_tooltips_new(); |
3981 gtk_tooltips_enable(GTK_TOOLTIPS(tabline_tooltip)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3982 # endif |
846 | 3983 |
3984 { | |
3985 GtkWidget *page, *label, *event_box; | |
791 | 3986 |
856 | 3987 /* Add the first tab. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3988 # if GTK_CHECK_VERSION(3,2,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3989 page = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3990 gtk_box_set_homogeneous(GTK_BOX(page), FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3991 # else |
846 | 3992 page = gtk_vbox_new(FALSE, 0); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3993 # endif |
846 | 3994 gtk_widget_show(page); |
3995 gtk_container_add(GTK_CONTAINER(gui.tabline), page); | |
3996 label = gtk_label_new("-Empty-"); | |
3997 gtk_widget_show(label); | |
3998 event_box = gtk_event_box_new(); | |
3999 gtk_widget_show(event_box); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4000 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4001 g_object_set_data(G_OBJECT(event_box), "tab_num", GINT_TO_POINTER(1L)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4002 # else |
1660 | 4003 gtk_object_set_user_data(GTK_OBJECT(event_box), (gpointer)1L); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4004 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4005 # if !GTK_CHECK_VERSION(3,14,0) |
851 | 4006 gtk_misc_set_padding(GTK_MISC(label), 2, 2); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4007 # endif |
846 | 4008 gtk_container_add(GTK_CONTAINER(event_box), label); |
4009 gtk_notebook_set_tab_label(GTK_NOTEBOOK(gui.tabline), page, event_box); | |
791 | 4010 } |
865 | 4011 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4012 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4013 g_signal_connect(G_OBJECT(gui.tabline), "switch-page", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4014 G_CALLBACK(on_select_tab), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4015 # else |
791 | 4016 gtk_signal_connect(GTK_OBJECT(gui.tabline), "switch_page", |
856 | 4017 GTK_SIGNAL_FUNC(on_select_tab), NULL); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4018 # endif |
791 | 4019 |
4020 /* Create a popup menu for the tab line and connect it. */ | |
4021 tabline_menu = create_tabline_menu(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4022 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4023 g_signal_connect_swapped(G_OBJECT(gui.tabline), "button-press-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4024 G_CALLBACK(on_tabline_menu), G_OBJECT(tabline_menu)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4025 # else |
791 | 4026 gtk_signal_connect_object(GTK_OBJECT(gui.tabline), "button_press_event", |
856 | 4027 GTK_SIGNAL_FUNC(on_tabline_menu), GTK_OBJECT(tabline_menu)); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4028 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4029 #endif /* FEAT_GUI_TABLINE */ |
685 | 4030 |
7 | 4031 gui.formwin = gtk_form_new(); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4032 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4033 gtk_container_set_border_width(GTK_CONTAINER(gui.formwin), 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4034 #else |
7 | 4035 gtk_container_border_width(GTK_CONTAINER(gui.formwin), 0); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4036 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4037 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 4038 gtk_widget_set_events(gui.formwin, GDK_EXPOSURE_MASK); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4039 #endif |
7 | 4040 |
4041 gui.drawarea = gtk_drawing_area_new(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4042 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4043 gui.surface = NULL; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4044 gui.by_signal = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4045 #endif |
7 | 4046 |
4047 /* Determine which events we will filter. */ | |
4048 gtk_widget_set_events(gui.drawarea, | |
4049 GDK_EXPOSURE_MASK | | |
4050 GDK_ENTER_NOTIFY_MASK | | |
4051 GDK_LEAVE_NOTIFY_MASK | | |
4052 GDK_BUTTON_PRESS_MASK | | |
4053 GDK_BUTTON_RELEASE_MASK | | |
4054 GDK_SCROLL_MASK | | |
4055 GDK_KEY_PRESS_MASK | | |
4056 GDK_KEY_RELEASE_MASK | | |
4057 GDK_POINTER_MOTION_MASK | | |
4058 GDK_POINTER_MOTION_HINT_MASK); | |
4059 | |
4060 gtk_widget_show(gui.drawarea); | |
4061 gtk_form_put(GTK_FORM(gui.formwin), gui.drawarea, 0, 0); | |
4062 gtk_widget_show(gui.formwin); | |
4063 gtk_box_pack_start(GTK_BOX(vbox), gui.formwin, TRUE, TRUE, 0); | |
4064 | |
4065 /* For GtkSockets, key-presses must go to the focus widget (drawarea) | |
4066 * and not the window. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4067 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4068 g_signal_connect((gtk_socket_id == 0) ? G_OBJECT(gui.mainwin) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4069 : G_OBJECT(gui.drawarea), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4070 "key-press-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4071 G_CALLBACK(key_press_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4072 #else |
7 | 4073 gtk_signal_connect((gtk_socket_id == 0) ? GTK_OBJECT(gui.mainwin) |
4074 : GTK_OBJECT(gui.drawarea), | |
4075 "key_press_event", | |
4076 GTK_SIGNAL_FUNC(key_press_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4077 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4078 #if defined(FEAT_XIM) || GTK_CHECK_VERSION(3,0,0) |
7 | 4079 /* Also forward key release events for the benefit of GTK+ 2 input |
4080 * modules. Try CTRL-SHIFT-xdigits to enter a Unicode code point. */ | |
4081 g_signal_connect((gtk_socket_id == 0) ? G_OBJECT(gui.mainwin) | |
4082 : G_OBJECT(gui.drawarea), | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4083 "key-release-event", |
7 | 4084 G_CALLBACK(&key_release_event), NULL); |
4085 #endif | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4086 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4087 g_signal_connect(G_OBJECT(gui.drawarea), "realize", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4088 G_CALLBACK(drawarea_realize_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4089 g_signal_connect(G_OBJECT(gui.drawarea), "unrealize", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4090 G_CALLBACK(drawarea_unrealize_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4091 g_signal_connect(G_OBJECT(gui.drawarea), "configure-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4092 G_CALLBACK(drawarea_configure_event_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4093 g_signal_connect_after(G_OBJECT(gui.drawarea), "style-set", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4094 G_CALLBACK(&drawarea_style_set_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4095 #else |
7 | 4096 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "realize", |
4097 GTK_SIGNAL_FUNC(drawarea_realize_cb), NULL); | |
4098 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "unrealize", | |
4099 GTK_SIGNAL_FUNC(drawarea_unrealize_cb), NULL); | |
4100 | |
4101 gtk_signal_connect_after(GTK_OBJECT(gui.drawarea), "style_set", | |
4102 GTK_SIGNAL_FUNC(&drawarea_style_set_cb), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4103 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4104 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4105 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 4106 gui.visibility = GDK_VISIBILITY_UNOBSCURED; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4107 #endif |
7 | 4108 |
4109 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
4110 wm_protocols_atom = gdk_atom_intern("WM_PROTOCOLS", FALSE); | |
4111 save_yourself_atom = gdk_atom_intern("WM_SAVE_YOURSELF", FALSE); | |
4112 #endif | |
4113 | |
4114 if (gtk_socket_id != 0) | |
1884 | 4115 /* make sure keyboard input can go to the drawarea */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4116 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4117 gtk_widget_set_can_focus(gui.drawarea, TRUE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4118 #else |
7 | 4119 GTK_WIDGET_SET_FLAGS(gui.drawarea, GTK_CAN_FOCUS); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4120 #endif |
7 | 4121 |
4122 /* | |
4123 * Set clipboard specific atoms | |
4124 */ | |
4125 vim_atom = gdk_atom_intern(VIM_ATOM_NAME, FALSE); | |
4126 vimenc_atom = gdk_atom_intern(VIMENC_ATOM_NAME, FALSE); | |
4127 clip_star.gtk_sel_atom = GDK_SELECTION_PRIMARY; | |
4128 clip_plus.gtk_sel_atom = gdk_atom_intern("CLIPBOARD", FALSE); | |
4129 | |
4130 /* | |
4131 * Start out by adding the configured border width into the border offset. | |
4132 */ | |
4133 gui.border_offset = gui.border_width; | |
4134 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4135 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4136 g_signal_connect(G_OBJECT(gui.drawarea), "draw", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4137 G_CALLBACK(draw_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4138 #else |
7 | 4139 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "visibility_notify_event", |
4140 GTK_SIGNAL_FUNC(visibility_event), NULL); | |
4141 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "expose_event", | |
4142 GTK_SIGNAL_FUNC(expose_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4143 #endif |
7 | 4144 |
4145 /* | |
4146 * Only install these enter/leave callbacks when 'p' in 'guioptions'. | |
4147 * Only needed for some window managers. | |
4148 */ | |
4149 if (vim_strchr(p_go, GO_POINTER) != NULL) | |
4150 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4151 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4152 g_signal_connect(G_OBJECT(gui.drawarea), "leave-notify-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4153 G_CALLBACK(leave_notify_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4154 g_signal_connect(G_OBJECT(gui.drawarea), "enter-notify-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4155 G_CALLBACK(enter_notify_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4156 #else |
7 | 4157 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "leave_notify_event", |
4158 GTK_SIGNAL_FUNC(leave_notify_event), NULL); | |
4159 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "enter_notify_event", | |
4160 GTK_SIGNAL_FUNC(enter_notify_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4161 #endif |
7 | 4162 } |
4163 | |
791 | 4164 /* Real windows can get focus ... GtkPlug, being a mere container can't, |
4165 * only its widgets. Arguably, this could be common code and we not use | |
4166 * the window focus at all, but let's be safe. | |
4167 */ | |
4168 if (gtk_socket_id == 0) | |
4169 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4170 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4171 g_signal_connect(G_OBJECT(gui.mainwin), "focus-out-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4172 G_CALLBACK(focus_out_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4173 g_signal_connect(G_OBJECT(gui.mainwin), "focus-in-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4174 G_CALLBACK(focus_in_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4175 #else |
856 | 4176 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "focus_out_event", |
4177 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
4178 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "focus_in_event", | |
4179 GTK_SIGNAL_FUNC(focus_in_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4180 #endif |
791 | 4181 } |
4182 else | |
4183 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4184 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4185 g_signal_connect(G_OBJECT(gui.drawarea), "focus-out-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4186 G_CALLBACK(focus_out_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4187 g_signal_connect(G_OBJECT(gui.drawarea), "focus-in-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4188 G_CALLBACK(focus_in_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4189 #else |
856 | 4190 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "focus_out_event", |
4191 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
4192 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "focus_in_event", | |
4193 GTK_SIGNAL_FUNC(focus_in_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4194 #endif |
791 | 4195 #ifdef FEAT_GUI_TABLINE |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4196 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4197 g_signal_connect(G_OBJECT(gui.tabline), "focus-out-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4198 G_CALLBACK(focus_out_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4199 g_signal_connect(G_OBJECT(gui.tabline), "focus-in-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4200 G_CALLBACK(focus_in_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4201 # else |
856 | 4202 gtk_signal_connect(GTK_OBJECT(gui.tabline), "focus_out_event", |
4203 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
4204 gtk_signal_connect(GTK_OBJECT(gui.tabline), "focus_in_event", | |
4205 GTK_SIGNAL_FUNC(focus_in_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4206 # endif |
791 | 4207 #endif /* FEAT_GUI_TABLINE */ |
4208 } | |
7 | 4209 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4210 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4211 g_signal_connect(G_OBJECT(gui.drawarea), "motion-notify-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4212 G_CALLBACK(motion_notify_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4213 g_signal_connect(G_OBJECT(gui.drawarea), "button-press-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4214 G_CALLBACK(button_press_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4215 g_signal_connect(G_OBJECT(gui.drawarea), "button-release-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4216 G_CALLBACK(button_release_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4217 g_signal_connect(G_OBJECT(gui.drawarea), "scroll-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4218 G_CALLBACK(&scroll_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4219 #else |
7 | 4220 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "motion_notify_event", |
4221 GTK_SIGNAL_FUNC(motion_notify_event), NULL); | |
4222 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "button_press_event", | |
4223 GTK_SIGNAL_FUNC(button_press_event), NULL); | |
4224 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "button_release_event", | |
4225 GTK_SIGNAL_FUNC(button_release_event), NULL); | |
4226 g_signal_connect(G_OBJECT(gui.drawarea), "scroll_event", | |
4227 G_CALLBACK(&scroll_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4228 #endif |
7 | 4229 |
4230 /* | |
4231 * Add selection handler functions. | |
4232 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4233 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4234 g_signal_connect(G_OBJECT(gui.drawarea), "selection-clear-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4235 G_CALLBACK(selection_clear_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4236 g_signal_connect(G_OBJECT(gui.drawarea), "selection-received", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4237 G_CALLBACK(selection_received_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4238 #else |
7 | 4239 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_clear_event", |
4240 GTK_SIGNAL_FUNC(selection_clear_event), NULL); | |
4241 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_received", | |
4242 GTK_SIGNAL_FUNC(selection_received_cb), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4243 #endif |
7 | 4244 |
2183 | 4245 gui_gtk_set_selection_targets(); |
7 | 4246 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4247 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4248 g_signal_connect(G_OBJECT(gui.drawarea), "selection-get", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4249 G_CALLBACK(selection_get_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4250 #else |
7 | 4251 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_get", |
4252 GTK_SIGNAL_FUNC(selection_get_cb), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4253 #endif |
7 | 4254 |
4255 /* Pretend we don't have input focus, we will get an event if we do. */ | |
4256 gui.in_focus = FALSE; | |
4257 | |
4258 return OK; | |
4259 } | |
4260 | |
4261 #if (defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) || defined(PROTO) | |
4262 /* | |
4263 * This is called from gui_start() after a fork() has been done. | |
4264 * We have to tell the session manager our new PID. | |
4265 */ | |
4266 void | |
4267 gui_mch_forked(void) | |
4268 { | |
4269 if (using_gnome) | |
4270 { | |
4271 GnomeClient *client; | |
4272 | |
4273 client = gnome_master_client(); | |
4274 | |
4275 if (client != NULL) | |
4276 gnome_client_set_process_id(client, getpid()); | |
4277 } | |
4278 } | |
4279 #endif /* FEAT_GUI_GNOME && FEAT_SESSION */ | |
4280 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4281 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4282 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4283 gui_gtk_get_rgb_from_pixel(guint32 pixel, GdkRGBA *result) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4284 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4285 GdkVisual * const visual = gtk_widget_get_visual(gui.drawarea); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4286 guint32 r_mask, g_mask, b_mask; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4287 gint r_shift, g_shift, b_shift; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4288 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4289 if (visual == NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4290 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4291 result->red = 0.0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4292 result->green = 0.0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4293 result->blue = 0.0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4294 result->alpha = 0.0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4295 return; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4296 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4297 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4298 gdk_visual_get_red_pixel_details(visual, &r_mask, &r_shift, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4299 gdk_visual_get_green_pixel_details(visual, &g_mask, &g_shift, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4300 gdk_visual_get_blue_pixel_details(visual, &b_mask, &b_shift, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4301 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4302 result->red = ((pixel & r_mask) >> r_shift) / 255.0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4303 result->green = ((pixel & g_mask) >> g_shift) / 255.0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4304 result->blue = ((pixel & b_mask) >> b_shift) / 255.0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4305 result->alpha = 1.0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4306 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4307 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4308 /* Convert a GdRGBA into a pixel value using drawarea's visual */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4309 static guint32 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4310 gui_gtk_get_pixel_from_rgb(const GdkRGBA *rgba) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4311 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4312 GdkVisual * const visual = gtk_widget_get_visual(gui.drawarea); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4313 guint32 r_mask, g_mask, b_mask; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4314 gint r_shift, g_shift, b_shift; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4315 guint32 r, g, b; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4316 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4317 if (visual == NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4318 return 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4319 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4320 gdk_visual_get_red_pixel_details(visual, &r_mask, &r_shift, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4321 gdk_visual_get_green_pixel_details(visual, &g_mask, &g_shift, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4322 gdk_visual_get_blue_pixel_details(visual, &b_mask, &b_shift, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4323 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4324 r = rgba->red * 65535; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4325 g = rgba->green * 65535; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4326 b = rgba->blue * 65535; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4327 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4328 return ((r << r_shift) & r_mask) | |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4329 ((g << g_shift) & g_mask) | |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4330 ((b << b_shift) & b_mask); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4331 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4332 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4333 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4334 set_cairo_source_rgb_from_pixel(cairo_t *cr, guint32 pixel) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4335 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4336 GdkRGBA result; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4337 gui_gtk_get_rgb_from_pixel(pixel, &result); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4338 cairo_set_source_rgb(cr, result.red, result.green, result.blue); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4339 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4340 #endif /* GTK_CHECK_VERSION(3,0,0) */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4341 |
7 | 4342 /* |
4343 * Called when the foreground or background color has been changed. | |
4344 * This used to change the graphics contexts directly but we are | |
4345 * currently manipulating them where desired. | |
4346 */ | |
4347 void | |
4348 gui_mch_new_colors(void) | |
4349 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4350 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4351 GdkWindow * const da_win = gtk_widget_get_window(gui.drawarea); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4352 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4353 if (gui.drawarea != NULL && gtk_widget_get_window(gui.drawarea) != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4354 #else |
7 | 4355 if (gui.drawarea != NULL && gui.drawarea->window != NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4356 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4357 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4358 #if GTK_CHECK_VERSION(3,4,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4359 GdkRGBA color; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4360 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4361 gui_gtk_get_rgb_from_pixel(gui.back_pixel, &color); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4362 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4363 cairo_pattern_t * const pat = cairo_pattern_create_rgba( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4364 color.red, color.green, color.blue, color.alpha); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4365 if (pat != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4366 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4367 gdk_window_set_background_pattern(da_win, pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4368 cairo_pattern_destroy(pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4369 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4370 else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4371 gdk_window_set_background_rgba(da_win, &color); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4372 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4373 #else /* !GTK_CHECK_VERSION(3,4,0) */ |
7 | 4374 GdkColor color = { 0, 0, 0, 0 }; |
4375 | |
4376 color.pixel = gui.back_pixel; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4377 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4378 gdk_window_set_background(da_win, &color); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4379 # else |
7 | 4380 gdk_window_set_background(gui.drawarea->window, &color); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4381 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4382 #endif /* !GTK_CHECK_VERSION(3,4,0) */ |
7 | 4383 } |
4384 } | |
4385 | |
4386 /* | |
4387 * This signal informs us about the need to rearrange our sub-widgets. | |
4388 */ | |
4389 static gint | |
1884 | 4390 form_configure_event(GtkWidget *widget UNUSED, |
4391 GdkEventConfigure *event, | |
4392 gpointer data UNUSED) | |
7 | 4393 { |
791 | 4394 int usable_height = event->height; |
4395 | |
4396 /* When in a GtkPlug, we can't guarantee valid heights (as a round | |
4397 * no. of char-heights), so we have to manually sanitise them. | |
4398 * Widths seem to sort themselves out, don't ask me why. | |
4399 */ | |
4400 if (gtk_socket_id != 0) | |
856 | 4401 usable_height -= (gui.char_height - (gui.char_height/2)); /* sic. */ |
791 | 4402 |
7 | 4403 gtk_form_freeze(GTK_FORM(gui.formwin)); |
791 | 4404 gui_resize_shell(event->width, usable_height); |
7 | 4405 gtk_form_thaw(GTK_FORM(gui.formwin)); |
4406 | |
4407 return TRUE; | |
4408 } | |
4409 | |
4410 /* | |
4411 * Function called when window already closed. | |
4412 * We can't do much more here than to trying to preserve what had been done, | |
4413 * since the window is already inevitably going away. | |
4414 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4415 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4416 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4417 mainwin_destroy_cb(GObject *object UNUSED, gpointer data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4418 #else |
7 | 4419 static void |
1884 | 4420 mainwin_destroy_cb(GtkObject *object UNUSED, gpointer data UNUSED) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4421 #endif |
7 | 4422 { |
4423 /* Don't write messages to the GUI anymore */ | |
4424 full_screen = FALSE; | |
4425 | |
4426 gui.mainwin = NULL; | |
4427 gui.drawarea = NULL; | |
4428 | |
4429 if (!exiting) /* only do anything if the destroy was unexpected */ | |
4430 { | |
419 | 4431 vim_strncpy(IObuff, |
4432 (char_u *)_("Vim: Main window unexpectedly destroyed\n"), | |
4433 IOSIZE - 1); | |
7 | 4434 preserve_exit(); |
4435 } | |
7380
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
4436 #ifdef USE_GRESOURCE |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
4437 gui_gtk_unregister_resource(); |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
4438 #endif |
7 | 4439 } |
4440 | |
791 | 4441 |
4442 /* | |
4443 * Bit of a hack to ensure we start GtkPlug windows with the correct window | |
4444 * hints (and thus the required size from -geom), but that after that we | |
4445 * put the hints back to normal (the actual minimum size) so we may | |
4446 * subsequently be resized smaller. GtkSocket (the parent end) uses the | |
1226 | 4447 * plug's window 'min hints to set *it's* minimum size, but that's also the |
791 | 4448 * only way we have of making ourselves bigger (by set lines/columns). |
4449 * Thus set hints at start-up to ensure correct init. size, then a | |
8301
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4450 * second after the final attempt to reset the real minimum hints (done by |
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4451 * scrollbar init.), actually do the standard hints and stop the timer. |
791 | 4452 * We'll not let the default hints be set while this timer's active. |
4453 */ | |
4454 static gboolean | |
1884 | 4455 check_startup_plug_hints(gpointer data UNUSED) |
791 | 4456 { |
4457 if (init_window_hints_state == 1) | |
4458 { | |
856 | 4459 /* Safe to use normal hints now */ |
4460 init_window_hints_state = 0; | |
4461 update_window_manager_hints(0, 0); | |
4462 return FALSE; /* stop timer */ | |
791 | 4463 } |
4464 | |
4465 /* Keep on trying */ | |
4466 init_window_hints_state = 1; | |
4467 return TRUE; | |
4468 } | |
4469 | |
7 | 4470 /* |
4471 * Open the GUI window which was created by a call to gui_mch_init(). | |
4472 */ | |
4473 int | |
4474 gui_mch_open(void) | |
4475 { | |
4476 guicolor_T fg_pixel = INVALCOLOR; | |
4477 guicolor_T bg_pixel = INVALCOLOR; | |
1966 | 4478 guint pixel_width; |
4479 guint pixel_height; | |
7 | 4480 |
4481 /* | |
4482 * Allow setting a window role on the command line, or invent one | |
4483 * if none was specified. This is mainly useful for GNOME session | |
4484 * support; allowing the WM to restore window placement. | |
4485 */ | |
4486 if (role_argument != NULL) | |
4487 { | |
4488 gtk_window_set_role(GTK_WINDOW(gui.mainwin), role_argument); | |
4489 } | |
4490 else | |
4491 { | |
4492 char *role; | |
4493 | |
4494 /* Invent a unique-enough ID string for the role */ | |
4495 role = g_strdup_printf("vim-%u-%u-%u", | |
4496 (unsigned)mch_get_pid(), | |
4497 (unsigned)g_random_int(), | |
4498 (unsigned)time(NULL)); | |
4499 | |
4500 gtk_window_set_role(GTK_WINDOW(gui.mainwin), role); | |
4501 g_free(role); | |
4502 } | |
4503 | |
4504 if (gui_win_x != -1 && gui_win_y != -1) | |
4505 gtk_window_move(GTK_WINDOW(gui.mainwin), gui_win_x, gui_win_y); | |
4506 | |
4507 /* Determine user specified geometry, if present. */ | |
4508 if (gui.geom != NULL) | |
4509 { | |
4510 int mask; | |
4511 unsigned int w, h; | |
4512 int x = 0; | |
4513 int y = 0; | |
4514 | |
4515 mask = XParseGeometry((char *)gui.geom, &x, &y, &w, &h); | |
4516 | |
4517 if (mask & WidthValue) | |
4518 Columns = w; | |
4519 if (mask & HeightValue) | |
857 | 4520 { |
1884 | 4521 if (p_window > (long)h - 1 || !option_was_set((char_u *)"window")) |
857 | 4522 p_window = h - 1; |
7 | 4523 Rows = h; |
857 | 4524 } |
5070
cf52d2a8c05c
updated for version 7.3.1278
Bram Moolenaar <bram@vim.org>
parents:
4474
diff
changeset
|
4525 limit_screen_size(); |
1426 | 4526 |
4527 pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width); | |
4528 pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height); | |
4529 | |
4530 pixel_width += get_menu_tool_width(); | |
4531 pixel_height += get_menu_tool_height(); | |
4532 | |
7 | 4533 if (mask & (XValue | YValue)) |
1426 | 4534 { |
1757 | 4535 int ww, hh; |
4536 gui_mch_get_screen_dimensions(&ww, &hh); | |
4537 hh += p_ghr + get_menu_tool_height(); | |
4538 ww += get_menu_tool_width(); | |
1426 | 4539 if (mask & XNegative) |
1757 | 4540 x += ww - pixel_width; |
1426 | 4541 if (mask & YNegative) |
1757 | 4542 y += hh - pixel_height; |
7 | 4543 gtk_window_move(GTK_WINDOW(gui.mainwin), x, y); |
1426 | 4544 } |
7 | 4545 vim_free(gui.geom); |
4546 gui.geom = NULL; | |
791 | 4547 |
856 | 4548 /* From now until everyone's stopped trying to set the window hints |
4549 * to their correct minimum values, stop them being set as we need | |
4550 * them to remain at our required size for the parent GtkSocket to | |
4551 * give us the right initial size. | |
4552 */ | |
791 | 4553 if (gtk_socket_id != 0 && (mask & WidthValue || mask & HeightValue)) |
856 | 4554 { |
4555 update_window_manager_hints(pixel_width, pixel_height); | |
4556 init_window_hints_state = 1; | |
4557 g_timeout_add(1000, check_startup_plug_hints, NULL); | |
4558 } | |
7 | 4559 } |
4560 | |
1966 | 4561 pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width); |
4562 pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height); | |
4563 /* For GTK2 changing the size of the form widget doesn't cause window | |
4564 * resizing. */ | |
2254
4620acaf4814
One more fix for conceal patch.
Bram Moolenaar <bram@vim.org>
parents:
2248
diff
changeset
|
4565 if (gtk_socket_id == 0) |
1966 | 4566 gtk_window_resize(GTK_WINDOW(gui.mainwin), pixel_width, pixel_height); |
791 | 4567 update_window_manager_hints(0, 0); |
7 | 4568 |
4569 if (foreground_argument != NULL) | |
4570 fg_pixel = gui_get_color((char_u *)foreground_argument); | |
4571 if (fg_pixel == INVALCOLOR) | |
4572 fg_pixel = gui_get_color((char_u *)"Black"); | |
4573 | |
4574 if (background_argument != NULL) | |
4575 bg_pixel = gui_get_color((char_u *)background_argument); | |
4576 if (bg_pixel == INVALCOLOR) | |
4577 bg_pixel = gui_get_color((char_u *)"White"); | |
4578 | |
4579 if (found_reverse_arg) | |
4580 { | |
4581 gui.def_norm_pixel = bg_pixel; | |
4582 gui.def_back_pixel = fg_pixel; | |
4583 } | |
4584 else | |
4585 { | |
4586 gui.def_norm_pixel = fg_pixel; | |
4587 gui.def_back_pixel = bg_pixel; | |
4588 } | |
4589 | |
4590 /* Get the colors from the "Normal" and "Menu" group (set in syntax.c or | |
4591 * in a vimrc file) */ | |
4592 set_normal_colors(); | |
4593 | |
4594 /* Check that none of the colors are the same as the background color */ | |
4595 gui_check_colors(); | |
4596 | |
4597 /* Get the colors for the highlight groups (gui_check_colors() might have | |
4598 * changed them). */ | |
4599 highlight_gui_started(); /* re-init colors and fonts */ | |
4600 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4601 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4602 g_signal_connect(G_OBJECT(gui.mainwin), "destroy", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4603 G_CALLBACK(mainwin_destroy_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4604 #else |
7 | 4605 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "destroy", |
4606 GTK_SIGNAL_FUNC(mainwin_destroy_cb), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4607 #endif |
7 | 4608 |
4609 #ifdef FEAT_HANGULIN | |
4610 hangul_keyboard_set(); | |
4611 #endif | |
4612 | |
4613 /* | |
4614 * Notify the fixed area about the need to resize the contents of the | |
4615 * gui.formwin, which we use for random positioning of the included | |
4616 * components. | |
4617 * | |
4618 * We connect this signal deferred finally after anything is in place, | |
4619 * since this is intended to handle resizements coming from the window | |
4620 * manager upon us and should not interfere with what VIM is requesting | |
4621 * upon startup. | |
4622 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4623 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4624 g_signal_connect(G_OBJECT(gui.formwin), "configure-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4625 G_CALLBACK(form_configure_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4626 #else |
7 | 4627 gtk_signal_connect(GTK_OBJECT(gui.formwin), "configure_event", |
4628 GTK_SIGNAL_FUNC(form_configure_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4629 #endif |
7 | 4630 |
4631 #ifdef FEAT_DND | |
2183 | 4632 /* Set up for receiving DND items. */ |
4633 gui_gtk_set_dnd_targets(); | |
7 | 4634 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4635 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4636 g_signal_connect(G_OBJECT(gui.drawarea), "drag-data-received", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4637 G_CALLBACK(drag_data_received_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4638 # else |
7 | 4639 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "drag_data_received", |
4640 GTK_SIGNAL_FUNC(drag_data_received_cb), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4641 # endif |
7 | 4642 #endif |
4643 | |
4644 /* With GTK+ 2, we need to iconify the window before calling show() | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
4645 * to avoid mapping the window for a short time. */ |
7 | 4646 if (found_iconic_arg && gtk_socket_id == 0) |
4647 gui_mch_iconify(); | |
4648 | |
4649 { | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
4650 #if defined(FEAT_GUI_GNOME) && defined(FEAT_MENU) |
7 | 4651 unsigned long menu_handler = 0; |
4652 # ifdef FEAT_TOOLBAR | |
4653 unsigned long tool_handler = 0; | |
4654 # endif | |
4655 /* | |
4656 * Urgh hackish :/ For some reason BonoboDockLayout always forces a | |
4657 * show when restoring the saved layout configuration. We can't just | |
4658 * hide the widgets again after gtk_widget_show(gui.mainwin) since it's | |
4659 * a toplevel window and thus will be realized immediately. Instead, | |
4660 * connect signal handlers to hide the widgets just after they've been | |
4661 * marked visible, but before the main window is realized. | |
4662 */ | |
4663 if (using_gnome && vim_strchr(p_go, GO_MENUS) == NULL) | |
4664 menu_handler = g_signal_connect_after(gui.menubar_h, "show", | |
4665 G_CALLBACK(>k_widget_hide), | |
4666 NULL); | |
4667 # ifdef FEAT_TOOLBAR | |
4668 if (using_gnome && vim_strchr(p_go, GO_TOOLBAR) == NULL | |
4669 && (toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS))) | |
4670 tool_handler = g_signal_connect_after(gui.toolbar_h, "show", | |
4671 G_CALLBACK(>k_widget_hide), | |
4672 NULL); | |
4673 # endif | |
4674 #endif | |
4675 gtk_widget_show(gui.mainwin); | |
4676 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
4677 #if defined(FEAT_GUI_GNOME) && defined(FEAT_MENU) |
7 | 4678 if (menu_handler != 0) |
4679 g_signal_handler_disconnect(gui.menubar_h, menu_handler); | |
4680 # ifdef FEAT_TOOLBAR | |
4681 if (tool_handler != 0) | |
4682 g_signal_handler_disconnect(gui.toolbar_h, tool_handler); | |
4683 # endif | |
4684 #endif | |
4685 } | |
4686 | |
4687 return OK; | |
4688 } | |
4689 | |
4690 | |
4691 void | |
1884 | 4692 gui_mch_exit(int rc UNUSED) |
7 | 4693 { |
4694 if (gui.mainwin != NULL) | |
4695 gtk_widget_destroy(gui.mainwin); | |
4696 } | |
4697 | |
4698 /* | |
4699 * Get the position of the top left corner of the window. | |
4700 */ | |
4701 int | |
4702 gui_mch_get_winpos(int *x, int *y) | |
4703 { | |
4704 gtk_window_get_position(GTK_WINDOW(gui.mainwin), x, y); | |
4705 return OK; | |
4706 } | |
4707 | |
4708 /* | |
4709 * Set the position of the top left corner of the window to the given | |
4710 * coordinates. | |
4711 */ | |
4712 void | |
4713 gui_mch_set_winpos(int x, int y) | |
4714 { | |
4715 gtk_window_move(GTK_WINDOW(gui.mainwin), x, y); | |
4716 } | |
4717 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4718 #if !GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4719 # if 0 |
7 | 4720 static int resize_idle_installed = FALSE; |
4721 /* | |
4722 * Idle handler to force resize. Used by gui_mch_set_shellsize() to ensure | |
4723 * the shell size doesn't exceed the window size, i.e. if the window manager | |
4724 * ignored our size request. Usually this happens if the window is maximized. | |
4725 * | |
4726 * FIXME: It'd be nice if we could find a little more orthodox solution. | |
4727 * See also the remark below in gui_mch_set_shellsize(). | |
4728 * | |
4729 * DISABLED: When doing ":set lines+=1" this function would first invoke | |
4730 * gui_resize_shell() with the old size, then the normal callback would | |
4731 * report the new size through form_configure_event(). That caused the window | |
4732 * layout to be messed up. | |
4733 */ | |
4734 static gboolean | |
4735 force_shell_resize_idle(gpointer data) | |
4736 { | |
4737 if (gui.mainwin != NULL | |
4738 && GTK_WIDGET_REALIZED(gui.mainwin) | |
4739 && GTK_WIDGET_VISIBLE(gui.mainwin)) | |
4740 { | |
4741 int width; | |
4742 int height; | |
4743 | |
4744 gtk_window_get_size(GTK_WINDOW(gui.mainwin), &width, &height); | |
4745 | |
4746 width -= get_menu_tool_width(); | |
4747 height -= get_menu_tool_height(); | |
4748 | |
4749 gui_resize_shell(width, height); | |
4750 } | |
4751 | |
4752 resize_idle_installed = FALSE; | |
4753 return FALSE; /* don't call me again */ | |
4754 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4755 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4756 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
4757 |
1967 | 4758 /* |
4759 * Return TRUE if the main window is maximized. | |
4760 */ | |
4761 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
4762 gui_mch_maximized(void) |
1967 | 4763 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4764 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4765 return (gui.mainwin != NULL && gtk_widget_get_window(gui.mainwin) != NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4766 && (gdk_window_get_state(gtk_widget_get_window(gui.mainwin)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4767 & GDK_WINDOW_STATE_MAXIMIZED)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4768 #else |
1967 | 4769 return (gui.mainwin != NULL && gui.mainwin->window != NULL |
4770 && (gdk_window_get_state(gui.mainwin->window) | |
4771 & GDK_WINDOW_STATE_MAXIMIZED)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4772 #endif |
1967 | 4773 } |
4774 | |
4775 /* | |
4776 * Unmaximize the main window | |
4777 */ | |
4778 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
4779 gui_mch_unmaximize(void) |
1967 | 4780 { |
4781 if (gui.mainwin != NULL) | |
4782 gtk_window_unmaximize(GTK_WINDOW(gui.mainwin)); | |
4783 } | |
4784 | |
7 | 4785 /* |
3014 | 4786 * Called when the font changed while the window is maximized. Compute the |
4787 * new Rows and Columns. This is like resizing the window. | |
4788 */ | |
4789 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
4790 gui_mch_newfont(void) |
3014 | 4791 { |
4792 int w, h; | |
4793 | |
4794 gtk_window_get_size(GTK_WINDOW(gui.mainwin), &w, &h); | |
4795 w -= get_menu_tool_width(); | |
4796 h -= get_menu_tool_height(); | |
4797 gui_resize_shell(w, h); | |
4798 } | |
4799 | |
4800 /* | |
7 | 4801 * Set the windows size. |
4802 */ | |
4803 void | |
4804 gui_mch_set_shellsize(int width, int height, | |
1884 | 4805 int min_width UNUSED, int min_height UNUSED, |
4806 int base_width UNUSED, int base_height UNUSED, | |
4807 int direction UNUSED) | |
7 | 4808 { |
4809 /* give GTK+ a chance to put all widget's into place */ | |
4810 gui_mch_update(); | |
4811 | |
791 | 4812 /* this will cause the proper resizement to happen too */ |
4813 if (gtk_socket_id == 0) | |
856 | 4814 update_window_manager_hints(0, 0); |
791 | 4815 |
7 | 4816 /* With GTK+ 2, changing the size of the form widget doesn't resize |
791 | 4817 * the window. So let's do it the other way around and resize the |
7 | 4818 * main window instead. */ |
4819 width += get_menu_tool_width(); | |
4820 height += get_menu_tool_height(); | |
4821 | |
791 | 4822 if (gtk_socket_id == 0) |
856 | 4823 gtk_window_resize(GTK_WINDOW(gui.mainwin), width, height); |
791 | 4824 else |
856 | 4825 update_window_manager_hints(width, height); |
7 | 4826 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4827 # if !GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4828 # if 0 |
7 | 4829 if (!resize_idle_installed) |
4830 { | |
4831 g_idle_add_full(GDK_PRIORITY_EVENTS + 10, | |
4832 &force_shell_resize_idle, NULL, NULL); | |
4833 resize_idle_installed = TRUE; | |
4834 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4835 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4836 # endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 4837 /* |
4838 * Wait until all events are processed to prevent a crash because the | |
4839 * real size of the drawing area doesn't reflect Vim's internal ideas. | |
4840 * | |
4841 * This is a bit of a hack, since Vim is a terminal application with a GUI | |
4842 * on top, while the GUI expects to be the boss. | |
4843 */ | |
4844 gui_mch_update(); | |
4845 } | |
4846 | |
4847 | |
4848 /* | |
4849 * The screen size is used to make sure the initial window doesn't get bigger | |
4850 * than the screen. This subtracts some room for menubar, toolbar and window | |
4851 * decorations. | |
4852 */ | |
4853 void | |
4854 gui_mch_get_screen_dimensions(int *screen_w, int *screen_h) | |
4855 { | |
4856 #ifdef HAVE_GTK_MULTIHEAD | |
4857 GdkScreen* screen; | |
4858 | |
4859 if (gui.mainwin != NULL && gtk_widget_has_screen(gui.mainwin)) | |
4860 screen = gtk_widget_get_screen(gui.mainwin); | |
4861 else | |
4862 screen = gdk_screen_get_default(); | |
4863 | |
4864 *screen_w = gdk_screen_get_width(screen); | |
4865 *screen_h = gdk_screen_get_height(screen) - p_ghr; | |
4866 #else | |
4867 *screen_w = gdk_screen_width(); | |
4868 /* Subtract 'guiheadroom' from the height to allow some room for the | |
4869 * window manager (task list and window title bar). */ | |
4870 *screen_h = gdk_screen_height() - p_ghr; | |
4871 #endif | |
4872 | |
4873 /* | |
4874 * FIXME: dirty trick: Because the gui_get_base_height() doesn't include | |
4875 * the toolbar and menubar for GTK, we subtract them from the screen | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
4876 * height, so that the window size can be made to fit on the screen. |
7 | 4877 * This should be completely changed later. |
4878 */ | |
4879 *screen_w -= get_menu_tool_width(); | |
4880 *screen_h -= get_menu_tool_height(); | |
4881 } | |
4882 | |
4883 #if defined(FEAT_TITLE) || defined(PROTO) | |
4884 void | |
1884 | 4885 gui_mch_settitle(char_u *title, char_u *icon UNUSED) |
7 | 4886 { |
4887 if (title != NULL && output_conv.vc_type != CONV_NONE) | |
4888 title = string_convert(&output_conv, title, NULL); | |
4889 | |
4890 gtk_window_set_title(GTK_WINDOW(gui.mainwin), (const char *)title); | |
4891 | |
4892 if (output_conv.vc_type != CONV_NONE) | |
4893 vim_free(title); | |
4894 } | |
4895 #endif /* FEAT_TITLE */ | |
4896 | |
4897 #if defined(FEAT_MENU) || defined(PROTO) | |
4898 void | |
4899 gui_mch_enable_menu(int showit) | |
4900 { | |
4901 GtkWidget *widget; | |
4902 | |
4903 # ifdef FEAT_GUI_GNOME | |
4904 if (using_gnome) | |
4905 widget = gui.menubar_h; | |
4906 else | |
4907 # endif | |
4908 widget = gui.menubar; | |
4909 | |
827 | 4910 /* Do not disable the menu while starting up, otherwise F10 doesn't work. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4911 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4912 if (!showit != !gtk_widget_get_visible(widget) && !gui.starting) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4913 # else |
827 | 4914 if (!showit != !GTK_WIDGET_VISIBLE(widget) && !gui.starting) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4915 # endif |
7 | 4916 { |
4917 if (showit) | |
4918 gtk_widget_show(widget); | |
4919 else | |
4920 gtk_widget_hide(widget); | |
4921 | |
791 | 4922 update_window_manager_hints(0, 0); |
7 | 4923 } |
4924 } | |
4925 #endif /* FEAT_MENU */ | |
4926 | |
4927 #if defined(FEAT_TOOLBAR) || defined(PROTO) | |
4928 void | |
4929 gui_mch_show_toolbar(int showit) | |
4930 { | |
4931 GtkWidget *widget; | |
4932 | |
4933 if (gui.toolbar == NULL) | |
4934 return; | |
4935 | |
4936 # ifdef FEAT_GUI_GNOME | |
4937 if (using_gnome) | |
4938 widget = gui.toolbar_h; | |
4939 else | |
4940 # endif | |
4941 widget = gui.toolbar; | |
4942 | |
4943 if (showit) | |
4944 set_toolbar_style(GTK_TOOLBAR(gui.toolbar)); | |
4945 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4946 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4947 if (!showit != !gtk_widget_get_visible(widget)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4948 # else |
7 | 4949 if (!showit != !GTK_WIDGET_VISIBLE(widget)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4950 # endif |
7 | 4951 { |
4952 if (showit) | |
4953 gtk_widget_show(widget); | |
4954 else | |
4955 gtk_widget_hide(widget); | |
4956 | |
791 | 4957 update_window_manager_hints(0, 0); |
7 | 4958 } |
4959 } | |
4960 #endif /* FEAT_TOOLBAR */ | |
4961 | |
4962 /* | |
4963 * Check if a given font is a CJK font. This is done in a very crude manner. It | |
4964 * just see if U+04E00 for zh and ja and U+AC00 for ko are covered in a given | |
4965 * font. Consequently, this function cannot be used as a general purpose check | |
4966 * for CJK-ness for which fontconfig APIs should be used. This is only used by | |
4967 * gui_mch_init_font() to deal with 'CJK fixed width fonts'. | |
4968 */ | |
4969 static int | |
4970 is_cjk_font(PangoFontDescription *font_desc) | |
4971 { | |
4972 static const char * const cjk_langs[] = | |
4973 {"zh_CN", "zh_TW", "zh_HK", "ja", "ko"}; | |
4974 | |
4975 PangoFont *font; | |
4976 unsigned i; | |
4977 int is_cjk = FALSE; | |
4978 | |
4979 font = pango_context_load_font(gui.text_context, font_desc); | |
4980 | |
4981 if (font == NULL) | |
4982 return FALSE; | |
4983 | |
4984 for (i = 0; !is_cjk && i < G_N_ELEMENTS(cjk_langs); ++i) | |
4985 { | |
4986 PangoCoverage *coverage; | |
4987 gunichar uc; | |
4988 | |
4989 coverage = pango_font_get_coverage( | |
4990 font, pango_language_from_string(cjk_langs[i])); | |
4991 | |
4992 if (coverage != NULL) | |
4993 { | |
4994 uc = (cjk_langs[i][0] == 'k') ? 0xAC00 : 0x4E00; | |
4995 is_cjk = (pango_coverage_get(coverage, uc) == PANGO_COVERAGE_EXACT); | |
4996 pango_coverage_unref(coverage); | |
4997 } | |
4998 } | |
4999 | |
5000 g_object_unref(font); | |
5001 | |
5002 return is_cjk; | |
5003 } | |
5004 | |
445 | 5005 /* |
5006 * Adjust gui.char_height (after 'linespace' was changed). | |
5007 */ | |
7 | 5008 int |
445 | 5009 gui_mch_adjust_charheight(void) |
7 | 5010 { |
5011 PangoFontMetrics *metrics; | |
5012 int ascent; | |
5013 int descent; | |
5014 | |
5015 metrics = pango_context_get_metrics(gui.text_context, gui.norm_font, | |
5016 pango_context_get_language(gui.text_context)); | |
5017 ascent = pango_font_metrics_get_ascent(metrics); | |
5018 descent = pango_font_metrics_get_descent(metrics); | |
5019 | |
5020 pango_font_metrics_unref(metrics); | |
5021 | |
5022 gui.char_height = (ascent + descent + PANGO_SCALE - 1) / PANGO_SCALE | |
445 | 5023 + p_linespace; |
136 | 5024 /* LINTED: avoid warning: bitwise operation on signed value */ |
7 | 5025 gui.char_ascent = PANGO_PIXELS(ascent + p_linespace * PANGO_SCALE / 2); |
5026 | |
5027 /* A not-positive value of char_height may crash Vim. Only happens | |
5028 * if 'linespace' is negative (which does make sense sometimes). */ | |
5029 gui.char_ascent = MAX(gui.char_ascent, 0); | |
5030 gui.char_height = MAX(gui.char_height, gui.char_ascent + 1); | |
5031 | |
5032 return OK; | |
5033 } | |
5034 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5035 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5036 /* Callback function used in gui_mch_font_dialog() */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5037 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5038 font_filter(const PangoFontFamily *family, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5039 const PangoFontFace *face UNUSED, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5040 gpointer data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5041 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5042 return pango_font_family_is_monospace((PangoFontFamily *)family); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5043 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5044 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5045 |
7 | 5046 /* |
5047 * Put up a font dialog and return the selected font name in allocated memory. | |
5048 * "oldval" is the previous value. Return NULL when cancelled. | |
5049 * This should probably go into gui_gtk.c. Hmm. | |
5050 * FIXME: | |
5051 * The GTK2 font selection dialog has no filtering API. So we could either | |
5052 * a) implement our own (possibly copying the code from somewhere else) or | |
5053 * b) just live with it. | |
5054 */ | |
5055 char_u * | |
5056 gui_mch_font_dialog(char_u *oldval) | |
5057 { | |
5058 GtkWidget *dialog; | |
5059 int response; | |
5060 char_u *fontname = NULL; | |
5061 char_u *oldname; | |
5062 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5063 #if GTK_CHECK_VERSION(3,2,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5064 dialog = gtk_font_chooser_dialog_new(NULL, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5065 gtk_font_chooser_set_filter_func(GTK_FONT_CHOOSER(dialog), font_filter, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5066 NULL, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5067 #else |
7 | 5068 dialog = gtk_font_selection_dialog_new(NULL); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5069 #endif |
7 | 5070 |
5071 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gui.mainwin)); | |
5072 gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); | |
5073 | |
5074 if (oldval != NULL && oldval[0] != NUL) | |
5075 { | |
5076 if (output_conv.vc_type != CONV_NONE) | |
5077 oldname = string_convert(&output_conv, oldval, NULL); | |
5078 else | |
5079 oldname = oldval; | |
5080 | |
5081 /* Annoying bug in GTK (or Pango): if the font name does not include a | |
5082 * size, zero is used. Use default point size ten. */ | |
5083 if (!vim_isdigit(oldname[STRLEN(oldname) - 1])) | |
5084 { | |
5085 char_u *p = vim_strnsave(oldname, STRLEN(oldname) + 3); | |
5086 | |
5087 if (p != NULL) | |
5088 { | |
5089 STRCPY(p + STRLEN(p), " 10"); | |
5090 if (oldname != oldval) | |
5091 vim_free(oldname); | |
5092 oldname = p; | |
5093 } | |
5094 } | |
5095 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5096 #if GTK_CHECK_VERSION(3,2,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5097 gtk_font_chooser_set_font( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5098 GTK_FONT_CHOOSER(dialog), (const gchar *)oldname); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5099 #else |
7 | 5100 gtk_font_selection_dialog_set_font_name( |
5101 GTK_FONT_SELECTION_DIALOG(dialog), (const char *)oldname); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5102 #endif |
7 | 5103 |
5104 if (oldname != oldval) | |
100 | 5105 vim_free(oldname); |
7 | 5106 } |
1959 | 5107 else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5108 #if GTK_CHECK_VERSION(3,2,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5109 gtk_font_chooser_set_font( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5110 GTK_FONT_CHOOSER(dialog), DEFAULT_FONT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5111 #else |
1959 | 5112 gtk_font_selection_dialog_set_font_name( |
5113 GTK_FONT_SELECTION_DIALOG(dialog), DEFAULT_FONT); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5114 #endif |
7 | 5115 |
5116 response = gtk_dialog_run(GTK_DIALOG(dialog)); | |
5117 | |
5118 if (response == GTK_RESPONSE_OK) | |
5119 { | |
5120 char *name; | |
5121 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5122 #if GTK_CHECK_VERSION(3,2,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5123 name = gtk_font_chooser_get_font(GTK_FONT_CHOOSER(dialog)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5124 #else |
7 | 5125 name = gtk_font_selection_dialog_get_font_name( |
5126 GTK_FONT_SELECTION_DIALOG(dialog)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5127 #endif |
7 | 5128 if (name != NULL) |
5129 { | |
714 | 5130 char_u *p; |
5131 | |
5132 /* Apparently some font names include a comma, need to escape | |
5133 * that, because in 'guifont' it separates names. */ | |
5134 p = vim_strsave_escaped((char_u *)name, (char_u *)","); | |
5135 g_free(name); | |
840 | 5136 if (p != NULL && input_conv.vc_type != CONV_NONE) |
714 | 5137 { |
5138 fontname = string_convert(&input_conv, p, NULL); | |
5139 vim_free(p); | |
5140 } | |
7 | 5141 else |
714 | 5142 fontname = p; |
7 | 5143 } |
5144 } | |
5145 | |
5146 if (response != GTK_RESPONSE_NONE) | |
5147 gtk_widget_destroy(dialog); | |
5148 | |
5149 return fontname; | |
5150 } | |
5151 | |
5152 /* | |
5153 * Some monospace fonts don't support a bold weight, and fall back | |
5154 * silently to the regular weight. But this is no good since our text | |
5155 * drawing function can emulate bold by overstriking. So let's try | |
5156 * to detect whether bold weight is actually available and emulate it | |
5157 * otherwise. | |
5158 * | |
5159 * Note that we don't need to check for italic style since Xft can | |
5160 * emulate italic on its own, provided you have a proper fontconfig | |
5161 * setup. We wouldn't be able to emulate it in Vim anyway. | |
5162 */ | |
5163 static void | |
5164 get_styled_font_variants(void) | |
5165 { | |
5166 PangoFontDescription *bold_font_desc; | |
5167 PangoFont *plain_font; | |
5168 PangoFont *bold_font; | |
5169 | |
5170 gui.font_can_bold = FALSE; | |
5171 | |
5172 plain_font = pango_context_load_font(gui.text_context, gui.norm_font); | |
5173 | |
5174 if (plain_font == NULL) | |
5175 return; | |
5176 | |
5177 bold_font_desc = pango_font_description_copy_static(gui.norm_font); | |
5178 pango_font_description_set_weight(bold_font_desc, PANGO_WEIGHT_BOLD); | |
5179 | |
5180 bold_font = pango_context_load_font(gui.text_context, bold_font_desc); | |
5181 /* | |
5182 * The comparison relies on the unique handle nature of a PangoFont*, | |
5183 * i.e. it's assumed that a different PangoFont* won't refer to the | |
5184 * same font. Seems to work, and failing here isn't critical anyway. | |
5185 */ | |
5186 if (bold_font != NULL) | |
5187 { | |
5188 gui.font_can_bold = (bold_font != plain_font); | |
5189 g_object_unref(bold_font); | |
5190 } | |
5191 | |
5192 pango_font_description_free(bold_font_desc); | |
5193 g_object_unref(plain_font); | |
5194 } | |
5195 | |
5196 static PangoEngineShape *default_shape_engine = NULL; | |
5197 | |
5198 /* | |
5199 * Create a map from ASCII characters in the range [32,126] to glyphs | |
5200 * of the current font. This is used by gui_gtk2_draw_string() to skip | |
5201 * the itemize and shaping process for the most common case. | |
5202 */ | |
5203 static void | |
5204 ascii_glyph_table_init(void) | |
5205 { | |
5206 char_u ascii_chars[128]; | |
5207 PangoAttrList *attr_list; | |
5208 GList *item_list; | |
5209 int i; | |
5210 | |
5211 if (gui.ascii_glyphs != NULL) | |
5212 pango_glyph_string_free(gui.ascii_glyphs); | |
5213 if (gui.ascii_font != NULL) | |
5214 g_object_unref(gui.ascii_font); | |
5215 | |
5216 gui.ascii_glyphs = NULL; | |
5217 gui.ascii_font = NULL; | |
5218 | |
5219 /* For safety, fill in question marks for the control characters. */ | |
5220 for (i = 0; i < 32; ++i) | |
5221 ascii_chars[i] = '?'; | |
5222 for (; i < 127; ++i) | |
5223 ascii_chars[i] = i; | |
5224 ascii_chars[i] = '?'; | |
5225 | |
5226 attr_list = pango_attr_list_new(); | |
5227 item_list = pango_itemize(gui.text_context, (const char *)ascii_chars, | |
5228 0, sizeof(ascii_chars), attr_list, NULL); | |
5229 | |
5230 if (item_list != NULL && item_list->next == NULL) /* play safe */ | |
5231 { | |
5232 PangoItem *item; | |
5233 int width; | |
5234 | |
5235 item = (PangoItem *)item_list->data; | |
5236 width = gui.char_width * PANGO_SCALE; | |
5237 | |
5238 /* Remember the shape engine used for ASCII. */ | |
5239 default_shape_engine = item->analysis.shape_engine; | |
5240 | |
5241 gui.ascii_font = item->analysis.font; | |
5242 g_object_ref(gui.ascii_font); | |
5243 | |
5244 gui.ascii_glyphs = pango_glyph_string_new(); | |
5245 | |
5246 pango_shape((const char *)ascii_chars, sizeof(ascii_chars), | |
5247 &item->analysis, gui.ascii_glyphs); | |
5248 | |
5249 g_return_if_fail(gui.ascii_glyphs->num_glyphs == sizeof(ascii_chars)); | |
5250 | |
5251 for (i = 0; i < gui.ascii_glyphs->num_glyphs; ++i) | |
5252 { | |
5253 PangoGlyphGeometry *geom; | |
5254 | |
5255 geom = &gui.ascii_glyphs->glyphs[i].geometry; | |
5256 geom->x_offset += MAX(0, width - geom->width) / 2; | |
5257 geom->width = width; | |
5258 } | |
5259 } | |
5260 | |
5261 g_list_foreach(item_list, (GFunc)&pango_item_free, NULL); | |
5262 g_list_free(item_list); | |
5263 pango_attr_list_unref(attr_list); | |
5264 } | |
5265 | |
5266 /* | |
5267 * Initialize Vim to use the font or fontset with the given name. | |
5268 * Return FAIL if the font could not be loaded, OK otherwise. | |
5269 */ | |
5270 int | |
1884 | 5271 gui_mch_init_font(char_u *font_name, int fontset UNUSED) |
7 | 5272 { |
5273 PangoFontDescription *font_desc; | |
5274 PangoLayout *layout; | |
5275 int width; | |
5276 | |
5277 /* If font_name is NULL, this means to use the default, which should | |
5278 * be present on all proper Pango/fontconfig installations. */ | |
5279 if (font_name == NULL) | |
5280 font_name = (char_u *)DEFAULT_FONT; | |
5281 | |
5282 font_desc = gui_mch_get_font(font_name, FALSE); | |
5283 | |
5284 if (font_desc == NULL) | |
5285 return FAIL; | |
5286 | |
5287 gui_mch_free_font(gui.norm_font); | |
5288 gui.norm_font = font_desc; | |
5289 | |
5290 pango_context_set_font_description(gui.text_context, font_desc); | |
5291 | |
5292 layout = pango_layout_new(gui.text_context); | |
5293 pango_layout_set_text(layout, "MW", 2); | |
5294 pango_layout_get_size(layout, &width, NULL); | |
5295 /* | |
5296 * Set char_width to half the width obtained from pango_layout_get_size() | |
5297 * for CJK fixed_width/bi-width fonts. An unpatched version of Xft leads | |
5298 * Pango to use the same width for both non-CJK characters (e.g. Latin | |
5299 * letters and numbers) and CJK characters. This results in 's p a c e d | |
5300 * o u t' rendering when a CJK 'fixed width' font is used. To work around | |
5301 * that, divide the width returned by Pango by 2 if cjk_width is equal to | |
5302 * width for CJK fonts. | |
5303 * | |
5304 * For related bugs, see: | |
5305 * http://bugzilla.gnome.org/show_bug.cgi?id=106618 | |
5306 * http://bugzilla.gnome.org/show_bug.cgi?id=106624 | |
5307 * | |
5308 * With this, for all four of the following cases, Vim works fine: | |
5309 * guifont=CJK_fixed_width_font | |
5310 * guifont=Non_CJK_fixed_font | |
5311 * guifont=Non_CJK_fixed_font,CJK_Fixed_font | |
5312 * guifont=Non_CJK_fixed_font guifontwide=CJK_fixed_font | |
5313 */ | |
5314 if (is_cjk_font(gui.norm_font)) | |
5315 { | |
5316 int cjk_width; | |
5317 | |
5318 /* Measure the text extent of U+4E00 and U+4E8C */ | |
5319 pango_layout_set_text(layout, "\344\270\200\344\272\214", -1); | |
5320 pango_layout_get_size(layout, &cjk_width, NULL); | |
5321 | |
5322 if (width == cjk_width) /* Xft not patched */ | |
5323 width /= 2; | |
5324 } | |
5325 g_object_unref(layout); | |
5326 | |
5327 gui.char_width = (width / 2 + PANGO_SCALE - 1) / PANGO_SCALE; | |
5328 | |
5329 /* A zero width may cause a crash. Happens for semi-invalid fontsets. */ | |
5330 if (gui.char_width <= 0) | |
5331 gui.char_width = 8; | |
5332 | |
445 | 5333 gui_mch_adjust_charheight(); |
7 | 5334 |
5335 /* Set the fontname, which will be used for information purposes */ | |
5336 hl_set_font_name(font_name); | |
5337 | |
5338 get_styled_font_variants(); | |
5339 ascii_glyph_table_init(); | |
5340 | |
5341 /* Avoid unnecessary overhead if 'guifontwide' is equal to 'guifont'. */ | |
5342 if (gui.wide_font != NULL | |
5343 && pango_font_description_equal(gui.norm_font, gui.wide_font)) | |
5344 { | |
5345 pango_font_description_free(gui.wide_font); | |
5346 gui.wide_font = NULL; | |
5347 } | |
5348 | |
1986 | 5349 if (gui_mch_maximized()) |
5350 { | |
5351 /* Update lines and columns in accordance with the new font, keep the | |
5352 * window maximized. */ | |
3014 | 5353 gui_mch_newfont(); |
1986 | 5354 } |
5355 else | |
5356 { | |
5357 /* Preserve the logical dimensions of the screen. */ | |
5358 update_window_manager_hints(0, 0); | |
5359 } | |
7 | 5360 |
5361 return OK; | |
5362 } | |
5363 | |
5364 /* | |
5365 * Get a reference to the font "name". | |
5366 * Return zero for failure. | |
5367 */ | |
5368 GuiFont | |
5369 gui_mch_get_font(char_u *name, int report_error) | |
5370 { | |
5371 PangoFontDescription *font; | |
5372 | |
5373 /* can't do this when GUI is not running */ | |
5374 if (!gui.in_use || name == NULL) | |
5375 return NULL; | |
5376 | |
5377 if (output_conv.vc_type != CONV_NONE) | |
5378 { | |
5379 char_u *buf; | |
5380 | |
5381 buf = string_convert(&output_conv, name, NULL); | |
5382 if (buf != NULL) | |
5383 { | |
5384 font = pango_font_description_from_string((const char *)buf); | |
5385 vim_free(buf); | |
5386 } | |
5387 else | |
5388 font = NULL; | |
5389 } | |
5390 else | |
5391 font = pango_font_description_from_string((const char *)name); | |
5392 | |
5393 if (font != NULL) | |
5394 { | |
5395 PangoFont *real_font; | |
5396 | |
5397 /* pango_context_load_font() bails out if no font size is set */ | |
5398 if (pango_font_description_get_size(font) <= 0) | |
5399 pango_font_description_set_size(font, 10 * PANGO_SCALE); | |
5400 | |
5401 real_font = pango_context_load_font(gui.text_context, font); | |
5402 | |
5403 if (real_font == NULL) | |
5404 { | |
5405 pango_font_description_free(font); | |
5406 font = NULL; | |
5407 } | |
5408 else | |
5409 g_object_unref(real_font); | |
5410 } | |
5411 | |
5412 if (font == NULL) | |
5413 { | |
5414 if (report_error) | |
1666 | 5415 EMSG2(_((char *)e_font), name); |
7 | 5416 return NULL; |
5417 } | |
5418 | |
5419 return font; | |
5420 } | |
5421 | |
39 | 5422 #if defined(FEAT_EVAL) || defined(PROTO) |
38 | 5423 /* |
5424 * Return the name of font "font" in allocated memory. | |
5425 */ | |
5426 char_u * | |
1884 | 5427 gui_mch_get_fontname(GuiFont font, char_u *name UNUSED) |
38 | 5428 { |
5429 if (font != NOFONT) | |
5430 { | |
944 | 5431 char *pangoname = pango_font_description_to_string(font); |
5432 | |
5433 if (pangoname != NULL) | |
38 | 5434 { |
944 | 5435 char_u *s = vim_strsave((char_u *)pangoname); |
5436 | |
5437 g_free(pangoname); | |
38 | 5438 return s; |
5439 } | |
5440 } | |
5441 return NULL; | |
5442 } | |
39 | 5443 #endif |
38 | 5444 |
7 | 5445 /* |
5446 * If a font is not going to be used, free its structure. | |
5447 */ | |
5448 void | |
5449 gui_mch_free_font(GuiFont font) | |
5450 { | |
5451 if (font != NOFONT) | |
5452 pango_font_description_free(font); | |
5453 } | |
5454 | |
5455 /* | |
5456 * Return the Pixel value (color) for the given color name. This routine was | |
5457 * pretty much taken from example code in the Silicon Graphics OSF/Motif | |
5458 * Programmer's Guide. | |
5459 * Return INVALCOLOR for error. | |
5460 */ | |
5461 guicolor_T | |
5462 gui_mch_get_color(char_u *name) | |
5463 { | |
5464 /* A number of colors that some X11 systems don't have */ | |
5465 static const char *const vimnames[][2] = | |
5466 { | |
834 | 5467 {"LightRed", "#FFBBBB"}, |
5468 {"LightGreen", "#88FF88"}, | |
5469 {"LightMagenta","#FFBBFF"}, | |
5470 {"DarkCyan", "#008888"}, | |
5471 {"DarkBlue", "#0000BB"}, | |
5472 {"DarkRed", "#BB0000"}, | |
5473 {"DarkMagenta", "#BB00BB"}, | |
5474 {"DarkGrey", "#BBBBBB"}, | |
5475 {"DarkYellow", "#BBBB00"}, | |
5476 {"Gray10", "#1A1A1A"}, | |
5477 {"Grey10", "#1A1A1A"}, | |
5478 {"Gray20", "#333333"}, | |
5479 {"Grey20", "#333333"}, | |
5480 {"Gray30", "#4D4D4D"}, | |
5481 {"Grey30", "#4D4D4D"}, | |
5482 {"Gray40", "#666666"}, | |
5483 {"Grey40", "#666666"}, | |
5484 {"Gray50", "#7F7F7F"}, | |
5485 {"Grey50", "#7F7F7F"}, | |
5486 {"Gray60", "#999999"}, | |
5487 {"Grey60", "#999999"}, | |
5488 {"Gray70", "#B3B3B3"}, | |
5489 {"Grey70", "#B3B3B3"}, | |
5490 {"Gray80", "#CCCCCC"}, | |
5491 {"Grey80", "#CCCCCC"}, | |
5492 {"Gray90", "#E5E5E5"}, | |
5493 {"Grey90", "#E5E5E5"}, | |
7 | 5494 {NULL, NULL} |
5495 }; | |
5496 | |
5497 if (!gui.in_use) /* can't do this when GUI not running */ | |
5498 return INVALCOLOR; | |
5499 | |
5500 while (name != NULL) | |
5501 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5502 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5503 GdkRGBA color; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5504 #else |
7 | 5505 GdkColor color; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5506 #endif |
7 | 5507 int parsed; |
5508 int i; | |
5509 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5510 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5511 parsed = gdk_rgba_parse(&color, (const gchar *)name); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5512 #else |
7 | 5513 parsed = gdk_color_parse((const char *)name, &color); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5514 #endif |
7 | 5515 |
5516 if (parsed) | |
5517 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5518 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5519 return (guicolor_T)gui_gtk_get_pixel_from_rgb(&color); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5520 #else |
7 | 5521 gdk_colormap_alloc_color(gtk_widget_get_colormap(gui.drawarea), |
5522 &color, FALSE, TRUE); | |
5523 return (guicolor_T)color.pixel; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5524 #endif |
7 | 5525 } |
5526 /* add a few builtin names and try again */ | |
5527 for (i = 0; ; ++i) | |
5528 { | |
5529 if (vimnames[i][0] == NULL) | |
5530 { | |
5531 name = NULL; | |
5532 break; | |
5533 } | |
5534 if (STRICMP(name, vimnames[i][0]) == 0) | |
5535 { | |
5536 name = (char_u *)vimnames[i][1]; | |
5537 break; | |
5538 } | |
5539 } | |
5540 } | |
5541 | |
5542 return INVALCOLOR; | |
5543 } | |
5544 | |
5545 /* | |
5546 * Set the current text foreground color. | |
5547 */ | |
5548 void | |
5549 gui_mch_set_fg_color(guicolor_T color) | |
5550 { | |
5551 gui.fgcolor->pixel = (unsigned long)color; | |
5552 } | |
5553 | |
5554 /* | |
5555 * Set the current text background color. | |
5556 */ | |
5557 void | |
5558 gui_mch_set_bg_color(guicolor_T color) | |
5559 { | |
5560 gui.bgcolor->pixel = (unsigned long)color; | |
5561 } | |
5562 | |
207 | 5563 /* |
5564 * Set the current text special color. | |
5565 */ | |
5566 void | |
5567 gui_mch_set_sp_color(guicolor_T color) | |
5568 { | |
5569 gui.spcolor->pixel = (unsigned long)color; | |
5570 } | |
5571 | |
7 | 5572 /* |
5573 * Function-like convenience macro for the sake of efficiency. | |
5574 */ | |
5575 #define INSERT_PANGO_ATTR(Attribute, AttrList, Start, End) \ | |
5576 G_STMT_START{ \ | |
5577 PangoAttribute *tmp_attr_; \ | |
5578 tmp_attr_ = (Attribute); \ | |
5579 tmp_attr_->start_index = (Start); \ | |
5580 tmp_attr_->end_index = (End); \ | |
5581 pango_attr_list_insert((AttrList), tmp_attr_); \ | |
5582 }G_STMT_END | |
5583 | |
5584 static void | |
5585 apply_wide_font_attr(char_u *s, int len, PangoAttrList *attr_list) | |
5586 { | |
5587 char_u *start = NULL; | |
5588 char_u *p; | |
5589 int uc; | |
5590 | |
5591 for (p = s; p < s + len; p += utf_byte2len(*p)) | |
5592 { | |
5593 uc = utf_ptr2char(p); | |
5594 | |
5595 if (start == NULL) | |
5596 { | |
5597 if (uc >= 0x80 && utf_char2cells(uc) == 2) | |
5598 start = p; | |
5599 } | |
5600 else if (uc < 0x80 /* optimization shortcut */ | |
5601 || (utf_char2cells(uc) != 2 && !utf_iscomposing(uc))) | |
5602 { | |
5603 INSERT_PANGO_ATTR(pango_attr_font_desc_new(gui.wide_font), | |
5604 attr_list, start - s, p - s); | |
5605 start = NULL; | |
5606 } | |
5607 } | |
5608 | |
5609 if (start != NULL) | |
5610 INSERT_PANGO_ATTR(pango_attr_font_desc_new(gui.wide_font), | |
5611 attr_list, start - s, len); | |
5612 } | |
5613 | |
5614 static int | |
5615 count_cluster_cells(char_u *s, PangoItem *item, | |
5616 PangoGlyphString* glyphs, int i, | |
5617 int *cluster_width, | |
5618 int *last_glyph_rbearing) | |
5619 { | |
5620 char_u *p; | |
5621 int next; /* glyph start index of next cluster */ | |
5622 int start, end; /* string segment of current cluster */ | |
5623 int width; /* real cluster width in Pango units */ | |
5624 int uc; | |
5625 int cellcount = 0; | |
5626 | |
5627 width = glyphs->glyphs[i].geometry.width; | |
5628 | |
5629 for (next = i + 1; next < glyphs->num_glyphs; ++next) | |
5630 { | |
5631 if (glyphs->glyphs[next].attr.is_cluster_start) | |
5632 break; | |
5633 else if (glyphs->glyphs[next].geometry.width > width) | |
5634 width = glyphs->glyphs[next].geometry.width; | |
5635 } | |
5636 | |
5637 start = item->offset + glyphs->log_clusters[i]; | |
5638 end = item->offset + ((next < glyphs->num_glyphs) ? | |
5639 glyphs->log_clusters[next] : item->length); | |
5640 | |
5641 for (p = s + start; p < s + end; p += utf_byte2len(*p)) | |
5642 { | |
5643 uc = utf_ptr2char(p); | |
5644 if (uc < 0x80) | |
5645 ++cellcount; | |
5646 else if (!utf_iscomposing(uc)) | |
5647 cellcount += utf_char2cells(uc); | |
5648 } | |
5649 | |
5650 if (last_glyph_rbearing != NULL | |
5651 && cellcount > 0 && next == glyphs->num_glyphs) | |
5652 { | |
5653 PangoRectangle ink_rect; | |
5654 /* | |
5655 * If a certain combining mark had to be taken from a non-monospace | |
5656 * font, we have to compensate manually by adapting x_offset according | |
5657 * to the ink extents of the previous glyph. | |
5658 */ | |
5659 pango_font_get_glyph_extents(item->analysis.font, | |
5660 glyphs->glyphs[i].glyph, | |
5661 &ink_rect, NULL); | |
5662 | |
5663 if (PANGO_RBEARING(ink_rect) > 0) | |
5664 *last_glyph_rbearing = PANGO_RBEARING(ink_rect); | |
5665 } | |
5666 | |
5667 if (cellcount > 0) | |
5668 *cluster_width = width; | |
5669 | |
5670 return cellcount; | |
5671 } | |
5672 | |
5673 /* | |
5674 * If there are only combining characters in the cluster, we cannot just | |
5675 * change the width of the previous glyph since there is none. Therefore | |
5676 * some guesswork is needed. | |
5677 * | |
5678 * If ink_rect.x is negative Pango apparently has taken care of the composing | |
5679 * by itself. Actually setting x_offset = 0 should be sufficient then, but due | |
5680 * to problems with composing from different fonts we still need to fine-tune | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
5681 * x_offset to avoid ugliness. |
7 | 5682 * |
5683 * If ink_rect.x is not negative, force overstriking by pointing x_offset to | |
5684 * the position of the previous glyph. Apparently this happens only with old | |
5685 * X fonts which don't provide the special combining information needed by | |
5686 * Pango. | |
5687 */ | |
5688 static void | |
5689 setup_zero_width_cluster(PangoItem *item, PangoGlyphInfo *glyph, | |
5690 int last_cellcount, int last_cluster_width, | |
5691 int last_glyph_rbearing) | |
5692 { | |
5693 PangoRectangle ink_rect; | |
5694 PangoRectangle logical_rect; | |
5695 int width; | |
5696 | |
5697 width = last_cellcount * gui.char_width * PANGO_SCALE; | |
5698 glyph->geometry.x_offset = -width + MAX(0, width - last_cluster_width) / 2; | |
5699 glyph->geometry.width = 0; | |
5700 | |
5701 pango_font_get_glyph_extents(item->analysis.font, | |
5702 glyph->glyph, | |
5703 &ink_rect, &logical_rect); | |
5704 if (ink_rect.x < 0) | |
5705 { | |
5706 glyph->geometry.x_offset += last_glyph_rbearing; | |
5707 glyph->geometry.y_offset = logical_rect.height | |
5708 - (gui.char_height - p_linespace) * PANGO_SCALE; | |
5709 } | |
2507
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
5710 else |
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
5711 /* If the accent width is smaller than the cluster width, position it |
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
5712 * in the middle. */ |
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
5713 glyph->geometry.x_offset = -width + MAX(0, width - ink_rect.width) / 2; |
7 | 5714 } |
5715 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5716 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5717 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5718 draw_glyph_string(int row, int col, int num_cells, int flags, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5719 PangoFont *font, PangoGlyphString *glyphs, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5720 cairo_t *cr) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5721 #else |
7 | 5722 static void |
5723 draw_glyph_string(int row, int col, int num_cells, int flags, | |
5724 PangoFont *font, PangoGlyphString *glyphs) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5725 #endif |
7 | 5726 { |
5727 if (!(flags & DRAW_TRANSP)) | |
5728 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5729 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5730 set_cairo_source_rgb_from_pixel(cr, gui.bgcolor->pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5731 cairo_rectangle(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5732 FILL_X(col), FILL_Y(row), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5733 num_cells * gui.char_width, gui.char_height); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5734 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5735 #else |
7 | 5736 gdk_gc_set_foreground(gui.text_gc, gui.bgcolor); |
5737 | |
5738 gdk_draw_rectangle(gui.drawarea->window, | |
5739 gui.text_gc, | |
5740 TRUE, | |
5741 FILL_X(col), | |
5742 FILL_Y(row), | |
5743 num_cells * gui.char_width, | |
5744 gui.char_height); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5745 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5746 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5747 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5748 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5749 set_cairo_source_rgb_from_pixel(cr, gui.fgcolor->pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5750 cairo_move_to(cr, TEXT_X(col), TEXT_Y(row)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5751 pango_cairo_show_glyph_string(cr, font, glyphs); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5752 #else |
7 | 5753 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
5754 | |
5755 gdk_draw_glyphs(gui.drawarea->window, | |
5756 gui.text_gc, | |
5757 font, | |
5758 TEXT_X(col), | |
5759 TEXT_Y(row), | |
5760 glyphs); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5761 #endif |
7 | 5762 |
5763 /* redraw the contents with an offset of 1 to emulate bold */ | |
5764 if ((flags & DRAW_BOLD) && !gui.font_can_bold) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5765 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5766 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5767 set_cairo_source_rgb_from_pixel(cr, gui.fgcolor->pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5768 cairo_move_to(cr, TEXT_X(col) + 1, TEXT_Y(row)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5769 pango_cairo_show_glyph_string(cr, font, glyphs); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5770 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5771 #else |
7 | 5772 gdk_draw_glyphs(gui.drawarea->window, |
5773 gui.text_gc, | |
5774 font, | |
5775 TEXT_X(col) + 1, | |
5776 TEXT_Y(row), | |
5777 glyphs); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5778 #endif |
7 | 5779 } |
5780 | |
207 | 5781 /* |
5782 * Draw underline and undercurl at the bottom of the character cell. | |
5783 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5784 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5785 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5786 draw_under(int flags, int row, int col, int cells, cairo_t *cr) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5787 #else |
207 | 5788 static void |
5789 draw_under(int flags, int row, int col, int cells) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5790 #endif |
207 | 5791 { |
5792 int i; | |
5793 int offset; | |
1884 | 5794 static const int val[8] = {1, 0, 0, 0, 1, 2, 2, 2 }; |
207 | 5795 int y = FILL_Y(row + 1) - 1; |
5796 | |
5797 /* Undercurl: draw curl at the bottom of the character cell. */ | |
5798 if (flags & DRAW_UNDERC) | |
5799 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5800 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5801 cairo_set_line_width(cr, 1.0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5802 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5803 set_cairo_source_rgb_from_pixel(cr, gui.spcolor->pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5804 for (i = FILL_X(col); i < FILL_X(col + cells); ++i) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5805 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5806 offset = val[i % 8]; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5807 cairo_line_to(cr, i, y - offset + 0.5); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5808 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5809 cairo_stroke(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5810 #else |
207 | 5811 gdk_gc_set_foreground(gui.text_gc, gui.spcolor); |
5812 for (i = FILL_X(col); i < FILL_X(col + cells); ++i) | |
5813 { | |
5814 offset = val[i % 8]; | |
5815 gdk_draw_point(gui.drawarea->window, gui.text_gc, i, y - offset); | |
5816 } | |
5817 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5818 #endif |
207 | 5819 } |
5820 | |
5821 /* Underline: draw a line at the bottom of the character cell. */ | |
5822 if (flags & DRAW_UNDERL) | |
5823 { | |
5824 /* When p_linespace is 0, overwrite the bottom row of pixels. | |
5825 * Otherwise put the line just below the character. */ | |
5826 if (p_linespace > 1) | |
5827 y -= p_linespace - 1; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5828 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5829 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5830 cairo_set_line_width(cr, 1.0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5831 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5832 set_cairo_source_rgb_from_pixel(cr, gui.fgcolor->pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5833 cairo_move_to(cr, FILL_X(col), y + 0.5); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5834 cairo_line_to(cr, FILL_X(col + cells), y + 0.5); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5835 cairo_stroke(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5836 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5837 #else |
207 | 5838 gdk_draw_line(gui.drawarea->window, gui.text_gc, |
5839 FILL_X(col), y, | |
5840 FILL_X(col + cells) - 1, y); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5841 #endif |
207 | 5842 } |
5843 } | |
5844 | |
7 | 5845 int |
5846 gui_gtk2_draw_string(int row, int col, char_u *s, int len, int flags) | |
5847 { | |
5848 GdkRectangle area; /* area for clip mask */ | |
5849 PangoGlyphString *glyphs; /* glyphs of current item */ | |
5850 int column_offset = 0; /* column offset in cells */ | |
5851 int i; | |
5852 char_u *conv_buf = NULL; /* result of UTF-8 conversion */ | |
5853 char_u *new_conv_buf; | |
5854 int convlen; | |
5855 char_u *sp, *bp; | |
5856 int plen; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5857 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5858 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5859 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5860 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5861 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5862 if (gui.text_context == NULL || gtk_widget_get_window(gui.drawarea) == NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5863 #else |
7 | 5864 if (gui.text_context == NULL || gui.drawarea->window == NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5865 #endif |
7 | 5866 return len; |
5867 | |
5868 if (output_conv.vc_type != CONV_NONE) | |
5869 { | |
5870 /* | |
5871 * Convert characters from 'encoding' to 'termencoding', which is set | |
5872 * to UTF-8 by gui_mch_init(). did_set_string_option() in option.c | |
5873 * prohibits changing this to something else than UTF-8 if the GUI is | |
5874 * in use. | |
5875 */ | |
5876 convlen = len; | |
5877 conv_buf = string_convert(&output_conv, s, &convlen); | |
5878 g_return_val_if_fail(conv_buf != NULL, len); | |
5879 | |
5880 /* Correct for differences in char width: some chars are | |
5881 * double-wide in 'encoding' but single-wide in utf-8. Add a space to | |
5882 * compensate for that. */ | |
5883 for (sp = s, bp = conv_buf; sp < s + len && bp < conv_buf + convlen; ) | |
5884 { | |
474 | 5885 plen = utf_ptr2len(bp); |
7 | 5886 if ((*mb_ptr2cells)(sp) == 2 && utf_ptr2cells(bp) == 1) |
5887 { | |
5888 new_conv_buf = alloc(convlen + 2); | |
5889 if (new_conv_buf == NULL) | |
5890 return len; | |
5891 plen += bp - conv_buf; | |
5892 mch_memmove(new_conv_buf, conv_buf, plen); | |
5893 new_conv_buf[plen] = ' '; | |
5894 mch_memmove(new_conv_buf + plen + 1, conv_buf + plen, | |
5895 convlen - plen + 1); | |
5896 vim_free(conv_buf); | |
5897 conv_buf = new_conv_buf; | |
5898 ++convlen; | |
5899 bp = conv_buf + plen; | |
5900 plen = 1; | |
5901 } | |
474 | 5902 sp += (*mb_ptr2len)(sp); |
7 | 5903 bp += plen; |
5904 } | |
5905 s = conv_buf; | |
5906 len = convlen; | |
5907 } | |
5908 | |
5909 /* | |
5910 * Restrict all drawing to the current screen line in order to prevent | |
5911 * fuzzy font lookups from messing up the screen. | |
5912 */ | |
5913 area.x = gui.border_offset; | |
5914 area.y = FILL_Y(row); | |
5915 area.width = gui.num_cols * gui.char_width; | |
5916 area.height = gui.char_height; | |
5917 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5918 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5919 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5920 cairo_rectangle(cr, area.x, area.y, area.width, area.height); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5921 cairo_clip(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5922 #else |
7 | 5923 gdk_gc_set_clip_origin(gui.text_gc, 0, 0); |
5924 gdk_gc_set_clip_rectangle(gui.text_gc, &area); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5925 #endif |
7 | 5926 |
5927 glyphs = pango_glyph_string_new(); | |
5928 | |
5929 /* | |
5930 * Optimization hack: If possible, skip the itemize and shaping process | |
5931 * for pure ASCII strings. This optimization is particularly effective | |
5932 * because Vim draws space characters to clear parts of the screen. | |
5933 */ | |
5934 if (!(flags & DRAW_ITALIC) | |
5935 && !((flags & DRAW_BOLD) && gui.font_can_bold) | |
5936 && gui.ascii_glyphs != NULL) | |
5937 { | |
5938 char_u *p; | |
5939 | |
5940 for (p = s; p < s + len; ++p) | |
5941 if (*p & 0x80) | |
5942 goto not_ascii; | |
5943 | |
5944 pango_glyph_string_set_size(glyphs, len); | |
5945 | |
5946 for (i = 0; i < len; ++i) | |
5947 { | |
5948 glyphs->glyphs[i] = gui.ascii_glyphs->glyphs[s[i]]; | |
5949 glyphs->log_clusters[i] = i; | |
5950 } | |
5951 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5952 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5953 draw_glyph_string(row, col, len, flags, gui.ascii_font, glyphs, cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5954 #else |
7 | 5955 draw_glyph_string(row, col, len, flags, gui.ascii_font, glyphs); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5956 #endif |
7 | 5957 |
5958 column_offset = len; | |
5959 } | |
5960 else | |
5961 not_ascii: | |
5962 { | |
5963 PangoAttrList *attr_list; | |
5964 GList *item_list; | |
5965 int cluster_width; | |
5966 int last_glyph_rbearing; | |
5967 int cells = 0; /* cells occupied by current cluster */ | |
5968 | |
26 | 5969 /* Safety check: pango crashes when invoked with invalid utf-8 |
5970 * characters. */ | |
5971 if (!utf_valid_string(s, s + len)) | |
5972 { | |
5973 column_offset = len; | |
5974 goto skipitall; | |
5975 } | |
5976 | |
7 | 5977 /* original width of the current cluster */ |
5978 cluster_width = PANGO_SCALE * gui.char_width; | |
5979 | |
5980 /* right bearing of the last non-composing glyph */ | |
5981 last_glyph_rbearing = PANGO_SCALE * gui.char_width; | |
5982 | |
5983 attr_list = pango_attr_list_new(); | |
5984 | |
5985 /* If 'guifontwide' is set then use that for double-width characters. | |
5986 * Otherwise just go with 'guifont' and let Pango do its thing. */ | |
5987 if (gui.wide_font != NULL) | |
5988 apply_wide_font_attr(s, len, attr_list); | |
5989 | |
5990 if ((flags & DRAW_BOLD) && gui.font_can_bold) | |
5991 INSERT_PANGO_ATTR(pango_attr_weight_new(PANGO_WEIGHT_BOLD), | |
5992 attr_list, 0, len); | |
5993 if (flags & DRAW_ITALIC) | |
5994 INSERT_PANGO_ATTR(pango_attr_style_new(PANGO_STYLE_ITALIC), | |
5995 attr_list, 0, len); | |
5996 /* | |
5997 * Break the text into segments with consistent directional level | |
5998 * and shaping engine. Pure Latin text needs only a single segment, | |
5999 * so there's no need to worry about the loop's efficiency. Better | |
6000 * try to optimize elsewhere, e.g. reducing exposes and stuff :) | |
6001 */ | |
6002 item_list = pango_itemize(gui.text_context, | |
6003 (const char *)s, 0, len, attr_list, NULL); | |
6004 | |
6005 while (item_list != NULL) | |
6006 { | |
6007 PangoItem *item; | |
6008 int item_cells = 0; /* item length in cells */ | |
6009 | |
6010 item = (PangoItem *)item_list->data; | |
6011 item_list = g_list_delete_link(item_list, item_list); | |
6012 /* | |
6013 * Increment the bidirectional embedding level by 1 if it is not | |
6014 * even. An odd number means the output will be RTL, but we don't | |
6015 * want that since Vim handles right-to-left text on its own. It | |
6016 * would probably be sufficient to just set level = 0, but you can | |
6017 * never know :) | |
6018 * | |
6019 * Unfortunately we can't take advantage of Pango's ability to | |
6020 * render both LTR and RTL at the same time. In order to support | |
6021 * that, Vim's main screen engine would have to make use of Pango | |
6022 * functionality. | |
6023 */ | |
6024 item->analysis.level = (item->analysis.level + 1) & (~1U); | |
6025 | |
6026 /* HACK: Overrule the shape engine, we don't want shaping to be | |
6027 * done, because drawing the cursor would change the display. */ | |
6028 item->analysis.shape_engine = default_shape_engine; | |
6029 | |
7098
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6030 #ifdef HAVE_PANGO_SHAPE_FULL |
7086
3825da022231
commit https://github.com/vim/vim/commit/7e2ec008f5c5152205d0b8a7d88177b374225d8d
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
6031 pango_shape_full((const char *)s + item->offset, item->length, |
3825da022231
commit https://github.com/vim/vim/commit/7e2ec008f5c5152205d0b8a7d88177b374225d8d
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
6032 (const char *)s, len, &item->analysis, glyphs); |
7098
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6033 #else |
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6034 pango_shape((const char *)s + item->offset, item->length, |
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6035 &item->analysis, glyphs); |
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6036 #endif |
7 | 6037 /* |
6038 * Fixed-width hack: iterate over the array and assign a fixed | |
6039 * width to each glyph, thus overriding the choice made by the | |
6040 * shaping engine. We use utf_char2cells() to determine the | |
6041 * number of cells needed. | |
6042 * | |
6043 * Also perform all kind of dark magic to get composing | |
6044 * characters right (and pretty too of course). | |
6045 */ | |
6046 for (i = 0; i < glyphs->num_glyphs; ++i) | |
6047 { | |
6048 PangoGlyphInfo *glyph; | |
6049 | |
6050 glyph = &glyphs->glyphs[i]; | |
6051 | |
6052 if (glyph->attr.is_cluster_start) | |
6053 { | |
6054 int cellcount; | |
6055 | |
6056 cellcount = count_cluster_cells( | |
6057 s, item, glyphs, i, &cluster_width, | |
6058 (item_list != NULL) ? &last_glyph_rbearing : NULL); | |
6059 | |
6060 if (cellcount > 0) | |
6061 { | |
6062 int width; | |
6063 | |
6064 width = cellcount * gui.char_width * PANGO_SCALE; | |
6065 glyph->geometry.x_offset += | |
6066 MAX(0, width - cluster_width) / 2; | |
6067 glyph->geometry.width = width; | |
6068 } | |
6069 else | |
6070 { | |
6071 /* If there are only combining characters in the | |
6072 * cluster, we cannot just change the width of the | |
6073 * previous glyph since there is none. Therefore | |
6074 * some guesswork is needed. */ | |
6075 setup_zero_width_cluster(item, glyph, cells, | |
6076 cluster_width, | |
6077 last_glyph_rbearing); | |
6078 } | |
6079 | |
6080 item_cells += cellcount; | |
6081 cells = cellcount; | |
6082 } | |
6083 else if (i > 0) | |
6084 { | |
6085 int width; | |
6086 | |
6087 /* There is a previous glyph, so we deal with combining | |
2507
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
6088 * characters the canonical way. |
2517
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6089 * In some circumstances Pango uses a positive x_offset, |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6090 * then use the width of the previous glyph for this one |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6091 * and set the previous width to zero. |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6092 * Otherwise we get a negative x_offset, Pango has already |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6093 * positioned the combining char, keep the widths as they |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6094 * are. |
2507
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
6095 * For both adjust the x_offset to position the glyph in |
2517
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6096 * the middle. */ |
2507
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
6097 if (glyph->geometry.x_offset >= 0) |
2517
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6098 { |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6099 glyphs->glyphs[i].geometry.width = |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6100 glyphs->glyphs[i - 1].geometry.width; |
2507
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
6101 glyphs->glyphs[i - 1].geometry.width = 0; |
2517
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6102 } |
7 | 6103 width = cells * gui.char_width * PANGO_SCALE; |
6104 glyph->geometry.x_offset += | |
6105 MAX(0, width - cluster_width) / 2; | |
6106 } | |
6107 else /* i == 0 "cannot happen" */ | |
6108 { | |
6109 glyph->geometry.width = 0; | |
6110 } | |
6111 } | |
6112 | |
6113 /*** Aaaaand action! ***/ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6114 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6115 draw_glyph_string(row, col + column_offset, item_cells, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6116 flags, item->analysis.font, glyphs, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6117 cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6118 #else |
7 | 6119 draw_glyph_string(row, col + column_offset, item_cells, |
6120 flags, item->analysis.font, glyphs); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6121 #endif |
7 | 6122 |
6123 pango_item_free(item); | |
6124 | |
6125 column_offset += item_cells; | |
6126 } | |
6127 | |
6128 pango_attr_list_unref(attr_list); | |
6129 } | |
6130 | |
26 | 6131 skipitall: |
207 | 6132 /* Draw underline and undercurl. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6133 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6134 draw_under(flags, row, col, column_offset, cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6135 #else |
207 | 6136 draw_under(flags, row, col, column_offset); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6137 #endif |
7 | 6138 |
6139 pango_glyph_string_free(glyphs); | |
6140 vim_free(conv_buf); | |
6141 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6142 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6143 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6144 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6145 gdk_window_invalidate_rect(gtk_widget_get_window(gui.drawarea), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6146 &area, FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6147 #else |
7 | 6148 gdk_gc_set_clip_rectangle(gui.text_gc, NULL); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6149 #endif |
7 | 6150 |
6151 return column_offset; | |
6152 } | |
6153 | |
6154 /* | |
6155 * Return OK if the key with the termcap name "name" is supported. | |
6156 */ | |
6157 int | |
6158 gui_mch_haskey(char_u *name) | |
6159 { | |
6160 int i; | |
6161 | |
6162 for (i = 0; special_keys[i].key_sym != 0; i++) | |
6163 if (name[0] == special_keys[i].code0 | |
6164 && name[1] == special_keys[i].code1) | |
6165 return OK; | |
6166 return FAIL; | |
6167 } | |
6168 | |
4133 | 6169 #if defined(FEAT_TITLE) || defined(FEAT_EVAL) || defined(PROTO) |
7 | 6170 /* |
6171 * Return the text window-id and display. Only required for X-based GUI's | |
6172 */ | |
6173 int | |
6174 gui_get_x11_windis(Window *win, Display **dis) | |
6175 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6176 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6177 if (gui.mainwin != NULL && gtk_widget_get_window(gui.mainwin) != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6178 #else |
7 | 6179 if (gui.mainwin != NULL && gui.mainwin->window != NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6180 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6181 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6182 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6183 *dis = GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.mainwin)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6184 *win = GDK_WINDOW_XID(gtk_widget_get_window(gui.mainwin)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6185 #else |
7 | 6186 *dis = GDK_WINDOW_XDISPLAY(gui.mainwin->window); |
6187 *win = GDK_WINDOW_XWINDOW(gui.mainwin->window); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6188 #endif |
7 | 6189 return OK; |
6190 } | |
6191 | |
6192 *dis = NULL; | |
6193 *win = 0; | |
6194 return FAIL; | |
6195 } | |
6196 #endif | |
6197 | |
6198 #if defined(FEAT_CLIENTSERVER) \ | |
6199 || (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO) | |
6200 | |
6201 Display * | |
6202 gui_mch_get_display(void) | |
6203 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6204 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6205 if (gui.mainwin != NULL && gtk_widget_get_window(gui.mainwin) != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6206 return GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.mainwin)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6207 #else |
7 | 6208 if (gui.mainwin != NULL && gui.mainwin->window != NULL) |
6209 return GDK_WINDOW_XDISPLAY(gui.mainwin->window); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6210 #endif |
7 | 6211 else |
6212 return NULL; | |
6213 } | |
6214 #endif | |
6215 | |
6216 void | |
6217 gui_mch_beep(void) | |
6218 { | |
6219 #ifdef HAVE_GTK_MULTIHEAD | |
6220 GdkDisplay *display; | |
6221 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6222 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6223 if (gui.mainwin != NULL && gtk_widget_get_realized(gui.mainwin)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6224 # else |
7 | 6225 if (gui.mainwin != NULL && GTK_WIDGET_REALIZED(gui.mainwin)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6226 # endif |
7 | 6227 display = gtk_widget_get_display(gui.mainwin); |
6228 else | |
6229 display = gdk_display_get_default(); | |
6230 | |
6231 if (display != NULL) | |
6232 gdk_display_beep(display); | |
6233 #else | |
6234 gdk_beep(); | |
6235 #endif | |
6236 } | |
6237 | |
6238 void | |
6239 gui_mch_flash(int msec) | |
6240 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6241 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6242 /* TODO Replace GdkGC with Cairo */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6243 (void)msec; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6244 #else |
7 | 6245 GdkGCValues values; |
6246 GdkGC *invert_gc; | |
6247 | |
6248 if (gui.drawarea->window == NULL) | |
6249 return; | |
6250 | |
6251 values.foreground.pixel = gui.norm_pixel ^ gui.back_pixel; | |
6252 values.background.pixel = gui.norm_pixel ^ gui.back_pixel; | |
6253 values.function = GDK_XOR; | |
6254 invert_gc = gdk_gc_new_with_values(gui.drawarea->window, | |
6255 &values, | |
6256 GDK_GC_FOREGROUND | | |
6257 GDK_GC_BACKGROUND | | |
6258 GDK_GC_FUNCTION); | |
6259 gdk_gc_set_exposures(invert_gc, | |
6260 gui.visibility != GDK_VISIBILITY_UNOBSCURED); | |
6261 /* | |
6262 * Do a visual beep by changing back and forth in some undetermined way, | |
6263 * the foreground and background colors. This is due to the fact that | |
6264 * there can't be really any prediction about the effects of XOR on | |
6265 * arbitrary X11 servers. However this seems to be enough for what we | |
6266 * intend it to do. | |
6267 */ | |
6268 gdk_draw_rectangle(gui.drawarea->window, invert_gc, | |
6269 TRUE, | |
6270 0, 0, | |
6271 FILL_X((int)Columns) + gui.border_offset, | |
6272 FILL_Y((int)Rows) + gui.border_offset); | |
6273 | |
6274 gui_mch_flush(); | |
6275 ui_delay((long)msec, TRUE); /* wait so many msec */ | |
6276 | |
6277 gdk_draw_rectangle(gui.drawarea->window, invert_gc, | |
6278 TRUE, | |
6279 0, 0, | |
6280 FILL_X((int)Columns) + gui.border_offset, | |
6281 FILL_Y((int)Rows) + gui.border_offset); | |
6282 | |
6283 gdk_gc_destroy(invert_gc); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6284 #endif |
7 | 6285 } |
6286 | |
6287 /* | |
6288 * Invert a rectangle from row r, column c, for nr rows and nc columns. | |
6289 */ | |
6290 void | |
6291 gui_mch_invert_rectangle(int r, int c, int nr, int nc) | |
6292 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6293 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6294 /* TODO Replace GdkGC with Cairo */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6295 (void)r; (void)c; (void)nr; (void)nc; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6296 #else |
7 | 6297 GdkGCValues values; |
6298 GdkGC *invert_gc; | |
6299 | |
6300 if (gui.drawarea->window == NULL) | |
6301 return; | |
6302 | |
944 | 6303 values.foreground.pixel = gui.norm_pixel ^ gui.back_pixel; |
6304 values.background.pixel = gui.norm_pixel ^ gui.back_pixel; | |
7 | 6305 values.function = GDK_XOR; |
6306 invert_gc = gdk_gc_new_with_values(gui.drawarea->window, | |
6307 &values, | |
6308 GDK_GC_FOREGROUND | | |
6309 GDK_GC_BACKGROUND | | |
6310 GDK_GC_FUNCTION); | |
944 | 6311 gdk_gc_set_exposures(invert_gc, gui.visibility != |
6312 GDK_VISIBILITY_UNOBSCURED); | |
7 | 6313 gdk_draw_rectangle(gui.drawarea->window, invert_gc, |
6314 TRUE, | |
6315 FILL_X(c), FILL_Y(r), | |
6316 (nc) * gui.char_width, (nr) * gui.char_height); | |
6317 gdk_gc_destroy(invert_gc); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6318 #endif |
7 | 6319 } |
6320 | |
6321 /* | |
6322 * Iconify the GUI window. | |
6323 */ | |
6324 void | |
6325 gui_mch_iconify(void) | |
6326 { | |
6327 gtk_window_iconify(GTK_WINDOW(gui.mainwin)); | |
6328 } | |
6329 | |
6330 #if defined(FEAT_EVAL) || defined(PROTO) | |
6331 /* | |
6332 * Bring the Vim window to the foreground. | |
6333 */ | |
6334 void | |
6335 gui_mch_set_foreground(void) | |
6336 { | |
6337 gtk_window_present(GTK_WINDOW(gui.mainwin)); | |
6338 } | |
6339 #endif | |
6340 | |
6341 /* | |
6342 * Draw a cursor without focus. | |
6343 */ | |
6344 void | |
6345 gui_mch_draw_hollow_cursor(guicolor_T color) | |
6346 { | |
6347 int i = 1; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6348 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6349 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6350 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6351 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6352 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6353 if (gtk_widget_get_window(gui.drawarea) == NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6354 #else |
7 | 6355 if (gui.drawarea->window == NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6356 #endif |
7 | 6357 return; |
6358 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6359 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6360 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6361 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6362 |
7 | 6363 gui_mch_set_fg_color(color); |
6364 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6365 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6366 set_cairo_source_rgb_from_pixel(cr, gui.fgcolor->pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6367 #else |
7 | 6368 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6369 #endif |
7 | 6370 if (mb_lefthalve(gui.row, gui.col)) |
6371 i = 2; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6372 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6373 cairo_set_line_width(cr, 1.0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6374 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6375 cairo_rectangle(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6376 FILL_X(gui.col) + 0.5, FILL_Y(gui.row) + 0.5, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6377 i * gui.char_width - 1, gui.char_height - 1); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6378 cairo_stroke(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6379 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6380 #else |
7 | 6381 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, |
6382 FALSE, | |
6383 FILL_X(gui.col), FILL_Y(gui.row), | |
6384 i * gui.char_width - 1, gui.char_height - 1); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6385 #endif |
7 | 6386 } |
6387 | |
6388 /* | |
6389 * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using | |
6390 * color "color". | |
6391 */ | |
6392 void | |
6393 gui_mch_draw_part_cursor(int w, int h, guicolor_T color) | |
6394 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6395 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6396 if (gtk_widget_get_window(gui.drawarea) == NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6397 #else |
7 | 6398 if (gui.drawarea->window == NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6399 #endif |
7 | 6400 return; |
6401 | |
6402 gui_mch_set_fg_color(color); | |
6403 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6404 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6405 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6406 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6407 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6408 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6409 set_cairo_source_rgb_from_pixel(cr, gui.fgcolor->pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6410 cairo_rectangle(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6411 # ifdef FEAT_RIGHTLEFT |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6412 /* vertical line should be on the right of current point */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6413 CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w : |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6414 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6415 FILL_X(gui.col), FILL_Y(gui.row) + gui.char_height - h, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6416 w, h); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6417 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6418 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6419 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6420 #else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6421 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
6422 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, | |
6423 TRUE, | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6424 # ifdef FEAT_RIGHTLEFT |
7 | 6425 /* vertical line should be on the right of current point */ |
6426 CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w : | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6427 # endif |
7 | 6428 FILL_X(gui.col), |
6429 FILL_Y(gui.row) + gui.char_height - h, | |
6430 w, h); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6431 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6432 } |
6433 | |
6434 | |
6435 /* | |
6436 * Catch up with any queued X11 events. This may put keyboard input into the | |
6437 * input buffer, call resize call-backs, trigger timers etc. If there is | |
6438 * nothing in the X11 event queue (& no timers pending), then we return | |
6439 * immediately. | |
6440 */ | |
6441 void | |
6442 gui_mch_update(void) | |
6443 { | |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
6444 while (g_main_context_pending(NULL) && !vim_is_input_buf_full()) |
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
6445 g_main_context_iteration(NULL, TRUE); |
7 | 6446 } |
6447 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6448 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6449 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6450 #else |
7 | 6451 static gint |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6452 #endif |
7 | 6453 input_timer_cb(gpointer data) |
6454 { | |
6455 int *timed_out = (int *) data; | |
6456 | |
1226 | 6457 /* Just inform the caller about the occurrence of it */ |
7 | 6458 *timed_out = TRUE; |
6459 | |
6460 return FALSE; /* don't happen again */ | |
6461 } | |
6462 | |
6463 /* | |
6464 * GUI input routine called by gui_wait_for_chars(). Waits for a character | |
6465 * from the keyboard. | |
6466 * wtime == -1 Wait forever. | |
6467 * wtime == 0 This should never happen. | |
6468 * wtime > 0 Wait wtime milliseconds for a character. | |
6469 * Returns OK if a character was found to be available within the given time, | |
6470 * or FAIL otherwise. | |
6471 */ | |
6472 int | |
6473 gui_mch_wait_for_chars(long wtime) | |
6474 { | |
6475 int focus; | |
6476 guint timer; | |
6477 static int timed_out; | |
6478 | |
6479 timed_out = FALSE; | |
6480 | |
6481 /* this timeout makes sure that we will return if no characters arrived in | |
6482 * time */ | |
6483 | |
6484 if (wtime > 0) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6485 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6486 timer = g_timeout_add((guint)wtime, input_timer_cb, &timed_out); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6487 #else |
7 | 6488 timer = gtk_timeout_add((guint32)wtime, input_timer_cb, &timed_out); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6489 #endif |
7 | 6490 else |
6491 timer = 0; | |
6492 | |
6493 focus = gui.in_focus; | |
6494 | |
6495 do | |
6496 { | |
6497 /* Stop or start blinking when focus changes */ | |
6498 if (gui.in_focus != focus) | |
6499 { | |
6500 if (gui.in_focus) | |
6501 gui_mch_start_blink(); | |
6502 else | |
6503 gui_mch_stop_blink(); | |
6504 focus = gui.in_focus; | |
6505 } | |
6506 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
6507 #ifdef MESSAGE_QUEUE |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
6508 parse_queued_messages(); |
1624 | 6509 #endif |
6510 | |
7 | 6511 /* |
6512 * Loop in GTK+ processing until a timeout or input occurs. | |
22 | 6513 * Skip this if input is available anyway (can happen in rare |
6514 * situations, sort of race condition). | |
7 | 6515 */ |
22 | 6516 if (!input_available()) |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
6517 g_main_context_iteration(NULL, TRUE); |
7 | 6518 |
6519 /* Got char, return immediately */ | |
6520 if (input_available()) | |
6521 { | |
6522 if (timer != 0 && !timed_out) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6523 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6524 g_source_remove(timer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6525 #else |
7 | 6526 gtk_timeout_remove(timer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6527 #endif |
7 | 6528 return OK; |
6529 } | |
6530 } while (wtime < 0 || !timed_out); | |
6531 | |
6532 /* | |
6533 * Flush all eventually pending (drawing) events. | |
6534 */ | |
6535 gui_mch_update(); | |
6536 | |
6537 return FAIL; | |
6538 } | |
6539 | |
6540 | |
6541 /**************************************************************************** | |
6542 * Output drawing routines. | |
6543 ****************************************************************************/ | |
6544 | |
6545 | |
6546 /* Flush any output to the screen */ | |
6547 void | |
6548 gui_mch_flush(void) | |
6549 { | |
6550 #ifdef HAVE_GTK_MULTIHEAD | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6551 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6552 if (gui.mainwin != NULL && gtk_widget_get_realized(gui.mainwin)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6553 # else |
7 | 6554 if (gui.mainwin != NULL && GTK_WIDGET_REALIZED(gui.mainwin)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6555 # endif |
7 | 6556 gdk_display_sync(gtk_widget_get_display(gui.mainwin)); |
6557 #else | |
6558 gdk_flush(); /* historical misnomer: calls XSync(), not XFlush() */ | |
6559 #endif | |
6560 /* This happens to actually do what gui_mch_flush() is supposed to do, | |
6561 * according to the comment above. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6562 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6563 if (gui.drawarea != NULL && gtk_widget_get_window(gui.drawarea) != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6564 gdk_window_process_updates(gtk_widget_get_window(gui.drawarea), FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6565 #else |
7 | 6566 if (gui.drawarea != NULL && gui.drawarea->window != NULL) |
6567 gdk_window_process_updates(gui.drawarea->window, FALSE); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6568 #endif |
7 | 6569 } |
6570 | |
6571 /* | |
6572 * Clear a rectangular region of the screen from text pos (row1, col1) to | |
6573 * (row2, col2) inclusive. | |
6574 */ | |
6575 void | |
6576 gui_mch_clear_block(int row1, int col1, int row2, int col2) | |
6577 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6578 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6579 if (gtk_widget_get_window(gui.drawarea) == NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6580 return; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6581 #else |
7 | 6582 GdkColor color; |
6583 | |
6584 if (gui.drawarea->window == NULL) | |
6585 return; | |
6586 | |
6587 color.pixel = gui.back_pixel; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6588 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6589 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6590 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6591 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6592 /* Add one pixel to the far right column in case a double-stroked |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6593 * bold glyph may sit there. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6594 const GdkRectangle rect = { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6595 FILL_X(col1), FILL_Y(row1), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6596 (col2 - col1 + 1) * gui.char_width + (col2 == Columns - 1), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6597 (row2 - row1 + 1) * gui.char_height |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6598 }; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6599 GdkWindow * const win = gtk_widget_get_window(gui.drawarea); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6600 cairo_t * const cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6601 cairo_pattern_t * const pat = gdk_window_get_background_pattern(win); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6602 if (pat != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6603 cairo_set_source(cr, pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6604 else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6605 set_cairo_source_rgb_from_pixel(cr, gui.back_pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6606 gdk_cairo_rectangle(cr, &rect); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6607 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6608 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6609 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6610 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6611 gdk_window_invalidate_rect(win, &rect, FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6612 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6613 #else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6614 gdk_gc_set_foreground(gui.text_gc, &color); |
6615 | |
6616 /* Clear one extra pixel at the far right, for when bold characters have | |
6617 * spilled over to the window border. */ | |
6618 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, TRUE, | |
6619 FILL_X(col1), FILL_Y(row1), | |
6620 (col2 - col1 + 1) * gui.char_width | |
6621 + (col2 == Columns - 1), | |
6622 (row2 - row1 + 1) * gui.char_height); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6623 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6624 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6625 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6626 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6627 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6628 gui_gtk_window_clear(GdkWindow *win) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6629 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6630 const GdkRectangle rect = { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6631 0, 0, gdk_window_get_width(win), gdk_window_get_height(win) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6632 }; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6633 cairo_t * const cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6634 cairo_pattern_t * const pat = gdk_window_get_background_pattern(win); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6635 if (pat != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6636 cairo_set_source(cr, pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6637 else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6638 set_cairo_source_rgb_from_pixel(cr, gui.back_pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6639 gdk_cairo_rectangle(cr, &rect); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6640 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6641 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6642 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6643 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6644 gdk_window_invalidate_rect(win, &rect, FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6645 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6646 #endif |
7 | 6647 |
6648 void | |
6649 gui_mch_clear_all(void) | |
6650 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6651 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6652 if (gtk_widget_get_window(gui.drawarea) != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6653 gui_gtk_window_clear(gtk_widget_get_window(gui.drawarea)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6654 #else |
7 | 6655 if (gui.drawarea->window != NULL) |
6656 gdk_window_clear(gui.drawarea->window); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6657 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6658 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6659 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6660 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 6661 /* |
6662 * Redraw any text revealed by scrolling up/down. | |
6663 */ | |
6664 static void | |
6665 check_copy_area(void) | |
6666 { | |
6667 GdkEvent *event; | |
6668 int expose_count; | |
6669 | |
6670 if (gui.visibility != GDK_VISIBILITY_PARTIAL) | |
6671 return; | |
6672 | |
6673 /* Avoid redrawing the cursor while scrolling or it'll end up where | |
6674 * we don't want it to be. I'm not sure if it's correct to call | |
6675 * gui_dont_update_cursor() at this point but it works as a quick | |
6676 * fix for now. */ | |
6677 gui_dont_update_cursor(); | |
6678 | |
6679 do | |
6680 { | |
6681 /* Wait to check whether the scroll worked or not. */ | |
6682 event = gdk_event_get_graphics_expose(gui.drawarea->window); | |
6683 | |
6684 if (event == NULL) | |
6685 break; /* received NoExpose event */ | |
6686 | |
6687 gui_redraw(event->expose.area.x, event->expose.area.y, | |
6688 event->expose.area.width, event->expose.area.height); | |
6689 | |
6690 expose_count = event->expose.count; | |
6691 gdk_event_free(event); | |
6692 } | |
6693 while (expose_count > 0); /* more events follow */ | |
6694 | |
6695 gui_can_update_cursor(); | |
6696 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6697 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6698 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6699 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6700 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6701 gui_gtk_surface_copy_rect(int dest_x, int dest_y, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6702 int src_x, int src_y, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6703 int width, int height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6704 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6705 cairo_t * const cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6706 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6707 cairo_rectangle(cr, dest_x, dest_y, width, height); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6708 cairo_clip(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6709 cairo_push_group(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6710 cairo_set_source_surface(cr, gui.surface, dest_x - src_x, dest_y - src_y); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6711 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6712 cairo_pop_group_to_source(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6713 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6714 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6715 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6716 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6717 #endif |
7 | 6718 |
6719 /* | |
6720 * Delete the given number of lines from the given row, scrolling up any | |
6721 * text further down within the scroll region. | |
6722 */ | |
6723 void | |
6724 gui_mch_delete_lines(int row, int num_lines) | |
6725 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6726 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6727 const int ncols = gui.scroll_region_right - gui.scroll_region_left + 1; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6728 const int nrows = gui.scroll_region_bot - row + 1; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6729 const int src_nrows = nrows - num_lines; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6730 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6731 gui_gtk_surface_copy_rect( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6732 FILL_X(gui.scroll_region_left), FILL_Y(row), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6733 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6734 gui.char_width * ncols + 1, gui.char_height * src_nrows); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6735 gui_clear_block( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6736 gui.scroll_region_bot - num_lines + 1, gui.scroll_region_left, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6737 gui.scroll_region_bot, gui.scroll_region_right); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6738 gui_gtk3_redraw( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6739 FILL_X(gui.scroll_region_left), FILL_Y(row), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6740 gui.char_width * ncols + 1, gui.char_height * nrows); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6741 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6742 gtk_widget_queue_draw_area(gui.drawarea, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6743 FILL_X(gui.scroll_region_left), FILL_Y(row), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6744 gui.char_width * ncols + 1, gui.char_height * nrows); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6745 #else |
7 | 6746 if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) |
6747 return; /* Can't see the window */ | |
6748 | |
6749 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
6750 gdk_gc_set_background(gui.text_gc, gui.bgcolor); | |
6751 | |
6752 /* copy one extra pixel, for when bold has spilled over */ | |
6753 gdk_window_copy_area(gui.drawarea->window, gui.text_gc, | |
6754 FILL_X(gui.scroll_region_left), FILL_Y(row), | |
6755 gui.drawarea->window, | |
6756 FILL_X(gui.scroll_region_left), | |
6757 FILL_Y(row + num_lines), | |
6758 gui.char_width * (gui.scroll_region_right | |
6759 - gui.scroll_region_left + 1) + 1, | |
6760 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1)); | |
6761 | |
6762 gui_clear_block(gui.scroll_region_bot - num_lines + 1, | |
6763 gui.scroll_region_left, | |
6764 gui.scroll_region_bot, gui.scroll_region_right); | |
6765 check_copy_area(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6766 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6767 } |
6768 | |
6769 /* | |
6770 * Insert the given number of lines before the given row, scrolling down any | |
6771 * following text within the scroll region. | |
6772 */ | |
6773 void | |
6774 gui_mch_insert_lines(int row, int num_lines) | |
6775 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6776 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6777 const int ncols = gui.scroll_region_right - gui.scroll_region_left + 1; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6778 const int nrows = gui.scroll_region_bot - row + 1; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6779 const int src_nrows = nrows - num_lines; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6780 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6781 gui_gtk_surface_copy_rect( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6782 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6783 FILL_X(gui.scroll_region_left), FILL_Y(row), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6784 gui.char_width * ncols + 1, gui.char_height * src_nrows); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6785 gui_mch_clear_block( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6786 row, gui.scroll_region_left, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6787 row + num_lines - 1, gui.scroll_region_right); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6788 gui_gtk3_redraw( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6789 FILL_X(gui.scroll_region_left), FILL_Y(row), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6790 gui.char_width * ncols + 1, gui.char_height * nrows); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6791 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6792 gtk_widget_queue_draw_area(gui.drawarea, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6793 FILL_X(gui.scroll_region_left), FILL_Y(row), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6794 gui.char_width * ncols + 1, gui.char_height * nrows); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6795 #else |
7 | 6796 if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) |
6797 return; /* Can't see the window */ | |
6798 | |
6799 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
6800 gdk_gc_set_background(gui.text_gc, gui.bgcolor); | |
6801 | |
6802 /* copy one extra pixel, for when bold has spilled over */ | |
6803 gdk_window_copy_area(gui.drawarea->window, gui.text_gc, | |
6804 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), | |
6805 gui.drawarea->window, | |
6806 FILL_X(gui.scroll_region_left), FILL_Y(row), | |
6807 gui.char_width * (gui.scroll_region_right | |
6808 - gui.scroll_region_left + 1) + 1, | |
6809 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1)); | |
6810 | |
6811 gui_clear_block(row, gui.scroll_region_left, | |
6812 row + num_lines - 1, gui.scroll_region_right); | |
6813 check_copy_area(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6814 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6815 } |
6816 | |
6817 /* | |
6818 * X Selection stuff, for cutting and pasting text to other windows. | |
6819 */ | |
6820 void | |
6821 clip_mch_request_selection(VimClipboard *cbd) | |
6822 { | |
6823 GdkAtom target; | |
6824 unsigned i; | |
1494 | 6825 time_t start; |
7 | 6826 |
6827 for (i = 0; i < N_SELECTION_TARGETS; ++i) | |
6828 { | |
1904 | 6829 if (!clip_html && selection_targets[i].info == TARGET_HTML) |
6830 continue; | |
7 | 6831 received_selection = RS_NONE; |
6832 target = gdk_atom_intern(selection_targets[i].target, FALSE); | |
6833 | |
6834 gtk_selection_convert(gui.drawarea, | |
6835 cbd->gtk_sel_atom, target, | |
6836 (guint32)GDK_CURRENT_TIME); | |
6837 | |
1494 | 6838 /* Hack: Wait up to three seconds for the selection. A hang was |
6839 * noticed here when using the netrw plugin combined with ":gui" | |
6840 * during the FocusGained event. */ | |
6841 start = time(NULL); | |
6842 while (received_selection == RS_NONE && time(NULL) < start + 3) | |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
6843 g_main_context_iteration(NULL, TRUE); /* wait for selection_received_cb */ |
7 | 6844 |
6845 if (received_selection != RS_FAIL) | |
6846 return; | |
6847 } | |
6848 | |
6849 /* Final fallback position - use the X CUT_BUFFER0 store */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6850 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6851 yank_cut_buffer0(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.mainwin)), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6852 cbd); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6853 #else |
1924 | 6854 yank_cut_buffer0(GDK_WINDOW_XDISPLAY(gui.mainwin->window), cbd); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6855 #endif |
7 | 6856 } |
6857 | |
6858 /* | |
6859 * Disown the selection. | |
6860 */ | |
6861 void | |
1884 | 6862 clip_mch_lose_selection(VimClipboard *cbd UNUSED) |
7 | 6863 { |
4209 | 6864 gtk_selection_owner_set(NULL, cbd->gtk_sel_atom, gui.event_time); |
7 | 6865 gui_mch_update(); |
6866 } | |
6867 | |
6868 /* | |
6869 * Own the selection and return OK if it worked. | |
6870 */ | |
6871 int | |
6872 clip_mch_own_selection(VimClipboard *cbd) | |
6873 { | |
6874 int success; | |
6875 | |
6876 success = gtk_selection_owner_set(gui.drawarea, cbd->gtk_sel_atom, | |
2923 | 6877 gui.event_time); |
7 | 6878 gui_mch_update(); |
6879 return (success) ? OK : FAIL; | |
6880 } | |
6881 | |
6882 /* | |
6883 * Send the current selection to the clipboard. Do nothing for X because we | |
6884 * will fill in the selection only when requested by another app. | |
6885 */ | |
6886 void | |
1884 | 6887 clip_mch_set_selection(VimClipboard *cbd UNUSED) |
7 | 6888 { |
6889 } | |
6890 | |
4209 | 6891 int |
6892 clip_gtk_owner_exists(VimClipboard *cbd) | |
6893 { | |
6894 return gdk_selection_owner_get(cbd->gtk_sel_atom) != NULL; | |
6895 } | |
6896 | |
7 | 6897 |
6898 #if defined(FEAT_MENU) || defined(PROTO) | |
6899 /* | |
6900 * Make a menu item appear either active or not active (grey or not grey). | |
6901 */ | |
6902 void | |
6903 gui_mch_menu_grey(vimmenu_T *menu, int grey) | |
6904 { | |
6905 if (menu->id == NULL) | |
6906 return; | |
6907 | |
6908 if (menu_is_separator(menu->name)) | |
6909 grey = TRUE; | |
6910 | |
6911 gui_mch_menu_hidden(menu, FALSE); | |
6912 /* Be clever about bitfields versus true booleans here! */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6913 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6914 if (!gtk_widget_get_sensitive(menu->id) == !grey) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6915 # else |
7 | 6916 if (!GTK_WIDGET_SENSITIVE(menu->id) == !grey) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6917 # endif |
7 | 6918 { |
6919 gtk_widget_set_sensitive(menu->id, !grey); | |
6920 gui_mch_update(); | |
6921 } | |
6922 } | |
6923 | |
6924 /* | |
6925 * Make menu item hidden or not hidden. | |
6926 */ | |
6927 void | |
6928 gui_mch_menu_hidden(vimmenu_T *menu, int hidden) | |
6929 { | |
6930 if (menu->id == 0) | |
6931 return; | |
6932 | |
6933 if (hidden) | |
6934 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6935 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6936 if (gtk_widget_get_visible(menu->id)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6937 # else |
7 | 6938 if (GTK_WIDGET_VISIBLE(menu->id)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6939 # endif |
7 | 6940 { |
6941 gtk_widget_hide(menu->id); | |
6942 gui_mch_update(); | |
6943 } | |
6944 } | |
6945 else | |
6946 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6947 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6948 if (!gtk_widget_get_visible(menu->id)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6949 # else |
7 | 6950 if (!GTK_WIDGET_VISIBLE(menu->id)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6951 # endif |
7 | 6952 { |
6953 gtk_widget_show(menu->id); | |
6954 gui_mch_update(); | |
6955 } | |
6956 } | |
6957 } | |
6958 | |
6959 /* | |
6960 * This is called after setting all the menus to grey/hidden or not. | |
6961 */ | |
6962 void | |
6963 gui_mch_draw_menubar(void) | |
6964 { | |
6965 /* just make sure that the visual changes get effect immediately */ | |
6966 gui_mch_update(); | |
6967 } | |
6968 #endif /* FEAT_MENU */ | |
6969 | |
6970 /* | |
6971 * Scrollbar stuff. | |
6972 */ | |
6973 void | |
6974 gui_mch_enable_scrollbar(scrollbar_T *sb, int flag) | |
6975 { | |
6976 if (sb->id == NULL) | |
6977 return; | |
6978 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6979 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6980 gtk_widget_set_visible(sb->id, flag); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6981 #else |
7 | 6982 if (flag) |
6983 gtk_widget_show(sb->id); | |
6984 else | |
6985 gtk_widget_hide(sb->id); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6986 #endif |
7 | 6987 |
791 | 6988 update_window_manager_hints(0, 0); |
7 | 6989 } |
6990 | |
6991 | |
6992 /* | |
6993 * Return the RGB value of a pixel as long. | |
6994 */ | |
6995 long_u | |
6996 gui_mch_get_rgb(guicolor_T pixel) | |
6997 { | |
6998 GdkColor color; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6999 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7000 GdkRGBA rgba; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7001 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7002 gui_gtk_get_rgb_from_pixel(pixel, &rgba); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7003 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7004 color.red = rgba.red * 65535; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7005 color.green = rgba.green * 65535; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7006 color.blue = rgba.blue * 65535; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7007 #else |
7 | 7008 gdk_colormap_query_color(gtk_widget_get_colormap(gui.drawarea), |
7009 (unsigned long)pixel, &color); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7010 #endif |
7 | 7011 |
7012 return (((unsigned)color.red & 0xff00) << 8) | |
7013 | ((unsigned)color.green & 0xff00) | |
7014 | (((unsigned)color.blue & 0xff00) >> 8); | |
7015 } | |
7016 | |
7017 /* | |
88 | 7018 * Get current mouse coordinates in text window. |
7 | 7019 */ |
88 | 7020 void |
7021 gui_mch_getmouse(int *x, int *y) | |
7 | 7022 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7023 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7024 gui_gtk_get_pointer(gui.drawarea, x, y, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7025 #else |
88 | 7026 gdk_window_get_pointer(gui.drawarea->window, x, y, NULL); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7027 #endif |
7 | 7028 } |
7029 | |
7030 void | |
7031 gui_mch_setmouse(int x, int y) | |
7032 { | |
7033 /* Sorry for the Xlib call, but we can't avoid it, since there is no | |
7034 * internal GDK mechanism present to accomplish this. (and for good | |
7035 * reason...) */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7036 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7037 XWarpPointer(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.drawarea)), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7038 (Window)0, GDK_WINDOW_XID(gtk_widget_get_window(gui.drawarea)), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7039 0, 0, 0U, 0U, x, y); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7040 #else |
7 | 7041 XWarpPointer(GDK_WINDOW_XDISPLAY(gui.drawarea->window), |
7042 (Window)0, GDK_WINDOW_XWINDOW(gui.drawarea->window), | |
7043 0, 0, 0U, 0U, x, y); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7044 #endif |
7 | 7045 } |
7046 | |
7047 | |
7048 #ifdef FEAT_MOUSESHAPE | |
7049 /* The last set mouse pointer shape is remembered, to be used when it goes | |
7050 * from hidden to not hidden. */ | |
7051 static int last_shape = 0; | |
7052 #endif | |
7053 | |
7054 /* | |
7055 * Use the blank mouse pointer or not. | |
7056 * | |
7057 * hide: TRUE = use blank ptr, FALSE = use parent ptr | |
7058 */ | |
7059 void | |
7060 gui_mch_mousehide(int hide) | |
7061 { | |
7062 if (gui.pointer_hidden != hide) | |
7063 { | |
7064 gui.pointer_hidden = hide; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7065 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7066 if (gtk_widget_get_window(gui.drawarea) && gui.blank_pointer != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7067 #else |
7 | 7068 if (gui.drawarea->window && gui.blank_pointer != NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7069 #endif |
7 | 7070 { |
7071 if (hide) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7072 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7073 gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7074 gui.blank_pointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7075 #else |
7 | 7076 gdk_window_set_cursor(gui.drawarea->window, gui.blank_pointer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7077 #endif |
7 | 7078 else |
7079 #ifdef FEAT_MOUSESHAPE | |
7080 mch_set_mouse_shape(last_shape); | |
8301
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7081 #elif GTK_CHECK_VERSION(3,0,0) |
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7082 gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), NULL); |
7 | 7083 #else |
7084 gdk_window_set_cursor(gui.drawarea->window, NULL); | |
7085 #endif | |
7086 } | |
7087 } | |
7088 } | |
7089 | |
7090 #if defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7091 | |
7092 /* Table for shape IDs. Keep in sync with the mshape_names[] table in | |
7093 * misc2.c! */ | |
7094 static const int mshape_ids[] = | |
7095 { | |
7096 GDK_LEFT_PTR, /* arrow */ | |
7097 GDK_CURSOR_IS_PIXMAP, /* blank */ | |
7098 GDK_XTERM, /* beam */ | |
7099 GDK_SB_V_DOUBLE_ARROW, /* updown */ | |
7100 GDK_SIZING, /* udsizing */ | |
7101 GDK_SB_H_DOUBLE_ARROW, /* leftright */ | |
7102 GDK_SIZING, /* lrsizing */ | |
7103 GDK_WATCH, /* busy */ | |
7104 GDK_X_CURSOR, /* no */ | |
7105 GDK_CROSSHAIR, /* crosshair */ | |
7106 GDK_HAND1, /* hand1 */ | |
7107 GDK_HAND2, /* hand2 */ | |
7108 GDK_PENCIL, /* pencil */ | |
7109 GDK_QUESTION_ARROW, /* question */ | |
7110 GDK_RIGHT_PTR, /* right-arrow */ | |
7111 GDK_CENTER_PTR, /* up-arrow */ | |
7112 GDK_LEFT_PTR /* last one */ | |
7113 }; | |
7114 | |
7115 void | |
7116 mch_set_mouse_shape(int shape) | |
7117 { | |
7118 int id; | |
7119 GdkCursor *c; | |
7120 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7121 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7122 if (gtk_widget_get_window(gui.drawarea) == NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7123 # else |
7 | 7124 if (gui.drawarea->window == NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7125 # endif |
7 | 7126 return; |
7127 | |
7128 if (shape == MSHAPE_HIDE || gui.pointer_hidden) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7129 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7130 gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7131 gui.blank_pointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7132 # else |
7 | 7133 gdk_window_set_cursor(gui.drawarea->window, gui.blank_pointer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7134 # endif |
7 | 7135 else |
7136 { | |
7137 if (shape >= MSHAPE_NUMBERED) | |
7138 { | |
7139 id = shape - MSHAPE_NUMBERED; | |
7140 if (id >= GDK_LAST_CURSOR) | |
7141 id = GDK_LEFT_PTR; | |
7142 else | |
7143 id &= ~1; /* they are always even (why?) */ | |
7144 } | |
1884 | 7145 else if (shape < (int)(sizeof(mshape_ids) / sizeof(int))) |
7 | 7146 id = mshape_ids[shape]; |
842 | 7147 else |
7148 return; | |
7 | 7149 # ifdef HAVE_GTK_MULTIHEAD |
7150 c = gdk_cursor_new_for_display( | |
136 | 7151 gtk_widget_get_display(gui.drawarea), (GdkCursorType)id); |
7 | 7152 # else |
136 | 7153 c = gdk_cursor_new((GdkCursorType)id); |
7 | 7154 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7155 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7156 gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), c); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7157 # else |
7 | 7158 gdk_window_set_cursor(gui.drawarea->window, c); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7159 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7160 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7161 g_object_unref(G_OBJECT(c)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7162 # else |
7 | 7163 gdk_cursor_destroy(c); /* Unref, actually. Bloody GTK+ 1. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7164 # endif |
7 | 7165 } |
7166 if (shape != MSHAPE_HIDE) | |
7167 last_shape = shape; | |
7168 } | |
7169 #endif /* FEAT_MOUSESHAPE */ | |
7170 | |
7171 | |
7172 #if defined(FEAT_SIGN_ICONS) || defined(PROTO) | |
7173 /* | |
7174 * Signs are currently always 2 chars wide. With GTK+ 2, the image will be | |
7175 * scaled down if the current font is not big enough, or scaled up if the image | |
7176 * size is less than 3/4 of the maximum sign size. With GTK+ 1, the pixmap | |
7177 * will be cut off if the current font is not big enough, or centered if it's | |
7178 * too small. | |
7179 */ | |
7180 # define SIGN_WIDTH (2 * gui.char_width) | |
7181 # define SIGN_HEIGHT (gui.char_height) | |
7182 # define SIGN_ASPECT ((double)SIGN_HEIGHT / (double)SIGN_WIDTH) | |
7183 | |
7184 void | |
7185 gui_mch_drawsign(int row, int col, int typenr) | |
7186 { | |
7187 GdkPixbuf *sign; | |
7188 | |
7189 sign = (GdkPixbuf *)sign_get_image(typenr); | |
7190 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7191 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7192 if (sign != NULL && gui.drawarea != NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7193 && gtk_widget_get_window(gui.drawarea) != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7194 # else |
7 | 7195 if (sign != NULL && gui.drawarea != NULL && gui.drawarea->window != NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7196 # endif |
7 | 7197 { |
7198 int width; | |
7199 int height; | |
7200 int xoffset; | |
7201 int yoffset; | |
7202 int need_scale; | |
7203 | |
7204 width = gdk_pixbuf_get_width(sign); | |
7205 height = gdk_pixbuf_get_height(sign); | |
7206 /* | |
7207 * Decide whether we need to scale. Allow one pixel of border | |
7208 * width to be cut off, in order to avoid excessive scaling for | |
7209 * tiny differences in font size. | |
5983 | 7210 * Do scale to fit the height to avoid gaps because of linespacing. |
7 | 7211 */ |
7212 need_scale = (width > SIGN_WIDTH + 2 | |
5983 | 7213 || height != SIGN_HEIGHT |
7 | 7214 || (width < 3 * SIGN_WIDTH / 4 |
7215 && height < 3 * SIGN_HEIGHT / 4)); | |
7216 if (need_scale) | |
7217 { | |
5983 | 7218 double aspect; |
7219 int w = width; | |
7220 int h = height; | |
7 | 7221 |
7222 /* Keep the original aspect ratio */ | |
7223 aspect = (double)height / (double)width; | |
7224 width = (double)SIGN_WIDTH * SIGN_ASPECT / aspect; | |
7225 width = MIN(width, SIGN_WIDTH); | |
5983 | 7226 if (((double)(MAX(height, SIGN_HEIGHT)) / |
7227 (double)(MIN(height, SIGN_HEIGHT))) < 1.15) | |
7228 { | |
7229 /* Change the aspect ratio by at most 15% to fill the | |
7230 * available space completly. */ | |
7231 height = (double)SIGN_HEIGHT * SIGN_ASPECT / aspect; | |
7232 height = MIN(height, SIGN_HEIGHT); | |
7233 } | |
7234 else | |
7235 height = (double)width * aspect; | |
7236 | |
7237 if (w == width && h == height) | |
7238 { | |
7239 /* no change in dimensions; don't decrease reference counter | |
7240 * (below) */ | |
7241 need_scale = FALSE; | |
7242 } | |
7243 else | |
7244 { | |
7245 /* This doesn't seem to be worth caching, and doing so would | |
7246 * complicate the code quite a bit. */ | |
7247 sign = gdk_pixbuf_scale_simple(sign, width, height, | |
7248 GDK_INTERP_BILINEAR); | |
7249 if (sign == NULL) | |
7250 return; /* out of memory */ | |
7251 } | |
7 | 7252 } |
7253 | |
7254 /* The origin is the upper-left corner of the pixmap. Therefore | |
7255 * these offset may become negative if the pixmap is smaller than | |
7256 * the 2x1 cells reserved for the sign icon. */ | |
7257 xoffset = (width - SIGN_WIDTH) / 2; | |
7258 yoffset = (height - SIGN_HEIGHT) / 2; | |
7259 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7260 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7261 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7262 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7263 cairo_surface_t *bg_surf; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7264 cairo_t *bg_cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7265 cairo_surface_t *sign_surf; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7266 cairo_t *sign_cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7267 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7268 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7269 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7270 bg_surf = cairo_surface_create_similar(gui.surface, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7271 cairo_surface_get_content(gui.surface), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7272 SIGN_WIDTH, SIGN_HEIGHT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7273 bg_cr = cairo_create(bg_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7274 set_cairo_source_rgb_from_pixel(bg_cr, gui.bgcolor->pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7275 cairo_paint(bg_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7276 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7277 sign_surf = cairo_surface_create_similar(gui.surface, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7278 cairo_surface_get_content(gui.surface), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7279 SIGN_WIDTH, SIGN_HEIGHT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7280 sign_cr = cairo_create(sign_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7281 gdk_cairo_set_source_pixbuf(sign_cr, sign, -xoffset, -yoffset); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7282 cairo_paint(sign_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7283 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7284 cairo_set_operator(sign_cr, CAIRO_OPERATOR_DEST_OVER); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7285 cairo_set_source_surface(sign_cr, bg_surf, 0, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7286 cairo_paint(sign_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7287 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7288 cairo_set_source_surface(cr, sign_surf, FILL_X(col), FILL_Y(row)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7289 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7290 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7291 cairo_destroy(sign_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7292 cairo_surface_destroy(sign_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7293 cairo_destroy(bg_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7294 cairo_surface_destroy(bg_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7295 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7296 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7297 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7298 gtk_widget_queue_draw_area(gui.drawarea, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7299 FILL_X(col), FILL_Y(col), width, height); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7300 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7301 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7302 # else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 7303 gdk_gc_set_foreground(gui.text_gc, gui.bgcolor); |
7304 | |
7305 gdk_draw_rectangle(gui.drawarea->window, | |
7306 gui.text_gc, | |
7307 TRUE, | |
7308 FILL_X(col), | |
7309 FILL_Y(row), | |
7310 SIGN_WIDTH, | |
7311 SIGN_HEIGHT); | |
7312 | |
7313 gdk_pixbuf_render_to_drawable_alpha(sign, | |
7314 gui.drawarea->window, | |
7315 MAX(0, xoffset), | |
7316 MAX(0, yoffset), | |
7317 FILL_X(col) - MIN(0, xoffset), | |
7318 FILL_Y(row) - MIN(0, yoffset), | |
7319 MIN(width, SIGN_WIDTH), | |
7320 MIN(height, SIGN_HEIGHT), | |
7321 GDK_PIXBUF_ALPHA_BILEVEL, | |
7322 127, | |
7323 GDK_RGB_DITHER_NORMAL, | |
7324 0, 0); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7325 # endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 7326 if (need_scale) |
7327 g_object_unref(sign); | |
7328 } | |
7329 } | |
7330 | |
7331 void * | |
7332 gui_mch_register_sign(char_u *signfile) | |
7333 { | |
7334 if (signfile[0] != NUL && signfile[0] != '-' && gui.in_use) | |
7335 { | |
7336 GdkPixbuf *sign; | |
7337 GError *error = NULL; | |
7338 char_u *message; | |
7339 | |
7340 sign = gdk_pixbuf_new_from_file((const char *)signfile, &error); | |
7341 | |
7342 if (error == NULL) | |
7343 return sign; | |
7344 | |
7345 message = (char_u *)error->message; | |
7346 | |
7347 if (message != NULL && input_conv.vc_type != CONV_NONE) | |
7348 message = string_convert(&input_conv, message, NULL); | |
7349 | |
7350 if (message != NULL) | |
7351 { | |
7352 /* The error message is already translated and will be more | |
7353 * descriptive than anything we could possibly do ourselves. */ | |
7354 EMSG2("E255: %s", message); | |
7355 | |
7356 if (input_conv.vc_type != CONV_NONE) | |
7357 vim_free(message); | |
7358 } | |
7359 g_error_free(error); | |
7360 } | |
7361 | |
7362 return NULL; | |
7363 } | |
7364 | |
7365 void | |
7366 gui_mch_destroy_sign(void *sign) | |
7367 { | |
7368 if (sign != NULL) | |
7369 g_object_unref(sign); | |
7370 } | |
7371 | |
7372 #endif /* FEAT_SIGN_ICONS */ |