Mercurial > vim
annotate src/gui_gtk_x11.c @ 13699:6b162e33d63a
Added tag v8.0.1721 for changeset 404b89cb1e2abe99b62e0ba923d6572d306c438b
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 15 Apr 2018 22:30:08 +0200 |
parents | 1feeefd8cddb |
children | 2f6f886d9a87 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9939
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
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 */ | |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
105 #define GET_X_ATOM(atom) gdk_x11_atom_to_xatom_for_display( \ |
7 | 106 gtk_widget_get_display(gui.mainwin), atom) |
107 | |
108 /* Selection type distinguishers */ | |
109 enum | |
110 { | |
111 TARGET_TYPE_NONE, | |
112 TARGET_UTF8_STRING, | |
113 TARGET_STRING, | |
114 TARGET_COMPOUND_TEXT, | |
1904 | 115 TARGET_HTML, |
7 | 116 TARGET_TEXT, |
117 TARGET_TEXT_URI_LIST, | |
118 TARGET_TEXT_PLAIN, | |
119 TARGET_VIM, | |
120 TARGET_VIMENC | |
121 }; | |
122 | |
123 /* | |
124 * Table of selection targets supported by Vim. | |
125 * Note: Order matters, preferred types should come first. | |
126 */ | |
127 static const GtkTargetEntry selection_targets[] = | |
128 { | |
129 {VIMENC_ATOM_NAME, 0, TARGET_VIMENC}, | |
130 {VIM_ATOM_NAME, 0, TARGET_VIM}, | |
1904 | 131 {"text/html", 0, TARGET_HTML}, |
7 | 132 {"UTF8_STRING", 0, TARGET_UTF8_STRING}, |
133 {"COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT}, | |
134 {"TEXT", 0, TARGET_TEXT}, | |
135 {"STRING", 0, TARGET_STRING} | |
136 }; | |
137 #define N_SELECTION_TARGETS (sizeof(selection_targets) / sizeof(selection_targets[0])) | |
138 | |
139 #ifdef FEAT_DND | |
140 /* | |
141 * Table of DnD targets supported by Vim. | |
142 * Note: Order matters, preferred types should come first. | |
143 */ | |
144 static const GtkTargetEntry dnd_targets[] = | |
145 { | |
146 {"text/uri-list", 0, TARGET_TEXT_URI_LIST}, | |
1904 | 147 {"text/html", 0, TARGET_HTML}, |
7 | 148 {"UTF8_STRING", 0, TARGET_UTF8_STRING}, |
149 {"STRING", 0, TARGET_STRING}, | |
150 {"text/plain", 0, TARGET_TEXT_PLAIN} | |
151 }; | |
152 # define N_DND_TARGETS (sizeof(dnd_targets) / sizeof(dnd_targets[0])) | |
153 #endif | |
154 | |
155 | |
156 /* | |
157 * "Monospace" is a standard font alias that should be present | |
158 * on all proper Pango/fontconfig installations. | |
159 */ | |
160 # define DEFAULT_FONT "Monospace 10" | |
161 | |
162 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
163 /* | |
164 * Atoms used to communicate save-yourself from the X11 session manager. There | |
165 * is no need to move them into the GUI struct, since they should be constant. | |
166 */ | |
167 static GdkAtom wm_protocols_atom = GDK_NONE; | |
168 static GdkAtom save_yourself_atom = GDK_NONE; | |
169 #endif | |
170 | |
171 /* | |
172 * Atoms used to control/reference X11 selections. | |
173 */ | |
1904 | 174 static GdkAtom html_atom = GDK_NONE; |
7 | 175 static GdkAtom utf8_string_atom = GDK_NONE; |
176 static GdkAtom vim_atom = GDK_NONE; /* Vim's own special selection format */ | |
177 static GdkAtom vimenc_atom = GDK_NONE; /* Vim's extended selection format */ | |
178 | |
179 /* | |
180 * Keycodes recognized by vim. | |
181 * NOTE: when changing this, the table in gui_x11.c probably needs the same | |
182 * change! | |
183 */ | |
184 static struct special_key | |
185 { | |
186 guint key_sym; | |
187 char_u code0; | |
188 char_u code1; | |
189 } | |
190 const special_keys[] = | |
191 { | |
192 {GDK_Up, 'k', 'u'}, | |
193 {GDK_Down, 'k', 'd'}, | |
194 {GDK_Left, 'k', 'l'}, | |
195 {GDK_Right, 'k', 'r'}, | |
196 {GDK_F1, 'k', '1'}, | |
197 {GDK_F2, 'k', '2'}, | |
198 {GDK_F3, 'k', '3'}, | |
199 {GDK_F4, 'k', '4'}, | |
200 {GDK_F5, 'k', '5'}, | |
201 {GDK_F6, 'k', '6'}, | |
202 {GDK_F7, 'k', '7'}, | |
203 {GDK_F8, 'k', '8'}, | |
204 {GDK_F9, 'k', '9'}, | |
205 {GDK_F10, 'k', ';'}, | |
206 {GDK_F11, 'F', '1'}, | |
207 {GDK_F12, 'F', '2'}, | |
208 {GDK_F13, 'F', '3'}, | |
209 {GDK_F14, 'F', '4'}, | |
210 {GDK_F15, 'F', '5'}, | |
211 {GDK_F16, 'F', '6'}, | |
212 {GDK_F17, 'F', '7'}, | |
213 {GDK_F18, 'F', '8'}, | |
214 {GDK_F19, 'F', '9'}, | |
215 {GDK_F20, 'F', 'A'}, | |
216 {GDK_F21, 'F', 'B'}, | |
217 {GDK_Pause, 'F', 'B'}, /* Pause == F21 according to netbeans.txt */ | |
218 {GDK_F22, 'F', 'C'}, | |
219 {GDK_F23, 'F', 'D'}, | |
220 {GDK_F24, 'F', 'E'}, | |
221 {GDK_F25, 'F', 'F'}, | |
222 {GDK_F26, 'F', 'G'}, | |
223 {GDK_F27, 'F', 'H'}, | |
224 {GDK_F28, 'F', 'I'}, | |
225 {GDK_F29, 'F', 'J'}, | |
226 {GDK_F30, 'F', 'K'}, | |
227 {GDK_F31, 'F', 'L'}, | |
228 {GDK_F32, 'F', 'M'}, | |
229 {GDK_F33, 'F', 'N'}, | |
230 {GDK_F34, 'F', 'O'}, | |
231 {GDK_F35, 'F', 'P'}, | |
232 #ifdef SunXK_F36 | |
233 {SunXK_F36, 'F', 'Q'}, | |
234 {SunXK_F37, 'F', 'R'}, | |
235 #endif | |
236 {GDK_Help, '%', '1'}, | |
237 {GDK_Undo, '&', '8'}, | |
238 {GDK_BackSpace, 'k', 'b'}, | |
239 {GDK_Insert, 'k', 'I'}, | |
240 {GDK_Delete, 'k', 'D'}, | |
241 {GDK_3270_BackTab, 'k', 'B'}, | |
242 {GDK_Clear, 'k', 'C'}, | |
243 {GDK_Home, 'k', 'h'}, | |
244 {GDK_End, '@', '7'}, | |
245 {GDK_Prior, 'k', 'P'}, | |
246 {GDK_Next, 'k', 'N'}, | |
247 {GDK_Print, '%', '9'}, | |
248 /* Keypad keys: */ | |
249 {GDK_KP_Left, 'k', 'l'}, | |
250 {GDK_KP_Right, 'k', 'r'}, | |
251 {GDK_KP_Up, 'k', 'u'}, | |
252 {GDK_KP_Down, 'k', 'd'}, | |
253 {GDK_KP_Insert, KS_EXTRA, (char_u)KE_KINS}, | |
254 {GDK_KP_Delete, KS_EXTRA, (char_u)KE_KDEL}, | |
255 {GDK_KP_Home, 'K', '1'}, | |
256 {GDK_KP_End, 'K', '4'}, | |
257 {GDK_KP_Prior, 'K', '3'}, /* page up */ | |
258 {GDK_KP_Next, 'K', '5'}, /* page down */ | |
259 | |
260 {GDK_KP_Add, 'K', '6'}, | |
261 {GDK_KP_Subtract, 'K', '7'}, | |
262 {GDK_KP_Divide, 'K', '8'}, | |
263 {GDK_KP_Multiply, 'K', '9'}, | |
264 {GDK_KP_Enter, 'K', 'A'}, | |
265 {GDK_KP_Decimal, 'K', 'B'}, | |
266 | |
267 {GDK_KP_0, 'K', 'C'}, | |
268 {GDK_KP_1, 'K', 'D'}, | |
269 {GDK_KP_2, 'K', 'E'}, | |
270 {GDK_KP_3, 'K', 'F'}, | |
271 {GDK_KP_4, 'K', 'G'}, | |
272 {GDK_KP_5, 'K', 'H'}, | |
273 {GDK_KP_6, 'K', 'I'}, | |
274 {GDK_KP_7, 'K', 'J'}, | |
275 {GDK_KP_8, 'K', 'K'}, | |
276 {GDK_KP_9, 'K', 'L'}, | |
277 | |
278 /* End of list marker: */ | |
279 {0, 0, 0} | |
280 }; | |
281 | |
282 /* | |
283 * Flags for command line options table below. | |
284 */ | |
285 #define ARG_FONT 1 | |
286 #define ARG_GEOMETRY 2 | |
287 #define ARG_REVERSE 3 | |
288 #define ARG_NOREVERSE 4 | |
289 #define ARG_BACKGROUND 5 | |
290 #define ARG_FOREGROUND 6 | |
291 #define ARG_ICONIC 7 | |
292 #define ARG_ROLE 8 | |
293 #define ARG_NETBEANS 9 | |
294 #define ARG_XRM 10 /* ignored */ | |
295 #define ARG_MENUFONT 11 /* ignored */ | |
296 #define ARG_INDEX_MASK 0x00ff | |
297 #define ARG_HAS_VALUE 0x0100 /* a value is expected after the argument */ | |
298 #define ARG_NEEDS_GUI 0x0200 /* need to initialize the GUI for this */ | |
299 #define ARG_FOR_GTK 0x0400 /* argument is handled by GTK+ or GNOME */ | |
300 #define ARG_COMPAT_LONG 0x0800 /* accept -foo but substitute with --foo */ | |
301 #define ARG_KEEP 0x1000 /* don't remove argument from argv[] */ | |
302 | |
303 /* | |
304 * This table holds all the X GUI command line options allowed. This includes | |
305 * the standard ones so that we can skip them when Vim is started without the | |
306 * GUI (but the GUI might start up later). | |
307 * | |
308 * When changing this, also update doc/gui_x11.txt and the usage message!!! | |
309 */ | |
310 typedef struct | |
311 { | |
312 const char *name; | |
313 unsigned int flags; | |
314 } | |
315 cmdline_option_T; | |
316 | |
317 static const cmdline_option_T cmdline_options[] = | |
318 { | |
319 /* We handle these options ourselves */ | |
320 {"-fn", ARG_FONT|ARG_HAS_VALUE}, | |
321 {"-font", ARG_FONT|ARG_HAS_VALUE}, | |
322 {"-geom", ARG_GEOMETRY|ARG_HAS_VALUE}, | |
323 {"-geometry", ARG_GEOMETRY|ARG_HAS_VALUE}, | |
324 {"-rv", ARG_REVERSE}, | |
325 {"-reverse", ARG_REVERSE}, | |
326 {"+rv", ARG_NOREVERSE}, | |
327 {"+reverse", ARG_NOREVERSE}, | |
328 {"-bg", ARG_BACKGROUND|ARG_HAS_VALUE}, | |
329 {"-background", ARG_BACKGROUND|ARG_HAS_VALUE}, | |
330 {"-fg", ARG_FOREGROUND|ARG_HAS_VALUE}, | |
331 {"-foreground", ARG_FOREGROUND|ARG_HAS_VALUE}, | |
332 {"-iconic", ARG_ICONIC}, | |
333 {"--role", ARG_ROLE|ARG_HAS_VALUE}, | |
334 #ifdef FEAT_NETBEANS_INTG | |
335 {"-nb", ARG_NETBEANS}, /* non-standard value format */ | |
336 {"-xrm", ARG_XRM|ARG_HAS_VALUE}, /* not implemented */ | |
337 {"-mf", ARG_MENUFONT|ARG_HAS_VALUE}, /* not implemented */ | |
338 {"-menufont", ARG_MENUFONT|ARG_HAS_VALUE}, /* not implemented */ | |
339 #endif | |
340 /* Arguments handled by GTK (and GNOME) internally. */ | |
341 {"--g-fatal-warnings", ARG_FOR_GTK}, | |
342 {"--gdk-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
343 {"--gdk-no-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
344 {"--gtk-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
345 {"--gtk-no-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
346 {"--gtk-module", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
347 {"--sync", ARG_FOR_GTK}, | |
348 {"--display", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
349 {"--name", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
350 {"--class", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
351 {"--screen", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
352 {"--gxid-host", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
353 {"--gxid-port", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
354 #ifdef FEAT_GUI_GNOME | |
355 {"--load-modules", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
356 {"--sm-client-id", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
357 {"--sm-config-prefix", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
358 {"--sm-disable", ARG_FOR_GTK}, | |
359 {"--oaf-ior-fd", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
360 {"--oaf-activate-iid", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
361 {"--oaf-private", ARG_FOR_GTK}, | |
362 {"--enable-sound", ARG_FOR_GTK}, | |
363 {"--disable-sound", ARG_FOR_GTK}, | |
364 {"--espeaker", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
365 {"-?", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
366 {"--help", ARG_FOR_GTK|ARG_NEEDS_GUI|ARG_KEEP}, | |
367 {"--usage", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
368 # if 0 /* conflicts with Vim's own --version argument */ | |
369 {"--version", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
370 # endif | |
371 {"--disable-crash-dialog", ARG_FOR_GTK}, | |
372 #endif | |
373 {NULL, 0} | |
374 }; | |
375 | |
376 static int gui_argc = 0; | |
377 static char **gui_argv = NULL; | |
378 | |
379 static const char *role_argument = NULL; | |
380 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
381 static const char *restart_command = NULL; | |
1898 | 382 static char *abs_restart_command = NULL; |
7 | 383 #endif |
384 static int found_iconic_arg = FALSE; | |
385 | |
386 #ifdef FEAT_GUI_GNOME | |
387 /* | |
388 * Can't use Gnome if --socketid given | |
389 */ | |
390 static int using_gnome = 0; | |
391 #else | |
392 # define using_gnome 0 | |
393 #endif | |
394 | |
395 /* | |
396 * Parse the GUI related command-line arguments. Any arguments used are | |
397 * deleted from argv, and *argc is decremented accordingly. This is called | |
398 * when vim is started, whether or not the GUI has been started. | |
399 */ | |
400 void | |
401 gui_mch_prepare(int *argc, char **argv) | |
402 { | |
403 const cmdline_option_T *option; | |
404 int i = 0; | |
405 int len = 0; | |
406 | |
407 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
408 /* | |
409 * Determine the command used to invoke Vim, to be passed as restart | |
410 * command to the session manager. If argv[0] contains any directory | |
411 * components try building an absolute path, otherwise leave it as is. | |
412 */ | |
413 restart_command = argv[0]; | |
414 | |
415 if (strchr(argv[0], G_DIR_SEPARATOR) != NULL) | |
416 { | |
417 char_u buf[MAXPATHL]; | |
418 | |
419 if (mch_FullName((char_u *)argv[0], buf, (int)sizeof(buf), TRUE) == OK) | |
1898 | 420 { |
421 abs_restart_command = (char *)vim_strsave(buf); | |
422 restart_command = abs_restart_command; | |
423 } | |
7 | 424 } |
425 #endif | |
426 | |
427 /* | |
428 * Move all the entries in argv which are relevant to GTK+ and GNOME | |
429 * into gui_argv. Freed later in gui_mch_init(). | |
430 */ | |
431 gui_argc = 0; | |
432 gui_argv = (char **)alloc((unsigned)((*argc + 1) * sizeof(char *))); | |
433 | |
434 g_return_if_fail(gui_argv != NULL); | |
435 | |
436 gui_argv[gui_argc++] = argv[i++]; | |
437 | |
438 while (i < *argc) | |
439 { | |
440 /* Don't waste CPU cycles on non-option arguments. */ | |
441 if (argv[i][0] != '-' && argv[i][0] != '+') | |
442 { | |
443 ++i; | |
444 continue; | |
445 } | |
446 | |
447 /* Look for argv[i] in cmdline_options[] table. */ | |
448 for (option = &cmdline_options[0]; option->name != NULL; ++option) | |
449 { | |
450 len = strlen(option->name); | |
451 | |
452 if (strncmp(argv[i], option->name, len) == 0) | |
453 { | |
454 if (argv[i][len] == '\0') | |
455 break; | |
456 /* allow --foo=bar style */ | |
457 if (argv[i][len] == '=' && (option->flags & ARG_HAS_VALUE)) | |
458 break; | |
459 #ifdef FEAT_NETBEANS_INTG | |
460 /* darn, -nb has non-standard syntax */ | |
461 if (vim_strchr((char_u *)":=", argv[i][len]) != NULL | |
462 && (option->flags & ARG_INDEX_MASK) == ARG_NETBEANS) | |
463 break; | |
464 #endif | |
465 } | |
466 else if ((option->flags & ARG_COMPAT_LONG) | |
467 && strcmp(argv[i], option->name + 1) == 0) | |
468 { | |
469 /* Replace the standard X arguments "-name" and "-display" | |
470 * with their GNU-style long option counterparts. */ | |
471 argv[i] = (char *)option->name; | |
472 break; | |
473 } | |
474 } | |
475 if (option->name == NULL) /* no match */ | |
476 { | |
477 ++i; | |
478 continue; | |
479 } | |
480 | |
481 if (option->flags & ARG_FOR_GTK) | |
482 { | |
483 /* Move the argument into gui_argv, which | |
484 * will later be passed to gtk_init_check() */ | |
485 gui_argv[gui_argc++] = argv[i]; | |
486 } | |
487 else | |
488 { | |
489 char *value = NULL; | |
490 | |
491 /* Extract the option's value if there is one. | |
492 * Accept both "--foo bar" and "--foo=bar" style. */ | |
493 if (option->flags & ARG_HAS_VALUE) | |
494 { | |
495 if (argv[i][len] == '=') | |
496 value = &argv[i][len + 1]; | |
497 else if (i + 1 < *argc && strcmp(argv[i + 1], "--") != 0) | |
498 value = argv[i + 1]; | |
499 } | |
500 | |
501 /* Check for options handled by Vim itself */ | |
502 switch (option->flags & ARG_INDEX_MASK) | |
503 { | |
504 case ARG_REVERSE: | |
505 found_reverse_arg = TRUE; | |
506 break; | |
507 case ARG_NOREVERSE: | |
508 found_reverse_arg = FALSE; | |
509 break; | |
510 case ARG_FONT: | |
511 font_argument = value; | |
512 break; | |
513 case ARG_GEOMETRY: | |
514 if (value != NULL) | |
515 gui.geom = vim_strsave((char_u *)value); | |
516 break; | |
517 case ARG_BACKGROUND: | |
518 background_argument = value; | |
519 break; | |
520 case ARG_FOREGROUND: | |
521 foreground_argument = value; | |
522 break; | |
523 case ARG_ICONIC: | |
524 found_iconic_arg = TRUE; | |
525 break; | |
526 case ARG_ROLE: | |
527 role_argument = value; /* used later in gui_mch_open() */ | |
528 break; | |
529 #ifdef FEAT_NETBEANS_INTG | |
530 case ARG_NETBEANS: | |
531 gui.dofork = FALSE; /* don't fork() when starting GUI */ | |
532 netbeansArg = argv[i]; | |
533 break; | |
534 #endif | |
535 default: | |
536 break; | |
537 } | |
538 } | |
539 | |
540 /* These arguments make gnome_program_init() print a message and exit. | |
9836
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
541 * Must start the GUI for this, otherwise ":gui" will exit later! |
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
542 * Only when the GUI can start. */ |
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
543 if ((option->flags & ARG_NEEDS_GUI) |
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
544 && gui_mch_early_init_check(FALSE) == OK) |
7 | 545 gui.starting = TRUE; |
546 | |
547 if (option->flags & ARG_KEEP) | |
548 ++i; | |
549 else | |
550 { | |
551 /* Remove the flag from the argument vector. */ | |
552 if (--*argc > i) | |
553 { | |
554 int n_strip = 1; | |
555 | |
556 /* Move the argument's value as well, if there is one. */ | |
557 if ((option->flags & ARG_HAS_VALUE) | |
558 && argv[i][len] != '=' | |
559 && strcmp(argv[i + 1], "--") != 0) | |
560 { | |
561 ++n_strip; | |
562 --*argc; | |
563 if (option->flags & ARG_FOR_GTK) | |
564 gui_argv[gui_argc++] = argv[i + 1]; | |
565 } | |
566 | |
567 if (*argc > i) | |
568 mch_memmove(&argv[i], &argv[i + n_strip], | |
569 (*argc - i) * sizeof(char *)); | |
570 } | |
571 argv[*argc] = NULL; | |
572 } | |
573 } | |
574 | |
575 gui_argv[gui_argc] = NULL; | |
576 } | |
577 | |
359 | 578 #if defined(EXITFREE) || defined(PROTO) |
579 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
580 gui_mch_free_all(void) |
359 | 581 { |
582 vim_free(gui_argv); | |
1898 | 583 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) |
584 vim_free(abs_restart_command); | |
585 #endif | |
359 | 586 } |
587 #endif | |
588 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
589 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 590 /* |
591 * This should be maybe completely removed. | |
592 * Doesn't seem possible, since check_copy_area() relies on | |
593 * this information. --danielk | |
594 */ | |
595 static gint | |
1884 | 596 visibility_event(GtkWidget *widget UNUSED, |
597 GdkEventVisibility *event, | |
598 gpointer data UNUSED) | |
7 | 599 { |
600 gui.visibility = event->state; | |
601 /* | |
602 * When we do an gdk_window_copy_area(), and the window is partially | |
603 * obscured, we want to receive an event to tell us whether it worked | |
604 * or not. | |
605 */ | |
606 if (gui.text_gc != NULL) | |
607 gdk_gc_set_exposures(gui.text_gc, | |
608 gui.visibility != GDK_VISIBILITY_UNOBSCURED); | |
609 return FALSE; | |
610 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
611 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 612 |
613 /* | |
614 * Redraw the corresponding portions of the screen. | |
615 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
616 #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
|
617 static gboolean is_key_pressed = FALSE; |
8412
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
618 static gboolean blink_mode = TRUE; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
619 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
620 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
|
621 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
|
622 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
623 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
624 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
|
625 { |
10920
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
626 /* Range checks are left to gui_redraw_block() */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
627 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
|
628 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
|
629 GUI_MON_NOCLEAR); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
630 } |
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 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
633 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
|
634 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
635 if (gui.row == gui.cursor_row) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
636 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
637 gui.by_signal = TRUE; |
8495
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
638 if (State & CMDLINE) |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
639 gui_update_cursor(TRUE, FALSE); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
640 else |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
641 gui_update_cursor(TRUE, TRUE); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
642 gui.by_signal = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
643 cairo_paint(cr); |
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 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
646 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
647 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
648 gui_gtk3_should_draw_cursor(void) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
649 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
650 unsigned int cond = 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
651 cond |= gui_gtk_is_blink_on(); |
8510
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
652 if (gui.cursor_col >= gui.col) |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
653 cond |= is_key_pressed; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
654 cond |= gui.in_focus == FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
655 return cond; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
656 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
657 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
658 static gboolean |
9232
a64e2a624fbe
commit https://github.com/vim/vim/commit/8e31fd52ec8be6ef1dc600b637d5f099d55e1715
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
659 draw_event(GtkWidget *widget UNUSED, |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
660 cairo_t *cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
661 gpointer user_data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
662 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
663 /* 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
|
664 if (gui.starting) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
665 return FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
666 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
667 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
|
668 /* 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
|
669 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
670 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
|
671 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
672 /* Draw the window without the cursor. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
673 gui.by_signal = TRUE; |
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 cairo_rectangle_list_t *list = NULL; |
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; |
10920
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
681 |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
682 /* First clear all the blocks and then redraw them. Just in case |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
683 * some blocks overlap. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
684 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
|
685 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
686 const cairo_rectangle_t rect = list->rectangles[i]; |
9232
a64e2a624fbe
commit https://github.com/vim/vim/commit/8e31fd52ec8be6ef1dc600b637d5f099d55e1715
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
687 |
10920
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
688 gui_mch_clear_block(Y_2_ROW((int)rect.y), 0, |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
689 Y_2_ROW((int)(rect.y + rect.height)) - 1, Columns - 1); |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
690 } |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
691 |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
692 for (i = 0; i < list->num_rectangles; i++) |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
693 { |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
694 const cairo_rectangle_t rect = list->rectangles[i]; |
9232
a64e2a624fbe
commit https://github.com/vim/vim/commit/8e31fd52ec8be6ef1dc600b637d5f099d55e1715
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
695 |
8412
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
696 if (blink_mode) |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
697 gui_gtk3_redraw(rect.x, rect.y, rect.width, rect.height); |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
698 else |
8510
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
699 { |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
700 if (get_real_state() & VISUAL) |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
701 gui_gtk3_redraw(rect.x, rect.y, |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
702 rect.width, rect.height); |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
703 else |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
704 gui_redraw(rect.x, rect.y, rect.width, rect.height); |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
705 } |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
706 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
707 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
708 cairo_rectangle_list_destroy(list); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
709 |
8510
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
710 if (get_real_state() & VISUAL) |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
711 { |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
712 if (gui.cursor_row == gui.row && gui.cursor_col >= gui.col) |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
713 gui_update_cursor(TRUE, TRUE); |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
714 } |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
715 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
716 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
717 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
718 gui.by_signal = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
719 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
720 /* Add the cursor to the window if necessary.*/ |
8510
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
721 if (gui_gtk3_should_draw_cursor() && blink_mode) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
722 gui_gtk3_update_cursor(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
723 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
724 return FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
725 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
726 #else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 727 static gint |
1884 | 728 expose_event(GtkWidget *widget UNUSED, |
729 GdkEventExpose *event, | |
730 gpointer data UNUSED) | |
7 | 731 { |
732 /* Skip this when the GUI isn't set up yet, will redraw later. */ | |
733 if (gui.starting) | |
734 return FALSE; | |
735 | |
736 out_flush(); /* make sure all output has been processed */ | |
737 gui_redraw(event->area.x, event->area.y, | |
738 event->area.width, event->area.height); | |
739 | |
740 /* Clear the border areas if needed */ | |
741 if (event->area.x < FILL_X(0)) | |
742 gdk_window_clear_area(gui.drawarea->window, 0, 0, FILL_X(0), 0); | |
743 if (event->area.y < FILL_Y(0)) | |
744 gdk_window_clear_area(gui.drawarea->window, 0, 0, 0, FILL_Y(0)); | |
745 if (event->area.x > FILL_X(Columns)) | |
746 gdk_window_clear_area(gui.drawarea->window, | |
747 FILL_X((int)Columns), 0, 0, 0); | |
748 if (event->area.y > FILL_Y(Rows)) | |
749 gdk_window_clear_area(gui.drawarea->window, 0, FILL_Y((int)Rows), 0, 0); | |
750 | |
751 return FALSE; | |
752 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
753 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 754 |
755 #ifdef FEAT_CLIENTSERVER | |
756 /* | |
757 * Handle changes to the "Comm" property | |
758 */ | |
759 static gint | |
1884 | 760 property_event(GtkWidget *widget, |
761 GdkEventProperty *event, | |
762 gpointer data UNUSED) | |
7 | 763 { |
764 if (event->type == GDK_PROPERTY_NOTIFY | |
765 && 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
|
766 # 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
|
767 && GDK_WINDOW_XID(event->window) == commWindow |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
768 # else |
7 | 769 && 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
|
770 # endif |
7 | 771 && GET_X_ATOM(event->atom) == commProperty) |
772 { | |
773 XEvent xev; | |
774 | |
775 /* Translate to XLib */ | |
776 xev.xproperty.type = PropertyNotify; | |
777 xev.xproperty.atom = commProperty; | |
778 xev.xproperty.window = commWindow; | |
779 xev.xproperty.state = PropertyNewValue; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
780 # 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
|
781 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
|
782 &xev, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
783 # else |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
784 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
|
785 # endif |
7 | 786 } |
787 return FALSE; | |
788 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
789 #endif /* defined(FEAT_CLIENTSERVER) */ |
7 | 790 |
791 | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
792 #if GTK_CHECK_VERSION(3,0,0) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
793 typedef gboolean timeout_cb_type; |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
794 #else |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
795 typedef gint timeout_cb_type; |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
796 #endif |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
797 |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
798 /* |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
799 * Start a timer that will invoke the specified callback. |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
800 * Returns the ID of the timer. |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
801 */ |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
802 static guint |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
803 timeout_add(int time, timeout_cb_type (*callback)(gpointer), int *flagp) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
804 { |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
805 #if GTK_CHECK_VERSION(3,0,0) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
806 return g_timeout_add((guint)time, (GSourceFunc)callback, flagp); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
807 #else |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
808 return gtk_timeout_add((guint32)time, (GtkFunction)callback, flagp); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
809 #endif |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
810 } |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
811 |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
812 static void |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
813 timeout_remove(guint timer) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
814 { |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
815 #if GTK_CHECK_VERSION(3,0,0) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
816 g_source_remove(timer); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
817 #else |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
818 gtk_timeout_remove(timer); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
819 #endif |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
820 } |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
821 |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
822 |
7 | 823 /**************************************************************************** |
824 * Focus handlers: | |
825 */ | |
826 | |
827 | |
828 /* | |
829 * This is a simple state machine: | |
830 * BLINK_NONE not blinking at all | |
831 * BLINK_OFF blinking, cursor is not shown | |
832 * BLINK_ON blinking, cursor is shown | |
833 */ | |
834 | |
835 #define BLINK_NONE 0 | |
836 #define BLINK_OFF 1 | |
837 #define BLINK_ON 2 | |
838 | |
839 static int blink_state = BLINK_NONE; | |
840 static long_u blink_waittime = 700; | |
841 static long_u blink_ontime = 400; | |
842 static long_u blink_offtime = 250; | |
843 static guint blink_timer = 0; | |
844 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
845 #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
|
846 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
847 gui_gtk_is_blink_on(void) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
848 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
849 return blink_state == BLINK_ON; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
850 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
851 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
852 |
9213
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
853 int |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
854 gui_mch_is_blinking(void) |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
855 { |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
856 return blink_state != BLINK_NONE; |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
857 } |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
858 |
9428
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
859 int |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
860 gui_mch_is_blink_off(void) |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
861 { |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
862 return blink_state == BLINK_OFF; |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
863 } |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
864 |
7 | 865 void |
866 gui_mch_set_blinking(long waittime, long on, long off) | |
867 { | |
8412
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
868 #if GTK_CHECK_VERSION(3,0,0) |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
869 if (waittime == 0 || on == 0 || off == 0) |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
870 { |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
871 blink_mode = FALSE; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
872 |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
873 blink_waittime = 700; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
874 blink_ontime = 400; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
875 blink_offtime = 250; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
876 } |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
877 else |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
878 { |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
879 blink_mode = TRUE; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
880 |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
881 blink_waittime = waittime; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
882 blink_ontime = on; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
883 blink_offtime = off; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
884 } |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
885 #else |
7 | 886 blink_waittime = waittime; |
887 blink_ontime = on; | |
888 blink_offtime = off; | |
8412
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
889 #endif |
7 | 890 } |
891 | |
892 /* | |
893 * Stop the cursor blinking. Show the cursor if it wasn't shown. | |
894 */ | |
895 void | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
896 gui_mch_stop_blink(int may_call_gui_update_cursor) |
7 | 897 { |
898 if (blink_timer) | |
899 { | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
900 timeout_remove(blink_timer); |
7 | 901 blink_timer = 0; |
902 } | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
903 if (blink_state == BLINK_OFF && may_call_gui_update_cursor) |
9489
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
904 { |
7 | 905 gui_update_cursor(TRUE, FALSE); |
9489
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
906 gui_mch_flush(); |
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
907 } |
7 | 908 blink_state = BLINK_NONE; |
909 } | |
910 | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
911 static timeout_cb_type |
1884 | 912 blink_cb(gpointer data UNUSED) |
7 | 913 { |
914 if (blink_state == BLINK_ON) | |
915 { | |
916 gui_undraw_cursor(); | |
917 blink_state = BLINK_OFF; | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
918 blink_timer = timeout_add(blink_offtime, blink_cb, NULL); |
7 | 919 } |
920 else | |
921 { | |
922 gui_update_cursor(TRUE, FALSE); | |
923 blink_state = BLINK_ON; | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
924 blink_timer = timeout_add(blink_ontime, blink_cb, NULL); |
7 | 925 } |
9489
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
926 gui_mch_flush(); |
7 | 927 |
928 return FALSE; /* don't happen again */ | |
929 } | |
930 | |
931 /* | |
932 * Start the cursor blinking. If it was already blinking, this restarts the | |
933 * waiting time and shows the cursor. | |
934 */ | |
935 void | |
936 gui_mch_start_blink(void) | |
937 { | |
938 if (blink_timer) | |
5818 | 939 { |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
940 timeout_remove(blink_timer); |
5818 | 941 blink_timer = 0; |
942 } | |
7 | 943 /* Only switch blinking on if none of the times is zero */ |
944 if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus) | |
945 { | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
946 blink_timer = timeout_add(blink_waittime, blink_cb, NULL); |
7 | 947 blink_state = BLINK_ON; |
948 gui_update_cursor(TRUE, FALSE); | |
9489
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
949 gui_mch_flush(); |
7 | 950 } |
951 } | |
952 | |
953 static gint | |
1884 | 954 enter_notify_event(GtkWidget *widget UNUSED, |
955 GdkEventCrossing *event UNUSED, | |
956 gpointer data UNUSED) | |
7 | 957 { |
958 if (blink_state == BLINK_NONE) | |
959 gui_mch_start_blink(); | |
960 | |
961 /* 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
|
962 #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
|
963 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
|
964 #else |
7 | 965 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
|
966 #endif |
7 | 967 gtk_widget_grab_focus(gui.drawarea); |
968 | |
969 return FALSE; | |
970 } | |
971 | |
972 static gint | |
1884 | 973 leave_notify_event(GtkWidget *widget UNUSED, |
974 GdkEventCrossing *event UNUSED, | |
975 gpointer data UNUSED) | |
7 | 976 { |
977 if (blink_state != BLINK_NONE) | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
978 gui_mch_stop_blink(TRUE); |
7 | 979 |
980 return FALSE; | |
981 } | |
982 | |
983 static gint | |
1884 | 984 focus_in_event(GtkWidget *widget, |
985 GdkEventFocus *event UNUSED, | |
986 gpointer data UNUSED) | |
7 | 987 { |
988 gui_focus_change(TRUE); | |
989 | |
990 if (blink_state == BLINK_NONE) | |
991 gui_mch_start_blink(); | |
992 | |
1380 | 993 /* make sure keyboard input goes to the draw area (if this is focus for a |
994 * window) */ | |
791 | 995 if (widget != gui.drawarea) |
856 | 996 gtk_widget_grab_focus(gui.drawarea); |
7 | 997 |
998 return TRUE; | |
999 } | |
1000 | |
1001 static gint | |
1884 | 1002 focus_out_event(GtkWidget *widget UNUSED, |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2301
diff
changeset
|
1003 GdkEventFocus *event UNUSED, |
1884 | 1004 gpointer data UNUSED) |
7 | 1005 { |
1006 gui_focus_change(FALSE); | |
1007 | |
1008 if (blink_state != BLINK_NONE) | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
1009 gui_mch_stop_blink(TRUE); |
7 | 1010 |
1011 return TRUE; | |
1012 } | |
1013 | |
1014 | |
1015 /* | |
1016 * Translate a GDK key value to UTF-8 independently of the current locale. | |
1017 * The output is written to string, which must have room for at least 6 bytes | |
1018 * plus the NUL terminator. Returns the length in bytes. | |
1019 * | |
1020 * This function is used in the GTK+ 2 GUI only. The GTK+ 1 code makes use | |
1021 * of GdkEventKey::string instead. But event->string is evil; see here why: | |
1022 * http://developer.gnome.org/doc/API/2.0/gdk/gdk-Event-Structures.html#GdkEventKey | |
1023 */ | |
1024 static int | |
1025 keyval_to_string(unsigned int keyval, unsigned int state, char_u *string) | |
1026 { | |
1027 int len; | |
1028 guint32 uc; | |
1029 | |
1030 uc = gdk_keyval_to_unicode(keyval); | |
1031 if (uc != 0) | |
1032 { | |
1033 /* Check for CTRL-foo */ | |
1034 if ((state & GDK_CONTROL_MASK) && uc >= 0x20 && uc < 0x80) | |
1035 { | |
1036 /* These mappings look arbitrary at the first glance, but in fact | |
1037 * resemble quite exactly the behaviour of the GTK+ 1.2 GUI on my | |
1038 * machine. The only difference is BS vs. DEL for CTRL-8 (makes | |
1039 * more sense and is consistent with usual terminal behaviour). */ | |
1040 if (uc >= '@') | |
1041 string[0] = uc & 0x1F; | |
1042 else if (uc == '2') | |
1043 string[0] = NUL; | |
1044 else if (uc >= '3' && uc <= '7') | |
1045 string[0] = uc ^ 0x28; | |
1046 else if (uc == '8') | |
1047 string[0] = BS; | |
1048 else if (uc == '?') | |
1049 string[0] = DEL; | |
1050 else | |
1051 string[0] = uc; | |
1052 len = 1; | |
1053 } | |
1054 else | |
1055 { | |
1056 /* Translate a normal key to UTF-8. This doesn't work for dead | |
1057 * keys of course, you _have_ to use an input method for that. */ | |
1058 len = utf_char2bytes((int)uc, string); | |
1059 } | |
1060 } | |
1061 else | |
1062 { | |
1063 /* Translate keys which are represented by ASCII control codes in Vim. | |
1064 * There are only a few of those; most control keys are translated to | |
1065 * special terminal-like control sequences. */ | |
1066 len = 1; | |
1067 switch (keyval) | |
1068 { | |
1069 case GDK_Tab: case GDK_KP_Tab: case GDK_ISO_Left_Tab: | |
1070 string[0] = TAB; | |
1071 break; | |
1072 case GDK_Linefeed: | |
1073 string[0] = NL; | |
1074 break; | |
1075 case GDK_Return: case GDK_ISO_Enter: case GDK_3270_Enter: | |
1076 string[0] = CAR; | |
1077 break; | |
1078 case GDK_Escape: | |
1079 string[0] = ESC; | |
1080 break; | |
1081 default: | |
1082 len = 0; | |
1083 break; | |
1084 } | |
1085 } | |
1086 string[len] = NUL; | |
1087 | |
1088 return len; | |
1089 } | |
1090 | |
179 | 1091 static int |
1092 modifiers_gdk2vim(guint state) | |
1093 { | |
1094 int modifiers = 0; | |
1095 | |
1096 if (state & GDK_SHIFT_MASK) | |
1097 modifiers |= MOD_MASK_SHIFT; | |
1098 if (state & GDK_CONTROL_MASK) | |
1099 modifiers |= MOD_MASK_CTRL; | |
1100 if (state & GDK_MOD1_MASK) | |
1101 modifiers |= MOD_MASK_ALT; | |
2550
7c1f73452ea6
Fix #ifdef for GDK_SUPER_MASK.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
1102 #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
|
1103 if (state & GDK_SUPER_MASK) |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1104 modifiers |= MOD_MASK_META; |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1105 #endif |
179 | 1106 if (state & GDK_MOD4_MASK) |
1107 modifiers |= MOD_MASK_META; | |
1108 | |
1109 return modifiers; | |
1110 } | |
1111 | |
1112 static int | |
1113 modifiers_gdk2mouse(guint state) | |
1114 { | |
1115 int modifiers = 0; | |
1116 | |
1117 if (state & GDK_SHIFT_MASK) | |
1118 modifiers |= MOUSE_SHIFT; | |
1119 if (state & GDK_CONTROL_MASK) | |
1120 modifiers |= MOUSE_CTRL; | |
1121 if (state & GDK_MOD1_MASK) | |
1122 modifiers |= MOUSE_ALT; | |
1123 | |
1124 return modifiers; | |
1125 } | |
1126 | |
7 | 1127 /* |
1128 * Main keyboard handler: | |
1129 */ | |
1130 static gint | |
1884 | 1131 key_press_event(GtkWidget *widget UNUSED, |
1132 GdkEventKey *event, | |
1133 gpointer data UNUSED) | |
7 | 1134 { |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1135 /* For GTK+ 2 we know for sure how large the string might get. |
7 | 1136 * (That is, up to 6 bytes + NUL + CSI escapes + safety measure.) */ |
1137 char_u string[32], string2[32]; | |
1138 guint key_sym; | |
1139 int len; | |
1140 int i; | |
1141 int modifiers; | |
1142 int key; | |
1143 guint state; | |
1144 char_u *s, *d; | |
1145 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1146 #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
|
1147 is_key_pressed = TRUE; |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
1148 gui_mch_stop_blink(TRUE); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1149 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1150 |
2923 | 1151 gui.event_time = event->time; |
7 | 1152 key_sym = event->keyval; |
1153 state = event->state; | |
1154 | |
1155 #ifdef FEAT_XIM | |
1156 if (xim_queue_key_press_event(event, TRUE)) | |
1157 return TRUE; | |
1158 #endif | |
1159 | |
1160 #ifdef FEAT_HANGULIN | |
1161 if (key_sym == GDK_space && (state & GDK_SHIFT_MASK)) | |
1162 { | |
1163 hangul_input_state_toggle(); | |
1164 return TRUE; | |
1165 } | |
1166 #endif | |
1167 | |
1168 #ifdef SunXK_F36 | |
1169 /* | |
1170 * These keys have bogus lookup strings, and trapping them here is | |
1171 * easier than trying to XRebindKeysym() on them with every possible | |
1172 * combination of modifiers. | |
1173 */ | |
1174 if (key_sym == SunXK_F36 || key_sym == SunXK_F37) | |
1175 len = 0; | |
1176 else | |
1177 #endif | |
1178 { | |
1179 len = keyval_to_string(key_sym, state, string2); | |
1180 | |
1181 /* Careful: convert_input() doesn't handle the NUL character. | |
1182 * No need to convert pure ASCII anyway, thus the len > 1 check. */ | |
1183 if (len > 1 && input_conv.vc_type != CONV_NONE) | |
1184 len = convert_input(string2, len, sizeof(string2)); | |
1185 | |
1186 s = string2; | |
1187 d = string; | |
1188 for (i = 0; i < len; ++i) | |
1189 { | |
1190 *d++ = s[i]; | |
1191 if (d[-1] == CSI && d + 2 < string + sizeof(string)) | |
1192 { | |
1193 /* Turn CSI into K_CSI. */ | |
1194 *d++ = KS_EXTRA; | |
1195 *d++ = (int)KE_CSI; | |
1196 } | |
1197 } | |
1198 len = d - string; | |
1199 } | |
1200 | |
1201 /* Shift-Tab results in Left_Tab, but we want <S-Tab> */ | |
1202 if (key_sym == GDK_ISO_Left_Tab) | |
1203 { | |
1204 key_sym = GDK_Tab; | |
1205 state |= GDK_SHIFT_MASK; | |
1206 } | |
1207 | |
1208 #ifdef FEAT_MENU | |
1209 /* If there is a menu and 'wak' is "yes", or 'wak' is "menu" and the key | |
1210 * is a menu shortcut, we ignore everything with the ALT modifier. */ | |
1211 if ((state & GDK_MOD1_MASK) | |
1212 && gui.menu_is_active | |
1213 && (*p_wak == 'y' | |
1214 || (*p_wak == 'm' | |
1215 && len == 1 | |
1216 && gui_is_menu_shortcut(string[0])))) | |
1217 /* For GTK2 we return false to signify that we haven't handled the | |
1218 * keypress, so that gtk will handle the mnemonic or accelerator. */ | |
1219 return FALSE; | |
1220 #endif | |
1221 | |
1222 /* Check for Alt/Meta key (Mod1Mask), but not for a BS, DEL or character | |
1223 * that already has the 8th bit set. | |
1224 * Don't do this for <S-M-Tab>, that should become K_S_TAB with ALT. | |
1225 * Don't do this for double-byte encodings, it turns the char into a lead | |
1226 * byte. */ | |
1227 if (len == 1 | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1228 && ((state & GDK_MOD1_MASK) |
2571
42bdbc2bbb59
Fix #ifdef for GDK_SUPER_MASK. (Stephan Schulz)
Bram Moolenaar <bram@vim.org>
parents:
2550
diff
changeset
|
1229 #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
|
1230 || (state & GDK_SUPER_MASK) |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1231 #endif |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1232 ) |
7 | 1233 && !(key_sym == GDK_BackSpace || key_sym == GDK_Delete) |
1234 && (string[0] & 0x80) == 0 | |
1235 && !(key_sym == GDK_Tab && (state & GDK_SHIFT_MASK)) | |
1236 && !enc_dbcs | |
1237 ) | |
1238 { | |
1239 string[0] |= 0x80; | |
1240 state &= ~GDK_MOD1_MASK; /* don't use it again */ | |
1241 if (enc_utf8) /* convert to utf-8 */ | |
1242 { | |
1243 string[1] = string[0] & 0xbf; | |
1244 string[0] = ((unsigned)string[0] >> 6) + 0xc0; | |
1245 if (string[1] == CSI) | |
1246 { | |
1247 string[2] = KS_EXTRA; | |
1248 string[3] = (int)KE_CSI; | |
1249 len = 4; | |
1250 } | |
1251 else | |
1252 len = 2; | |
1253 } | |
1254 } | |
1255 | |
1256 /* Check for special keys. Also do this when len == 1 (key has an ASCII | |
1257 * value) to detect backspace, delete and keypad keys. */ | |
1258 if (len == 0 || len == 1) | |
1259 { | |
1260 for (i = 0; special_keys[i].key_sym != 0; i++) | |
1261 { | |
1262 if (special_keys[i].key_sym == key_sym) | |
1263 { | |
1264 string[0] = CSI; | |
1265 string[1] = special_keys[i].code0; | |
1266 string[2] = special_keys[i].code1; | |
1267 len = -3; | |
1268 break; | |
1269 } | |
1270 } | |
1271 } | |
1272 | |
1273 if (len == 0) /* Unrecognized key */ | |
1274 return TRUE; | |
1275 | |
1276 /* Special keys (and a few others) may have modifiers. Also when using a | |
1277 * double-byte encoding (can't set the 8th bit). */ | |
1278 if (len == -3 || key_sym == GDK_space || key_sym == GDK_Tab | |
1279 || key_sym == GDK_Return || key_sym == GDK_Linefeed | |
1280 || key_sym == GDK_Escape || key_sym == GDK_KP_Tab | |
1281 || 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
|
1282 || (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
|
1283 #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
|
1284 || (state & GDK_SUPER_MASK) |
7 | 1285 #endif |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1286 ))) |
7 | 1287 { |
179 | 1288 modifiers = modifiers_gdk2vim(state); |
7 | 1289 |
1290 /* | |
1291 * For some keys a shift modifier is translated into another key | |
1292 * code. | |
1293 */ | |
1294 if (len == -3) | |
1295 key = TO_SPECIAL(string[1], string[2]); | |
1296 else | |
1297 key = string[0]; | |
1298 | |
1299 key = simplify_key(key, &modifiers); | |
1300 if (key == CSI) | |
1301 key = K_CSI; | |
1302 if (IS_SPECIAL(key)) | |
1303 { | |
1304 string[0] = CSI; | |
1305 string[1] = K_SECOND(key); | |
1306 string[2] = K_THIRD(key); | |
1307 len = 3; | |
1308 } | |
1309 else | |
1310 { | |
1311 string[0] = key; | |
1312 len = 1; | |
1313 } | |
1314 | |
1315 if (modifiers != 0) | |
1316 { | |
1317 string2[0] = CSI; | |
1318 string2[1] = KS_MODIFIER; | |
1319 string2[2] = modifiers; | |
1320 add_to_input_buf(string2, 3); | |
1321 } | |
1322 } | |
1323 | |
1324 if (len == 1 && ((string[0] == Ctrl_C && ctrl_c_interrupts) | |
1325 || (string[0] == intr_char && intr_char != Ctrl_C))) | |
1326 { | |
1327 trash_input_buf(); | |
1328 got_int = TRUE; | |
1329 } | |
1330 | |
1331 add_to_input_buf(string, len); | |
1332 | |
1333 /* blank out the pointer if necessary */ | |
1334 if (p_mh) | |
1335 gui_mch_mousehide(TRUE); | |
1336 | |
1337 return TRUE; | |
1338 } | |
1339 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1340 #if defined(FEAT_XIM) || GTK_CHECK_VERSION(3,0,0) |
7 | 1341 static gboolean |
1884 | 1342 key_release_event(GtkWidget *widget UNUSED, |
1343 GdkEventKey *event, | |
1344 gpointer data UNUSED) | |
7 | 1345 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1346 # 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
|
1347 is_key_pressed = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1348 gui_mch_start_blink(); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1349 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1350 # if defined(FEAT_XIM) |
2923 | 1351 gui.event_time = event->time; |
7 | 1352 /* |
1353 * GTK+ 2 input methods may do fancy stuff on key release events too. | |
1354 * With the default IM for instance, you can enter any UCS code point | |
1355 * by holding down CTRL-SHIFT and typing hexadecimal digits. | |
1356 */ | |
1357 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
|
1358 # else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1359 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1360 # endif |
7 | 1361 } |
1362 #endif | |
1363 | |
1364 | |
1365 /**************************************************************************** | |
1366 * Selection handlers: | |
1367 */ | |
1368 | |
13503
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1369 /* Remember when clip_lose_selection was called from here, we must not call |
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1370 * gtk_selection_owner_set() then. */ |
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1371 static int in_selection_clear_event = FALSE; |
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1372 |
7 | 1373 static gint |
1884 | 1374 selection_clear_event(GtkWidget *widget UNUSED, |
7 | 1375 GdkEventSelection *event, |
1884 | 1376 gpointer user_data UNUSED) |
7 | 1377 { |
13503
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1378 in_selection_clear_event = TRUE; |
7 | 1379 if (event->selection == clip_plus.gtk_sel_atom) |
1380 clip_lose_selection(&clip_plus); | |
1381 else | |
1382 clip_lose_selection(&clip_star); | |
13503
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1383 in_selection_clear_event = FALSE; |
7 | 1384 |
1385 return TRUE; | |
1386 } | |
1387 | |
1388 #define RS_NONE 0 /* selection_received_cb() not called yet */ | |
1389 #define RS_OK 1 /* selection_received_cb() called and OK */ | |
1390 #define RS_FAIL 2 /* selection_received_cb() called and failed */ | |
1391 static int received_selection = RS_NONE; | |
1392 | |
1393 static void | |
1884 | 1394 selection_received_cb(GtkWidget *widget UNUSED, |
7 | 1395 GtkSelectionData *data, |
1884 | 1396 guint time_ UNUSED, |
1397 gpointer user_data UNUSED) | |
7 | 1398 { |
1399 VimClipboard *cbd; | |
1400 char_u *text; | |
1401 char_u *tmpbuf = NULL; | |
1402 guchar *tmpbuf_utf8 = NULL; | |
1403 int len; | |
2896 | 1404 int motion_type = MAUTO; |
7 | 1405 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1406 #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
|
1407 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
|
1408 #else |
7 | 1409 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
|
1410 #endif |
7 | 1411 cbd = &clip_plus; |
1412 else | |
1413 cbd = &clip_star; | |
1414 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1415 #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
|
1416 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
|
1417 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
|
1418 #else |
7 | 1419 text = (char_u *)data->data; |
1420 len = data->length; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1421 #endif |
7 | 1422 |
1423 if (text == NULL || len <= 0) | |
1424 { | |
1425 received_selection = RS_FAIL; | |
1426 /* clip_free_selection(cbd); ??? */ | |
1427 | |
1428 return; | |
1429 } | |
1430 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1431 #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
|
1432 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
|
1433 #else |
7 | 1434 if (data->type == vim_atom) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1435 #endif |
7 | 1436 { |
1437 motion_type = *text++; | |
1438 --len; | |
1439 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1440 #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
|
1441 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
|
1442 #else |
7 | 1443 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
|
1444 #endif |
7 | 1445 { |
1446 char_u *enc; | |
1447 vimconv_T conv; | |
1448 | |
1449 motion_type = *text++; | |
1450 --len; | |
1451 | |
1452 enc = text; | |
1453 text += STRLEN(text) + 1; | |
1454 len -= text - enc; | |
1455 | |
1456 /* If the encoding of the text is different from 'encoding', attempt | |
1457 * converting it. */ | |
1458 conv.vc_type = CONV_NONE; | |
1459 convert_setup(&conv, enc, p_enc); | |
1460 if (conv.vc_type != CONV_NONE) | |
1461 { | |
1462 tmpbuf = string_convert(&conv, text, &len); | |
1463 if (tmpbuf != NULL) | |
1464 text = tmpbuf; | |
1465 convert_setup(&conv, NULL, NULL); | |
1466 } | |
1467 } | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1468 |
7 | 1469 /* gtk_selection_data_get_text() handles all the nasty details |
1470 * and targets and encodings etc. This rocks so hard. */ | |
1471 else | |
1472 { | |
1473 tmpbuf_utf8 = gtk_selection_data_get_text(data); | |
1474 if (tmpbuf_utf8 != NULL) | |
1475 { | |
1476 len = STRLEN(tmpbuf_utf8); | |
1477 if (input_conv.vc_type != CONV_NONE) | |
1478 { | |
1479 tmpbuf = string_convert(&input_conv, tmpbuf_utf8, &len); | |
1480 if (tmpbuf != NULL) | |
1481 text = tmpbuf; | |
1482 } | |
1483 else | |
1484 text = tmpbuf_utf8; | |
1485 } | |
1904 | 1486 else if (len >= 2 && text[0] == 0xff && text[1] == 0xfe) |
1487 { | |
1488 vimconv_T conv; | |
1489 | |
1490 /* UTF-16, we get this for HTML */ | |
1491 conv.vc_type = CONV_NONE; | |
1492 convert_setup_ext(&conv, (char_u *)"utf-16le", FALSE, p_enc, TRUE); | |
1493 | |
1494 if (conv.vc_type != CONV_NONE) | |
1495 { | |
1496 text += 2; | |
1497 len -= 2; | |
1498 tmpbuf = string_convert(&conv, text, &len); | |
1499 convert_setup(&conv, NULL, NULL); | |
1500 } | |
1501 if (tmpbuf != NULL) | |
1502 text = tmpbuf; | |
1503 } | |
7 | 1504 } |
1505 | |
4352 | 1506 /* Chop off any trailing NUL bytes. OpenOffice sends these. */ |
2183 | 1507 while (len > 0 && text[len - 1] == NUL) |
1508 --len; | |
1509 | |
7 | 1510 clip_yank_selection(motion_type, text, (long)len, cbd); |
1511 received_selection = RS_OK; | |
1512 vim_free(tmpbuf); | |
1513 g_free(tmpbuf_utf8); | |
1514 } | |
1515 | |
1516 /* | |
1517 * Prepare our selection data for passing it to the external selection | |
1518 * client. | |
1519 */ | |
1520 static void | |
1884 | 1521 selection_get_cb(GtkWidget *widget UNUSED, |
7 | 1522 GtkSelectionData *selection_data, |
1523 guint info, | |
1884 | 1524 guint time_ UNUSED, |
1525 gpointer user_data UNUSED) | |
7 | 1526 { |
1527 char_u *string; | |
1528 char_u *tmpbuf; | |
1529 long_u tmplen; | |
1530 int length; | |
1531 int motion_type; | |
1532 GdkAtom type; | |
1533 VimClipboard *cbd; | |
1534 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1535 #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
|
1536 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
|
1537 == clip_plus.gtk_sel_atom) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1538 #else |
7 | 1539 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
|
1540 #endif |
7 | 1541 cbd = &clip_plus; |
1542 else | |
1543 cbd = &clip_star; | |
1544 | |
1545 if (!cbd->owned) | |
1546 return; /* Shouldn't ever happen */ | |
1547 | |
1548 if (info != (guint)TARGET_STRING | |
1904 | 1549 && (!clip_html || info != (guint)TARGET_HTML) |
7 | 1550 && info != (guint)TARGET_UTF8_STRING |
1551 && info != (guint)TARGET_VIMENC | |
1552 && info != (guint)TARGET_VIM | |
1553 && info != (guint)TARGET_COMPOUND_TEXT | |
1554 && info != (guint)TARGET_TEXT) | |
1555 return; | |
1556 | |
1557 /* get the selection from the '*'/'+' register */ | |
1558 clip_get_selection(cbd); | |
1559 | |
1560 motion_type = clip_convert_selection(&string, &tmplen, cbd); | |
1561 if (motion_type < 0 || string == NULL) | |
1562 return; | |
1563 /* Due to int arguments we can't handle more than G_MAXINT. Also | |
1564 * reserve one extra byte for NUL or the motion type; just in case. | |
1565 * (Not that pasting 2G of text is ever going to work, but... ;-) */ | |
1566 length = MIN(tmplen, (long_u)(G_MAXINT - 1)); | |
1567 | |
1568 if (info == (guint)TARGET_VIM) | |
1569 { | |
1570 tmpbuf = alloc((unsigned)length + 1); | |
1571 if (tmpbuf != NULL) | |
1572 { | |
1573 tmpbuf[0] = motion_type; | |
1574 mch_memmove(tmpbuf + 1, string, (size_t)length); | |
1575 } | |
1576 /* For our own format, the first byte contains the motion type */ | |
1577 ++length; | |
1578 vim_free(string); | |
1579 string = tmpbuf; | |
1580 type = vim_atom; | |
1581 } | |
1582 | |
1904 | 1583 else if (info == (guint)TARGET_HTML) |
1584 { | |
1585 vimconv_T conv; | |
1586 | |
1587 /* Since we get utf-16, we probably should set it as well. */ | |
1588 conv.vc_type = CONV_NONE; | |
1589 convert_setup_ext(&conv, p_enc, TRUE, (char_u *)"utf-16le", FALSE); | |
1590 if (conv.vc_type != CONV_NONE) | |
1591 { | |
1592 tmpbuf = string_convert(&conv, string, &length); | |
1593 convert_setup(&conv, NULL, NULL); | |
1594 vim_free(string); | |
1595 string = tmpbuf; | |
1596 } | |
1597 | |
1598 /* Prepend the BOM: "fffe" */ | |
1599 if (string != NULL) | |
1600 { | |
1601 tmpbuf = alloc(length + 2); | |
1602 tmpbuf[0] = 0xff; | |
1603 tmpbuf[1] = 0xfe; | |
1604 mch_memmove(tmpbuf + 2, string, (size_t)length); | |
1605 vim_free(string); | |
1606 string = tmpbuf; | |
1607 length += 2; | |
1608 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1609 #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
|
1610 /* 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
|
1611 * overwritten by gtk_selection_data_set() that follows. */ |
1904 | 1612 selection_data->type = selection_data->target; |
1613 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
|
1614 #endif |
1904 | 1615 gtk_selection_data_set(selection_data, html_atom, 16, |
1616 string, length); | |
1617 vim_free(string); | |
1618 } | |
1619 return; | |
1620 } | |
7 | 1621 else if (info == (guint)TARGET_VIMENC) |
1622 { | |
1623 int l = STRLEN(p_enc); | |
1624 | |
1625 /* contents: motion_type 'encoding' NUL text */ | |
1626 tmpbuf = alloc((unsigned)length + l + 2); | |
1627 if (tmpbuf != NULL) | |
1628 { | |
1629 tmpbuf[0] = motion_type; | |
1630 STRCPY(tmpbuf + 1, p_enc); | |
1631 mch_memmove(tmpbuf + l + 2, string, (size_t)length); | |
1632 } | |
1633 length += l + 2; | |
1634 vim_free(string); | |
1635 string = tmpbuf; | |
1636 type = vimenc_atom; | |
1637 } | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1638 |
7 | 1639 /* gtk_selection_data_set_text() handles everything for us. This is |
1640 * so easy and simple and cool, it'd be insane not to use it. */ | |
1641 else | |
1642 { | |
1643 if (output_conv.vc_type != CONV_NONE) | |
1644 { | |
1645 tmpbuf = string_convert(&output_conv, string, &length); | |
1646 vim_free(string); | |
1647 if (tmpbuf == NULL) | |
1648 return; | |
1649 string = tmpbuf; | |
1650 } | |
1651 /* Validate the string to avoid runtime warnings */ | |
1652 if (g_utf8_validate((const char *)string, (gssize)length, NULL)) | |
1653 { | |
1654 gtk_selection_data_set_text(selection_data, | |
1655 (const char *)string, length); | |
1656 } | |
1657 vim_free(string); | |
1658 return; | |
1659 } | |
1660 | |
1661 if (string != NULL) | |
1662 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1663 #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
|
1664 /* 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
|
1665 * overwritten by gtk_selection_data_set() that follows. */ |
7 | 1666 selection_data->type = selection_data->target; |
1667 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
|
1668 #endif |
7 | 1669 gtk_selection_data_set(selection_data, type, 8, string, length); |
1670 vim_free(string); | |
1671 } | |
1672 } | |
1673 | |
1674 /* | |
3518 | 1675 * Check if the GUI can be started. Called before gvimrc is sourced and |
1676 * before fork(). | |
1677 * Return OK or FAIL. | |
1678 */ | |
1679 int | |
9836
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
1680 gui_mch_early_init_check(int give_message) |
3518 | 1681 { |
1682 char_u *p; | |
1683 | |
1684 /* Guess that when $DISPLAY isn't set the GUI can't start. */ | |
1685 p = mch_getenv((char_u *)"DISPLAY"); | |
1686 if (p == NULL || *p == NUL) | |
1687 { | |
1688 gui.dying = TRUE; | |
9836
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
1689 if (give_message) |
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
1690 EMSG(_((char *)e_opendisp)); |
3518 | 1691 return FAIL; |
1692 } | |
1693 return OK; | |
1694 } | |
1695 | |
1696 /* | |
1697 * Check if the GUI can be started. Called before gvimrc is sourced but after | |
1698 * fork(). | |
7 | 1699 * Return OK or FAIL. |
1700 */ | |
1701 int | |
1702 gui_mch_init_check(void) | |
1703 { | |
7679
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1704 #ifdef USE_GRESOURCE |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1705 static int res_registered = FALSE; |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1706 |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1707 if (!res_registered) |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1708 { |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1709 /* 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
|
1710 * 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
|
1711 res_registered = TRUE; |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1712 gui_gtk_register_resource(); |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1713 } |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1714 #endif |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1715 |
8851
1b38596644ba
commit https://github.com/vim/vim/commit/f80663f17b2f2499b45eb4467088704c8298c385
Christian Brabandt <cb@256bit.org>
parents:
8510
diff
changeset
|
1716 #if GTK_CHECK_VERSION(3,10,0) |
1b38596644ba
commit https://github.com/vim/vim/commit/f80663f17b2f2499b45eb4467088704c8298c385
Christian Brabandt <cb@256bit.org>
parents:
8510
diff
changeset
|
1717 /* Vim currently assumes that Gtk means X11, so it cannot use native Gtk |
1b38596644ba
commit https://github.com/vim/vim/commit/f80663f17b2f2499b45eb4467088704c8298c385
Christian Brabandt <cb@256bit.org>
parents:
8510
diff
changeset
|
1718 * support for other backends such as Wayland. */ |
1b38596644ba
commit https://github.com/vim/vim/commit/f80663f17b2f2499b45eb4467088704c8298c385
Christian Brabandt <cb@256bit.org>
parents:
8510
diff
changeset
|
1719 gdk_set_allowed_backends ("x11"); |
1b38596644ba
commit https://github.com/vim/vim/commit/f80663f17b2f2499b45eb4467088704c8298c385
Christian Brabandt <cb@256bit.org>
parents:
8510
diff
changeset
|
1720 #endif |
1b38596644ba
commit https://github.com/vim/vim/commit/f80663f17b2f2499b45eb4467088704c8298c385
Christian Brabandt <cb@256bit.org>
parents:
8510
diff
changeset
|
1721 |
7 | 1722 #ifdef FEAT_GUI_GNOME |
1723 if (gtk_socket_id == 0) | |
1724 using_gnome = 1; | |
1725 #endif | |
1726 | |
4474 | 1727 /* This defaults to argv[0], but we want it to match the name of the |
1728 * shipped gvim.desktop so that Vim's windows can be associated with this | |
1729 * file. */ | |
1730 g_set_prgname("gvim"); | |
1731 | |
7 | 1732 /* Don't use gtk_init() or gnome_init(), it exits on failure. */ |
1733 if (!gtk_init_check(&gui_argc, &gui_argv)) | |
1734 { | |
1735 gui.dying = TRUE; | |
1666 | 1736 EMSG(_((char *)e_opendisp)); |
7 | 1737 return FAIL; |
1738 } | |
1739 | |
1740 return OK; | |
1741 } | |
1742 | |
1743 /**************************************************************************** | |
1744 * Mouse handling callbacks | |
1745 */ | |
1746 | |
1747 | |
1748 static guint mouse_click_timer = 0; | |
1749 static int mouse_timed_out = TRUE; | |
1750 | |
1751 /* | |
1752 * Timer used to recognize multiple clicks of the mouse button | |
1753 */ | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
1754 static timeout_cb_type |
7 | 1755 mouse_click_timer_cb(gpointer data) |
1756 { | |
1757 /* we don't use this information currently */ | |
1758 int *timed_out = (int *) data; | |
1759 | |
1760 *timed_out = TRUE; | |
1761 return FALSE; /* don't happen again */ | |
1762 } | |
1763 | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
1764 static guint motion_repeat_timer = 0; |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
1765 static int motion_repeat_offset = FALSE; |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
1766 static timeout_cb_type motion_repeat_timer_cb(gpointer); |
7 | 1767 |
1768 static void | |
1769 process_motion_notify(int x, int y, GdkModifierType state) | |
1770 { | |
1771 int button; | |
1772 int_u vim_modifiers; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1773 #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
|
1774 GtkAllocation allocation; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1775 #endif |
7 | 1776 |
1777 button = (state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | | |
1778 GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | | |
1779 GDK_BUTTON5_MASK)) | |
1780 ? MOUSE_DRAG : ' '; | |
1781 | |
1782 /* If our pointer is currently hidden, then we should show it. */ | |
1783 gui_mch_mousehide(FALSE); | |
1784 | |
1785 /* Just moving the rodent above the drawing area without any button | |
1786 * being pressed. */ | |
1787 if (button != MOUSE_DRAG) | |
1788 { | |
1789 gui_mouse_moved(x, y); | |
1790 return; | |
1791 } | |
1792 | |
1793 /* translate modifier coding between the main engine and GTK */ | |
179 | 1794 vim_modifiers = modifiers_gdk2mouse(state); |
7 | 1795 |
1226 | 1796 /* inform the editor engine about the occurrence of this event */ |
7 | 1797 gui_send_mouse_event(button, x, y, FALSE, vim_modifiers); |
1798 | |
1799 /* | |
1800 * Auto repeat timer handling. | |
1801 */ | |
8218
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 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
|
1804 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1805 if (x < 0 || y < 0 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1806 || x >= allocation.width |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1807 || y >= allocation.height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1808 #else |
7 | 1809 if (x < 0 || y < 0 |
1810 || x >= gui.drawarea->allocation.width | |
1811 || y >= gui.drawarea->allocation.height) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1812 #endif |
7 | 1813 { |
1814 | |
1815 int dx; | |
1816 int dy; | |
1817 int offshoot; | |
1818 int delay = 10; | |
1819 | |
1820 /* Calculate the maximal distance of the cursor from the drawing area. | |
1821 * (offshoot can't become negative here!). | |
1822 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1823 #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
|
1824 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
|
1825 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
|
1826 #else |
7 | 1827 dx = x < 0 ? -x : x - gui.drawarea->allocation.width; |
1828 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
|
1829 #endif |
7 | 1830 |
1831 offshoot = dx > dy ? dx : dy; | |
1832 | |
1884 | 1833 /* Make a linearly decaying timer delay with a threshold of 5 at a |
7 | 1834 * distance of 127 pixels from the main window. |
1835 * | |
1836 * One could think endlessly about the most ergonomic variant here. | |
1837 * For example it could make sense to calculate the distance from the | |
1838 * drags start instead... | |
1839 * | |
1840 * Maybe a parabolic interpolation would suite us better here too... | |
1841 */ | |
1842 if (offshoot > 127) | |
1843 { | |
1844 /* 5 appears to be somehow near to my perceptual limits :-). */ | |
1845 delay = 5; | |
1846 } | |
1847 else | |
1848 { | |
1849 delay = (130 * (127 - offshoot)) / 127 + 5; | |
1850 } | |
1851 | |
1852 /* shoot again */ | |
1853 if (!motion_repeat_timer) | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
1854 motion_repeat_timer = timeout_add(delay, motion_repeat_timer_cb, |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
1855 NULL); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1856 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1857 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1858 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1859 #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
|
1860 static GdkDevice * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1861 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
|
1862 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1863 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
|
1864 GdkDisplay * const dpy = gdk_window_get_display(win); |
8926
fc69eed19ba7
commit https://github.com/vim/vim/commit/30e12d259ee78272359f9da2655d0593a4f6a626
Christian Brabandt <cb@256bit.org>
parents:
8851
diff
changeset
|
1865 # if GTK_CHECK_VERSION(3,20,0) |
fc69eed19ba7
commit https://github.com/vim/vim/commit/30e12d259ee78272359f9da2655d0593a4f6a626
Christian Brabandt <cb@256bit.org>
parents:
8851
diff
changeset
|
1866 GdkSeat * const seat = gdk_display_get_default_seat(dpy); |
fc69eed19ba7
commit https://github.com/vim/vim/commit/30e12d259ee78272359f9da2655d0593a4f6a626
Christian Brabandt <cb@256bit.org>
parents:
8851
diff
changeset
|
1867 return gdk_seat_get_pointer(seat); |
fc69eed19ba7
commit https://github.com/vim/vim/commit/30e12d259ee78272359f9da2655d0593a4f6a626
Christian Brabandt <cb@256bit.org>
parents:
8851
diff
changeset
|
1868 # else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1869 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
|
1870 return gdk_device_manager_get_client_pointer(mngr); |
8926
fc69eed19ba7
commit https://github.com/vim/vim/commit/30e12d259ee78272359f9da2655d0593a4f6a626
Christian Brabandt <cb@256bit.org>
parents:
8851
diff
changeset
|
1871 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1872 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1873 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1874 static GdkWindow * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1875 gui_gtk_get_pointer(GtkWidget *widget, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1876 gint *x, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1877 gint *y, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1878 GdkModifierType *state) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1879 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1880 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
|
1881 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
|
1882 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
|
1883 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1884 |
8397
1e58a938aafc
commit https://github.com/vim/vim/commit/2369c15407cf9a730a396ebf9709abb280c5ce48
Christian Brabandt <cb@256bit.org>
parents:
8301
diff
changeset
|
1885 # if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1886 static GdkWindow * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1887 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
|
1888 gint *x, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1889 gint *y) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1890 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1891 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
|
1892 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
|
1893 } |
8397
1e58a938aafc
commit https://github.com/vim/vim/commit/2369c15407cf9a730a396ebf9709abb280c5ce48
Christian Brabandt <cb@256bit.org>
parents:
8301
diff
changeset
|
1894 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1895 #endif |
7 | 1896 |
1897 /* | |
1898 * Timer used to recognize multiple clicks of the mouse button. | |
1899 */ | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
1900 static timeout_cb_type |
1884 | 1901 motion_repeat_timer_cb(gpointer data UNUSED) |
7 | 1902 { |
1903 int x; | |
1904 int y; | |
1905 GdkModifierType state; | |
1906 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1907 #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
|
1908 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
|
1909 #else |
7 | 1910 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
|
1911 #endif |
7 | 1912 |
1913 if (!(state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | | |
1914 GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | | |
1915 GDK_BUTTON5_MASK))) | |
1916 { | |
1917 motion_repeat_timer = 0; | |
1918 return FALSE; | |
1919 } | |
1920 | |
1921 /* If there already is a mouse click in the input buffer, wait another | |
1922 * time (otherwise we would create a backlog of clicks) */ | |
1923 if (vim_used_in_input_buf() > 10) | |
1924 return TRUE; | |
1925 | |
1926 motion_repeat_timer = 0; | |
1927 | |
1928 /* | |
1929 * Fake a motion event. | |
1930 * Trick: Pretend the mouse moved to the next character on every other | |
1931 * event, otherwise drag events will be discarded, because they are still | |
1932 * in the same character. | |
1933 */ | |
1934 if (motion_repeat_offset) | |
1935 x += gui.char_width; | |
1936 | |
1937 motion_repeat_offset = !motion_repeat_offset; | |
1938 process_motion_notify(x, y, state); | |
1939 | |
1940 /* Don't happen again. We will get reinstalled in the synthetic event | |
1941 * if needed -- thus repeating should still work. */ | |
1942 return FALSE; | |
1943 } | |
1944 | |
1945 static gint | |
1884 | 1946 motion_notify_event(GtkWidget *widget, |
1947 GdkEventMotion *event, | |
1948 gpointer data UNUSED) | |
7 | 1949 { |
1950 if (event->is_hint) | |
1951 { | |
1952 int x; | |
1953 int y; | |
1954 GdkModifierType state; | |
1955 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1956 #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
|
1957 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
|
1958 #else |
7 | 1959 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
|
1960 #endif |
7 | 1961 process_motion_notify(x, y, state); |
1962 } | |
1963 else | |
1964 { | |
1965 process_motion_notify((int)event->x, (int)event->y, | |
1966 (GdkModifierType)event->state); | |
1967 } | |
1968 | |
1969 return TRUE; /* handled */ | |
1970 } | |
1971 | |
1972 | |
1973 /* | |
1974 * Mouse button handling. Note please that we are capturing multiple click's | |
1975 * by our own timeout mechanism instead of the one provided by GTK+ itself. | |
1976 * This is due to the way the generic VIM code is recognizing multiple clicks. | |
1977 */ | |
1978 static gint | |
1884 | 1979 button_press_event(GtkWidget *widget, |
1980 GdkEventButton *event, | |
1981 gpointer data UNUSED) | |
7 | 1982 { |
1983 int button; | |
1984 int repeated_click = FALSE; | |
1985 int x, y; | |
1986 int_u vim_modifiers; | |
1987 | |
2923 | 1988 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
|
1989 |
7 | 1990 /* 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
|
1991 #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
|
1992 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
|
1993 #else |
7 | 1994 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
|
1995 #endif |
7 | 1996 gtk_widget_grab_focus(widget); |
1997 | |
1998 /* | |
1999 * Don't let additional events about multiple clicks send by GTK to us | |
2000 * after the initial button press event confuse us. | |
2001 */ | |
2002 if (event->type != GDK_BUTTON_PRESS) | |
2003 return FALSE; | |
2004 | |
2005 x = event->x; | |
2006 y = event->y; | |
2007 | |
2008 /* Handle multiple clicks */ | |
2009 if (!mouse_timed_out && mouse_click_timer) | |
2010 { | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
2011 timeout_remove(mouse_click_timer); |
7 | 2012 mouse_click_timer = 0; |
2013 repeated_click = TRUE; | |
2014 } | |
2015 | |
2016 mouse_timed_out = FALSE; | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
2017 mouse_click_timer = timeout_add(p_mouset, mouse_click_timer_cb, |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
2018 &mouse_timed_out); |
7 | 2019 |
2020 switch (event->button) | |
2021 { | |
7260
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2022 /* 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
|
2023 * 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
|
2024 case 1: button = MOUSE_LEFT; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2025 case 2: button = MOUSE_MIDDLE; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2026 case 3: button = MOUSE_RIGHT; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2027 case 8: button = MOUSE_X1; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2028 case 9: button = MOUSE_X2; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2029 default: |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2030 return FALSE; /* Unknown button */ |
7 | 2031 } |
2032 | |
2033 #ifdef FEAT_XIM | |
2034 /* cancel any preediting */ | |
2035 if (im_is_preediting()) | |
2036 xim_reset(); | |
2037 #endif | |
2038 | |
179 | 2039 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 2040 |
2041 gui_send_mouse_event(button, x, y, repeated_click, vim_modifiers); | |
2042 | |
2043 return TRUE; | |
2044 } | |
2045 | |
2046 /* | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
2047 * GTK+ 2 abstracts scrolling via the GdkEventScroll. |
7 | 2048 */ |
2049 static gboolean | |
1884 | 2050 scroll_event(GtkWidget *widget, |
2051 GdkEventScroll *event, | |
2052 gpointer data UNUSED) | |
7 | 2053 { |
2054 int button; | |
179 | 2055 int_u vim_modifiers; |
7 | 2056 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2057 #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
|
2058 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
|
2059 #else |
7 | 2060 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
|
2061 #endif |
7 | 2062 gtk_widget_grab_focus(widget); |
2063 | |
2064 switch (event->direction) | |
2065 { | |
2066 case GDK_SCROLL_UP: | |
2067 button = MOUSE_4; | |
2068 break; | |
2069 case GDK_SCROLL_DOWN: | |
2070 button = MOUSE_5; | |
2071 break; | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2072 case GDK_SCROLL_LEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2073 button = MOUSE_7; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2074 break; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2075 case GDK_SCROLL_RIGHT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2076 button = MOUSE_6; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2077 break; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2078 default: /* This shouldn't happen */ |
7 | 2079 return FALSE; |
2080 } | |
2081 | |
2082 # ifdef FEAT_XIM | |
2083 /* cancel any preediting */ | |
2084 if (im_is_preediting()) | |
2085 xim_reset(); | |
2086 # endif | |
2087 | |
179 | 2088 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 2089 |
2090 gui_send_mouse_event(button, (int)event->x, (int)event->y, | |
2091 FALSE, vim_modifiers); | |
2092 | |
2093 return TRUE; | |
2094 } | |
2095 | |
2096 | |
2097 static gint | |
1884 | 2098 button_release_event(GtkWidget *widget UNUSED, |
2099 GdkEventButton *event, | |
2100 gpointer data UNUSED) | |
7 | 2101 { |
2102 int x, y; | |
2103 int_u vim_modifiers; | |
2104 | |
2923 | 2105 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
|
2106 |
7 | 2107 /* Remove any motion "machine gun" timers used for automatic further |
2108 extension of allocation areas if outside of the applications window | |
2109 area .*/ | |
2110 if (motion_repeat_timer) | |
2111 { | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
2112 timeout_remove(motion_repeat_timer); |
7 | 2113 motion_repeat_timer = 0; |
2114 } | |
2115 | |
2116 x = event->x; | |
2117 y = event->y; | |
2118 | |
179 | 2119 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 2120 |
2121 gui_send_mouse_event(MOUSE_RELEASE, x, y, FALSE, vim_modifiers); | |
2122 | |
2123 return TRUE; | |
2124 } | |
2125 | |
2126 | |
2127 #ifdef FEAT_DND | |
2128 /**************************************************************************** | |
2129 * Drag aNd Drop support handlers. | |
2130 */ | |
2131 | |
2132 /* | |
2133 * Count how many items there may be and separate them with a NUL. | |
2134 * Apparently the items are separated with \r\n. This is not documented, | |
2135 * thus be careful not to go past the end. Also allow separation with | |
2136 * NUL characters. | |
2137 */ | |
2138 static int | |
2139 count_and_decode_uri_list(char_u *out, char_u *raw, int len) | |
2140 { | |
2141 int i; | |
2142 char_u *p = out; | |
2143 int count = 0; | |
2144 | |
2145 for (i = 0; i < len; ++i) | |
2146 { | |
2147 if (raw[i] == NUL || raw[i] == '\n' || raw[i] == '\r') | |
2148 { | |
2149 if (p > out && p[-1] != NUL) | |
2150 { | |
2151 ++count; | |
2152 *p++ = NUL; | |
2153 } | |
2154 } | |
2155 else if (raw[i] == '%' && i + 2 < len && hexhex2nr(raw + i + 1) > 0) | |
2156 { | |
2157 *p++ = hexhex2nr(raw + i + 1); | |
2158 i += 2; | |
2159 } | |
2160 else | |
2161 *p++ = raw[i]; | |
2162 } | |
2163 if (p > out && p[-1] != NUL) | |
2164 { | |
2165 *p = NUL; /* last item didn't have \r or \n */ | |
2166 ++count; | |
2167 } | |
2168 return count; | |
2169 } | |
2170 | |
2171 /* | |
2172 * Parse NUL separated "src" strings. Make it an array "outlist" form. On | |
2173 * this process, URI which protocol is not "file:" are removed. Return | |
2174 * length of array (less than "max"). | |
2175 */ | |
2176 static int | |
2177 filter_uri_list(char_u **outlist, int max, char_u *src) | |
2178 { | |
2179 int i, j; | |
2180 | |
2181 for (i = j = 0; i < max; ++i) | |
2182 { | |
2183 outlist[i] = NULL; | |
2184 if (STRNCMP(src, "file:", 5) == 0) | |
2185 { | |
2186 src += 5; | |
2187 if (STRNCMP(src, "//localhost", 11) == 0) | |
2188 src += 11; | |
2189 while (src[0] == '/' && src[1] == '/') | |
2190 ++src; | |
2191 outlist[j++] = vim_strsave(src); | |
2192 } | |
2193 src += STRLEN(src) + 1; | |
2194 } | |
2195 return j; | |
2196 } | |
2197 | |
2198 static char_u ** | |
2199 parse_uri_list(int *count, char_u *data, int len) | |
2200 { | |
2201 int n = 0; | |
2202 char_u *tmp = NULL; | |
9252
c25898cc99c1
commit https://github.com/vim/vim/commit/945ec093cd4ddefab930239990564b12eb232153
Christian Brabandt <cb@256bit.org>
parents:
9232
diff
changeset
|
2203 char_u **array = NULL; |
7 | 2204 |
2205 if (data != NULL && len > 0 && (tmp = (char_u *)alloc(len + 1)) != NULL) | |
2206 { | |
2207 n = count_and_decode_uri_list(tmp, data, len); | |
2208 if (n > 0 && (array = (char_u **)alloc(n * sizeof(char_u *))) != NULL) | |
2209 n = filter_uri_list(array, n, tmp); | |
2210 } | |
2211 vim_free(tmp); | |
2212 *count = n; | |
2213 return array; | |
2214 } | |
2215 | |
2216 static void | |
2217 drag_handle_uri_list(GdkDragContext *context, | |
2218 GtkSelectionData *data, | |
2219 guint time_, | |
2220 GdkModifierType state, | |
2221 gint x, | |
2222 gint y) | |
2223 { | |
2224 char_u **fnames; | |
2225 int nfiles = 0; | |
2226 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2227 # 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
|
2228 fnames = parse_uri_list(&nfiles, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2229 (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
|
2230 gtk_selection_data_get_length(data)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2231 # else |
7 | 2232 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
|
2233 # endif |
7 | 2234 |
2235 if (fnames != NULL && nfiles > 0) | |
2236 { | |
179 | 2237 int_u modifiers; |
7 | 2238 |
2239 gtk_drag_finish(context, TRUE, FALSE, time_); /* accept */ | |
2240 | |
179 | 2241 modifiers = modifiers_gdk2mouse(state); |
7 | 2242 |
2243 gui_handle_drop(x, y, modifiers, fnames, nfiles); | |
2244 } | |
840 | 2245 else |
2246 vim_free(fnames); | |
7 | 2247 } |
2248 | |
2249 static void | |
2250 drag_handle_text(GdkDragContext *context, | |
2251 GtkSelectionData *data, | |
2252 guint time_, | |
2253 GdkModifierType state) | |
2254 { | |
2255 char_u dropkey[6] = {CSI, KS_MODIFIER, 0, CSI, KS_EXTRA, (char_u)KE_DROP}; | |
2256 char_u *text; | |
2257 int len; | |
2258 char_u *tmpbuf = NULL; | |
2259 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2260 # 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
|
2261 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
|
2262 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
|
2263 # else |
7 | 2264 text = data->data; |
2265 len = data->length; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2266 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2267 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2268 # 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
|
2269 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
|
2270 # else |
7 | 2271 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
|
2272 # endif |
7 | 2273 { |
2274 if (input_conv.vc_type != CONV_NONE) | |
2275 tmpbuf = string_convert(&input_conv, text, &len); | |
2276 if (tmpbuf != NULL) | |
2277 text = tmpbuf; | |
2278 } | |
2279 | |
2280 dnd_yank_drag_data(text, (long)len); | |
2281 gtk_drag_finish(context, TRUE, FALSE, time_); /* accept */ | |
2282 vim_free(tmpbuf); | |
2283 | |
179 | 2284 dropkey[2] = modifiers_gdk2vim(state); |
7 | 2285 |
2286 if (dropkey[2] != 0) | |
2287 add_to_input_buf(dropkey, (int)sizeof(dropkey)); | |
2288 else | |
2289 add_to_input_buf(dropkey + 3, (int)(sizeof(dropkey) - 3)); | |
2290 } | |
2291 | |
2292 /* | |
2293 * DND receiver. | |
2294 */ | |
2295 static void | |
2296 drag_data_received_cb(GtkWidget *widget, | |
2297 GdkDragContext *context, | |
2298 gint x, | |
2299 gint y, | |
2300 GtkSelectionData *data, | |
2301 guint info, | |
2302 guint time_, | |
1884 | 2303 gpointer user_data UNUSED) |
7 | 2304 { |
2305 GdkModifierType state; | |
2306 | |
2307 /* Guard against trash */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2308 # 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
|
2309 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
|
2310 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
|
2311 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
|
2312 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2313 if (data_data == NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2314 || data_length <= 0 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2315 || data_format != 8 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2316 || data_data[data_length] != '\0') |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2317 # else |
7 | 2318 if (data->data == NULL |
2319 || data->length <= 0 | |
2320 || data->format != 8 | |
2321 || data->data[data->length] != '\0') | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2322 # endif |
7 | 2323 { |
2324 gtk_drag_finish(context, FALSE, FALSE, time_); | |
2325 return; | |
2326 } | |
2327 | |
2328 /* Get the current modifier state for proper distinguishment between | |
2329 * different operations later. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2330 #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
|
2331 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
|
2332 # else |
7 | 2333 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
|
2334 # endif |
7 | 2335 |
2336 /* Not sure about the role of "text/plain" here... */ | |
2337 if (info == (guint)TARGET_TEXT_URI_LIST) | |
2338 drag_handle_uri_list(context, data, time_, state, x, y); | |
2339 else | |
2340 drag_handle_text(context, data, time_, state); | |
2341 | |
2342 } | |
2343 #endif /* FEAT_DND */ | |
2344 | |
2345 | |
2346 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
2347 /* | |
2348 * GnomeClient interact callback. Check for unsaved buffers that cannot | |
2349 * be abandoned and pop up a dialog asking the user for confirmation if | |
2350 * necessary. | |
2351 */ | |
2352 static void | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2353 sm_client_check_changed_any(GnomeClient *client UNUSED, |
7 | 2354 gint key, |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2355 GnomeDialogType type UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2356 gpointer data UNUSED) |
7 | 2357 { |
2358 cmdmod_T save_cmdmod; | |
2359 gboolean shutdown_cancelled; | |
2360 | |
2361 save_cmdmod = cmdmod; | |
2362 | |
2363 # ifdef FEAT_BROWSE | |
2364 cmdmod.browse = TRUE; | |
2365 # endif | |
2366 # if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
2367 cmdmod.confirm = TRUE; | |
2368 # endif | |
2369 /* | |
2370 * If there are changed buffers, present the user with | |
2371 * a dialog if possible, otherwise give an error message. | |
2372 */ | |
7469
15eefe1b0dad
commit https://github.com/vim/vim/commit/027387f70c671f62e3e08e0bdd09ec05b0232735
Christian Brabandt <cb@256bit.org>
parents:
7380
diff
changeset
|
2373 shutdown_cancelled = check_changed_any(FALSE, FALSE); |
7 | 2374 |
2375 exiting = FALSE; | |
2376 cmdmod = save_cmdmod; | |
2377 setcursor(); /* position the cursor */ | |
2378 out_flush(); | |
2379 /* | |
2380 * If the user hit the [Cancel] button the whole shutdown | |
2381 * will be cancelled. Wow, quite powerful feature (: | |
2382 */ | |
2383 gnome_interaction_key_return(key, shutdown_cancelled); | |
2384 } | |
2385 | |
2386 /* | |
2387 * Generate a script that can be used to restore the current editing session. | |
2388 * Save the value of v:this_session before running :mksession in order to make | |
2389 * automagic session save fully transparent. Return TRUE on success. | |
2390 */ | |
2391 static int | |
2392 write_session_file(char_u *filename) | |
2393 { | |
2394 char_u *escaped_filename; | |
2395 char *mksession_cmdline; | |
2396 unsigned int save_ssop_flags; | |
2397 int failed; | |
2398 | |
2399 /* | |
2400 * Build an ex command line to create a script that restores the current | |
2401 * session if executed. Escape the filename to avoid nasty surprises. | |
2402 */ | |
2403 escaped_filename = vim_strsave_escaped(filename, escape_chars); | |
2404 if (escaped_filename == NULL) | |
2405 return FALSE; | |
1296 | 2406 mksession_cmdline = g_strconcat("mksession ", (char *)escaped_filename, |
2407 NULL); | |
7 | 2408 vim_free(escaped_filename); |
1296 | 2409 |
7 | 2410 /* |
2411 * Use a reasonable hardcoded set of 'sessionoptions' flags to avoid | |
2412 * unpredictable effects when the session is saved automatically. Also, | |
2413 * we definitely need SSOP_GLOBALS to be able to restore v:this_session. | |
2414 * Don't use SSOP_BUFFERS to prevent the buffer list from becoming | |
2415 * enormously large if the GNOME session feature is used regularly. | |
2416 */ | |
2417 save_ssop_flags = ssop_flags; | |
2418 ssop_flags = (SSOP_BLANK|SSOP_CURDIR|SSOP_FOLDS|SSOP_GLOBALS | |
1296 | 2419 |SSOP_HELP|SSOP_OPTIONS|SSOP_WINSIZE|SSOP_TABPAGES); |
7 | 2420 |
2421 do_cmdline_cmd((char_u *)"let Save_VV_this_session = v:this_session"); | |
2422 failed = (do_cmdline_cmd((char_u *)mksession_cmdline) == FAIL); | |
2423 do_cmdline_cmd((char_u *)"let v:this_session = Save_VV_this_session"); | |
150 | 2424 do_unlet((char_u *)"Save_VV_this_session", TRUE); |
7 | 2425 |
2426 ssop_flags = save_ssop_flags; | |
2427 g_free(mksession_cmdline); | |
5905 | 2428 |
7 | 2429 /* |
2430 * Reopen the file and append a command to restore v:this_session, | |
2431 * as if this save never happened. This is to avoid conflicts with | |
2432 * the user's own sessions. FIXME: It's probably less hackish to add | |
2433 * a "stealth" flag to 'sessionoptions' -- gotta ask Bram. | |
2434 */ | |
2435 if (!failed) | |
2436 { | |
2437 FILE *fd; | |
2438 | |
2439 fd = open_exfile(filename, TRUE, APPENDBIN); | |
2440 | |
2441 failed = (fd == NULL | |
2442 || put_line(fd, "let v:this_session = Save_VV_this_session") == FAIL | |
2443 || put_line(fd, "unlet Save_VV_this_session") == FAIL); | |
2444 | |
2445 if (fd != NULL && fclose(fd) != 0) | |
2446 failed = TRUE; | |
2447 | |
2448 if (failed) | |
2449 mch_remove(filename); | |
2450 } | |
2451 | |
2452 return !failed; | |
2453 } | |
2454 | |
2455 /* | |
2456 * "save_yourself" signal handler. Initiate an interaction to ask the user | |
2457 * for confirmation if necessary. Save the current editing session and tell | |
2458 * the session manager how to restart Vim. | |
2459 */ | |
2460 static gboolean | |
2461 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
|
2462 gint phase UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2463 GnomeSaveStyle save_style UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2464 gboolean shutdown UNUSED, |
7 | 2465 GnomeInteractStyle interact_style, |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2466 gboolean fast UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2467 gpointer data UNUSED) |
7 | 2468 { |
2469 static const char suffix[] = "-session.vim"; | |
2470 char *session_file; | |
2471 unsigned int len; | |
2472 gboolean success; | |
2473 | |
2474 /* Always request an interaction if possible. check_changed_any() | |
2475 * won't actually show a dialog unless any buffers have been modified. | |
2476 * There doesn't seem to be an obvious way to check that without | |
2477 * automatically firing the dialog. Anyway, it works just fine. */ | |
2478 if (interact_style == GNOME_INTERACT_ANY) | |
2479 gnome_client_request_interaction(client, GNOME_DIALOG_NORMAL, | |
2480 &sm_client_check_changed_any, | |
2481 NULL); | |
2482 out_flush(); | |
2483 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
2484 | |
2485 /* The path is unique for each session save. We do neither know nor care | |
2486 * which session script will actually be used later. This decision is in | |
2487 * the domain of the session manager. */ | |
2488 session_file = gnome_config_get_real_path( | |
2489 gnome_client_get_config_prefix(client)); | |
2490 len = strlen(session_file); | |
2491 | |
2492 if (len > 0 && session_file[len-1] == G_DIR_SEPARATOR) | |
2493 --len; /* get rid of the superfluous trailing '/' */ | |
2494 | |
2495 session_file = g_renew(char, session_file, len + sizeof(suffix)); | |
2496 memcpy(session_file + len, suffix, sizeof(suffix)); | |
2497 | |
2498 success = write_session_file((char_u *)session_file); | |
2499 | |
2500 if (success) | |
2501 { | |
2502 const char *argv[8]; | |
2503 int i; | |
2504 | |
2505 /* Tell the session manager how to wipe out the stored session data. | |
2506 * This isn't as dangerous as it looks, don't worry :) session_file | |
2507 * is a unique absolute filename. Usually it'll be something like | |
2508 * `/home/user/.gnome2/vim-XXXXXX-session.vim'. */ | |
2509 i = 0; | |
2510 argv[i++] = "rm"; | |
2511 argv[i++] = session_file; | |
2512 argv[i] = NULL; | |
2513 | |
2514 gnome_client_set_discard_command(client, i, (char **)argv); | |
2515 | |
2516 /* Tell the session manager how to restore the just saved session. | |
2517 * This is easily done thanks to Vim's -S option. Pass the -f flag | |
2518 * since there's no need to fork -- it might even cause confusion. | |
2519 * Also pass the window role to give the WM something to match on. | |
2520 * The role is set in gui_mch_open(), thus should _never_ be NULL. */ | |
2521 i = 0; | |
2522 argv[i++] = restart_command; | |
2523 argv[i++] = "-f"; | |
2524 argv[i++] = "-g"; | |
2525 argv[i++] = "--role"; | |
2526 argv[i++] = gtk_window_get_role(GTK_WINDOW(gui.mainwin)); | |
2527 argv[i++] = "-S"; | |
2528 argv[i++] = session_file; | |
2529 argv[i] = NULL; | |
2530 | |
2531 gnome_client_set_restart_command(client, i, (char **)argv); | |
2532 gnome_client_set_clone_command(client, 0, NULL); | |
2533 } | |
2534 | |
2535 g_free(session_file); | |
2536 | |
2537 return success; | |
2538 } | |
2539 | |
2540 /* | |
2541 * Called when the session manager wants us to die. There isn't much to save | |
2542 * here since "save_yourself" has been emitted before (unless serious trouble | |
2543 * is happening). | |
2544 */ | |
2545 static void | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2546 sm_client_die(GnomeClient *client UNUSED, gpointer data UNUSED) |
7 | 2547 { |
2548 /* Don't write messages to the GUI anymore */ | |
2549 full_screen = FALSE; | |
2550 | |
1666 | 2551 vim_strncpy(IObuff, (char_u *) |
419 | 2552 _("Vim: Received \"die\" request from session manager\n"), |
1666 | 2553 IOSIZE - 1); |
7 | 2554 preserve_exit(); |
2555 } | |
2556 | |
2557 /* | |
2558 * Connect our signal handlers to be notified on session save and shutdown. | |
2559 */ | |
2560 static void | |
2561 setup_save_yourself(void) | |
2562 { | |
2563 GnomeClient *client; | |
2564 | |
2565 client = gnome_master_client(); | |
2566 | |
2567 if (client != NULL) | |
2568 { | |
2569 /* Must use the deprecated gtk_signal_connect() for compatibility | |
2570 * with GNOME 1. Arrgh, zombies! */ | |
2571 gtk_signal_connect(GTK_OBJECT(client), "save_yourself", | |
2572 GTK_SIGNAL_FUNC(&sm_client_save_yourself), NULL); | |
2573 gtk_signal_connect(GTK_OBJECT(client), "die", | |
2574 GTK_SIGNAL_FUNC(&sm_client_die), NULL); | |
2575 } | |
2576 } | |
2577 | |
2578 #else /* !(FEAT_GUI_GNOME && FEAT_SESSION) */ | |
2579 | |
2580 # ifdef USE_XSMP | |
2581 /* | |
2582 * GTK tells us that XSMP needs attention | |
2583 */ | |
2584 static gboolean | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2585 local_xsmp_handle_requests( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2586 GIOChannel *source UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2587 GIOCondition condition, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2588 gpointer data) |
7 | 2589 { |
2590 if (condition == G_IO_IN) | |
2591 { | |
2592 /* Do stuff; maybe close connection */ | |
2593 if (xsmp_handle_requests() == FAIL) | |
2594 g_io_channel_unref((GIOChannel *)data); | |
2595 return TRUE; | |
2596 } | |
2597 /* Error */ | |
2598 g_io_channel_unref((GIOChannel *)data); | |
2599 xsmp_close(); | |
2600 return TRUE; | |
2601 } | |
2602 # endif /* USE_XSMP */ | |
2603 | |
2604 /* | |
2605 * Setup the WM_PROTOCOLS to indicate we want the WM_SAVE_YOURSELF event. | |
2606 * This is an ugly use of X functions. GTK doesn't offer an alternative. | |
2607 */ | |
2608 static void | |
2609 setup_save_yourself(void) | |
2610 { | |
2611 Atom *existing_atoms = NULL; | |
2612 int count = 0; | |
2613 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2614 # ifdef USE_XSMP |
7 | 2615 if (xsmp_icefd != -1) |
2616 { | |
2617 /* | |
2618 * Use XSMP is preference to legacy WM_SAVE_YOURSELF; | |
2619 * set up GTK IO monitor | |
2620 */ | |
2621 GIOChannel *g_io = g_io_channel_unix_new(xsmp_icefd); | |
2622 | |
2623 g_io_add_watch(g_io, G_IO_IN | G_IO_ERR | G_IO_HUP, | |
2624 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
|
2625 g_io_channel_unref(g_io); |
7 | 2626 } |
2627 else | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2628 # endif |
7 | 2629 { |
2630 /* Fall back to old method */ | |
2631 | |
2632 /* first get the existing value */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2633 # 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
|
2634 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
|
2635 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2636 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
|
2637 GDK_WINDOW_XID(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2638 &existing_atoms, &count)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2639 # else |
7 | 2640 if (XGetWMProtocols(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2641 GDK_WINDOW_XWINDOW(gui.mainwin->window), | |
2642 &existing_atoms, &count)) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2643 # endif |
7 | 2644 { |
2645 Atom *new_atoms; | |
2646 Atom save_yourself_xatom; | |
2647 int i; | |
2648 | |
2649 save_yourself_xatom = GET_X_ATOM(save_yourself_atom); | |
2650 | |
2651 /* check if WM_SAVE_YOURSELF isn't there yet */ | |
2652 for (i = 0; i < count; ++i) | |
2653 if (existing_atoms[i] == save_yourself_xatom) | |
2654 break; | |
2655 | |
2656 if (i == count) | |
2657 { | |
2658 /* allocate an Atoms array which is one item longer */ | |
2659 new_atoms = (Atom *)alloc((unsigned)((count + 1) | |
2660 * sizeof(Atom))); | |
2661 if (new_atoms != NULL) | |
2662 { | |
2663 memcpy(new_atoms, existing_atoms, count * sizeof(Atom)); | |
2664 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
|
2665 # 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
|
2666 XSetWMProtocols(GDK_WINDOW_XDISPLAY(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2667 GDK_WINDOW_XID(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2668 # else |
7 | 2669 XSetWMProtocols(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2670 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
|
2671 # endif |
7 | 2672 new_atoms, count + 1); |
2673 vim_free(new_atoms); | |
2674 } | |
2675 } | |
2676 XFree(existing_atoms); | |
2677 } | |
2678 } | |
2679 } | |
2680 | |
2681 /* | |
2682 * Installing a global event filter seems to be the only way to catch | |
2683 * client messages of type WM_PROTOCOLS without overriding GDK's own | |
2684 * client message event filter. Well, that's still better than trying | |
2685 * to guess what the GDK filter had done if it had been invoked instead | |
2686 * | |
2687 * GTK2_FIXME: This doesn't seem to work. For some reason we never | |
2688 * receive WM_SAVE_YOURSELF even though everything is set up correctly. | |
2689 * I have the nasty feeling modern session managers just don't send this | |
2690 * deprecated message anymore. Addition: confirmed by several people. | |
2691 * | |
2692 * The GNOME session support is much cooler anyway. Unlike this ugly | |
2693 * WM_SAVE_YOURSELF hack it actually stores the session... And yes, | |
2694 * it should work with KDE as well. | |
2695 */ | |
2696 static GdkFilterReturn | |
1884 | 2697 global_event_filter(GdkXEvent *xev, |
2698 GdkEvent *event UNUSED, | |
2699 gpointer data UNUSED) | |
7 | 2700 { |
2701 XEvent *xevent = (XEvent *)xev; | |
2702 | |
2703 if (xevent != NULL | |
2704 && xevent->type == ClientMessage | |
2705 && xevent->xclient.message_type == GET_X_ATOM(wm_protocols_atom) | |
1884 | 2706 && (long_u)xevent->xclient.data.l[0] |
2707 == GET_X_ATOM(save_yourself_atom)) | |
7 | 2708 { |
2709 out_flush(); | |
2710 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
2711 /* | |
2712 * Set the window's WM_COMMAND property, to let the window manager | |
2713 * know we are done saving ourselves. We don't want to be | |
2714 * restarted, thus set argv to NULL. | |
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 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
|
2718 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
|
2719 # else |
7 | 2720 XSetCommand(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2721 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
|
2722 # endif |
7 | 2723 NULL, 0); |
2724 return GDK_FILTER_REMOVE; | |
2725 } | |
2726 | |
2727 return GDK_FILTER_CONTINUE; | |
2728 } | |
2729 #endif /* !(FEAT_GUI_GNOME && FEAT_SESSION) */ | |
2730 | |
2731 | |
2732 /* | |
2733 * Setup the window icon & xcmdsrv comm after the main window has been realized. | |
2734 */ | |
2735 static void | |
1884 | 2736 mainwin_realize(GtkWidget *widget UNUSED, gpointer data UNUSED) |
7 | 2737 { |
2738 /* If you get an error message here, you still need to unpack the runtime | |
2739 * archive! */ | |
2740 #ifdef magick | |
2741 # undef magick | |
2742 #endif | |
2743 /* A bit hackish, but avoids casting later and allows optimization */ | |
2744 # define static static const | |
2745 #define magick vim32x32 | |
2746 #include "../runtime/vim32x32.xpm" | |
2747 #undef magick | |
2748 #define magick vim16x16 | |
2749 #include "../runtime/vim16x16.xpm" | |
2750 #undef magick | |
2751 #define magick vim48x48 | |
2752 #include "../runtime/vim48x48.xpm" | |
2753 #undef magick | |
2754 # undef static | |
2755 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2756 #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
|
2757 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
|
2758 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2759 |
7 | 2760 /* When started with "--echo-wid" argument, write window ID on stdout. */ |
2761 if (echo_wid_arg) | |
2762 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2763 #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
|
2764 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
|
2765 #else |
7 | 2766 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
|
2767 #endif |
7 | 2768 fflush(stdout); |
2769 } | |
2770 | |
2771 if (vim_strchr(p_go, GO_ICON) != NULL) | |
2772 { | |
2773 /* | |
2774 * Add an icon to the main window. For fun and convenience of the user. | |
2775 */ | |
2776 GList *icons = NULL; | |
2777 | |
2778 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim16x16)); | |
2779 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim32x32)); | |
2780 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim48x48)); | |
2781 | |
2782 gtk_window_set_icon_list(GTK_WINDOW(gui.mainwin), icons); | |
2783 | |
2784 g_list_foreach(icons, (GFunc)&g_object_unref, NULL); | |
2785 g_list_free(icons); | |
2786 } | |
2787 | |
2788 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
2789 /* Register a handler for WM_SAVE_YOURSELF with GDK's low-level X I/F */ | |
2790 gdk_window_add_filter(NULL, &global_event_filter, NULL); | |
2791 #endif | |
2792 /* Setup to indicate to the window manager that we want to catch the | |
2793 * WM_SAVE_YOURSELF event. For GNOME, this connects to the session | |
2794 * manager instead. */ | |
2795 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
2796 if (using_gnome) | |
2797 #endif | |
2798 setup_save_yourself(); | |
2799 | |
2800 #ifdef FEAT_CLIENTSERVER | |
2801 if (serverName == NULL && serverDelayedStartName != NULL) | |
2802 { | |
2803 /* 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
|
2804 # 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
|
2805 commWindow = GDK_WINDOW_XID(mainwin_win); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2806 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2807 (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
|
2808 serverDelayedStartName); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2809 # else |
7 | 2810 commWindow = GDK_WINDOW_XWINDOW(gui.mainwin->window); |
2811 | |
2812 (void)serverRegisterName(GDK_WINDOW_XDISPLAY(gui.mainwin->window), | |
2813 serverDelayedStartName); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2814 # endif |
7 | 2815 } |
2816 else | |
2817 { | |
2818 /* | |
2819 * Cannot handle "XLib-only" windows with gtk event routines, we'll | |
2820 * have to change the "server" registration to that of the main window | |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2821 * If we have not registered a name yet, remember the window. |
7 | 2822 */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2823 # 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
|
2824 serverChangeRegisteredWindow(GDK_WINDOW_XDISPLAY(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2825 GDK_WINDOW_XID(mainwin_win)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2826 # else |
7 | 2827 serverChangeRegisteredWindow(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2828 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
|
2829 # endif |
7 | 2830 } |
2831 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
|
2832 # 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
|
2833 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
|
2834 G_CALLBACK(property_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2835 # else |
7 | 2836 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "property_notify_event", |
2837 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
|
2838 # endif |
7 | 2839 #endif |
2840 } | |
2841 | |
2842 static GdkCursor * | |
2843 create_blank_pointer(void) | |
2844 { | |
2845 GdkWindow *root_window = NULL; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2846 #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
|
2847 GdkPixbuf *blank_mask; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2848 #else |
7 | 2849 GdkPixmap *blank_mask; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2850 #endif |
7 | 2851 GdkCursor *cursor; |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2852 #if GTK_CHECK_VERSION(3,0,0) |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2853 GdkRGBA color = { 0.0, 0.0, 0.0, 1.0 }; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2854 #else |
7 | 2855 GdkColor color = { 0, 0, 0, 0 }; |
2856 char blank_data[] = { 0x0 }; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2857 #endif |
7 | 2858 |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2859 #if GTK_CHECK_VERSION(3,12,0) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2860 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2861 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
|
2862 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
|
2863 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
|
2864 } |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2865 #else |
7 | 2866 root_window = gtk_widget_get_root_window(gui.mainwin); |
2867 #endif | |
2868 | |
2869 /* Create a pseudo blank pointer, which is in fact one pixel by one pixel | |
2870 * in size. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2871 #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
|
2872 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2873 cairo_surface_t *surf; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2874 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2875 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2876 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
|
2877 cr = cairo_create(surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2878 |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2879 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2880 color.red, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2881 color.green, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2882 color.blue, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2883 color.alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2884 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
|
2885 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2886 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2887 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2888 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
|
2889 cairo_surface_destroy(surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2890 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2891 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
|
2892 blank_mask, 0, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2893 g_object_unref(blank_mask); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2894 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2895 #else |
7 | 2896 blank_mask = gdk_bitmap_create_from_data(root_window, blank_data, 1, 1); |
2897 cursor = gdk_cursor_new_from_pixmap(blank_mask, blank_mask, | |
2898 &color, &color, 0, 0); | |
2899 gdk_bitmap_unref(blank_mask); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2900 #endif |
7 | 2901 |
2902 return cursor; | |
2903 } | |
2904 | |
2905 static void | |
2906 mainwin_screen_changed_cb(GtkWidget *widget, | |
1884 | 2907 GdkScreen *previous_screen UNUSED, |
2908 gpointer data UNUSED) | |
7 | 2909 { |
2910 if (!gtk_widget_has_screen(widget)) | |
2911 return; | |
2912 | |
2913 /* | |
1226 | 2914 * Recreate the invisible mouse cursor. |
7 | 2915 */ |
2916 if (gui.blank_pointer != NULL) | |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2917 #if GTK_CHECK_VERSION(3,0,0) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2918 g_object_unref(G_OBJECT(gui.blank_pointer)); |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2919 #else |
7 | 2920 gdk_cursor_unref(gui.blank_pointer); |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2921 #endif |
7 | 2922 |
2923 gui.blank_pointer = create_blank_pointer(); | |
2924 | |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2925 #if GTK_CHECK_VERSION(3,0,0) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2926 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
|
2927 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
|
2928 gui.blank_pointer); |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2929 #else |
7 | 2930 if (gui.pointer_hidden && gui.drawarea->window != NULL) |
2931 gdk_window_set_cursor(gui.drawarea->window, gui.blank_pointer); | |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2932 #endif |
7 | 2933 |
2934 /* | |
2935 * Create a new PangoContext for this screen, and initialize it | |
2936 * with the current font if necessary. | |
2937 */ | |
2938 if (gui.text_context != NULL) | |
2939 g_object_unref(gui.text_context); | |
2940 | |
2941 gui.text_context = gtk_widget_create_pango_context(widget); | |
2942 pango_context_set_base_dir(gui.text_context, PANGO_DIRECTION_LTR); | |
2943 | |
2944 if (gui.norm_font != NULL) | |
2945 { | |
38 | 2946 gui_mch_init_font(p_guifont, FALSE); |
12802
29a728529f92
patch 8.0.1278: GUI window always resizes when adding scrollbar
Christian Brabandt <cb@256bit.org>
parents:
12666
diff
changeset
|
2947 gui_set_shellsize(TRUE, FALSE, RESIZE_BOTH); |
7 | 2948 } |
2949 } | |
2950 | |
2951 /* | |
2952 * After the drawing area comes up, we calculate all colors and create the | |
2953 * dummy blank cursor. | |
2954 * | |
2955 * Don't try to set any VIM scrollbar sizes anywhere here. I'm relying on the | |
2956 * fact that the main VIM engine doesn't take them into account anywhere. | |
2957 */ | |
2958 static void | |
1884 | 2959 drawarea_realize_cb(GtkWidget *widget, gpointer data UNUSED) |
7 | 2960 { |
2961 GtkWidget *sbar; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2962 #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
|
2963 GtkAllocation allocation; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2964 #endif |
7 | 2965 |
2966 #ifdef FEAT_XIM | |
2967 xim_init(); | |
2968 #endif | |
2969 gui_mch_new_colors(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2970 #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
|
2971 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
|
2972 gtk_widget_get_window(widget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2973 CAIRO_CONTENT_COLOR_ALPHA, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2974 gtk_widget_get_allocated_width(widget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2975 gtk_widget_get_allocated_height(widget)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2976 #else |
7 | 2977 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
|
2978 #endif |
7 | 2979 |
2980 gui.blank_pointer = create_blank_pointer(); | |
2981 if (gui.pointer_hidden) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2982 #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
|
2983 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
|
2984 #else |
7 | 2985 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
|
2986 #endif |
7 | 2987 |
2988 /* get the actual size of the scrollbars, if they are realized */ | |
2989 sbar = firstwin->w_scrollbars[SBAR_LEFT].id; | |
2990 if (!sbar || (!gui.which_scrollbars[SBAR_LEFT] | |
2991 && firstwin->w_scrollbars[SBAR_RIGHT].id)) | |
2992 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
|
2993 #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
|
2994 gtk_widget_get_allocation(sbar, &allocation); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2995 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
|
2996 gui.scrollbar_width = allocation.width; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2997 #else |
7 | 2998 if (sbar && GTK_WIDGET_REALIZED(sbar) && sbar->allocation.width) |
2999 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
|
3000 #endif |
7 | 3001 |
3002 sbar = gui.bottom_sbar.id; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3003 #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
|
3004 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
|
3005 gui.scrollbar_height = allocation.height; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3006 #else |
7 | 3007 if (sbar && GTK_WIDGET_REALIZED(sbar) && sbar->allocation.height) |
3008 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
|
3009 #endif |
7 | 3010 } |
3011 | |
3012 /* | |
3013 * Properly clean up on shutdown. | |
3014 */ | |
3015 static void | |
1884 | 3016 drawarea_unrealize_cb(GtkWidget *widget UNUSED, gpointer data UNUSED) |
7 | 3017 { |
3018 /* Don't write messages to the GUI anymore */ | |
3019 full_screen = FALSE; | |
3020 | |
3021 #ifdef FEAT_XIM | |
3022 im_shutdown(); | |
3023 #endif | |
3024 if (gui.ascii_glyphs != NULL) | |
3025 { | |
3026 pango_glyph_string_free(gui.ascii_glyphs); | |
3027 gui.ascii_glyphs = NULL; | |
3028 } | |
3029 if (gui.ascii_font != NULL) | |
3030 { | |
3031 g_object_unref(gui.ascii_font); | |
3032 gui.ascii_font = NULL; | |
3033 } | |
3034 g_object_unref(gui.text_context); | |
3035 gui.text_context = NULL; | |
3036 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3037 #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
|
3038 if (gui.surface != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3039 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3040 cairo_surface_destroy(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3041 gui.surface = NULL; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3042 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3043 #else |
7 | 3044 g_object_unref(gui.text_gc); |
3045 gui.text_gc = NULL; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3046 #endif |
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 #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
|
3049 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
|
3050 #else |
7 | 3051 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
|
3052 #endif |
7 | 3053 gui.blank_pointer = NULL; |
3054 } | |
3055 | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3056 #if GTK_CHECK_VERSION(3,22,2) |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3057 static void |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3058 drawarea_style_updated_cb(GtkWidget *widget UNUSED, |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3059 gpointer data UNUSED) |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3060 #else |
7 | 3061 static void |
1884 | 3062 drawarea_style_set_cb(GtkWidget *widget UNUSED, |
3063 GtkStyle *previous_style UNUSED, | |
3064 gpointer data UNUSED) | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3065 #endif |
7 | 3066 { |
3067 gui_mch_new_colors(); | |
3068 } | |
3069 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3070 #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
|
3071 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3072 drawarea_configure_event_cb(GtkWidget *widget, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3073 GdkEventConfigure *event, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3074 gpointer data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3075 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3076 static int cur_width = 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3077 static int cur_height = 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3078 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3079 g_return_val_if_fail(event |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3080 && 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
|
3081 |
10402
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
3082 # if GTK_CHECK_VERSION(3,22,2) && !GTK_CHECK_VERSION(3,22,4) |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3083 /* As of 3.22.2, GdkWindows have started distributing configure events to |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3084 * their "native" children (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=12579fe71b3b8f79eb9c1b80e429443bcc437dd0). |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3085 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3086 * As can be seen from the implementation of move_native_children() and |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3087 * configure_native_child() in gdkwindow.c, those functions actually |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3088 * propagate configure events to every child, failing to distinguish |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3089 * "native" one from non-native one. |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3090 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3091 * Naturally, configure events propagated to here like that are fallacious |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3092 * and, as a matter of fact, they trigger a geometric collapse of |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3093 * gui.drawarea in fullscreen and miximized modes. |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3094 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3095 * To filter out such nuisance events, we are making use of the fact that |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3096 * the field send_event of such GdkEventConfigures is set to FALSE in |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3097 * configure_native_child(). |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3098 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3099 * Obviously, this is a terrible hack making GVim depend on GTK's |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3100 * implementation details. Therefore, watch out any relevant internal |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3101 * changes happening in GTK in the feature (sigh). |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3102 */ |
10402
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
3103 /* Follow-up |
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
3104 * After a few weeks later, the GdkWindow change mentioned above was |
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
3105 * reverted (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=f70039cb9603a02d2369fec4038abf40a1711155). |
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
3106 * The corresponding official release is 3.22.4. */ |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3107 if (event->send_event == FALSE) |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3108 return TRUE; |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3109 # endif |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3110 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3111 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
|
3112 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3113 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3114 cur_width = event->width; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3115 cur_height = event->height; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3116 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3117 if (gui.surface != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3118 cairo_surface_destroy(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3119 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3120 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
|
3121 gtk_widget_get_window(widget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3122 CAIRO_CONTENT_COLOR_ALPHA, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3123 event->width, event->height); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3124 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3125 gtk_widget_queue_draw(widget); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3126 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3127 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3128 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3129 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3130 |
7 | 3131 /* |
3132 * Callback routine for the "delete_event" signal on the toplevel window. | |
3133 * Tries to vim gracefully, or refuses to exit with changed buffers. | |
3134 */ | |
3135 static gint | |
1884 | 3136 delete_event_cb(GtkWidget *widget UNUSED, |
3137 GdkEventAny *event UNUSED, | |
3138 gpointer data UNUSED) | |
7 | 3139 { |
3140 gui_shell_closed(); | |
3141 return TRUE; | |
3142 } | |
3143 | |
685 | 3144 #if defined(FEAT_MENU) || defined(FEAT_TOOLBAR) || defined(FEAT_GUI_TABLINE) |
3145 static int | |
3146 get_item_dimensions(GtkWidget *widget, GtkOrientation orientation) | |
3147 { | |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3148 # ifdef FEAT_GUI_GNOME |
685 | 3149 GtkOrientation item_orientation = GTK_ORIENTATION_HORIZONTAL; |
3150 | |
3151 if (using_gnome && widget != NULL) | |
3152 { | |
856 | 3153 GtkWidget *parent; |
685 | 3154 BonoboDockItem *dockitem; |
3155 | |
791 | 3156 parent = gtk_widget_get_parent(widget); |
856 | 3157 if (G_TYPE_FROM_INSTANCE(parent) == BONOBO_TYPE_DOCK_ITEM) |
3158 { | |
3159 /* Only menu & toolbar are dock items. Could tabline be? | |
3160 * Seem to be only the 2 defined in GNOME */ | |
3161 widget = parent; | |
3162 dockitem = BONOBO_DOCK_ITEM(widget); | |
3163 | |
3164 if (dockitem == NULL || dockitem->is_floating) | |
3165 return 0; | |
3166 item_orientation = bonobo_dock_item_get_orientation(dockitem); | |
3167 } | |
685 | 3168 } |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3169 # else |
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3170 # define item_orientation GTK_ORIENTATION_HORIZONTAL |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3171 # endif |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3172 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3173 # 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
|
3174 if (widget != NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3175 && item_orientation == orientation |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3176 && gtk_widget_get_realized(widget) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3177 && gtk_widget_get_visible(widget)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3178 # else |
685 | 3179 if (widget != NULL |
3180 && item_orientation == orientation | |
3181 && GTK_WIDGET_REALIZED(widget) | |
3182 && GTK_WIDGET_VISIBLE(widget)) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3183 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3184 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3185 # 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
|
3186 GtkAllocation allocation; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3187 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3188 gtk_widget_get_allocation(widget, &allocation); |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3189 return allocation.height; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3190 # else |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3191 # ifdef FEAT_GUI_GNOME |
685 | 3192 if (orientation == GTK_ORIENTATION_HORIZONTAL) |
3193 return widget->allocation.height; | |
3194 else | |
3195 return widget->allocation.width; | |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3196 # else |
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3197 return widget->allocation.height; |
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3198 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3199 # endif |
685 | 3200 } |
3201 return 0; | |
3202 } | |
3203 #endif | |
3204 | |
3205 static int | |
3206 get_menu_tool_width(void) | |
3207 { | |
3208 int width = 0; | |
3209 | |
3210 #ifdef FEAT_GUI_GNOME /* these are never vertical without GNOME */ | |
3211 # ifdef FEAT_MENU | |
3212 width += get_item_dimensions(gui.menubar, GTK_ORIENTATION_VERTICAL); | |
3213 # endif | |
3214 # ifdef FEAT_TOOLBAR | |
3215 width += get_item_dimensions(gui.toolbar, GTK_ORIENTATION_VERTICAL); | |
3216 # endif | |
3217 # ifdef FEAT_GUI_TABLINE | |
782 | 3218 if (gui.tabline != NULL) |
3219 width += get_item_dimensions(gui.tabline, GTK_ORIENTATION_VERTICAL); | |
685 | 3220 # endif |
3221 #endif | |
3222 | |
3223 return width; | |
3224 } | |
3225 | |
3226 static int | |
3227 get_menu_tool_height(void) | |
3228 { | |
3229 int height = 0; | |
3230 | |
3231 #ifdef FEAT_MENU | |
3232 height += get_item_dimensions(gui.menubar, GTK_ORIENTATION_HORIZONTAL); | |
3233 #endif | |
3234 #ifdef FEAT_TOOLBAR | |
3235 height += get_item_dimensions(gui.toolbar, GTK_ORIENTATION_HORIZONTAL); | |
3236 #endif | |
3237 #ifdef FEAT_GUI_TABLINE | |
782 | 3238 if (gui.tabline != NULL) |
3239 height += get_item_dimensions(gui.tabline, GTK_ORIENTATION_HORIZONTAL); | |
685 | 3240 #endif |
3241 | |
3242 return height; | |
3243 } | |
3244 | |
791 | 3245 /* This controls whether we can set the real window hints at |
3246 * start-up when in a GtkPlug. | |
3247 * 0 = normal processing (default) | |
3248 * 1 = init. hints set, no-one's tried to reset since last check | |
3249 * 2 = init. hints set, attempt made to change hints | |
3250 */ | |
3251 static int init_window_hints_state = 0; | |
3252 | |
685 | 3253 static void |
791 | 3254 update_window_manager_hints(int force_width, int force_height) |
685 | 3255 { |
3256 static int old_width = 0; | |
3257 static int old_height = 0; | |
791 | 3258 static int old_min_width = 0; |
3259 static int old_min_height = 0; | |
685 | 3260 static int old_char_width = 0; |
3261 static int old_char_height = 0; | |
3262 | |
3263 int width; | |
3264 int height; | |
791 | 3265 int min_width; |
3266 int min_height; | |
3267 | |
3268 /* At start-up, don't try to set the hints until the initial | |
3269 * values have been used (those that dictate our initial size) | |
1884 | 3270 * Let forced (i.e., correct) values through always. |
791 | 3271 */ |
3272 if (!(force_width && force_height) && init_window_hints_state > 0) | |
3273 { | |
856 | 3274 /* Don't do it! */ |
3275 init_window_hints_state = 2; | |
3276 return; | |
791 | 3277 } |
685 | 3278 |
3279 /* This also needs to be done when the main window isn't there yet, | |
3280 * otherwise the hints don't work. */ | |
3281 width = gui_get_base_width(); | |
3282 height = gui_get_base_height(); | |
3283 # ifdef FEAT_MENU | |
3284 height += tabline_height() * gui.char_height; | |
3285 # endif | |
3286 width += get_menu_tool_width(); | |
3287 height += get_menu_tool_height(); | |
3288 | |
791 | 3289 /* GtkSockets use GtkPlug's [gui,mainwin] min-size hints to determine |
1226 | 3290 * their actual widget size. When we set our size ourselves (e.g., |
791 | 3291 * 'set columns=' or init. -geom) we briefly set the min. to the size |
3292 * we wish to be instead of the legitimate minimum so that we actually | |
3293 * resize correctly. | |
3294 */ | |
3295 if (force_width && force_height) | |
3296 { | |
856 | 3297 min_width = force_width; |
3298 min_height = force_height; | |
791 | 3299 } |
3300 else | |
3301 { | |
856 | 3302 min_width = width + MIN_COLUMNS * gui.char_width; |
3303 min_height = height + MIN_LINES * gui.char_height; | |
791 | 3304 } |
3305 | |
685 | 3306 /* Avoid an expose event when the size didn't change. */ |
3307 if (width != old_width | |
3308 || height != old_height | |
856 | 3309 || min_width != old_min_width |
791 | 3310 || min_height != old_min_height |
685 | 3311 || gui.char_width != old_char_width |
3312 || gui.char_height != old_char_height) | |
3313 { | |
3314 GdkGeometry geometry; | |
3315 GdkWindowHints geometry_mask; | |
3316 | |
3317 geometry.width_inc = gui.char_width; | |
3318 geometry.height_inc = gui.char_height; | |
3319 geometry.base_width = width; | |
3320 geometry.base_height = height; | |
856 | 3321 geometry.min_width = min_width; |
3322 geometry.min_height = min_height; | |
685 | 3323 geometry_mask = GDK_HINT_BASE_SIZE|GDK_HINT_RESIZE_INC |
3324 |GDK_HINT_MIN_SIZE; | |
3325 /* Using gui.formwin as geometry widget doesn't work as expected | |
3326 * with GTK+ 2 -- dunno why. Presumably all the resizing hacks | |
3327 * in Vim confuse GTK+. */ | |
3328 gtk_window_set_geometry_hints(GTK_WINDOW(gui.mainwin), gui.mainwin, | |
3329 &geometry, geometry_mask); | |
856 | 3330 old_width = width; |
3331 old_height = height; | |
3332 old_min_width = min_width; | |
3333 old_min_height = min_height; | |
3334 old_char_width = gui.char_width; | |
3335 old_char_height = gui.char_height; | |
685 | 3336 } |
3337 } | |
3338 | |
7 | 3339 #ifdef FEAT_TOOLBAR |
3340 | |
3341 /* | |
3342 * This extra effort wouldn't be necessary if we only used stock icons in the | |
3343 * toolbar, as we do for all builtin icons. But user-defined toolbar icons | |
3344 * shouldn't be treated differently, thus we do need this. | |
3345 */ | |
3346 static void | |
3347 icon_size_changed_foreach(GtkWidget *widget, gpointer user_data) | |
3348 { | |
3349 if (GTK_IS_IMAGE(widget)) | |
3350 { | |
3351 GtkImage *image = (GtkImage *)widget; | |
3352 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3353 # 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
|
3354 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
|
3355 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3356 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
|
3357 const gchar *icon_name; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3358 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3359 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
|
3360 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3361 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
|
3362 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3363 # else |
7 | 3364 /* User-defined icons are stored in a GtkIconSet */ |
3365 if (gtk_image_get_storage_type(image) == GTK_IMAGE_ICON_SET) | |
3366 { | |
3367 GtkIconSet *icon_set; | |
3368 GtkIconSize icon_size; | |
3369 | |
3370 gtk_image_get_icon_set(image, &icon_set, &icon_size); | |
3371 icon_size = (GtkIconSize)(long)user_data; | |
3372 | |
3373 gtk_icon_set_ref(icon_set); | |
3374 gtk_image_set_from_icon_set(image, icon_set, icon_size); | |
3375 gtk_icon_set_unref(icon_set); | |
3376 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3377 # endif |
7 | 3378 } |
3379 else if (GTK_IS_CONTAINER(widget)) | |
3380 { | |
3381 gtk_container_foreach((GtkContainer *)widget, | |
3382 &icon_size_changed_foreach, | |
3383 user_data); | |
3384 } | |
3385 } | |
3386 | |
3387 static void | |
3388 set_toolbar_style(GtkToolbar *toolbar) | |
3389 { | |
3390 GtkToolbarStyle style; | |
3391 GtkIconSize size; | |
3392 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
|
3393 |
7 | 3394 if ((toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS | TOOLBAR_HORIZ)) |
3395 == (TOOLBAR_TEXT | TOOLBAR_ICONS | TOOLBAR_HORIZ)) | |
3396 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
|
3397 else if ((toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS)) |
7 | 3398 == (TOOLBAR_TEXT | TOOLBAR_ICONS)) |
3399 style = GTK_TOOLBAR_BOTH; | |
3400 else if (toolbar_flags & TOOLBAR_TEXT) | |
3401 style = GTK_TOOLBAR_TEXT; | |
3402 else | |
3403 style = GTK_TOOLBAR_ICONS; | |
3404 | |
3405 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
|
3406 # if !GTK_CHECK_VERSION(3,0,0) |
7 | 3407 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
|
3408 # endif |
7 | 3409 |
3410 switch (tbis_flags) | |
3411 { | |
3412 case TBIS_TINY: size = GTK_ICON_SIZE_MENU; break; | |
3413 case TBIS_SMALL: size = GTK_ICON_SIZE_SMALL_TOOLBAR; break; | |
3414 case TBIS_MEDIUM: size = GTK_ICON_SIZE_BUTTON; break; | |
3415 case TBIS_LARGE: size = GTK_ICON_SIZE_LARGE_TOOLBAR; break; | |
8469
42020d59a432
commit https://github.com/vim/vim/commit/beb003b303cde1e55634aae9f810535684b76211
Christian Brabandt <cb@256bit.org>
parents:
8412
diff
changeset
|
3416 case TBIS_HUGE: size = GTK_ICON_SIZE_DND; break; |
42020d59a432
commit https://github.com/vim/vim/commit/beb003b303cde1e55634aae9f810535684b76211
Christian Brabandt <cb@256bit.org>
parents:
8412
diff
changeset
|
3417 case TBIS_GIANT: size = GTK_ICON_SIZE_DIALOG; break; |
7 | 3418 default: size = GTK_ICON_SIZE_INVALID; break; |
3419 } | |
3420 oldsize = gtk_toolbar_get_icon_size(toolbar); | |
3421 | |
3422 if (size == GTK_ICON_SIZE_INVALID) | |
3423 { | |
3424 /* Let global user preferences decide the icon size. */ | |
3425 gtk_toolbar_unset_icon_size(toolbar); | |
3426 size = gtk_toolbar_get_icon_size(toolbar); | |
3427 } | |
3428 if (size != oldsize) | |
3429 { | |
3430 gtk_container_foreach(GTK_CONTAINER(toolbar), | |
3431 &icon_size_changed_foreach, | |
3432 GINT_TO_POINTER((int)size)); | |
3433 } | |
3434 gtk_toolbar_set_icon_size(toolbar, size); | |
3435 } | |
3436 | |
3437 #endif /* FEAT_TOOLBAR */ | |
3438 | |
685 | 3439 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
3440 static int ignore_tabline_evt = FALSE; | |
689 | 3441 static GtkWidget *tabline_menu; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3442 # if !GTK_CHECK_VERSION(3,0,0) |
846 | 3443 static GtkTooltips *tabline_tooltip; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3444 # endif |
689 | 3445 static int clicked_page; /* page clicked in tab line */ |
3446 | |
3447 /* | |
3448 * Handle selecting an item in the tab line popup menu. | |
3449 */ | |
3450 static void | |
1884 | 3451 tabline_menu_handler(GtkMenuItem *item UNUSED, gpointer user_data) |
689 | 3452 { |
3453 /* Add the string cmd into input buffer */ | |
824 | 3454 send_tabline_menu_event(clicked_page, (int)(long)user_data); |
689 | 3455 } |
3456 | |
851 | 3457 static void |
3458 add_tabline_menu_item(GtkWidget *menu, char_u *text, int resp) | |
3459 { | |
3460 GtkWidget *item; | |
3461 char_u *utf_text; | |
3462 | |
3463 utf_text = CONVERT_TO_UTF8(text); | |
3464 item = gtk_menu_item_new_with_label((const char *)utf_text); | |
3465 gtk_widget_show(item); | |
3466 CONVERT_TO_UTF8_FREE(utf_text); | |
3467 | |
3468 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
|
3469 # 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
|
3470 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
|
3471 G_CALLBACK(tabline_menu_handler), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3472 GINT_TO_POINTER(resp)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3473 # else |
851 | 3474 gtk_signal_connect(GTK_OBJECT(item), "activate", |
3475 GTK_SIGNAL_FUNC(tabline_menu_handler), | |
1660 | 3476 (gpointer)(long)resp); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3477 # endif |
851 | 3478 } |
3479 | |
689 | 3480 /* |
3481 * Create a menu for the tab line. | |
3482 */ | |
3483 static GtkWidget * | |
3484 create_tabline_menu(void) | |
3485 { | |
851 | 3486 GtkWidget *menu; |
689 | 3487 |
3488 menu = gtk_menu_new(); | |
6819 | 3489 if (first_tabpage->tp_next != NULL) |
3490 add_tabline_menu_item(menu, (char_u *)_("Close tab"), | |
3491 TABLINE_MENU_CLOSE); | |
851 | 3492 add_tabline_menu_item(menu, (char_u *)_("New tab"), TABLINE_MENU_NEW); |
3493 add_tabline_menu_item(menu, (char_u *)_("Open Tab..."), TABLINE_MENU_OPEN); | |
689 | 3494 |
3495 return menu; | |
3496 } | |
3497 | |
3498 static gboolean | |
3499 on_tabline_menu(GtkWidget *widget, GdkEvent *event) | |
3500 { | |
3501 /* Was this button press event ? */ | |
3502 if (event->type == GDK_BUTTON_PRESS) | |
3503 { | |
3504 GdkEventButton *bevent = (GdkEventButton *)event; | |
3505 int x = bevent->x; | |
851 | 3506 int y = bevent->y; |
3507 GtkWidget *tabwidget; | |
3508 GdkWindow *tabwin; | |
689 | 3509 |
844 | 3510 /* When ignoring events return TRUE so that the selected page doesn't |
3511 * change. */ | |
3512 if (hold_gui_events | |
3513 # ifdef FEAT_CMDWIN | |
3514 || cmdwin_type != 0 | |
3515 # endif | |
3516 ) | |
3517 return TRUE; | |
3518 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3519 # 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
|
3520 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
|
3521 # else |
851 | 3522 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
|
3523 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3524 |
851 | 3525 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
|
3526 # 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
|
3527 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
|
3528 "tab_num")); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3529 # else |
851 | 3530 clicked_page = (int)(long)gtk_object_get_user_data( |
3531 GTK_OBJECT(tabwidget)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3532 # endif |
689 | 3533 |
3534 /* If the event was generated for 3rd button popup the menu. */ | |
3535 if (bevent->button == 3) | |
3536 { | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3537 # if GTK_CHECK_VERSION(3,22,2) |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3538 gtk_menu_popup_at_pointer(GTK_MENU(widget), event); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3539 # else |
689 | 3540 gtk_menu_popup(GTK_MENU(widget), NULL, NULL, NULL, NULL, |
3541 bevent->button, bevent->time); | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3542 # endif |
689 | 3543 /* We handled the event. */ |
3544 return TRUE; | |
3545 } | |
868 | 3546 else if (bevent->button == 1) |
693 | 3547 { |
868 | 3548 if (clicked_page == 0) |
3549 { | |
1394 | 3550 /* Click after all tabs moves to next tab page. When "x" is |
3551 * 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
|
3552 send_tabline_event(x < 50 ? -1 : 0); |
868 | 3553 } |
693 | 3554 } |
689 | 3555 } |
844 | 3556 |
689 | 3557 /* We didn't handle the event. */ |
3558 return FALSE; | |
3559 } | |
685 | 3560 |
3561 /* | |
3562 * Handle selecting one of the tabs. | |
3563 */ | |
3564 static void | |
3565 on_select_tab( | |
1884 | 3566 GtkNotebook *notebook UNUSED, |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3567 # 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
|
3568 gpointer *page UNUSED, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3569 # else |
1884 | 3570 GtkNotebookPage *page UNUSED, |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3571 # endif |
944 | 3572 gint idx, |
1884 | 3573 gpointer data UNUSED) |
685 | 3574 { |
3575 if (!ignore_tabline_evt) | |
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
|
3576 send_tabline_event(idx + 1); |
12666
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3577 } |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3578 |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3579 /* |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3580 * Handle reordering the tabs (using D&D). |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3581 */ |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3582 static void |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3583 on_tab_reordered( |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3584 GtkNotebook *notebook UNUSED, |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3585 # if GTK_CHECK_VERSION(3,0,0) |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3586 gpointer *page UNUSED, |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3587 # else |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3588 GtkNotebookPage *page UNUSED, |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3589 # endif |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3590 gint idx, |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3591 gpointer data UNUSED) |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3592 { |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3593 if (!ignore_tabline_evt) |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3594 { |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3595 if ((tabpage_index(curtab) - 1) < idx) |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3596 tabpage_move(idx + 1); |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3597 else |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3598 tabpage_move(idx); |
693 | 3599 } |
685 | 3600 } |
3601 | |
3602 /* | |
3603 * Show or hide the tabline. | |
3604 */ | |
3605 void | |
3606 gui_mch_show_tabline(int showit) | |
3607 { | |
3608 if (gui.tabline == NULL) | |
3609 return; | |
3610 | |
3611 if (!showit != !gtk_notebook_get_show_tabs(GTK_NOTEBOOK(gui.tabline))) | |
3612 { | |
708 | 3613 /* Note: this may cause a resize event */ |
685 | 3614 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gui.tabline), showit); |
791 | 3615 update_window_manager_hints(0, 0); |
868 | 3616 if (showit) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3617 # 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
|
3618 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
|
3619 # else |
868 | 3620 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
|
3621 # endif |
868 | 3622 } |
3623 | |
3624 gui_mch_update(); | |
685 | 3625 } |
3626 | |
3627 /* | |
708 | 3628 * Return TRUE when tabline is displayed. |
3629 */ | |
3630 int | |
3631 gui_mch_showing_tabline(void) | |
3632 { | |
3633 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
|
3634 && gtk_notebook_get_show_tabs(GTK_NOTEBOOK(gui.tabline)); |
708 | 3635 } |
3636 | |
3637 /* | |
685 | 3638 * Update the labels of the tabline. |
3639 */ | |
3640 void | |
3641 gui_mch_update_tabline(void) | |
3642 { | |
3643 GtkWidget *page; | |
846 | 3644 GtkWidget *event_box; |
685 | 3645 GtkWidget *label; |
3646 tabpage_T *tp; | |
3647 int nr = 0; | |
851 | 3648 int tab_num; |
685 | 3649 int curtabidx = 0; |
836 | 3650 char_u *labeltext; |
685 | 3651 |
3652 if (gui.tabline == NULL) | |
3653 return; | |
3654 | |
3655 ignore_tabline_evt = TRUE; | |
3656 | |
3657 /* Add a label for each tab page. They all contain the same text area. */ | |
3658 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr) | |
3659 { | |
3660 if (tp == curtab) | |
3661 curtabidx = nr; | |
3662 | |
851 | 3663 tab_num = nr + 1; |
3664 | |
685 | 3665 page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr); |
3666 if (page == NULL) | |
3667 { | |
3668 /* Add notebook page */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3669 # 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
|
3670 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
|
3671 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
|
3672 # else |
685 | 3673 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
|
3674 # endif |
685 | 3675 gtk_widget_show(page); |
846 | 3676 event_box = gtk_event_box_new(); |
3677 gtk_widget_show(event_box); | |
685 | 3678 label = gtk_label_new("-Empty-"); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3679 # if !GTK_CHECK_VERSION(3,14,0) |
851 | 3680 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
|
3681 # endif |
846 | 3682 gtk_container_add(GTK_CONTAINER(event_box), label); |
685 | 3683 gtk_widget_show(label); |
3684 gtk_notebook_insert_page(GTK_NOTEBOOK(gui.tabline), | |
3685 page, | |
846 | 3686 event_box, |
685 | 3687 nr++); |
12666
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3688 gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(gui.tabline), |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3689 page, |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3690 TRUE); |
685 | 3691 } |
3692 | |
846 | 3693 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
|
3694 # 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
|
3695 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
|
3696 GINT_TO_POINTER(tab_num)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3697 # else |
1660 | 3698 gtk_object_set_user_data(GTK_OBJECT(event_box), |
3699 (gpointer)(long)tab_num); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3700 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3701 # 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
|
3702 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
|
3703 # else |
846 | 3704 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
|
3705 # endif |
839 | 3706 get_tabline_label(tp, FALSE); |
836 | 3707 labeltext = CONVERT_TO_UTF8(NameBuff); |
846 | 3708 gtk_label_set_text(GTK_LABEL(label), (const char *)labeltext); |
836 | 3709 CONVERT_TO_UTF8_FREE(labeltext); |
846 | 3710 |
3711 get_tabline_label(tp, TRUE); | |
3712 labeltext = CONVERT_TO_UTF8(NameBuff); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3713 # 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
|
3714 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
|
3715 # else |
846 | 3716 gtk_tooltips_set_tip(GTK_TOOLTIPS(tabline_tooltip), event_box, |
3717 (const char *)labeltext, NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3718 # endif |
846 | 3719 CONVERT_TO_UTF8_FREE(labeltext); |
685 | 3720 } |
3721 | |
3722 /* Remove any old labels. */ | |
3723 while (gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr) != NULL) | |
3724 gtk_notebook_remove_page(GTK_NOTEBOOK(gui.tabline), nr); | |
3725 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3726 # 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
|
3727 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
|
3728 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
|
3729 # else |
685 | 3730 if (gtk_notebook_current_page(GTK_NOTEBOOK(gui.tabline)) != curtabidx) |
856 | 3731 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
|
3732 # endif |
685 | 3733 |
851 | 3734 /* Make sure everything is in place before drawing text. */ |
3735 gui_mch_update(); | |
3736 | |
685 | 3737 ignore_tabline_evt = FALSE; |
3738 } | |
3739 | |
3740 /* | |
3741 * Set the current tab to "nr". First tab is 1. | |
3742 */ | |
3743 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
3744 gui_mch_set_curtab(int nr) |
685 | 3745 { |
3746 if (gui.tabline == NULL) | |
3747 return; | |
3748 | |
3749 ignore_tabline_evt = TRUE; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3750 # 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
|
3751 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
|
3752 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
|
3753 # else |
685 | 3754 if (gtk_notebook_current_page(GTK_NOTEBOOK(gui.tabline)) != nr - 1) |
856 | 3755 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
|
3756 # endif |
685 | 3757 ignore_tabline_evt = FALSE; |
3758 } | |
3759 | |
3760 #endif /* FEAT_GUI_TABLINE */ | |
3761 | |
7 | 3762 /* |
2183 | 3763 * Add selection targets for PRIMARY and CLIPBOARD selections. |
3764 */ | |
3765 void | |
3766 gui_gtk_set_selection_targets(void) | |
3767 { | |
3768 int i, j = 0; | |
3769 int n_targets = N_SELECTION_TARGETS; | |
3770 GtkTargetEntry targets[N_SELECTION_TARGETS]; | |
3771 | |
3772 for (i = 0; i < (int)N_SELECTION_TARGETS; ++i) | |
3773 { | |
3518 | 3774 /* OpenOffice tries to use TARGET_HTML and fails when we don't |
2183 | 3775 * return something, instead of trying another target. Therefore only |
3776 * offer TARGET_HTML when it works. */ | |
3777 if (!clip_html && selection_targets[i].info == TARGET_HTML) | |
3778 n_targets--; | |
3779 else | |
3780 targets[j++] = selection_targets[i]; | |
3781 } | |
3782 | |
3783 gtk_selection_clear_targets(gui.drawarea, (GdkAtom)GDK_SELECTION_PRIMARY); | |
3784 gtk_selection_clear_targets(gui.drawarea, (GdkAtom)clip_plus.gtk_sel_atom); | |
3785 gtk_selection_add_targets(gui.drawarea, | |
3786 (GdkAtom)GDK_SELECTION_PRIMARY, | |
3787 targets, n_targets); | |
3788 gtk_selection_add_targets(gui.drawarea, | |
3789 (GdkAtom)clip_plus.gtk_sel_atom, | |
3790 targets, n_targets); | |
3791 } | |
3792 | |
3793 /* | |
3794 * Set up for receiving DND items. | |
3795 */ | |
3796 void | |
3797 gui_gtk_set_dnd_targets(void) | |
3798 { | |
3799 int i, j = 0; | |
3800 int n_targets = N_DND_TARGETS; | |
3801 GtkTargetEntry targets[N_DND_TARGETS]; | |
3802 | |
3803 for (i = 0; i < (int)N_DND_TARGETS; ++i) | |
3804 { | |
3154 | 3805 if (!clip_html && dnd_targets[i].info == TARGET_HTML) |
2183 | 3806 n_targets--; |
3807 else | |
3808 targets[j++] = dnd_targets[i]; | |
3809 } | |
3810 | |
3811 gtk_drag_dest_unset(gui.drawarea); | |
3812 gtk_drag_dest_set(gui.drawarea, | |
3813 GTK_DEST_DEFAULT_ALL, | |
3814 targets, n_targets, | |
2718 | 3815 GDK_ACTION_COPY | GDK_ACTION_MOVE); |
2183 | 3816 } |
3817 | |
3818 /* | |
7 | 3819 * Initialize the GUI. Create all the windows, set up all the callbacks etc. |
3820 * Returns OK for success, FAIL when the GUI can't be started. | |
3821 */ | |
3822 int | |
3823 gui_mch_init(void) | |
3824 { | |
3825 GtkWidget *vbox; | |
3826 | |
3827 #ifdef FEAT_GUI_GNOME | |
3828 /* Initialize the GNOME libraries. gnome_program_init()/gnome_init() | |
3829 * exits on failure, but that's a non-issue because we already called | |
3830 * gtk_init_check() in gui_mch_init_check(). */ | |
3831 if (using_gnome) | |
4045 | 3832 { |
7 | 3833 gnome_program_init(VIMPACKAGE, VIM_VERSION_SHORT, |
3834 LIBGNOMEUI_MODULE, gui_argc, gui_argv, NULL); | |
4045 | 3835 # if defined(FEAT_FLOAT) && defined(LC_NUMERIC) |
5854 | 3836 { |
3837 char *p = setlocale(LC_NUMERIC, NULL); | |
3838 | |
3839 /* Make sure strtod() uses a decimal point, not a comma. Gnome | |
3840 * init may change it. */ | |
3841 if (p == NULL || strcmp(p, "C") != 0) | |
3842 setlocale(LC_NUMERIC, "C"); | |
3843 } | |
4045 | 3844 # endif |
3845 } | |
7 | 3846 #endif |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13152
diff
changeset
|
3847 VIM_CLEAR(gui_argv); |
7 | 3848 |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3849 #if GLIB_CHECK_VERSION(2,1,3) |
7 | 3850 /* Set the human-readable application name */ |
3851 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
|
3852 #endif |
7 | 3853 /* |
3854 * Force UTF-8 output no matter what the value of 'encoding' is. | |
3855 * did_set_string_option() in option.c prohibits changing 'termencoding' | |
3856 * to something else than UTF-8 if the GUI is in use. | |
3857 */ | |
3858 set_option_value((char_u *)"termencoding", 0L, (char_u *)"utf-8", 0); | |
3859 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3860 #ifdef FEAT_TOOLBAR |
7 | 3861 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
|
3862 #endif |
7 | 3863 /* FIXME: Need to install the classic icons and a gtkrc.classic file. |
3864 * 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
|
3865 #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
|
3866 # if 0 |
7 | 3867 gtk_rc_parse("gtkrc"); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3868 # endif |
7 | 3869 #endif |
3870 | |
3871 /* Initialize values */ | |
3872 gui.border_width = 2; | |
3873 gui.scrollbar_width = SB_DEFAULT_WIDTH; | |
3874 gui.scrollbar_height = SB_DEFAULT_WIDTH; | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
3875 #if GTK_CHECK_VERSION(3,0,0) |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
3876 gui.fgcolor = g_new(GdkRGBA, 1); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
3877 gui.bgcolor = g_new(GdkRGBA, 1); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
3878 gui.spcolor = g_new(GdkRGBA, 1); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
3879 #else |
136 | 3880 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
7 | 3881 gui.fgcolor = g_new0(GdkColor, 1); |
136 | 3882 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
7 | 3883 gui.bgcolor = g_new0(GdkColor, 1); |
207 | 3884 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
3885 gui.spcolor = g_new0(GdkColor, 1); | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
3886 #endif |
7 | 3887 |
3888 /* Initialise atoms */ | |
1904 | 3889 html_atom = gdk_atom_intern("text/html", FALSE); |
7 | 3890 utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE); |
3891 | |
3892 /* Set default foreground and background colors. */ | |
3893 gui.norm_pixel = gui.def_norm_pixel; | |
3894 gui.back_pixel = gui.def_back_pixel; | |
3895 | |
3896 if (gtk_socket_id != 0) | |
3897 { | |
3898 GtkWidget *plug; | |
3899 | |
3900 /* Use GtkSocket from another app. */ | |
3901 plug = gtk_plug_new_for_display(gdk_display_get_default(), | |
3902 gtk_socket_id); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3903 #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
|
3904 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
|
3905 #else |
7 | 3906 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
|
3907 #endif |
7 | 3908 { |
3909 gui.mainwin = plug; | |
3910 } | |
3911 else | |
3912 { | |
3913 g_warning("Connection to GTK+ socket (ID %u) failed", | |
3914 (unsigned int)gtk_socket_id); | |
3915 /* Pretend we never wanted it if it failed (get own window) */ | |
3916 gtk_socket_id = 0; | |
3917 } | |
3918 } | |
3919 | |
3920 if (gtk_socket_id == 0) | |
3921 { | |
3922 #ifdef FEAT_GUI_GNOME | |
3923 if (using_gnome) | |
3924 { | |
3925 gui.mainwin = gnome_app_new("Vim", NULL); | |
3926 # ifdef USE_XSMP | |
3927 /* Use the GNOME save-yourself functionality now. */ | |
3928 xsmp_close(); | |
3929 # endif | |
3930 } | |
3931 else | |
3932 #endif | |
3933 gui.mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
3934 } | |
3935 | |
3936 gtk_widget_set_name(gui.mainwin, "vim-main-window"); | |
3937 | |
3938 /* Create the PangoContext used for drawing all text. */ | |
3939 gui.text_context = gtk_widget_create_pango_context(gui.mainwin); | |
3940 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
|
3941 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3942 #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
|
3943 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
|
3944 #else |
7 | 3945 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
|
3946 #endif |
7 | 3947 gtk_widget_add_events(gui.mainwin, GDK_VISIBILITY_NOTIFY_MASK); |
3948 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3949 #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
|
3950 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
|
3951 G_CALLBACK(&delete_event_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3952 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3953 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
|
3954 G_CALLBACK(&mainwin_realize), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3955 #else |
7 | 3956 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "delete_event", |
3957 GTK_SIGNAL_FUNC(&delete_event_cb), NULL); | |
3958 | |
3959 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "realize", | |
3960 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
|
3961 #endif |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3962 |
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3963 g_signal_connect(G_OBJECT(gui.mainwin), "screen-changed", |
7 | 3964 G_CALLBACK(&mainwin_screen_changed_cb), NULL); |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3965 |
7 | 3966 gui.accel_group = gtk_accel_group_new(); |
3967 gtk_window_add_accel_group(GTK_WINDOW(gui.mainwin), gui.accel_group); | |
3968 | |
685 | 3969 /* 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
|
3970 #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
|
3971 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
|
3972 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
|
3973 #else |
7 | 3974 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
|
3975 #endif |
7 | 3976 |
3977 #ifdef FEAT_GUI_GNOME | |
3978 if (using_gnome) | |
3979 { | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3980 # if defined(FEAT_MENU) |
7 | 3981 /* automagically restore menubar/toolbar placement */ |
3982 gnome_app_enable_layout_config(GNOME_APP(gui.mainwin), TRUE); | |
3983 # endif | |
3984 gnome_app_set_contents(GNOME_APP(gui.mainwin), vbox); | |
3985 } | |
3986 else | |
3987 #endif | |
3988 { | |
3989 gtk_container_add(GTK_CONTAINER(gui.mainwin), vbox); | |
3990 gtk_widget_show(vbox); | |
3991 } | |
3992 | |
3993 #ifdef FEAT_MENU | |
3994 /* | |
3995 * Create the menubar and handle | |
3996 */ | |
3997 gui.menubar = gtk_menu_bar_new(); | |
3998 gtk_widget_set_name(gui.menubar, "vim-menubar"); | |
3999 | |
36 | 4000 /* Avoid that GTK takes <F10> away from us. */ |
4001 { | |
4002 GtkSettings *gtk_settings; | |
4003 | |
4004 gtk_settings = gtk_settings_get_for_screen(gdk_screen_get_default()); | |
4005 g_object_set(gtk_settings, "gtk-menu-bar-accel", NULL, NULL); | |
4006 } | |
4007 | |
4008 | |
7 | 4009 # ifdef FEAT_GUI_GNOME |
4010 if (using_gnome) | |
4011 { | |
4012 BonoboDockItem *dockitem; | |
4013 | |
4014 gnome_app_set_menus(GNOME_APP(gui.mainwin), GTK_MENU_BAR(gui.menubar)); | |
4015 dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), | |
4016 GNOME_APP_MENUBAR_NAME); | |
798 | 4017 /* We don't want the menu to float. */ |
4018 bonobo_dock_item_set_behavior(dockitem, | |
4019 bonobo_dock_item_get_behavior(dockitem) | |
4020 | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); | |
7 | 4021 gui.menubar_h = GTK_WIDGET(dockitem); |
4022 } | |
4023 else | |
4024 # endif /* FEAT_GUI_GNOME */ | |
4025 { | |
827 | 4026 /* Always show the menubar, otherwise <F10> doesn't work. It may be |
4027 * disabled in gui_init() later. */ | |
4028 gtk_widget_show(gui.menubar); | |
7 | 4029 gtk_box_pack_start(GTK_BOX(vbox), gui.menubar, FALSE, FALSE, 0); |
4030 } | |
4031 #endif /* FEAT_MENU */ | |
4032 | |
4033 #ifdef FEAT_TOOLBAR | |
4034 /* | |
4035 * Create the toolbar and handle | |
4036 */ | |
4037 /* some aesthetics on the toolbar */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4038 # ifdef USE_GTK3 |
8301
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4039 /* 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
|
4040 /* 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
|
4041 * 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
|
4042 # else |
7 | 4043 gtk_rc_parse_string( |
4044 "style \"vim-toolbar-style\" {\n" | |
4045 " GtkToolbar::button_relief = GTK_RELIEF_NONE\n" | |
4046 "}\n" | |
4047 "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
|
4048 # endif |
7 | 4049 gui.toolbar = gtk_toolbar_new(); |
4050 gtk_widget_set_name(gui.toolbar, "vim-toolbar"); | |
4051 set_toolbar_style(GTK_TOOLBAR(gui.toolbar)); | |
4052 | |
4053 # ifdef FEAT_GUI_GNOME | |
4054 if (using_gnome) | |
4055 { | |
4056 BonoboDockItem *dockitem; | |
4057 | |
4058 gnome_app_set_toolbar(GNOME_APP(gui.mainwin), GTK_TOOLBAR(gui.toolbar)); | |
4059 dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), | |
4060 GNOME_APP_TOOLBAR_NAME); | |
4061 gui.toolbar_h = GTK_WIDGET(dockitem); | |
795 | 4062 /* When the toolbar is floating it gets stuck. So long as that isn't |
798 | 4063 * fixed let's disallow floating. */ |
795 | 4064 bonobo_dock_item_set_behavior(dockitem, |
798 | 4065 bonobo_dock_item_get_behavior(dockitem) |
4066 | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); | |
7 | 4067 gtk_container_set_border_width(GTK_CONTAINER(gui.toolbar), 0); |
4068 } | |
4069 else | |
4070 # endif /* FEAT_GUI_GNOME */ | |
4071 { | |
4072 if (vim_strchr(p_go, GO_TOOLBAR) != NULL | |
4073 && (toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS))) | |
4074 gtk_widget_show(gui.toolbar); | |
4075 gtk_box_pack_start(GTK_BOX(vbox), gui.toolbar, FALSE, FALSE, 0); | |
4076 } | |
4077 #endif /* FEAT_TOOLBAR */ | |
4078 | |
685 | 4079 #ifdef FEAT_GUI_TABLINE |
782 | 4080 /* |
4081 * Use a Notebook for the tab pages labels. The labels are hidden by | |
4082 * default. | |
4083 */ | |
791 | 4084 gui.tabline = gtk_notebook_new(); |
4085 gtk_widget_show(gui.tabline); | |
4086 gtk_box_pack_start(GTK_BOX(vbox), gui.tabline, FALSE, FALSE, 0); | |
4087 gtk_notebook_set_show_border(GTK_NOTEBOOK(gui.tabline), FALSE); | |
4088 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gui.tabline), FALSE); | |
841 | 4089 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
|
4090 # if !GTK_CHECK_VERSION(3,0,0) |
868 | 4091 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
|
4092 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4093 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4094 # if !GTK_CHECK_VERSION(3,0,0) |
846 | 4095 tabline_tooltip = gtk_tooltips_new(); |
4096 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
|
4097 # endif |
846 | 4098 |
4099 { | |
4100 GtkWidget *page, *label, *event_box; | |
791 | 4101 |
856 | 4102 /* Add the first tab. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4103 # 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
|
4104 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
|
4105 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
|
4106 # else |
846 | 4107 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
|
4108 # endif |
846 | 4109 gtk_widget_show(page); |
4110 gtk_container_add(GTK_CONTAINER(gui.tabline), page); | |
4111 label = gtk_label_new("-Empty-"); | |
4112 gtk_widget_show(label); | |
4113 event_box = gtk_event_box_new(); | |
4114 gtk_widget_show(event_box); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4115 # 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
|
4116 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
|
4117 # else |
1660 | 4118 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
|
4119 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4120 # if !GTK_CHECK_VERSION(3,14,0) |
851 | 4121 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
|
4122 # endif |
846 | 4123 gtk_container_add(GTK_CONTAINER(event_box), label); |
4124 gtk_notebook_set_tab_label(GTK_NOTEBOOK(gui.tabline), page, event_box); | |
12666
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
4125 gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(gui.tabline), page, TRUE); |
791 | 4126 } |
865 | 4127 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4128 # 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
|
4129 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
|
4130 G_CALLBACK(on_select_tab), NULL); |
12666
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
4131 g_signal_connect(G_OBJECT(gui.tabline), "page-reordered", |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
4132 G_CALLBACK(on_tab_reordered), NULL); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4133 # else |
791 | 4134 gtk_signal_connect(GTK_OBJECT(gui.tabline), "switch_page", |
856 | 4135 GTK_SIGNAL_FUNC(on_select_tab), NULL); |
12666
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
4136 gtk_signal_connect(GTK_OBJECT(gui.tabline), "page-reordered", |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
4137 GTK_SIGNAL_FUNC(on_tab_reordered), NULL); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4138 # endif |
791 | 4139 |
4140 /* Create a popup menu for the tab line and connect it. */ | |
4141 tabline_menu = create_tabline_menu(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4142 # 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
|
4143 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
|
4144 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
|
4145 # else |
791 | 4146 gtk_signal_connect_object(GTK_OBJECT(gui.tabline), "button_press_event", |
856 | 4147 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
|
4148 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4149 #endif /* FEAT_GUI_TABLINE */ |
685 | 4150 |
7 | 4151 gui.formwin = gtk_form_new(); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4152 #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
|
4153 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
|
4154 #else |
7 | 4155 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
|
4156 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4157 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 4158 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
|
4159 #endif |
7 | 4160 |
4161 gui.drawarea = gtk_drawing_area_new(); | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4162 #if GTK_CHECK_VERSION(3,22,2) |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4163 gtk_widget_set_name(gui.drawarea, "vim-gui-drawarea"); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4164 #endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4165 #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
|
4166 gui.surface = NULL; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4167 gui.by_signal = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4168 #endif |
7 | 4169 |
4170 /* Determine which events we will filter. */ | |
4171 gtk_widget_set_events(gui.drawarea, | |
4172 GDK_EXPOSURE_MASK | | |
4173 GDK_ENTER_NOTIFY_MASK | | |
4174 GDK_LEAVE_NOTIFY_MASK | | |
4175 GDK_BUTTON_PRESS_MASK | | |
4176 GDK_BUTTON_RELEASE_MASK | | |
4177 GDK_SCROLL_MASK | | |
4178 GDK_KEY_PRESS_MASK | | |
4179 GDK_KEY_RELEASE_MASK | | |
4180 GDK_POINTER_MOTION_MASK | | |
4181 GDK_POINTER_MOTION_HINT_MASK); | |
4182 | |
4183 gtk_widget_show(gui.drawarea); | |
4184 gtk_form_put(GTK_FORM(gui.formwin), gui.drawarea, 0, 0); | |
4185 gtk_widget_show(gui.formwin); | |
4186 gtk_box_pack_start(GTK_BOX(vbox), gui.formwin, TRUE, TRUE, 0); | |
4187 | |
4188 /* For GtkSockets, key-presses must go to the focus widget (drawarea) | |
4189 * and not the window. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4190 #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
|
4191 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
|
4192 : G_OBJECT(gui.drawarea), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4193 "key-press-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4194 G_CALLBACK(key_press_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4195 #else |
7 | 4196 gtk_signal_connect((gtk_socket_id == 0) ? GTK_OBJECT(gui.mainwin) |
4197 : GTK_OBJECT(gui.drawarea), | |
4198 "key_press_event", | |
4199 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
|
4200 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4201 #if defined(FEAT_XIM) || GTK_CHECK_VERSION(3,0,0) |
7 | 4202 /* Also forward key release events for the benefit of GTK+ 2 input |
4203 * modules. Try CTRL-SHIFT-xdigits to enter a Unicode code point. */ | |
4204 g_signal_connect((gtk_socket_id == 0) ? G_OBJECT(gui.mainwin) | |
4205 : G_OBJECT(gui.drawarea), | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4206 "key-release-event", |
7 | 4207 G_CALLBACK(&key_release_event), NULL); |
4208 #endif | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4209 #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
|
4210 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
|
4211 G_CALLBACK(drawarea_realize_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4212 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
|
4213 G_CALLBACK(drawarea_unrealize_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4214 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
|
4215 G_CALLBACK(drawarea_configure_event_cb), NULL); |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4216 # if GTK_CHECK_VERSION(3,22,2) |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4217 g_signal_connect_after(G_OBJECT(gui.drawarea), "style-updated", |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4218 G_CALLBACK(&drawarea_style_updated_cb), NULL); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4219 # else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4220 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
|
4221 G_CALLBACK(&drawarea_style_set_cb), NULL); |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4222 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4223 #else |
7 | 4224 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "realize", |
4225 GTK_SIGNAL_FUNC(drawarea_realize_cb), NULL); | |
4226 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "unrealize", | |
4227 GTK_SIGNAL_FUNC(drawarea_unrealize_cb), NULL); | |
4228 | |
4229 gtk_signal_connect_after(GTK_OBJECT(gui.drawarea), "style_set", | |
4230 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
|
4231 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4232 |
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) |
7 | 4234 gui.visibility = GDK_VISIBILITY_UNOBSCURED; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4235 #endif |
7 | 4236 |
4237 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
4238 wm_protocols_atom = gdk_atom_intern("WM_PROTOCOLS", FALSE); | |
4239 save_yourself_atom = gdk_atom_intern("WM_SAVE_YOURSELF", FALSE); | |
4240 #endif | |
4241 | |
4242 if (gtk_socket_id != 0) | |
1884 | 4243 /* 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
|
4244 #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
|
4245 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
|
4246 #else |
7 | 4247 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
|
4248 #endif |
7 | 4249 |
4250 /* | |
4251 * Set clipboard specific atoms | |
4252 */ | |
4253 vim_atom = gdk_atom_intern(VIM_ATOM_NAME, FALSE); | |
4254 vimenc_atom = gdk_atom_intern(VIMENC_ATOM_NAME, FALSE); | |
4255 clip_star.gtk_sel_atom = GDK_SELECTION_PRIMARY; | |
4256 clip_plus.gtk_sel_atom = gdk_atom_intern("CLIPBOARD", FALSE); | |
4257 | |
4258 /* | |
4259 * Start out by adding the configured border width into the border offset. | |
4260 */ | |
4261 gui.border_offset = gui.border_width; | |
4262 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4263 #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
|
4264 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
|
4265 G_CALLBACK(draw_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4266 #else |
7 | 4267 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "visibility_notify_event", |
4268 GTK_SIGNAL_FUNC(visibility_event), NULL); | |
4269 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "expose_event", | |
4270 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
|
4271 #endif |
7 | 4272 |
4273 /* | |
4274 * Only install these enter/leave callbacks when 'p' in 'guioptions'. | |
4275 * Only needed for some window managers. | |
4276 */ | |
4277 if (vim_strchr(p_go, GO_POINTER) != NULL) | |
4278 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4279 #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
|
4280 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
|
4281 G_CALLBACK(leave_notify_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4282 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
|
4283 G_CALLBACK(enter_notify_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4284 #else |
7 | 4285 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "leave_notify_event", |
4286 GTK_SIGNAL_FUNC(leave_notify_event), NULL); | |
4287 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "enter_notify_event", | |
4288 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
|
4289 #endif |
7 | 4290 } |
4291 | |
791 | 4292 /* Real windows can get focus ... GtkPlug, being a mere container can't, |
4293 * only its widgets. Arguably, this could be common code and we not use | |
4294 * the window focus at all, but let's be safe. | |
4295 */ | |
4296 if (gtk_socket_id == 0) | |
4297 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4298 #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
|
4299 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
|
4300 G_CALLBACK(focus_out_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4301 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
|
4302 G_CALLBACK(focus_in_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4303 #else |
856 | 4304 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "focus_out_event", |
4305 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
4306 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "focus_in_event", | |
4307 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
|
4308 #endif |
791 | 4309 } |
4310 else | |
4311 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4312 #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
|
4313 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
|
4314 G_CALLBACK(focus_out_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4315 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
|
4316 G_CALLBACK(focus_in_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4317 #else |
856 | 4318 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "focus_out_event", |
4319 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
4320 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "focus_in_event", | |
4321 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
|
4322 #endif |
791 | 4323 #ifdef FEAT_GUI_TABLINE |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4324 # 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
|
4325 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
|
4326 G_CALLBACK(focus_out_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4327 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
|
4328 G_CALLBACK(focus_in_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4329 # else |
856 | 4330 gtk_signal_connect(GTK_OBJECT(gui.tabline), "focus_out_event", |
4331 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
4332 gtk_signal_connect(GTK_OBJECT(gui.tabline), "focus_in_event", | |
4333 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
|
4334 # endif |
791 | 4335 #endif /* FEAT_GUI_TABLINE */ |
4336 } | |
7 | 4337 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4338 #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
|
4339 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
|
4340 G_CALLBACK(motion_notify_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4341 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
|
4342 G_CALLBACK(button_press_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4343 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
|
4344 G_CALLBACK(button_release_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4345 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
|
4346 G_CALLBACK(&scroll_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4347 #else |
7 | 4348 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "motion_notify_event", |
4349 GTK_SIGNAL_FUNC(motion_notify_event), NULL); | |
4350 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "button_press_event", | |
4351 GTK_SIGNAL_FUNC(button_press_event), NULL); | |
4352 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "button_release_event", | |
4353 GTK_SIGNAL_FUNC(button_release_event), NULL); | |
4354 g_signal_connect(G_OBJECT(gui.drawarea), "scroll_event", | |
4355 G_CALLBACK(&scroll_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4356 #endif |
7 | 4357 |
4358 /* | |
4359 * Add selection handler functions. | |
4360 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4361 #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
|
4362 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
|
4363 G_CALLBACK(selection_clear_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4364 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
|
4365 G_CALLBACK(selection_received_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4366 #else |
7 | 4367 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_clear_event", |
4368 GTK_SIGNAL_FUNC(selection_clear_event), NULL); | |
4369 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_received", | |
4370 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
|
4371 #endif |
7 | 4372 |
2183 | 4373 gui_gtk_set_selection_targets(); |
7 | 4374 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4375 #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
|
4376 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
|
4377 G_CALLBACK(selection_get_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4378 #else |
7 | 4379 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_get", |
4380 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
|
4381 #endif |
7 | 4382 |
4383 /* Pretend we don't have input focus, we will get an event if we do. */ | |
4384 gui.in_focus = FALSE; | |
4385 | |
4386 return OK; | |
4387 } | |
4388 | |
4389 #if (defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) || defined(PROTO) | |
4390 /* | |
4391 * This is called from gui_start() after a fork() has been done. | |
4392 * We have to tell the session manager our new PID. | |
4393 */ | |
4394 void | |
4395 gui_mch_forked(void) | |
4396 { | |
4397 if (using_gnome) | |
4398 { | |
4399 GnomeClient *client; | |
4400 | |
4401 client = gnome_master_client(); | |
4402 | |
4403 if (client != NULL) | |
4404 gnome_client_set_process_id(client, getpid()); | |
4405 } | |
4406 } | |
4407 #endif /* FEAT_GUI_GNOME && FEAT_SESSION */ | |
4408 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4409 #if GTK_CHECK_VERSION(3,0,0) |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4410 static GdkRGBA |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4411 color_to_rgba(guicolor_T color) |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4412 { |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4413 GdkRGBA rgba; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4414 rgba.red = ((color & 0xff0000) >> 16) / 255.0; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4415 rgba.green = ((color & 0xff00) >> 8) / 255.0; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4416 rgba.blue = ((color & 0xff)) / 255.0; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4417 rgba.alpha = 1.0; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4418 return rgba; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4419 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4420 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4421 static void |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4422 set_cairo_source_rgba_from_color(cairo_t *cr, guicolor_T color) |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4423 { |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4424 const GdkRGBA rgba = color_to_rgba(color); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4425 cairo_set_source_rgba(cr, rgba.red, rgba.green, rgba.blue, rgba.alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4426 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4427 #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
|
4428 |
7 | 4429 /* |
4430 * Called when the foreground or background color has been changed. | |
4431 * This used to change the graphics contexts directly but we are | |
4432 * currently manipulating them where desired. | |
4433 */ | |
4434 void | |
4435 gui_mch_new_colors(void) | |
4436 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4437 #if GTK_CHECK_VERSION(3,0,0) |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4438 # if !GTK_CHECK_VERSION(3,22,2) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4439 GdkWindow * const da_win = gtk_widget_get_window(gui.drawarea); |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4440 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4441 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4442 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
|
4443 #else |
7 | 4444 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
|
4445 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4446 { |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4447 #if GTK_CHECK_VERSION(3,22,2) |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4448 GtkStyleContext * const context |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4449 = gtk_widget_get_style_context(gui.drawarea); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4450 GtkCssProvider * const provider = gtk_css_provider_new(); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4451 gchar * const css = g_strdup_printf( |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4452 "widget#vim-gui-drawarea {\n" |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4453 " background-color: #%.2lx%.2lx%.2lx;\n" |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4454 "}\n", |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4455 (gui.back_pixel >> 16) & 0xff, |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4456 (gui.back_pixel >> 8) & 0xff, |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4457 gui.back_pixel & 0xff); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4458 |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4459 gtk_css_provider_load_from_data(provider, css, -1, NULL); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4460 gtk_style_context_add_provider(context, |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4461 GTK_STYLE_PROVIDER(provider), G_MAXUINT); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4462 |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4463 g_free(css); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4464 g_object_unref(provider); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4465 #elif GTK_CHECK_VERSION(3,4,0) /* !GTK_CHECK_VERSION(3,22,2) */ |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4466 GdkRGBA rgba; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4467 |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4468 rgba = color_to_rgba(gui.back_pixel); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4469 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4470 cairo_pattern_t * const pat = cairo_pattern_create_rgba( |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4471 rgba.red, rgba.green, rgba.blue, rgba.alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4472 if (pat != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4473 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4474 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
|
4475 cairo_pattern_destroy(pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4476 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4477 else |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4478 gdk_window_set_background_rgba(da_win, &rgba); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4479 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4480 #else /* !GTK_CHECK_VERSION(3,4,0) */ |
7 | 4481 GdkColor color = { 0, 0, 0, 0 }; |
4482 | |
4483 color.pixel = gui.back_pixel; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4484 # 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
|
4485 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
|
4486 # else |
7 | 4487 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
|
4488 # endif |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4489 #endif /* !GTK_CHECK_VERSION(3,22,2) */ |
7 | 4490 } |
4491 } | |
4492 | |
4493 /* | |
4494 * This signal informs us about the need to rearrange our sub-widgets. | |
4495 */ | |
4496 static gint | |
1884 | 4497 form_configure_event(GtkWidget *widget UNUSED, |
4498 GdkEventConfigure *event, | |
4499 gpointer data UNUSED) | |
7 | 4500 { |
791 | 4501 int usable_height = event->height; |
4502 | |
10402
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
4503 #if GTK_CHECK_VERSION(3,22,2) && !GTK_CHECK_VERSION(3,22,4) |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4504 /* As of 3.22.2, GdkWindows have started distributing configure events to |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4505 * their "native" children (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=12579fe71b3b8f79eb9c1b80e429443bcc437dd0). |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4506 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4507 * As can be seen from the implementation of move_native_children() and |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4508 * configure_native_child() in gdkwindow.c, those functions actually |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4509 * propagate configure events to every child, failing to distinguish |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4510 * "native" one from non-native one. |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4511 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4512 * Naturally, configure events propagated to here like that are fallacious |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4513 * and, as a matter of fact, they trigger a geometric collapse of |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4514 * gui.formwin. |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4515 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4516 * To filter out such fallacious events, check if the given event is the |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4517 * one that was sent out to the right place. Ignore it if not. |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4518 */ |
10402
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
4519 /* Follow-up |
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
4520 * After a few weeks later, the GdkWindow change mentioned above was |
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
4521 * reverted (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=f70039cb9603a02d2369fec4038abf40a1711155). |
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
4522 * The corresponding official release is 3.22.4. */ |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4523 if (event->window != gtk_widget_get_window(gui.formwin)) |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4524 return TRUE; |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4525 #endif |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4526 |
791 | 4527 /* When in a GtkPlug, we can't guarantee valid heights (as a round |
4528 * no. of char-heights), so we have to manually sanitise them. | |
4529 * Widths seem to sort themselves out, don't ask me why. | |
4530 */ | |
4531 if (gtk_socket_id != 0) | |
856 | 4532 usable_height -= (gui.char_height - (gui.char_height/2)); /* sic. */ |
791 | 4533 |
7 | 4534 gtk_form_freeze(GTK_FORM(gui.formwin)); |
791 | 4535 gui_resize_shell(event->width, usable_height); |
7 | 4536 gtk_form_thaw(GTK_FORM(gui.formwin)); |
4537 | |
4538 return TRUE; | |
4539 } | |
4540 | |
4541 /* | |
4542 * Function called when window already closed. | |
4543 * We can't do much more here than to trying to preserve what had been done, | |
4544 * since the window is already inevitably going away. | |
4545 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4546 #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
|
4547 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4548 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
|
4549 #else |
7 | 4550 static void |
1884 | 4551 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
|
4552 #endif |
7 | 4553 { |
4554 /* Don't write messages to the GUI anymore */ | |
4555 full_screen = FALSE; | |
4556 | |
4557 gui.mainwin = NULL; | |
4558 gui.drawarea = NULL; | |
4559 | |
4560 if (!exiting) /* only do anything if the destroy was unexpected */ | |
4561 { | |
419 | 4562 vim_strncpy(IObuff, |
4563 (char_u *)_("Vim: Main window unexpectedly destroyed\n"), | |
4564 IOSIZE - 1); | |
7 | 4565 preserve_exit(); |
4566 } | |
7380
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
4567 #ifdef USE_GRESOURCE |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
4568 gui_gtk_unregister_resource(); |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
4569 #endif |
7 | 4570 } |
4571 | |
791 | 4572 |
4573 /* | |
4574 * Bit of a hack to ensure we start GtkPlug windows with the correct window | |
4575 * hints (and thus the required size from -geom), but that after that we | |
4576 * put the hints back to normal (the actual minimum size) so we may | |
4577 * subsequently be resized smaller. GtkSocket (the parent end) uses the | |
1226 | 4578 * plug's window 'min hints to set *it's* minimum size, but that's also the |
791 | 4579 * only way we have of making ourselves bigger (by set lines/columns). |
4580 * 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
|
4581 * 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
|
4582 * scrollbar init.), actually do the standard hints and stop the timer. |
791 | 4583 * We'll not let the default hints be set while this timer's active. |
4584 */ | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
4585 static timeout_cb_type |
1884 | 4586 check_startup_plug_hints(gpointer data UNUSED) |
791 | 4587 { |
4588 if (init_window_hints_state == 1) | |
4589 { | |
856 | 4590 /* Safe to use normal hints now */ |
4591 init_window_hints_state = 0; | |
4592 update_window_manager_hints(0, 0); | |
4593 return FALSE; /* stop timer */ | |
791 | 4594 } |
4595 | |
4596 /* Keep on trying */ | |
4597 init_window_hints_state = 1; | |
4598 return TRUE; | |
4599 } | |
4600 | |
7 | 4601 /* |
4602 * Open the GUI window which was created by a call to gui_mch_init(). | |
4603 */ | |
4604 int | |
4605 gui_mch_open(void) | |
4606 { | |
4607 guicolor_T fg_pixel = INVALCOLOR; | |
4608 guicolor_T bg_pixel = INVALCOLOR; | |
1966 | 4609 guint pixel_width; |
4610 guint pixel_height; | |
7 | 4611 |
4612 /* | |
4613 * Allow setting a window role on the command line, or invent one | |
4614 * if none was specified. This is mainly useful for GNOME session | |
4615 * support; allowing the WM to restore window placement. | |
4616 */ | |
4617 if (role_argument != NULL) | |
4618 { | |
4619 gtk_window_set_role(GTK_WINDOW(gui.mainwin), role_argument); | |
4620 } | |
4621 else | |
4622 { | |
4623 char *role; | |
4624 | |
4625 /* Invent a unique-enough ID string for the role */ | |
4626 role = g_strdup_printf("vim-%u-%u-%u", | |
4627 (unsigned)mch_get_pid(), | |
4628 (unsigned)g_random_int(), | |
4629 (unsigned)time(NULL)); | |
4630 | |
4631 gtk_window_set_role(GTK_WINDOW(gui.mainwin), role); | |
4632 g_free(role); | |
4633 } | |
4634 | |
4635 if (gui_win_x != -1 && gui_win_y != -1) | |
4636 gtk_window_move(GTK_WINDOW(gui.mainwin), gui_win_x, gui_win_y); | |
4637 | |
4638 /* Determine user specified geometry, if present. */ | |
4639 if (gui.geom != NULL) | |
4640 { | |
4641 int mask; | |
4642 unsigned int w, h; | |
4643 int x = 0; | |
4644 int y = 0; | |
4645 | |
4646 mask = XParseGeometry((char *)gui.geom, &x, &y, &w, &h); | |
4647 | |
4648 if (mask & WidthValue) | |
4649 Columns = w; | |
4650 if (mask & HeightValue) | |
857 | 4651 { |
1884 | 4652 if (p_window > (long)h - 1 || !option_was_set((char_u *)"window")) |
857 | 4653 p_window = h - 1; |
7 | 4654 Rows = h; |
857 | 4655 } |
5070
cf52d2a8c05c
updated for version 7.3.1278
Bram Moolenaar <bram@vim.org>
parents:
4474
diff
changeset
|
4656 limit_screen_size(); |
1426 | 4657 |
4658 pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width); | |
4659 pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height); | |
4660 | |
4661 pixel_width += get_menu_tool_width(); | |
4662 pixel_height += get_menu_tool_height(); | |
4663 | |
7 | 4664 if (mask & (XValue | YValue)) |
1426 | 4665 { |
1757 | 4666 int ww, hh; |
4667 gui_mch_get_screen_dimensions(&ww, &hh); | |
4668 hh += p_ghr + get_menu_tool_height(); | |
4669 ww += get_menu_tool_width(); | |
1426 | 4670 if (mask & XNegative) |
1757 | 4671 x += ww - pixel_width; |
1426 | 4672 if (mask & YNegative) |
1757 | 4673 y += hh - pixel_height; |
7 | 4674 gtk_window_move(GTK_WINDOW(gui.mainwin), x, y); |
1426 | 4675 } |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13152
diff
changeset
|
4676 VIM_CLEAR(gui.geom); |
791 | 4677 |
856 | 4678 /* From now until everyone's stopped trying to set the window hints |
4679 * to their correct minimum values, stop them being set as we need | |
4680 * them to remain at our required size for the parent GtkSocket to | |
4681 * give us the right initial size. | |
4682 */ | |
791 | 4683 if (gtk_socket_id != 0 && (mask & WidthValue || mask & HeightValue)) |
856 | 4684 { |
4685 update_window_manager_hints(pixel_width, pixel_height); | |
4686 init_window_hints_state = 1; | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
4687 timeout_add(1000, check_startup_plug_hints, NULL); |
856 | 4688 } |
7 | 4689 } |
4690 | |
1966 | 4691 pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width); |
4692 pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height); | |
4693 /* For GTK2 changing the size of the form widget doesn't cause window | |
4694 * resizing. */ | |
2254
4620acaf4814
One more fix for conceal patch.
Bram Moolenaar <bram@vim.org>
parents:
2248
diff
changeset
|
4695 if (gtk_socket_id == 0) |
1966 | 4696 gtk_window_resize(GTK_WINDOW(gui.mainwin), pixel_width, pixel_height); |
791 | 4697 update_window_manager_hints(0, 0); |
7 | 4698 |
4699 if (foreground_argument != NULL) | |
4700 fg_pixel = gui_get_color((char_u *)foreground_argument); | |
4701 if (fg_pixel == INVALCOLOR) | |
4702 fg_pixel = gui_get_color((char_u *)"Black"); | |
4703 | |
4704 if (background_argument != NULL) | |
4705 bg_pixel = gui_get_color((char_u *)background_argument); | |
4706 if (bg_pixel == INVALCOLOR) | |
4707 bg_pixel = gui_get_color((char_u *)"White"); | |
4708 | |
4709 if (found_reverse_arg) | |
4710 { | |
4711 gui.def_norm_pixel = bg_pixel; | |
4712 gui.def_back_pixel = fg_pixel; | |
4713 } | |
4714 else | |
4715 { | |
4716 gui.def_norm_pixel = fg_pixel; | |
4717 gui.def_back_pixel = bg_pixel; | |
4718 } | |
4719 | |
4720 /* Get the colors from the "Normal" and "Menu" group (set in syntax.c or | |
4721 * in a vimrc file) */ | |
4722 set_normal_colors(); | |
4723 | |
4724 /* Check that none of the colors are the same as the background color */ | |
4725 gui_check_colors(); | |
4726 | |
4727 /* Get the colors for the highlight groups (gui_check_colors() might have | |
4728 * changed them). */ | |
4729 highlight_gui_started(); /* re-init colors and fonts */ | |
4730 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4731 #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
|
4732 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
|
4733 G_CALLBACK(mainwin_destroy_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4734 #else |
7 | 4735 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "destroy", |
4736 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
|
4737 #endif |
7 | 4738 |
4739 #ifdef FEAT_HANGULIN | |
4740 hangul_keyboard_set(); | |
4741 #endif | |
4742 | |
4743 /* | |
4744 * Notify the fixed area about the need to resize the contents of the | |
4745 * gui.formwin, which we use for random positioning of the included | |
4746 * components. | |
4747 * | |
4748 * We connect this signal deferred finally after anything is in place, | |
4749 * since this is intended to handle resizements coming from the window | |
4750 * manager upon us and should not interfere with what VIM is requesting | |
4751 * upon startup. | |
4752 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4753 #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
|
4754 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
|
4755 G_CALLBACK(form_configure_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4756 #else |
7 | 4757 gtk_signal_connect(GTK_OBJECT(gui.formwin), "configure_event", |
4758 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
|
4759 #endif |
7 | 4760 |
4761 #ifdef FEAT_DND | |
2183 | 4762 /* Set up for receiving DND items. */ |
4763 gui_gtk_set_dnd_targets(); | |
7 | 4764 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4765 # 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
|
4766 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
|
4767 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
|
4768 # else |
7 | 4769 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "drag_data_received", |
4770 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
|
4771 # endif |
7 | 4772 #endif |
4773 | |
4774 /* 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
|
4775 * to avoid mapping the window for a short time. */ |
7 | 4776 if (found_iconic_arg && gtk_socket_id == 0) |
4777 gui_mch_iconify(); | |
4778 | |
4779 { | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
4780 #if defined(FEAT_GUI_GNOME) && defined(FEAT_MENU) |
7 | 4781 unsigned long menu_handler = 0; |
4782 # ifdef FEAT_TOOLBAR | |
4783 unsigned long tool_handler = 0; | |
4784 # endif | |
4785 /* | |
4786 * Urgh hackish :/ For some reason BonoboDockLayout always forces a | |
4787 * show when restoring the saved layout configuration. We can't just | |
4788 * hide the widgets again after gtk_widget_show(gui.mainwin) since it's | |
4789 * a toplevel window and thus will be realized immediately. Instead, | |
4790 * connect signal handlers to hide the widgets just after they've been | |
4791 * marked visible, but before the main window is realized. | |
4792 */ | |
4793 if (using_gnome && vim_strchr(p_go, GO_MENUS) == NULL) | |
4794 menu_handler = g_signal_connect_after(gui.menubar_h, "show", | |
4795 G_CALLBACK(>k_widget_hide), | |
4796 NULL); | |
4797 # ifdef FEAT_TOOLBAR | |
4798 if (using_gnome && vim_strchr(p_go, GO_TOOLBAR) == NULL | |
4799 && (toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS))) | |
4800 tool_handler = g_signal_connect_after(gui.toolbar_h, "show", | |
4801 G_CALLBACK(>k_widget_hide), | |
4802 NULL); | |
4803 # endif | |
4804 #endif | |
4805 gtk_widget_show(gui.mainwin); | |
4806 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
4807 #if defined(FEAT_GUI_GNOME) && defined(FEAT_MENU) |
7 | 4808 if (menu_handler != 0) |
4809 g_signal_handler_disconnect(gui.menubar_h, menu_handler); | |
4810 # ifdef FEAT_TOOLBAR | |
4811 if (tool_handler != 0) | |
4812 g_signal_handler_disconnect(gui.toolbar_h, tool_handler); | |
4813 # endif | |
4814 #endif | |
4815 } | |
4816 | |
4817 return OK; | |
4818 } | |
4819 | |
4820 | |
4821 void | |
1884 | 4822 gui_mch_exit(int rc UNUSED) |
7 | 4823 { |
4824 if (gui.mainwin != NULL) | |
4825 gtk_widget_destroy(gui.mainwin); | |
4826 } | |
4827 | |
4828 /* | |
4829 * Get the position of the top left corner of the window. | |
4830 */ | |
4831 int | |
4832 gui_mch_get_winpos(int *x, int *y) | |
4833 { | |
4834 gtk_window_get_position(GTK_WINDOW(gui.mainwin), x, y); | |
4835 return OK; | |
4836 } | |
4837 | |
4838 /* | |
4839 * Set the position of the top left corner of the window to the given | |
4840 * coordinates. | |
4841 */ | |
4842 void | |
4843 gui_mch_set_winpos(int x, int y) | |
4844 { | |
4845 gtk_window_move(GTK_WINDOW(gui.mainwin), x, y); | |
4846 } | |
4847 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4848 #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
|
4849 # if 0 |
7 | 4850 static int resize_idle_installed = FALSE; |
4851 /* | |
4852 * Idle handler to force resize. Used by gui_mch_set_shellsize() to ensure | |
4853 * the shell size doesn't exceed the window size, i.e. if the window manager | |
4854 * ignored our size request. Usually this happens if the window is maximized. | |
4855 * | |
4856 * FIXME: It'd be nice if we could find a little more orthodox solution. | |
4857 * See also the remark below in gui_mch_set_shellsize(). | |
4858 * | |
4859 * DISABLED: When doing ":set lines+=1" this function would first invoke | |
4860 * gui_resize_shell() with the old size, then the normal callback would | |
4861 * report the new size through form_configure_event(). That caused the window | |
4862 * layout to be messed up. | |
4863 */ | |
4864 static gboolean | |
4865 force_shell_resize_idle(gpointer data) | |
4866 { | |
4867 if (gui.mainwin != NULL | |
4868 && GTK_WIDGET_REALIZED(gui.mainwin) | |
4869 && GTK_WIDGET_VISIBLE(gui.mainwin)) | |
4870 { | |
4871 int width; | |
4872 int height; | |
4873 | |
4874 gtk_window_get_size(GTK_WINDOW(gui.mainwin), &width, &height); | |
4875 | |
4876 width -= get_menu_tool_width(); | |
4877 height -= get_menu_tool_height(); | |
4878 | |
4879 gui_resize_shell(width, height); | |
4880 } | |
4881 | |
4882 resize_idle_installed = FALSE; | |
4883 return FALSE; /* don't call me again */ | |
4884 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4885 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4886 #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
|
4887 |
1967 | 4888 /* |
4889 * Return TRUE if the main window is maximized. | |
4890 */ | |
4891 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
4892 gui_mch_maximized(void) |
1967 | 4893 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4894 #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
|
4895 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
|
4896 && (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
|
4897 & GDK_WINDOW_STATE_MAXIMIZED)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4898 #else |
1967 | 4899 return (gui.mainwin != NULL && gui.mainwin->window != NULL |
4900 && (gdk_window_get_state(gui.mainwin->window) | |
4901 & GDK_WINDOW_STATE_MAXIMIZED)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4902 #endif |
1967 | 4903 } |
4904 | |
4905 /* | |
4906 * Unmaximize the main window | |
4907 */ | |
4908 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
4909 gui_mch_unmaximize(void) |
1967 | 4910 { |
4911 if (gui.mainwin != NULL) | |
4912 gtk_window_unmaximize(GTK_WINDOW(gui.mainwin)); | |
4913 } | |
4914 | |
7 | 4915 /* |
12802
29a728529f92
patch 8.0.1278: GUI window always resizes when adding scrollbar
Christian Brabandt <cb@256bit.org>
parents:
12666
diff
changeset
|
4916 * Called when the font changed while the window is maximized or GO_KEEPWINSIZE |
29a728529f92
patch 8.0.1278: GUI window always resizes when adding scrollbar
Christian Brabandt <cb@256bit.org>
parents:
12666
diff
changeset
|
4917 * is set. Compute the new Rows and Columns. This is like resizing the |
29a728529f92
patch 8.0.1278: GUI window always resizes when adding scrollbar
Christian Brabandt <cb@256bit.org>
parents:
12666
diff
changeset
|
4918 * window. |
3014 | 4919 */ |
4920 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
4921 gui_mch_newfont(void) |
3014 | 4922 { |
4923 int w, h; | |
4924 | |
4925 gtk_window_get_size(GTK_WINDOW(gui.mainwin), &w, &h); | |
4926 w -= get_menu_tool_width(); | |
4927 h -= get_menu_tool_height(); | |
4928 gui_resize_shell(w, h); | |
4929 } | |
4930 | |
4931 /* | |
7 | 4932 * Set the windows size. |
4933 */ | |
4934 void | |
4935 gui_mch_set_shellsize(int width, int height, | |
1884 | 4936 int min_width UNUSED, int min_height UNUSED, |
4937 int base_width UNUSED, int base_height UNUSED, | |
4938 int direction UNUSED) | |
7 | 4939 { |
4940 /* give GTK+ a chance to put all widget's into place */ | |
4941 gui_mch_update(); | |
4942 | |
791 | 4943 /* this will cause the proper resizement to happen too */ |
4944 if (gtk_socket_id == 0) | |
856 | 4945 update_window_manager_hints(0, 0); |
791 | 4946 |
7 | 4947 /* With GTK+ 2, changing the size of the form widget doesn't resize |
791 | 4948 * the window. So let's do it the other way around and resize the |
7 | 4949 * main window instead. */ |
4950 width += get_menu_tool_width(); | |
4951 height += get_menu_tool_height(); | |
4952 | |
791 | 4953 if (gtk_socket_id == 0) |
856 | 4954 gtk_window_resize(GTK_WINDOW(gui.mainwin), width, height); |
791 | 4955 else |
856 | 4956 update_window_manager_hints(width, height); |
7 | 4957 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4958 # 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
|
4959 # if 0 |
7 | 4960 if (!resize_idle_installed) |
4961 { | |
4962 g_idle_add_full(GDK_PRIORITY_EVENTS + 10, | |
4963 &force_shell_resize_idle, NULL, NULL); | |
4964 resize_idle_installed = TRUE; | |
4965 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4966 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4967 # endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 4968 /* |
4969 * Wait until all events are processed to prevent a crash because the | |
4970 * real size of the drawing area doesn't reflect Vim's internal ideas. | |
4971 * | |
4972 * This is a bit of a hack, since Vim is a terminal application with a GUI | |
4973 * on top, while the GUI expects to be the boss. | |
4974 */ | |
4975 gui_mch_update(); | |
4976 } | |
4977 | |
12409
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4978 void |
12413
ca7f2685e339
patch 8.0.1086: can't build with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
12409
diff
changeset
|
4979 gui_gtk_get_screen_size_of_win(GtkWidget *wid, int *width, int *height) |
12409
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4980 { |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4981 #if GTK_CHECK_VERSION(3,22,0) |
12413
ca7f2685e339
patch 8.0.1086: can't build with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
12409
diff
changeset
|
4982 GdkDisplay *dpy = gtk_widget_get_display(wid); |
ca7f2685e339
patch 8.0.1086: can't build with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
12409
diff
changeset
|
4983 GdkWindow *win = gtk_widget_get_window(wid); |
12409
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4984 GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win); |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4985 GdkRectangle geometry; |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4986 |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4987 gdk_monitor_get_geometry(monitor, &geometry); |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4988 *width = geometry.width; |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4989 *height = geometry.height; |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4990 #else |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4991 GdkScreen* screen; |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4992 |
12413
ca7f2685e339
patch 8.0.1086: can't build with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
12409
diff
changeset
|
4993 if (wid != NULL && gtk_widget_has_screen(wid)) |
ca7f2685e339
patch 8.0.1086: can't build with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
12409
diff
changeset
|
4994 screen = gtk_widget_get_screen(wid); |
12409
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4995 else |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4996 screen = gdk_screen_get_default(); |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4997 *width = gdk_screen_get_width(screen); |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4998 *height = gdk_screen_get_height(screen); |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4999 #endif |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
5000 } |
7 | 5001 |
5002 /* | |
5003 * The screen size is used to make sure the initial window doesn't get bigger | |
5004 * than the screen. This subtracts some room for menubar, toolbar and window | |
5005 * decorations. | |
5006 */ | |
5007 void | |
5008 gui_mch_get_screen_dimensions(int *screen_w, int *screen_h) | |
5009 { | |
12409
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
5010 gui_gtk_get_screen_size_of_win(gui.mainwin, screen_w, screen_h); |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
5011 |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
5012 /* Subtract 'guiheadroom' from the height to allow some room for the |
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
5013 * window manager (task list and window title bar). */ |
12409
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
5014 *screen_h -= p_ghr; |
7 | 5015 |
5016 /* | |
5017 * FIXME: dirty trick: Because the gui_get_base_height() doesn't include | |
5018 * 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
|
5019 * height, so that the window size can be made to fit on the screen. |
7 | 5020 * This should be completely changed later. |
5021 */ | |
5022 *screen_w -= get_menu_tool_width(); | |
5023 *screen_h -= get_menu_tool_height(); | |
5024 } | |
5025 | |
5026 #if defined(FEAT_TITLE) || defined(PROTO) | |
5027 void | |
1884 | 5028 gui_mch_settitle(char_u *title, char_u *icon UNUSED) |
7 | 5029 { |
5030 if (title != NULL && output_conv.vc_type != CONV_NONE) | |
5031 title = string_convert(&output_conv, title, NULL); | |
5032 | |
5033 gtk_window_set_title(GTK_WINDOW(gui.mainwin), (const char *)title); | |
5034 | |
5035 if (output_conv.vc_type != CONV_NONE) | |
5036 vim_free(title); | |
5037 } | |
5038 #endif /* FEAT_TITLE */ | |
5039 | |
5040 #if defined(FEAT_MENU) || defined(PROTO) | |
5041 void | |
5042 gui_mch_enable_menu(int showit) | |
5043 { | |
5044 GtkWidget *widget; | |
5045 | |
5046 # ifdef FEAT_GUI_GNOME | |
5047 if (using_gnome) | |
5048 widget = gui.menubar_h; | |
5049 else | |
5050 # endif | |
5051 widget = gui.menubar; | |
5052 | |
827 | 5053 /* 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
|
5054 # 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
|
5055 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
|
5056 # else |
827 | 5057 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
|
5058 # endif |
7 | 5059 { |
5060 if (showit) | |
5061 gtk_widget_show(widget); | |
5062 else | |
5063 gtk_widget_hide(widget); | |
5064 | |
791 | 5065 update_window_manager_hints(0, 0); |
7 | 5066 } |
5067 } | |
5068 #endif /* FEAT_MENU */ | |
5069 | |
5070 #if defined(FEAT_TOOLBAR) || defined(PROTO) | |
5071 void | |
5072 gui_mch_show_toolbar(int showit) | |
5073 { | |
5074 GtkWidget *widget; | |
5075 | |
5076 if (gui.toolbar == NULL) | |
5077 return; | |
5078 | |
5079 # ifdef FEAT_GUI_GNOME | |
5080 if (using_gnome) | |
5081 widget = gui.toolbar_h; | |
5082 else | |
5083 # endif | |
5084 widget = gui.toolbar; | |
5085 | |
5086 if (showit) | |
5087 set_toolbar_style(GTK_TOOLBAR(gui.toolbar)); | |
5088 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5089 # 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
|
5090 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
|
5091 # else |
7 | 5092 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
|
5093 # endif |
7 | 5094 { |
5095 if (showit) | |
5096 gtk_widget_show(widget); | |
5097 else | |
5098 gtk_widget_hide(widget); | |
5099 | |
791 | 5100 update_window_manager_hints(0, 0); |
7 | 5101 } |
5102 } | |
5103 #endif /* FEAT_TOOLBAR */ | |
5104 | |
5105 /* | |
5106 * Check if a given font is a CJK font. This is done in a very crude manner. It | |
5107 * just see if U+04E00 for zh and ja and U+AC00 for ko are covered in a given | |
5108 * font. Consequently, this function cannot be used as a general purpose check | |
5109 * for CJK-ness for which fontconfig APIs should be used. This is only used by | |
5110 * gui_mch_init_font() to deal with 'CJK fixed width fonts'. | |
5111 */ | |
5112 static int | |
5113 is_cjk_font(PangoFontDescription *font_desc) | |
5114 { | |
5115 static const char * const cjk_langs[] = | |
5116 {"zh_CN", "zh_TW", "zh_HK", "ja", "ko"}; | |
5117 | |
5118 PangoFont *font; | |
5119 unsigned i; | |
5120 int is_cjk = FALSE; | |
5121 | |
5122 font = pango_context_load_font(gui.text_context, font_desc); | |
5123 | |
5124 if (font == NULL) | |
5125 return FALSE; | |
5126 | |
5127 for (i = 0; !is_cjk && i < G_N_ELEMENTS(cjk_langs); ++i) | |
5128 { | |
5129 PangoCoverage *coverage; | |
5130 gunichar uc; | |
5131 | |
5132 coverage = pango_font_get_coverage( | |
5133 font, pango_language_from_string(cjk_langs[i])); | |
5134 | |
5135 if (coverage != NULL) | |
5136 { | |
5137 uc = (cjk_langs[i][0] == 'k') ? 0xAC00 : 0x4E00; | |
5138 is_cjk = (pango_coverage_get(coverage, uc) == PANGO_COVERAGE_EXACT); | |
5139 pango_coverage_unref(coverage); | |
5140 } | |
5141 } | |
5142 | |
5143 g_object_unref(font); | |
5144 | |
5145 return is_cjk; | |
5146 } | |
5147 | |
445 | 5148 /* |
5149 * Adjust gui.char_height (after 'linespace' was changed). | |
5150 */ | |
7 | 5151 int |
445 | 5152 gui_mch_adjust_charheight(void) |
7 | 5153 { |
5154 PangoFontMetrics *metrics; | |
5155 int ascent; | |
5156 int descent; | |
5157 | |
5158 metrics = pango_context_get_metrics(gui.text_context, gui.norm_font, | |
5159 pango_context_get_language(gui.text_context)); | |
5160 ascent = pango_font_metrics_get_ascent(metrics); | |
5161 descent = pango_font_metrics_get_descent(metrics); | |
5162 | |
5163 pango_font_metrics_unref(metrics); | |
5164 | |
5165 gui.char_height = (ascent + descent + PANGO_SCALE - 1) / PANGO_SCALE | |
445 | 5166 + p_linespace; |
136 | 5167 /* LINTED: avoid warning: bitwise operation on signed value */ |
7 | 5168 gui.char_ascent = PANGO_PIXELS(ascent + p_linespace * PANGO_SCALE / 2); |
5169 | |
5170 /* A not-positive value of char_height may crash Vim. Only happens | |
5171 * if 'linespace' is negative (which does make sense sometimes). */ | |
5172 gui.char_ascent = MAX(gui.char_ascent, 0); | |
5173 gui.char_height = MAX(gui.char_height, gui.char_ascent + 1); | |
5174 | |
5175 return OK; | |
5176 } | |
5177 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5178 #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
|
5179 /* 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
|
5180 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5181 font_filter(const PangoFontFamily *family, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5182 const PangoFontFace *face UNUSED, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5183 gpointer data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5184 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5185 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
|
5186 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5187 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5188 |
7 | 5189 /* |
5190 * Put up a font dialog and return the selected font name in allocated memory. | |
5191 * "oldval" is the previous value. Return NULL when cancelled. | |
5192 * This should probably go into gui_gtk.c. Hmm. | |
5193 * FIXME: | |
5194 * The GTK2 font selection dialog has no filtering API. So we could either | |
5195 * a) implement our own (possibly copying the code from somewhere else) or | |
5196 * b) just live with it. | |
5197 */ | |
5198 char_u * | |
5199 gui_mch_font_dialog(char_u *oldval) | |
5200 { | |
5201 GtkWidget *dialog; | |
5202 int response; | |
5203 char_u *fontname = NULL; | |
5204 char_u *oldname; | |
5205 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5206 #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
|
5207 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
|
5208 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
|
5209 NULL, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5210 #else |
7 | 5211 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
|
5212 #endif |
7 | 5213 |
5214 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gui.mainwin)); | |
5215 gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); | |
5216 | |
5217 if (oldval != NULL && oldval[0] != NUL) | |
5218 { | |
5219 if (output_conv.vc_type != CONV_NONE) | |
5220 oldname = string_convert(&output_conv, oldval, NULL); | |
5221 else | |
5222 oldname = oldval; | |
5223 | |
5224 /* Annoying bug in GTK (or Pango): if the font name does not include a | |
5225 * size, zero is used. Use default point size ten. */ | |
5226 if (!vim_isdigit(oldname[STRLEN(oldname) - 1])) | |
5227 { | |
5228 char_u *p = vim_strnsave(oldname, STRLEN(oldname) + 3); | |
5229 | |
5230 if (p != NULL) | |
5231 { | |
5232 STRCPY(p + STRLEN(p), " 10"); | |
5233 if (oldname != oldval) | |
5234 vim_free(oldname); | |
5235 oldname = p; | |
5236 } | |
5237 } | |
5238 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5239 #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
|
5240 gtk_font_chooser_set_font( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5241 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
|
5242 #else |
7 | 5243 gtk_font_selection_dialog_set_font_name( |
5244 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
|
5245 #endif |
7 | 5246 |
5247 if (oldname != oldval) | |
100 | 5248 vim_free(oldname); |
7 | 5249 } |
1959 | 5250 else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5251 #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
|
5252 gtk_font_chooser_set_font( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5253 GTK_FONT_CHOOSER(dialog), DEFAULT_FONT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5254 #else |
1959 | 5255 gtk_font_selection_dialog_set_font_name( |
5256 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
|
5257 #endif |
7 | 5258 |
5259 response = gtk_dialog_run(GTK_DIALOG(dialog)); | |
5260 | |
5261 if (response == GTK_RESPONSE_OK) | |
5262 { | |
5263 char *name; | |
5264 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5265 #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
|
5266 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
|
5267 #else |
7 | 5268 name = gtk_font_selection_dialog_get_font_name( |
5269 GTK_FONT_SELECTION_DIALOG(dialog)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5270 #endif |
7 | 5271 if (name != NULL) |
5272 { | |
714 | 5273 char_u *p; |
5274 | |
5275 /* Apparently some font names include a comma, need to escape | |
5276 * that, because in 'guifont' it separates names. */ | |
5277 p = vim_strsave_escaped((char_u *)name, (char_u *)","); | |
5278 g_free(name); | |
840 | 5279 if (p != NULL && input_conv.vc_type != CONV_NONE) |
714 | 5280 { |
5281 fontname = string_convert(&input_conv, p, NULL); | |
5282 vim_free(p); | |
5283 } | |
7 | 5284 else |
714 | 5285 fontname = p; |
7 | 5286 } |
5287 } | |
5288 | |
5289 if (response != GTK_RESPONSE_NONE) | |
5290 gtk_widget_destroy(dialog); | |
5291 | |
5292 return fontname; | |
5293 } | |
5294 | |
5295 /* | |
5296 * Some monospace fonts don't support a bold weight, and fall back | |
5297 * silently to the regular weight. But this is no good since our text | |
5298 * drawing function can emulate bold by overstriking. So let's try | |
5299 * to detect whether bold weight is actually available and emulate it | |
5300 * otherwise. | |
5301 * | |
5302 * Note that we don't need to check for italic style since Xft can | |
5303 * emulate italic on its own, provided you have a proper fontconfig | |
5304 * setup. We wouldn't be able to emulate it in Vim anyway. | |
5305 */ | |
5306 static void | |
5307 get_styled_font_variants(void) | |
5308 { | |
5309 PangoFontDescription *bold_font_desc; | |
5310 PangoFont *plain_font; | |
5311 PangoFont *bold_font; | |
5312 | |
5313 gui.font_can_bold = FALSE; | |
5314 | |
5315 plain_font = pango_context_load_font(gui.text_context, gui.norm_font); | |
5316 | |
5317 if (plain_font == NULL) | |
5318 return; | |
5319 | |
5320 bold_font_desc = pango_font_description_copy_static(gui.norm_font); | |
5321 pango_font_description_set_weight(bold_font_desc, PANGO_WEIGHT_BOLD); | |
5322 | |
5323 bold_font = pango_context_load_font(gui.text_context, bold_font_desc); | |
5324 /* | |
5325 * The comparison relies on the unique handle nature of a PangoFont*, | |
5326 * i.e. it's assumed that a different PangoFont* won't refer to the | |
5327 * same font. Seems to work, and failing here isn't critical anyway. | |
5328 */ | |
5329 if (bold_font != NULL) | |
5330 { | |
5331 gui.font_can_bold = (bold_font != plain_font); | |
5332 g_object_unref(bold_font); | |
5333 } | |
5334 | |
5335 pango_font_description_free(bold_font_desc); | |
5336 g_object_unref(plain_font); | |
5337 } | |
5338 | |
5339 static PangoEngineShape *default_shape_engine = NULL; | |
5340 | |
5341 /* | |
5342 * Create a map from ASCII characters in the range [32,126] to glyphs | |
5343 * of the current font. This is used by gui_gtk2_draw_string() to skip | |
5344 * the itemize and shaping process for the most common case. | |
5345 */ | |
5346 static void | |
5347 ascii_glyph_table_init(void) | |
5348 { | |
9879
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5349 char_u ascii_chars[2 * 128]; |
7 | 5350 PangoAttrList *attr_list; |
5351 GList *item_list; | |
5352 int i; | |
5353 | |
5354 if (gui.ascii_glyphs != NULL) | |
5355 pango_glyph_string_free(gui.ascii_glyphs); | |
5356 if (gui.ascii_font != NULL) | |
5357 g_object_unref(gui.ascii_font); | |
5358 | |
5359 gui.ascii_glyphs = NULL; | |
5360 gui.ascii_font = NULL; | |
5361 | |
9879
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5362 /* For safety, fill in question marks for the control characters. |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5363 * Put a space between characters to avoid shaping. */ |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5364 for (i = 0; i < 128; ++i) |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5365 { |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5366 if (i >= 32 && i < 127) |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5367 ascii_chars[2 * i] = i; |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5368 else |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5369 ascii_chars[2 * i] = '?'; |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5370 ascii_chars[2 * i + 1] = ' '; |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5371 } |
7 | 5372 |
5373 attr_list = pango_attr_list_new(); | |
5374 item_list = pango_itemize(gui.text_context, (const char *)ascii_chars, | |
5375 0, sizeof(ascii_chars), attr_list, NULL); | |
5376 | |
5377 if (item_list != NULL && item_list->next == NULL) /* play safe */ | |
5378 { | |
5379 PangoItem *item; | |
5380 int width; | |
5381 | |
5382 item = (PangoItem *)item_list->data; | |
5383 width = gui.char_width * PANGO_SCALE; | |
5384 | |
5385 /* Remember the shape engine used for ASCII. */ | |
5386 default_shape_engine = item->analysis.shape_engine; | |
5387 | |
5388 gui.ascii_font = item->analysis.font; | |
5389 g_object_ref(gui.ascii_font); | |
5390 | |
5391 gui.ascii_glyphs = pango_glyph_string_new(); | |
5392 | |
5393 pango_shape((const char *)ascii_chars, sizeof(ascii_chars), | |
5394 &item->analysis, gui.ascii_glyphs); | |
5395 | |
5396 g_return_if_fail(gui.ascii_glyphs->num_glyphs == sizeof(ascii_chars)); | |
5397 | |
5398 for (i = 0; i < gui.ascii_glyphs->num_glyphs; ++i) | |
5399 { | |
5400 PangoGlyphGeometry *geom; | |
5401 | |
5402 geom = &gui.ascii_glyphs->glyphs[i].geometry; | |
5403 geom->x_offset += MAX(0, width - geom->width) / 2; | |
5404 geom->width = width; | |
5405 } | |
5406 } | |
5407 | |
5408 g_list_foreach(item_list, (GFunc)&pango_item_free, NULL); | |
5409 g_list_free(item_list); | |
5410 pango_attr_list_unref(attr_list); | |
5411 } | |
5412 | |
5413 /* | |
5414 * Initialize Vim to use the font or fontset with the given name. | |
5415 * Return FAIL if the font could not be loaded, OK otherwise. | |
5416 */ | |
5417 int | |
1884 | 5418 gui_mch_init_font(char_u *font_name, int fontset UNUSED) |
7 | 5419 { |
5420 PangoFontDescription *font_desc; | |
5421 PangoLayout *layout; | |
5422 int width; | |
5423 | |
5424 /* If font_name is NULL, this means to use the default, which should | |
5425 * be present on all proper Pango/fontconfig installations. */ | |
5426 if (font_name == NULL) | |
5427 font_name = (char_u *)DEFAULT_FONT; | |
5428 | |
5429 font_desc = gui_mch_get_font(font_name, FALSE); | |
5430 | |
5431 if (font_desc == NULL) | |
5432 return FAIL; | |
5433 | |
5434 gui_mch_free_font(gui.norm_font); | |
5435 gui.norm_font = font_desc; | |
5436 | |
5437 pango_context_set_font_description(gui.text_context, font_desc); | |
5438 | |
5439 layout = pango_layout_new(gui.text_context); | |
5440 pango_layout_set_text(layout, "MW", 2); | |
5441 pango_layout_get_size(layout, &width, NULL); | |
5442 /* | |
5443 * Set char_width to half the width obtained from pango_layout_get_size() | |
5444 * for CJK fixed_width/bi-width fonts. An unpatched version of Xft leads | |
5445 * Pango to use the same width for both non-CJK characters (e.g. Latin | |
5446 * letters and numbers) and CJK characters. This results in 's p a c e d | |
5447 * o u t' rendering when a CJK 'fixed width' font is used. To work around | |
5448 * that, divide the width returned by Pango by 2 if cjk_width is equal to | |
5449 * width for CJK fonts. | |
5450 * | |
5451 * For related bugs, see: | |
5452 * http://bugzilla.gnome.org/show_bug.cgi?id=106618 | |
5453 * http://bugzilla.gnome.org/show_bug.cgi?id=106624 | |
5454 * | |
5455 * With this, for all four of the following cases, Vim works fine: | |
5456 * guifont=CJK_fixed_width_font | |
5457 * guifont=Non_CJK_fixed_font | |
5458 * guifont=Non_CJK_fixed_font,CJK_Fixed_font | |
5459 * guifont=Non_CJK_fixed_font guifontwide=CJK_fixed_font | |
5460 */ | |
5461 if (is_cjk_font(gui.norm_font)) | |
5462 { | |
5463 int cjk_width; | |
5464 | |
5465 /* Measure the text extent of U+4E00 and U+4E8C */ | |
5466 pango_layout_set_text(layout, "\344\270\200\344\272\214", -1); | |
5467 pango_layout_get_size(layout, &cjk_width, NULL); | |
5468 | |
5469 if (width == cjk_width) /* Xft not patched */ | |
5470 width /= 2; | |
5471 } | |
5472 g_object_unref(layout); | |
5473 | |
5474 gui.char_width = (width / 2 + PANGO_SCALE - 1) / PANGO_SCALE; | |
5475 | |
5476 /* A zero width may cause a crash. Happens for semi-invalid fontsets. */ | |
5477 if (gui.char_width <= 0) | |
5478 gui.char_width = 8; | |
5479 | |
445 | 5480 gui_mch_adjust_charheight(); |
7 | 5481 |
5482 /* Set the fontname, which will be used for information purposes */ | |
5483 hl_set_font_name(font_name); | |
5484 | |
5485 get_styled_font_variants(); | |
5486 ascii_glyph_table_init(); | |
5487 | |
5488 /* Avoid unnecessary overhead if 'guifontwide' is equal to 'guifont'. */ | |
5489 if (gui.wide_font != NULL | |
5490 && pango_font_description_equal(gui.norm_font, gui.wide_font)) | |
5491 { | |
5492 pango_font_description_free(gui.wide_font); | |
5493 gui.wide_font = NULL; | |
5494 } | |
5495 | |
1986 | 5496 if (gui_mch_maximized()) |
5497 { | |
5498 /* Update lines and columns in accordance with the new font, keep the | |
5499 * window maximized. */ | |
3014 | 5500 gui_mch_newfont(); |
1986 | 5501 } |
5502 else | |
5503 { | |
5504 /* Preserve the logical dimensions of the screen. */ | |
5505 update_window_manager_hints(0, 0); | |
5506 } | |
7 | 5507 |
5508 return OK; | |
5509 } | |
5510 | |
5511 /* | |
5512 * Get a reference to the font "name". | |
5513 * Return zero for failure. | |
5514 */ | |
5515 GuiFont | |
5516 gui_mch_get_font(char_u *name, int report_error) | |
5517 { | |
5518 PangoFontDescription *font; | |
5519 | |
5520 /* can't do this when GUI is not running */ | |
5521 if (!gui.in_use || name == NULL) | |
5522 return NULL; | |
5523 | |
5524 if (output_conv.vc_type != CONV_NONE) | |
5525 { | |
5526 char_u *buf; | |
5527 | |
5528 buf = string_convert(&output_conv, name, NULL); | |
5529 if (buf != NULL) | |
5530 { | |
5531 font = pango_font_description_from_string((const char *)buf); | |
5532 vim_free(buf); | |
5533 } | |
5534 else | |
5535 font = NULL; | |
5536 } | |
5537 else | |
5538 font = pango_font_description_from_string((const char *)name); | |
5539 | |
5540 if (font != NULL) | |
5541 { | |
5542 PangoFont *real_font; | |
5543 | |
5544 /* pango_context_load_font() bails out if no font size is set */ | |
5545 if (pango_font_description_get_size(font) <= 0) | |
5546 pango_font_description_set_size(font, 10 * PANGO_SCALE); | |
5547 | |
5548 real_font = pango_context_load_font(gui.text_context, font); | |
5549 | |
5550 if (real_font == NULL) | |
5551 { | |
5552 pango_font_description_free(font); | |
5553 font = NULL; | |
5554 } | |
5555 else | |
5556 g_object_unref(real_font); | |
5557 } | |
5558 | |
5559 if (font == NULL) | |
5560 { | |
5561 if (report_error) | |
1666 | 5562 EMSG2(_((char *)e_font), name); |
7 | 5563 return NULL; |
5564 } | |
5565 | |
5566 return font; | |
5567 } | |
5568 | |
39 | 5569 #if defined(FEAT_EVAL) || defined(PROTO) |
38 | 5570 /* |
5571 * Return the name of font "font" in allocated memory. | |
5572 */ | |
5573 char_u * | |
1884 | 5574 gui_mch_get_fontname(GuiFont font, char_u *name UNUSED) |
38 | 5575 { |
5576 if (font != NOFONT) | |
5577 { | |
944 | 5578 char *pangoname = pango_font_description_to_string(font); |
5579 | |
5580 if (pangoname != NULL) | |
38 | 5581 { |
944 | 5582 char_u *s = vim_strsave((char_u *)pangoname); |
5583 | |
5584 g_free(pangoname); | |
38 | 5585 return s; |
5586 } | |
5587 } | |
5588 return NULL; | |
5589 } | |
39 | 5590 #endif |
38 | 5591 |
7 | 5592 /* |
5593 * If a font is not going to be used, free its structure. | |
5594 */ | |
5595 void | |
5596 gui_mch_free_font(GuiFont font) | |
5597 { | |
5598 if (font != NOFONT) | |
5599 pango_font_description_free(font); | |
5600 } | |
5601 | |
5602 /* | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5603 * Return the Pixel value (color) for the given color name. |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5604 * |
7 | 5605 * Return INVALCOLOR for error. |
5606 */ | |
5607 guicolor_T | |
5608 gui_mch_get_color(char_u *name) | |
5609 { | |
13674
1feeefd8cddb
patch 8.0.1709: some non-C89 code may slip through
Christian Brabandt <cb@256bit.org>
parents:
13503
diff
changeset
|
5610 guicolor_T color = INVALCOLOR; |
1feeefd8cddb
patch 8.0.1709: some non-C89 code may slip through
Christian Brabandt <cb@256bit.org>
parents:
13503
diff
changeset
|
5611 |
7 | 5612 if (!gui.in_use) /* can't do this when GUI not running */ |
13674
1feeefd8cddb
patch 8.0.1709: some non-C89 code may slip through
Christian Brabandt <cb@256bit.org>
parents:
13503
diff
changeset
|
5613 return color; |
1feeefd8cddb
patch 8.0.1709: some non-C89 code may slip through
Christian Brabandt <cb@256bit.org>
parents:
13503
diff
changeset
|
5614 |
1feeefd8cddb
patch 8.0.1709: some non-C89 code may slip through
Christian Brabandt <cb@256bit.org>
parents:
13503
diff
changeset
|
5615 if (name != NULL) |
1feeefd8cddb
patch 8.0.1709: some non-C89 code may slip through
Christian Brabandt <cb@256bit.org>
parents:
13503
diff
changeset
|
5616 color = gui_get_color_cmn(name); |
7 | 5617 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5618 #if GTK_CHECK_VERSION(3,0,0) |
13674
1feeefd8cddb
patch 8.0.1709: some non-C89 code may slip through
Christian Brabandt <cb@256bit.org>
parents:
13503
diff
changeset
|
5619 return color; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5620 #else |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5621 if (color == INVALCOLOR) |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5622 return INVALCOLOR; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5623 |
11745
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5624 return gui_mch_get_rgb_color( |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5625 (color & 0xff0000) >> 16, |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5626 (color & 0xff00) >> 8, |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5627 color & 0xff); |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5628 #endif |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5629 } |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5630 |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5631 /* |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5632 * Return the Pixel value (color) for the given RGB values. |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5633 * Return INVALCOLOR for error. |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5634 */ |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5635 guicolor_T |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5636 gui_mch_get_rgb_color(int r, int g, int b) |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5637 { |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5638 #if GTK_CHECK_VERSION(3,0,0) |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5639 return gui_get_rgb_color_cmn(r, g, b); |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5640 #else |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5641 GdkColor gcolor; |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5642 int ret; |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5643 |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5644 gcolor.red = (guint16)(r / 255.0 * 65535 + 0.5); |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5645 gcolor.green = (guint16)(g / 255.0 * 65535 + 0.5); |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5646 gcolor.blue = (guint16)(b / 255.0 * 65535 + 0.5); |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5647 |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5648 ret = gdk_colormap_alloc_color(gtk_widget_get_colormap(gui.drawarea), |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5649 &gcolor, FALSE, TRUE); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5650 |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5651 return ret != 0 ? (guicolor_T)gcolor.pixel : INVALCOLOR; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5652 #endif |
7 | 5653 } |
5654 | |
5655 /* | |
5656 * Set the current text foreground color. | |
5657 */ | |
5658 void | |
5659 gui_mch_set_fg_color(guicolor_T color) | |
5660 { | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5661 #if GTK_CHECK_VERSION(3,0,0) |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5662 *gui.fgcolor = color_to_rgba(color); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5663 #else |
7 | 5664 gui.fgcolor->pixel = (unsigned long)color; |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5665 #endif |
7 | 5666 } |
5667 | |
5668 /* | |
5669 * Set the current text background color. | |
5670 */ | |
5671 void | |
5672 gui_mch_set_bg_color(guicolor_T color) | |
5673 { | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5674 #if GTK_CHECK_VERSION(3,0,0) |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5675 *gui.bgcolor = color_to_rgba(color); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5676 #else |
7 | 5677 gui.bgcolor->pixel = (unsigned long)color; |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5678 #endif |
7 | 5679 } |
5680 | |
207 | 5681 /* |
5682 * Set the current text special color. | |
5683 */ | |
5684 void | |
5685 gui_mch_set_sp_color(guicolor_T color) | |
5686 { | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5687 #if GTK_CHECK_VERSION(3,0,0) |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5688 *gui.spcolor = color_to_rgba(color); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5689 #else |
207 | 5690 gui.spcolor->pixel = (unsigned long)color; |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5691 #endif |
207 | 5692 } |
5693 | |
7 | 5694 /* |
5695 * Function-like convenience macro for the sake of efficiency. | |
5696 */ | |
5697 #define INSERT_PANGO_ATTR(Attribute, AttrList, Start, End) \ | |
5698 G_STMT_START{ \ | |
5699 PangoAttribute *tmp_attr_; \ | |
5700 tmp_attr_ = (Attribute); \ | |
5701 tmp_attr_->start_index = (Start); \ | |
5702 tmp_attr_->end_index = (End); \ | |
5703 pango_attr_list_insert((AttrList), tmp_attr_); \ | |
5704 }G_STMT_END | |
5705 | |
5706 static void | |
5707 apply_wide_font_attr(char_u *s, int len, PangoAttrList *attr_list) | |
5708 { | |
5709 char_u *start = NULL; | |
5710 char_u *p; | |
5711 int uc; | |
5712 | |
5713 for (p = s; p < s + len; p += utf_byte2len(*p)) | |
5714 { | |
5715 uc = utf_ptr2char(p); | |
5716 | |
5717 if (start == NULL) | |
5718 { | |
5719 if (uc >= 0x80 && utf_char2cells(uc) == 2) | |
5720 start = p; | |
5721 } | |
5722 else if (uc < 0x80 /* optimization shortcut */ | |
5723 || (utf_char2cells(uc) != 2 && !utf_iscomposing(uc))) | |
5724 { | |
5725 INSERT_PANGO_ATTR(pango_attr_font_desc_new(gui.wide_font), | |
5726 attr_list, start - s, p - s); | |
5727 start = NULL; | |
5728 } | |
5729 } | |
5730 | |
5731 if (start != NULL) | |
5732 INSERT_PANGO_ATTR(pango_attr_font_desc_new(gui.wide_font), | |
5733 attr_list, start - s, len); | |
5734 } | |
5735 | |
5736 static int | |
5737 count_cluster_cells(char_u *s, PangoItem *item, | |
5738 PangoGlyphString* glyphs, int i, | |
5739 int *cluster_width, | |
5740 int *last_glyph_rbearing) | |
5741 { | |
5742 char_u *p; | |
5743 int next; /* glyph start index of next cluster */ | |
5744 int start, end; /* string segment of current cluster */ | |
5745 int width; /* real cluster width in Pango units */ | |
5746 int uc; | |
5747 int cellcount = 0; | |
5748 | |
5749 width = glyphs->glyphs[i].geometry.width; | |
5750 | |
5751 for (next = i + 1; next < glyphs->num_glyphs; ++next) | |
5752 { | |
5753 if (glyphs->glyphs[next].attr.is_cluster_start) | |
5754 break; | |
5755 else if (glyphs->glyphs[next].geometry.width > width) | |
5756 width = glyphs->glyphs[next].geometry.width; | |
5757 } | |
5758 | |
5759 start = item->offset + glyphs->log_clusters[i]; | |
5760 end = item->offset + ((next < glyphs->num_glyphs) ? | |
5761 glyphs->log_clusters[next] : item->length); | |
5762 | |
5763 for (p = s + start; p < s + end; p += utf_byte2len(*p)) | |
5764 { | |
5765 uc = utf_ptr2char(p); | |
5766 if (uc < 0x80) | |
5767 ++cellcount; | |
5768 else if (!utf_iscomposing(uc)) | |
5769 cellcount += utf_char2cells(uc); | |
5770 } | |
5771 | |
5772 if (last_glyph_rbearing != NULL | |
5773 && cellcount > 0 && next == glyphs->num_glyphs) | |
5774 { | |
5775 PangoRectangle ink_rect; | |
5776 /* | |
5777 * If a certain combining mark had to be taken from a non-monospace | |
5778 * font, we have to compensate manually by adapting x_offset according | |
5779 * to the ink extents of the previous glyph. | |
5780 */ | |
5781 pango_font_get_glyph_extents(item->analysis.font, | |
5782 glyphs->glyphs[i].glyph, | |
5783 &ink_rect, NULL); | |
5784 | |
5785 if (PANGO_RBEARING(ink_rect) > 0) | |
5786 *last_glyph_rbearing = PANGO_RBEARING(ink_rect); | |
5787 } | |
5788 | |
5789 if (cellcount > 0) | |
5790 *cluster_width = width; | |
5791 | |
5792 return cellcount; | |
5793 } | |
5794 | |
5795 /* | |
5796 * If there are only combining characters in the cluster, we cannot just | |
5797 * change the width of the previous glyph since there is none. Therefore | |
5798 * some guesswork is needed. | |
5799 * | |
5800 * If ink_rect.x is negative Pango apparently has taken care of the composing | |
5801 * by itself. Actually setting x_offset = 0 should be sufficient then, but due | |
5802 * 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
|
5803 * x_offset to avoid ugliness. |
7 | 5804 * |
5805 * If ink_rect.x is not negative, force overstriking by pointing x_offset to | |
5806 * the position of the previous glyph. Apparently this happens only with old | |
5807 * X fonts which don't provide the special combining information needed by | |
5808 * Pango. | |
5809 */ | |
5810 static void | |
5811 setup_zero_width_cluster(PangoItem *item, PangoGlyphInfo *glyph, | |
5812 int last_cellcount, int last_cluster_width, | |
5813 int last_glyph_rbearing) | |
5814 { | |
5815 PangoRectangle ink_rect; | |
5816 PangoRectangle logical_rect; | |
5817 int width; | |
5818 | |
5819 width = last_cellcount * gui.char_width * PANGO_SCALE; | |
5820 glyph->geometry.x_offset = -width + MAX(0, width - last_cluster_width) / 2; | |
5821 glyph->geometry.width = 0; | |
5822 | |
5823 pango_font_get_glyph_extents(item->analysis.font, | |
5824 glyph->glyph, | |
5825 &ink_rect, &logical_rect); | |
5826 if (ink_rect.x < 0) | |
5827 { | |
5828 glyph->geometry.x_offset += last_glyph_rbearing; | |
5829 glyph->geometry.y_offset = logical_rect.height | |
5830 - (gui.char_height - p_linespace) * PANGO_SCALE; | |
5831 } | |
2507
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
5832 else |
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
5833 /* 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
|
5834 * 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
|
5835 glyph->geometry.x_offset = -width + MAX(0, width - ink_rect.width) / 2; |
7 | 5836 } |
5837 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5838 #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
|
5839 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5840 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
|
5841 PangoFont *font, PangoGlyphString *glyphs, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5842 cairo_t *cr) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5843 #else |
7 | 5844 static void |
5845 draw_glyph_string(int row, int col, int num_cells, int flags, | |
5846 PangoFont *font, PangoGlyphString *glyphs) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5847 #endif |
7 | 5848 { |
5849 if (!(flags & DRAW_TRANSP)) | |
5850 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5851 #if GTK_CHECK_VERSION(3,0,0) |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5852 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5853 gui.bgcolor->red, gui.bgcolor->green, gui.bgcolor->blue, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5854 gui.bgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5855 cairo_rectangle(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5856 FILL_X(col), FILL_Y(row), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5857 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
|
5858 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5859 #else |
7 | 5860 gdk_gc_set_foreground(gui.text_gc, gui.bgcolor); |
5861 | |
5862 gdk_draw_rectangle(gui.drawarea->window, | |
5863 gui.text_gc, | |
5864 TRUE, | |
5865 FILL_X(col), | |
5866 FILL_Y(row), | |
5867 num_cells * gui.char_width, | |
5868 gui.char_height); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5869 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5870 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5871 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5872 #if GTK_CHECK_VERSION(3,0,0) |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5873 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5874 gui.fgcolor->red, gui.fgcolor->green, gui.fgcolor->blue, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5875 gui.fgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5876 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
|
5877 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
|
5878 #else |
7 | 5879 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
5880 | |
5881 gdk_draw_glyphs(gui.drawarea->window, | |
5882 gui.text_gc, | |
5883 font, | |
5884 TEXT_X(col), | |
5885 TEXT_Y(row), | |
5886 glyphs); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5887 #endif |
7 | 5888 |
5889 /* redraw the contents with an offset of 1 to emulate bold */ | |
5890 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
|
5891 #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
|
5892 { |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5893 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5894 gui.fgcolor->red, gui.fgcolor->green, gui.fgcolor->blue, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5895 gui.fgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5896 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
|
5897 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
|
5898 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5899 #else |
7 | 5900 gdk_draw_glyphs(gui.drawarea->window, |
5901 gui.text_gc, | |
5902 font, | |
5903 TEXT_X(col) + 1, | |
5904 TEXT_Y(row), | |
5905 glyphs); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5906 #endif |
7 | 5907 } |
5908 | |
207 | 5909 /* |
5910 * Draw underline and undercurl at the bottom of the character cell. | |
5911 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5912 #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
|
5913 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5914 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
|
5915 #else |
207 | 5916 static void |
5917 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
|
5918 #endif |
207 | 5919 { |
5920 int i; | |
5921 int offset; | |
1884 | 5922 static const int val[8] = {1, 0, 0, 0, 1, 2, 2, 2 }; |
207 | 5923 int y = FILL_Y(row + 1) - 1; |
5924 | |
5925 /* Undercurl: draw curl at the bottom of the character cell. */ | |
5926 if (flags & DRAW_UNDERC) | |
5927 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5928 #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
|
5929 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
|
5930 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5931 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5932 gui.spcolor->red, gui.spcolor->green, gui.spcolor->blue, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5933 gui.spcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5934 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
|
5935 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5936 offset = val[i % 8]; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5937 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
|
5938 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5939 cairo_stroke(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5940 #else |
207 | 5941 gdk_gc_set_foreground(gui.text_gc, gui.spcolor); |
5942 for (i = FILL_X(col); i < FILL_X(col + cells); ++i) | |
5943 { | |
5944 offset = val[i % 8]; | |
5945 gdk_draw_point(gui.drawarea->window, gui.text_gc, i, y - offset); | |
5946 } | |
5947 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
|
5948 #endif |
207 | 5949 } |
5950 | |
12317
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5951 /* Draw a strikethrough line */ |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5952 if (flags & DRAW_STRIKE) |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5953 { |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5954 #if GTK_CHECK_VERSION(3,0,0) |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5955 cairo_set_line_width(cr, 1.0); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5956 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5957 cairo_set_source_rgba(cr, |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5958 gui.spcolor->red, gui.spcolor->green, gui.spcolor->blue, |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5959 gui.spcolor->alpha); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5960 cairo_move_to(cr, FILL_X(col), y + 1 - gui.char_height/2 + 0.5); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5961 cairo_line_to(cr, FILL_X(col + cells), y + 1 - gui.char_height/2 + 0.5); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5962 cairo_stroke(cr); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5963 #else |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5964 gdk_gc_set_foreground(gui.text_gc, gui.spcolor); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5965 gdk_draw_line(gui.drawarea->window, gui.text_gc, |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5966 FILL_X(col), y + 1 - gui.char_height/2, |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5967 FILL_X(col + cells), y + 1 - gui.char_height/2); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5968 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5969 #endif |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5970 } |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5971 |
207 | 5972 /* Underline: draw a line at the bottom of the character cell. */ |
5973 if (flags & DRAW_UNDERL) | |
5974 { | |
5975 /* When p_linespace is 0, overwrite the bottom row of pixels. | |
5976 * Otherwise put the line just below the character. */ | |
5977 if (p_linespace > 1) | |
5978 y -= p_linespace - 1; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5979 #if GTK_CHECK_VERSION(3,0,0) |
12317
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5980 cairo_set_line_width(cr, 1.0); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5981 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5982 cairo_set_source_rgba(cr, |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5983 gui.fgcolor->red, gui.fgcolor->green, gui.fgcolor->blue, |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5984 gui.fgcolor->alpha); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5985 cairo_move_to(cr, FILL_X(col), y + 0.5); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5986 cairo_line_to(cr, FILL_X(col + cells), y + 0.5); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5987 cairo_stroke(cr); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5988 #else |
207 | 5989 gdk_draw_line(gui.drawarea->window, gui.text_gc, |
5990 FILL_X(col), y, | |
5991 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
|
5992 #endif |
207 | 5993 } |
5994 } | |
5995 | |
7 | 5996 int |
5997 gui_gtk2_draw_string(int row, int col, char_u *s, int len, int flags) | |
5998 { | |
5999 GdkRectangle area; /* area for clip mask */ | |
6000 PangoGlyphString *glyphs; /* glyphs of current item */ | |
6001 int column_offset = 0; /* column offset in cells */ | |
6002 int i; | |
6003 char_u *conv_buf = NULL; /* result of UTF-8 conversion */ | |
6004 char_u *new_conv_buf; | |
6005 int convlen; | |
6006 char_u *sp, *bp; | |
6007 int plen; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6008 #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
|
6009 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6010 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6011 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6012 #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
|
6013 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
|
6014 #else |
7 | 6015 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
|
6016 #endif |
7 | 6017 return len; |
6018 | |
6019 if (output_conv.vc_type != CONV_NONE) | |
6020 { | |
6021 /* | |
6022 * Convert characters from 'encoding' to 'termencoding', which is set | |
6023 * to UTF-8 by gui_mch_init(). did_set_string_option() in option.c | |
6024 * prohibits changing this to something else than UTF-8 if the GUI is | |
6025 * in use. | |
6026 */ | |
6027 convlen = len; | |
6028 conv_buf = string_convert(&output_conv, s, &convlen); | |
6029 g_return_val_if_fail(conv_buf != NULL, len); | |
6030 | |
6031 /* Correct for differences in char width: some chars are | |
6032 * double-wide in 'encoding' but single-wide in utf-8. Add a space to | |
6033 * compensate for that. */ | |
6034 for (sp = s, bp = conv_buf; sp < s + len && bp < conv_buf + convlen; ) | |
6035 { | |
474 | 6036 plen = utf_ptr2len(bp); |
7 | 6037 if ((*mb_ptr2cells)(sp) == 2 && utf_ptr2cells(bp) == 1) |
6038 { | |
6039 new_conv_buf = alloc(convlen + 2); | |
6040 if (new_conv_buf == NULL) | |
6041 return len; | |
6042 plen += bp - conv_buf; | |
6043 mch_memmove(new_conv_buf, conv_buf, plen); | |
6044 new_conv_buf[plen] = ' '; | |
6045 mch_memmove(new_conv_buf + plen + 1, conv_buf + plen, | |
6046 convlen - plen + 1); | |
6047 vim_free(conv_buf); | |
6048 conv_buf = new_conv_buf; | |
6049 ++convlen; | |
6050 bp = conv_buf + plen; | |
6051 plen = 1; | |
6052 } | |
474 | 6053 sp += (*mb_ptr2len)(sp); |
7 | 6054 bp += plen; |
6055 } | |
6056 s = conv_buf; | |
6057 len = convlen; | |
6058 } | |
6059 | |
6060 /* | |
6061 * Restrict all drawing to the current screen line in order to prevent | |
6062 * fuzzy font lookups from messing up the screen. | |
6063 */ | |
6064 area.x = gui.border_offset; | |
6065 area.y = FILL_Y(row); | |
6066 area.width = gui.num_cols * gui.char_width; | |
6067 area.height = gui.char_height; | |
6068 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6069 #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
|
6070 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6071 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
|
6072 cairo_clip(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6073 #else |
7 | 6074 gdk_gc_set_clip_origin(gui.text_gc, 0, 0); |
6075 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
|
6076 #endif |
7 | 6077 |
6078 glyphs = pango_glyph_string_new(); | |
6079 | |
6080 /* | |
6081 * Optimization hack: If possible, skip the itemize and shaping process | |
6082 * for pure ASCII strings. This optimization is particularly effective | |
6083 * because Vim draws space characters to clear parts of the screen. | |
6084 */ | |
6085 if (!(flags & DRAW_ITALIC) | |
6086 && !((flags & DRAW_BOLD) && gui.font_can_bold) | |
6087 && gui.ascii_glyphs != NULL) | |
6088 { | |
6089 char_u *p; | |
6090 | |
6091 for (p = s; p < s + len; ++p) | |
6092 if (*p & 0x80) | |
6093 goto not_ascii; | |
6094 | |
6095 pango_glyph_string_set_size(glyphs, len); | |
6096 | |
6097 for (i = 0; i < len; ++i) | |
6098 { | |
9879
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
6099 glyphs->glyphs[i] = gui.ascii_glyphs->glyphs[2 * s[i]]; |
7 | 6100 glyphs->log_clusters[i] = i; |
6101 } | |
6102 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6103 #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
|
6104 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
|
6105 #else |
7 | 6106 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
|
6107 #endif |
7 | 6108 |
6109 column_offset = len; | |
6110 } | |
6111 else | |
6112 not_ascii: | |
6113 { | |
6114 PangoAttrList *attr_list; | |
6115 GList *item_list; | |
6116 int cluster_width; | |
6117 int last_glyph_rbearing; | |
6118 int cells = 0; /* cells occupied by current cluster */ | |
6119 | |
26 | 6120 /* Safety check: pango crashes when invoked with invalid utf-8 |
6121 * characters. */ | |
6122 if (!utf_valid_string(s, s + len)) | |
6123 { | |
6124 column_offset = len; | |
6125 goto skipitall; | |
6126 } | |
6127 | |
7 | 6128 /* original width of the current cluster */ |
6129 cluster_width = PANGO_SCALE * gui.char_width; | |
6130 | |
6131 /* right bearing of the last non-composing glyph */ | |
6132 last_glyph_rbearing = PANGO_SCALE * gui.char_width; | |
6133 | |
6134 attr_list = pango_attr_list_new(); | |
6135 | |
6136 /* If 'guifontwide' is set then use that for double-width characters. | |
6137 * Otherwise just go with 'guifont' and let Pango do its thing. */ | |
6138 if (gui.wide_font != NULL) | |
6139 apply_wide_font_attr(s, len, attr_list); | |
6140 | |
6141 if ((flags & DRAW_BOLD) && gui.font_can_bold) | |
6142 INSERT_PANGO_ATTR(pango_attr_weight_new(PANGO_WEIGHT_BOLD), | |
6143 attr_list, 0, len); | |
6144 if (flags & DRAW_ITALIC) | |
6145 INSERT_PANGO_ATTR(pango_attr_style_new(PANGO_STYLE_ITALIC), | |
6146 attr_list, 0, len); | |
6147 /* | |
6148 * Break the text into segments with consistent directional level | |
6149 * and shaping engine. Pure Latin text needs only a single segment, | |
6150 * so there's no need to worry about the loop's efficiency. Better | |
6151 * try to optimize elsewhere, e.g. reducing exposes and stuff :) | |
6152 */ | |
6153 item_list = pango_itemize(gui.text_context, | |
6154 (const char *)s, 0, len, attr_list, NULL); | |
6155 | |
6156 while (item_list != NULL) | |
6157 { | |
6158 PangoItem *item; | |
6159 int item_cells = 0; /* item length in cells */ | |
6160 | |
6161 item = (PangoItem *)item_list->data; | |
6162 item_list = g_list_delete_link(item_list, item_list); | |
6163 /* | |
6164 * Increment the bidirectional embedding level by 1 if it is not | |
6165 * even. An odd number means the output will be RTL, but we don't | |
6166 * want that since Vim handles right-to-left text on its own. It | |
6167 * would probably be sufficient to just set level = 0, but you can | |
6168 * never know :) | |
6169 * | |
6170 * Unfortunately we can't take advantage of Pango's ability to | |
6171 * render both LTR and RTL at the same time. In order to support | |
6172 * that, Vim's main screen engine would have to make use of Pango | |
6173 * functionality. | |
6174 */ | |
6175 item->analysis.level = (item->analysis.level + 1) & (~1U); | |
6176 | |
6177 /* HACK: Overrule the shape engine, we don't want shaping to be | |
6178 * done, because drawing the cursor would change the display. */ | |
6179 item->analysis.shape_engine = default_shape_engine; | |
6180 | |
7098
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6181 #ifdef HAVE_PANGO_SHAPE_FULL |
7086
3825da022231
commit https://github.com/vim/vim/commit/7e2ec008f5c5152205d0b8a7d88177b374225d8d
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
6182 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
|
6183 (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
|
6184 #else |
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6185 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
|
6186 &item->analysis, glyphs); |
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6187 #endif |
7 | 6188 /* |
6189 * Fixed-width hack: iterate over the array and assign a fixed | |
6190 * width to each glyph, thus overriding the choice made by the | |
6191 * shaping engine. We use utf_char2cells() to determine the | |
6192 * number of cells needed. | |
6193 * | |
6194 * Also perform all kind of dark magic to get composing | |
6195 * characters right (and pretty too of course). | |
6196 */ | |
6197 for (i = 0; i < glyphs->num_glyphs; ++i) | |
6198 { | |
6199 PangoGlyphInfo *glyph; | |
6200 | |
6201 glyph = &glyphs->glyphs[i]; | |
6202 | |
6203 if (glyph->attr.is_cluster_start) | |
6204 { | |
6205 int cellcount; | |
6206 | |
6207 cellcount = count_cluster_cells( | |
6208 s, item, glyphs, i, &cluster_width, | |
6209 (item_list != NULL) ? &last_glyph_rbearing : NULL); | |
6210 | |
6211 if (cellcount > 0) | |
6212 { | |
6213 int width; | |
6214 | |
6215 width = cellcount * gui.char_width * PANGO_SCALE; | |
6216 glyph->geometry.x_offset += | |
6217 MAX(0, width - cluster_width) / 2; | |
6218 glyph->geometry.width = width; | |
6219 } | |
6220 else | |
6221 { | |
6222 /* If there are only combining characters in the | |
6223 * cluster, we cannot just change the width of the | |
6224 * previous glyph since there is none. Therefore | |
6225 * some guesswork is needed. */ | |
6226 setup_zero_width_cluster(item, glyph, cells, | |
6227 cluster_width, | |
6228 last_glyph_rbearing); | |
6229 } | |
6230 | |
6231 item_cells += cellcount; | |
6232 cells = cellcount; | |
6233 } | |
6234 else if (i > 0) | |
6235 { | |
6236 int width; | |
6237 | |
6238 /* 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
|
6239 * characters the canonical way. |
2517
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6240 * 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
|
6241 * 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
|
6242 * and set the previous width to zero. |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6243 * 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
|
6244 * 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
|
6245 * 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
|
6246 * 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
|
6247 * 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
|
6248 if (glyph->geometry.x_offset >= 0) |
2517
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6249 { |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6250 glyphs->glyphs[i].geometry.width = |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6251 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
|
6252 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
|
6253 } |
7 | 6254 width = cells * gui.char_width * PANGO_SCALE; |
6255 glyph->geometry.x_offset += | |
6256 MAX(0, width - cluster_width) / 2; | |
6257 } | |
6258 else /* i == 0 "cannot happen" */ | |
6259 { | |
6260 glyph->geometry.width = 0; | |
6261 } | |
6262 } | |
6263 | |
6264 /*** Aaaaand action! ***/ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6265 #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
|
6266 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
|
6267 flags, item->analysis.font, glyphs, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6268 cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6269 #else |
7 | 6270 draw_glyph_string(row, col + column_offset, item_cells, |
6271 flags, item->analysis.font, glyphs); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6272 #endif |
7 | 6273 |
6274 pango_item_free(item); | |
6275 | |
6276 column_offset += item_cells; | |
6277 } | |
6278 | |
6279 pango_attr_list_unref(attr_list); | |
6280 } | |
6281 | |
26 | 6282 skipitall: |
207 | 6283 /* Draw underline and undercurl. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6284 #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
|
6285 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
|
6286 #else |
207 | 6287 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
|
6288 #endif |
7 | 6289 |
6290 pango_glyph_string_free(glyphs); | |
6291 vim_free(conv_buf); | |
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 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6295 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6296 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
|
6297 &area, FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6298 #else |
7 | 6299 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
|
6300 #endif |
7 | 6301 |
6302 return column_offset; | |
6303 } | |
6304 | |
6305 /* | |
6306 * Return OK if the key with the termcap name "name" is supported. | |
6307 */ | |
6308 int | |
6309 gui_mch_haskey(char_u *name) | |
6310 { | |
6311 int i; | |
6312 | |
6313 for (i = 0; special_keys[i].key_sym != 0; i++) | |
6314 if (name[0] == special_keys[i].code0 | |
6315 && name[1] == special_keys[i].code1) | |
6316 return OK; | |
6317 return FAIL; | |
6318 } | |
6319 | |
4133 | 6320 #if defined(FEAT_TITLE) || defined(FEAT_EVAL) || defined(PROTO) |
7 | 6321 /* |
6322 * Return the text window-id and display. Only required for X-based GUI's | |
6323 */ | |
6324 int | |
6325 gui_get_x11_windis(Window *win, Display **dis) | |
6326 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6327 #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
|
6328 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
|
6329 #else |
7 | 6330 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
|
6331 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6332 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6333 #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
|
6334 *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
|
6335 *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
|
6336 #else |
7 | 6337 *dis = GDK_WINDOW_XDISPLAY(gui.mainwin->window); |
6338 *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
|
6339 #endif |
7 | 6340 return OK; |
6341 } | |
6342 | |
6343 *dis = NULL; | |
6344 *win = 0; | |
6345 return FAIL; | |
6346 } | |
6347 #endif | |
6348 | |
6349 #if defined(FEAT_CLIENTSERVER) \ | |
6350 || (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO) | |
6351 | |
6352 Display * | |
6353 gui_mch_get_display(void) | |
6354 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6355 #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
|
6356 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
|
6357 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
|
6358 #else |
7 | 6359 if (gui.mainwin != NULL && gui.mainwin->window != NULL) |
6360 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
|
6361 #endif |
7 | 6362 else |
6363 return NULL; | |
6364 } | |
6365 #endif | |
6366 | |
6367 void | |
6368 gui_mch_beep(void) | |
6369 { | |
6370 GdkDisplay *display; | |
6371 | |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6372 #if GTK_CHECK_VERSION(3,0,0) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6373 if (gui.mainwin != NULL && gtk_widget_get_realized(gui.mainwin)) |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6374 #else |
7 | 6375 if (gui.mainwin != NULL && GTK_WIDGET_REALIZED(gui.mainwin)) |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6376 #endif |
7 | 6377 display = gtk_widget_get_display(gui.mainwin); |
6378 else | |
6379 display = gdk_display_get_default(); | |
6380 | |
6381 if (display != NULL) | |
6382 gdk_display_beep(display); | |
6383 } | |
6384 | |
6385 void | |
6386 gui_mch_flash(int msec) | |
6387 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6388 #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
|
6389 /* TODO Replace GdkGC with Cairo */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6390 (void)msec; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6391 #else |
7 | 6392 GdkGCValues values; |
6393 GdkGC *invert_gc; | |
6394 | |
6395 if (gui.drawarea->window == NULL) | |
6396 return; | |
6397 | |
6398 values.foreground.pixel = gui.norm_pixel ^ gui.back_pixel; | |
6399 values.background.pixel = gui.norm_pixel ^ gui.back_pixel; | |
6400 values.function = GDK_XOR; | |
6401 invert_gc = gdk_gc_new_with_values(gui.drawarea->window, | |
6402 &values, | |
6403 GDK_GC_FOREGROUND | | |
6404 GDK_GC_BACKGROUND | | |
6405 GDK_GC_FUNCTION); | |
6406 gdk_gc_set_exposures(invert_gc, | |
6407 gui.visibility != GDK_VISIBILITY_UNOBSCURED); | |
6408 /* | |
6409 * Do a visual beep by changing back and forth in some undetermined way, | |
6410 * the foreground and background colors. This is due to the fact that | |
6411 * there can't be really any prediction about the effects of XOR on | |
6412 * arbitrary X11 servers. However this seems to be enough for what we | |
6413 * intend it to do. | |
6414 */ | |
6415 gdk_draw_rectangle(gui.drawarea->window, invert_gc, | |
6416 TRUE, | |
6417 0, 0, | |
6418 FILL_X((int)Columns) + gui.border_offset, | |
6419 FILL_Y((int)Rows) + gui.border_offset); | |
6420 | |
6421 gui_mch_flush(); | |
6422 ui_delay((long)msec, TRUE); /* wait so many msec */ | |
6423 | |
6424 gdk_draw_rectangle(gui.drawarea->window, invert_gc, | |
6425 TRUE, | |
6426 0, 0, | |
6427 FILL_X((int)Columns) + gui.border_offset, | |
6428 FILL_Y((int)Rows) + gui.border_offset); | |
6429 | |
6430 gdk_gc_destroy(invert_gc); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6431 #endif |
7 | 6432 } |
6433 | |
6434 /* | |
6435 * Invert a rectangle from row r, column c, for nr rows and nc columns. | |
6436 */ | |
6437 void | |
6438 gui_mch_invert_rectangle(int r, int c, int nr, int nc) | |
6439 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6440 #if GTK_CHECK_VERSION(3,0,0) |
8495
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6441 const GdkRectangle rect = { |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6442 FILL_X(c), FILL_Y(r), nc * gui.char_width, nr * gui.char_height |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6443 }; |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6444 cairo_t * const cr = cairo_create(gui.surface); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6445 |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6446 set_cairo_source_rgba_from_color(cr, gui.norm_pixel ^ gui.back_pixel); |
8495
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6447 # if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,9,2) |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6448 cairo_set_operator(cr, CAIRO_OPERATOR_DIFFERENCE); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6449 # else |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6450 /* Give an implementation for older cairo versions if necessary. */ |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6451 # endif |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6452 gdk_cairo_rectangle(cr, &rect); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6453 cairo_fill(cr); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6454 |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6455 cairo_destroy(cr); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6456 |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6457 if (!gui.by_signal) |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6458 gtk_widget_queue_draw_area(gui.drawarea, rect.x, rect.y, |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6459 rect.width, rect.height); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6460 #else |
7 | 6461 GdkGCValues values; |
6462 GdkGC *invert_gc; | |
6463 | |
6464 if (gui.drawarea->window == NULL) | |
6465 return; | |
6466 | |
944 | 6467 values.foreground.pixel = gui.norm_pixel ^ gui.back_pixel; |
6468 values.background.pixel = gui.norm_pixel ^ gui.back_pixel; | |
7 | 6469 values.function = GDK_XOR; |
6470 invert_gc = gdk_gc_new_with_values(gui.drawarea->window, | |
6471 &values, | |
6472 GDK_GC_FOREGROUND | | |
6473 GDK_GC_BACKGROUND | | |
6474 GDK_GC_FUNCTION); | |
944 | 6475 gdk_gc_set_exposures(invert_gc, gui.visibility != |
6476 GDK_VISIBILITY_UNOBSCURED); | |
7 | 6477 gdk_draw_rectangle(gui.drawarea->window, invert_gc, |
6478 TRUE, | |
6479 FILL_X(c), FILL_Y(r), | |
6480 (nc) * gui.char_width, (nr) * gui.char_height); | |
6481 gdk_gc_destroy(invert_gc); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6482 #endif |
7 | 6483 } |
6484 | |
6485 /* | |
6486 * Iconify the GUI window. | |
6487 */ | |
6488 void | |
6489 gui_mch_iconify(void) | |
6490 { | |
6491 gtk_window_iconify(GTK_WINDOW(gui.mainwin)); | |
6492 } | |
6493 | |
6494 #if defined(FEAT_EVAL) || defined(PROTO) | |
6495 /* | |
6496 * Bring the Vim window to the foreground. | |
6497 */ | |
6498 void | |
6499 gui_mch_set_foreground(void) | |
6500 { | |
6501 gtk_window_present(GTK_WINDOW(gui.mainwin)); | |
6502 } | |
6503 #endif | |
6504 | |
6505 /* | |
6506 * Draw a cursor without focus. | |
6507 */ | |
6508 void | |
6509 gui_mch_draw_hollow_cursor(guicolor_T color) | |
6510 { | |
6511 int i = 1; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6512 #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
|
6513 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6514 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6515 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6516 #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
|
6517 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
|
6518 #else |
7 | 6519 if (gui.drawarea->window == NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6520 #endif |
7 | 6521 return; |
6522 | |
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 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6525 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6526 |
7 | 6527 gui_mch_set_fg_color(color); |
6528 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6529 #if GTK_CHECK_VERSION(3,0,0) |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6530 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6531 gui.fgcolor->red, gui.fgcolor->green, gui.fgcolor->blue, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6532 gui.fgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6533 #else |
7 | 6534 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
|
6535 #endif |
7 | 6536 if (mb_lefthalve(gui.row, gui.col)) |
6537 i = 2; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6538 #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
|
6539 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
|
6540 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
|
6541 cairo_rectangle(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6542 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
|
6543 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
|
6544 cairo_stroke(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6545 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6546 #else |
7 | 6547 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, |
6548 FALSE, | |
6549 FILL_X(gui.col), FILL_Y(gui.row), | |
6550 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
|
6551 #endif |
7 | 6552 } |
6553 | |
6554 /* | |
6555 * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using | |
6556 * color "color". | |
6557 */ | |
6558 void | |
6559 gui_mch_draw_part_cursor(int w, int h, guicolor_T color) | |
6560 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6561 #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
|
6562 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
|
6563 #else |
7 | 6564 if (gui.drawarea->window == NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6565 #endif |
7 | 6566 return; |
6567 | |
6568 gui_mch_set_fg_color(color); | |
6569 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6570 #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
|
6571 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6572 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6573 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6574 cr = cairo_create(gui.surface); |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6575 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6576 gui.fgcolor->red, gui.fgcolor->green, gui.fgcolor->blue, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6577 gui.fgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6578 cairo_rectangle(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6579 # ifdef FEAT_RIGHTLEFT |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6580 /* 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
|
6581 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
|
6582 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6583 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
|
6584 w, h); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6585 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6586 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6587 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6588 #else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6589 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
6590 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, | |
6591 TRUE, | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6592 # ifdef FEAT_RIGHTLEFT |
7 | 6593 /* vertical line should be on the right of current point */ |
6594 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
|
6595 # endif |
7 | 6596 FILL_X(gui.col), |
6597 FILL_Y(gui.row) + gui.char_height - h, | |
6598 w, h); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6599 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6600 } |
6601 | |
6602 | |
6603 /* | |
6604 * Catch up with any queued X11 events. This may put keyboard input into the | |
6605 * input buffer, call resize call-backs, trigger timers etc. If there is | |
6606 * nothing in the X11 event queue (& no timers pending), then we return | |
6607 * immediately. | |
6608 */ | |
6609 void | |
6610 gui_mch_update(void) | |
6611 { | |
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
|
6612 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
|
6613 g_main_context_iteration(NULL, TRUE); |
7 | 6614 } |
6615 | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6616 static timeout_cb_type |
7 | 6617 input_timer_cb(gpointer data) |
6618 { | |
6619 int *timed_out = (int *) data; | |
6620 | |
1226 | 6621 /* Just inform the caller about the occurrence of it */ |
7 | 6622 *timed_out = TRUE; |
6623 | |
6624 return FALSE; /* don't happen again */ | |
6625 } | |
6626 | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6627 #ifdef FEAT_JOB_CHANNEL |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6628 static timeout_cb_type |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6629 channel_poll_cb(gpointer data UNUSED) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6630 { |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6631 /* Using an event handler for a channel that may be disconnected does |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6632 * not work, it hangs. Instead poll for messages. */ |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6633 channel_handle_events(TRUE); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6634 parse_queued_messages(); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6635 |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6636 return TRUE; /* repeat */ |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6637 } |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6638 #endif |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6639 |
7 | 6640 /* |
6641 * GUI input routine called by gui_wait_for_chars(). Waits for a character | |
6642 * from the keyboard. | |
6643 * wtime == -1 Wait forever. | |
6644 * wtime == 0 This should never happen. | |
6645 * wtime > 0 Wait wtime milliseconds for a character. | |
6646 * Returns OK if a character was found to be available within the given time, | |
6647 * or FAIL otherwise. | |
6648 */ | |
6649 int | |
6650 gui_mch_wait_for_chars(long wtime) | |
6651 { | |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6652 int focus; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6653 guint timer; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6654 static int timed_out; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6655 int retval = FAIL; |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6656 #ifdef FEAT_JOB_CHANNEL |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6657 guint channel_timer = 0; |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6658 #endif |
7 | 6659 |
6660 timed_out = FALSE; | |
6661 | |
6662 /* this timeout makes sure that we will return if no characters arrived in | |
6663 * time */ | |
6664 if (wtime > 0) | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6665 timer = timeout_add(wtime, input_timer_cb, &timed_out); |
7 | 6666 else |
6667 timer = 0; | |
6668 | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6669 #ifdef FEAT_JOB_CHANNEL |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6670 /* If there is a channel with the keep_open flag we need to poll for input |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6671 * on them. */ |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6672 if (channel_any_keep_open()) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6673 channel_timer = timeout_add(20, channel_poll_cb, NULL); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6674 #endif |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6675 |
7 | 6676 focus = gui.in_focus; |
6677 | |
6678 do | |
6679 { | |
6680 /* Stop or start blinking when focus changes */ | |
6681 if (gui.in_focus != focus) | |
6682 { | |
6683 if (gui.in_focus) | |
6684 gui_mch_start_blink(); | |
6685 else | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
6686 gui_mch_stop_blink(TRUE); |
7 | 6687 focus = gui.in_focus; |
6688 } | |
6689 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
6690 #ifdef MESSAGE_QUEUE |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6691 # ifdef FEAT_TIMERS |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6692 did_add_timer = FALSE; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6693 # endif |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
6694 parse_queued_messages(); |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6695 # ifdef FEAT_TIMERS |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6696 if (did_add_timer) |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6697 /* Need to recompute the waiting time. */ |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6698 goto theend; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6699 # endif |
1624 | 6700 #endif |
6701 | |
7 | 6702 /* |
6703 * Loop in GTK+ processing until a timeout or input occurs. | |
22 | 6704 * Skip this if input is available anyway (can happen in rare |
6705 * situations, sort of race condition). | |
7 | 6706 */ |
22 | 6707 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
|
6708 g_main_context_iteration(NULL, TRUE); |
7 | 6709 |
6710 /* Got char, return immediately */ | |
6711 if (input_available()) | |
6712 { | |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6713 retval = OK; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6714 goto theend; |
7 | 6715 } |
6716 } while (wtime < 0 || !timed_out); | |
6717 | |
6718 /* | |
6719 * Flush all eventually pending (drawing) events. | |
6720 */ | |
6721 gui_mch_update(); | |
6722 | |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6723 theend: |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6724 if (timer != 0 && !timed_out) |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6725 timeout_remove(timer); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6726 #ifdef FEAT_JOB_CHANNEL |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6727 if (channel_timer != 0) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6728 timeout_remove(channel_timer); |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6729 #endif |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6730 |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6731 return retval; |
7 | 6732 } |
6733 | |
6734 | |
6735 /**************************************************************************** | |
6736 * Output drawing routines. | |
6737 ****************************************************************************/ | |
6738 | |
6739 | |
6740 /* Flush any output to the screen */ | |
6741 void | |
6742 gui_mch_flush(void) | |
6743 { | |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6744 #if GTK_CHECK_VERSION(3,0,0) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6745 if (gui.mainwin != NULL && gtk_widget_get_realized(gui.mainwin)) |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6746 #else |
7 | 6747 if (gui.mainwin != NULL && GTK_WIDGET_REALIZED(gui.mainwin)) |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6748 #endif |
9523
9d1abad90d6c
commit https://github.com/vim/vim/commit/fdadad994a6e8f6cc8b11519082e23200b96d0ba
Christian Brabandt <cb@256bit.org>
parents:
9489
diff
changeset
|
6749 gdk_display_flush(gtk_widget_get_display(gui.mainwin)); |
7 | 6750 } |
6751 | |
6752 /* | |
6753 * Clear a rectangular region of the screen from text pos (row1, col1) to | |
6754 * (row2, col2) inclusive. | |
6755 */ | |
6756 void | |
10920
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6757 gui_mch_clear_block(int row1arg, int col1arg, int row2arg, int col2arg) |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6758 { |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6759 |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6760 int col1 = check_col(col1arg); |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6761 int col2 = check_col(col2arg); |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6762 int row1 = check_row(row1arg); |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6763 int row2 = check_row(row2arg); |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6764 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6765 #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
|
6766 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
|
6767 return; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6768 #else |
7 | 6769 GdkColor color; |
6770 | |
6771 if (gui.drawarea->window == NULL) | |
6772 return; | |
6773 | |
6774 color.pixel = gui.back_pixel; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6775 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6776 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6777 #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
|
6778 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6779 /* 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
|
6780 * bold glyph may sit there. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6781 const GdkRectangle rect = { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6782 FILL_X(col1), FILL_Y(row1), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6783 (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
|
6784 (row2 - row1 + 1) * gui.char_height |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6785 }; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6786 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
|
6787 cairo_t * const cr = cairo_create(gui.surface); |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6788 # if GTK_CHECK_VERSION(3,22,2) |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6789 set_cairo_source_rgba_from_color(cr, gui.back_pixel); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6790 # else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6791 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
|
6792 if (pat != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6793 cairo_set_source(cr, pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6794 else |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6795 set_cairo_source_rgba_from_color(cr, gui.back_pixel); |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6796 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6797 gdk_cairo_rectangle(cr, &rect); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6798 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6799 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6800 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6801 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6802 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
|
6803 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6804 #else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6805 gdk_gc_set_foreground(gui.text_gc, &color); |
6806 | |
6807 /* Clear one extra pixel at the far right, for when bold characters have | |
6808 * spilled over to the window border. */ | |
6809 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, TRUE, | |
6810 FILL_X(col1), FILL_Y(row1), | |
6811 (col2 - col1 + 1) * gui.char_width | |
6812 + (col2 == Columns - 1), | |
6813 (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
|
6814 #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
|
6815 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6816 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6817 #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
|
6818 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6819 gui_gtk_window_clear(GdkWindow *win) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6820 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6821 const GdkRectangle rect = { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6822 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
|
6823 }; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6824 cairo_t * const cr = cairo_create(gui.surface); |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6825 # if GTK_CHECK_VERSION(3,22,2) |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6826 set_cairo_source_rgba_from_color(cr, gui.back_pixel); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6827 # else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6828 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
|
6829 if (pat != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6830 cairo_set_source(cr, pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6831 else |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6832 set_cairo_source_rgba_from_color(cr, gui.back_pixel); |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6833 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6834 gdk_cairo_rectangle(cr, &rect); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6835 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6836 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6837 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6838 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6839 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
|
6840 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6841 #endif |
7 | 6842 |
6843 void | |
6844 gui_mch_clear_all(void) | |
6845 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6846 #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
|
6847 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
|
6848 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
|
6849 #else |
7 | 6850 if (gui.drawarea->window != NULL) |
6851 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
|
6852 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6853 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6854 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6855 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 6856 /* |
6857 * Redraw any text revealed by scrolling up/down. | |
6858 */ | |
6859 static void | |
6860 check_copy_area(void) | |
6861 { | |
6862 GdkEvent *event; | |
6863 int expose_count; | |
6864 | |
6865 if (gui.visibility != GDK_VISIBILITY_PARTIAL) | |
6866 return; | |
6867 | |
6868 /* Avoid redrawing the cursor while scrolling or it'll end up where | |
6869 * we don't want it to be. I'm not sure if it's correct to call | |
6870 * gui_dont_update_cursor() at this point but it works as a quick | |
6871 * fix for now. */ | |
9848
664276833670
commit https://github.com/vim/vim/commit/107abd2ca53c31fd3bb40d77ff296e98eaae2975
Christian Brabandt <cb@256bit.org>
parents:
9836
diff
changeset
|
6872 gui_dont_update_cursor(TRUE); |
7 | 6873 |
6874 do | |
6875 { | |
6876 /* Wait to check whether the scroll worked or not. */ | |
6877 event = gdk_event_get_graphics_expose(gui.drawarea->window); | |
6878 | |
6879 if (event == NULL) | |
6880 break; /* received NoExpose event */ | |
6881 | |
6882 gui_redraw(event->expose.area.x, event->expose.area.y, | |
6883 event->expose.area.width, event->expose.area.height); | |
6884 | |
6885 expose_count = event->expose.count; | |
6886 gdk_event_free(event); | |
6887 } | |
6888 while (expose_count > 0); /* more events follow */ | |
6889 | |
6890 gui_can_update_cursor(); | |
6891 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6892 #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
|
6893 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6894 #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
|
6895 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6896 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
|
6897 int src_x, int src_y, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6898 int width, int height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6899 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6900 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
|
6901 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6902 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
|
6903 cairo_clip(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6904 cairo_push_group(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6905 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
|
6906 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6907 cairo_pop_group_to_source(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6908 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6909 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6910 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6911 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6912 #endif |
7 | 6913 |
6914 /* | |
6915 * Delete the given number of lines from the given row, scrolling up any | |
6916 * text further down within the scroll region. | |
6917 */ | |
6918 void | |
6919 gui_mch_delete_lines(int row, int num_lines) | |
6920 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6921 #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
|
6922 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
|
6923 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
|
6924 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
|
6925 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6926 gui_gtk_surface_copy_rect( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6927 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
|
6928 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
|
6929 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
|
6930 gui_clear_block( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6931 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
|
6932 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
|
6933 gui_gtk3_redraw( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6934 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
|
6935 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
|
6936 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6937 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
|
6938 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
|
6939 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
|
6940 #else |
7 | 6941 if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) |
6942 return; /* Can't see the window */ | |
6943 | |
6944 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
6945 gdk_gc_set_background(gui.text_gc, gui.bgcolor); | |
6946 | |
6947 /* copy one extra pixel, for when bold has spilled over */ | |
6948 gdk_window_copy_area(gui.drawarea->window, gui.text_gc, | |
6949 FILL_X(gui.scroll_region_left), FILL_Y(row), | |
6950 gui.drawarea->window, | |
6951 FILL_X(gui.scroll_region_left), | |
6952 FILL_Y(row + num_lines), | |
6953 gui.char_width * (gui.scroll_region_right | |
6954 - gui.scroll_region_left + 1) + 1, | |
6955 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1)); | |
6956 | |
6957 gui_clear_block(gui.scroll_region_bot - num_lines + 1, | |
6958 gui.scroll_region_left, | |
6959 gui.scroll_region_bot, gui.scroll_region_right); | |
6960 check_copy_area(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6961 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6962 } |
6963 | |
6964 /* | |
6965 * Insert the given number of lines before the given row, scrolling down any | |
6966 * following text within the scroll region. | |
6967 */ | |
6968 void | |
6969 gui_mch_insert_lines(int row, int num_lines) | |
6970 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6971 #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
|
6972 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
|
6973 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
|
6974 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
|
6975 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6976 gui_gtk_surface_copy_rect( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6977 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
|
6978 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
|
6979 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
|
6980 gui_mch_clear_block( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6981 row, gui.scroll_region_left, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6982 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
|
6983 gui_gtk3_redraw( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6984 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
|
6985 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
|
6986 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6987 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
|
6988 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
|
6989 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
|
6990 #else |
7 | 6991 if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) |
6992 return; /* Can't see the window */ | |
6993 | |
6994 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
6995 gdk_gc_set_background(gui.text_gc, gui.bgcolor); | |
6996 | |
6997 /* copy one extra pixel, for when bold has spilled over */ | |
6998 gdk_window_copy_area(gui.drawarea->window, gui.text_gc, | |
6999 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), | |
7000 gui.drawarea->window, | |
7001 FILL_X(gui.scroll_region_left), FILL_Y(row), | |
7002 gui.char_width * (gui.scroll_region_right | |
7003 - gui.scroll_region_left + 1) + 1, | |
7004 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1)); | |
7005 | |
7006 gui_clear_block(row, gui.scroll_region_left, | |
7007 row + num_lines - 1, gui.scroll_region_right); | |
7008 check_copy_area(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7009 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 7010 } |
7011 | |
7012 /* | |
7013 * X Selection stuff, for cutting and pasting text to other windows. | |
7014 */ | |
7015 void | |
7016 clip_mch_request_selection(VimClipboard *cbd) | |
7017 { | |
7018 GdkAtom target; | |
7019 unsigned i; | |
1494 | 7020 time_t start; |
7 | 7021 |
7022 for (i = 0; i < N_SELECTION_TARGETS; ++i) | |
7023 { | |
1904 | 7024 if (!clip_html && selection_targets[i].info == TARGET_HTML) |
7025 continue; | |
7 | 7026 received_selection = RS_NONE; |
7027 target = gdk_atom_intern(selection_targets[i].target, FALSE); | |
7028 | |
7029 gtk_selection_convert(gui.drawarea, | |
7030 cbd->gtk_sel_atom, target, | |
7031 (guint32)GDK_CURRENT_TIME); | |
7032 | |
1494 | 7033 /* Hack: Wait up to three seconds for the selection. A hang was |
7034 * noticed here when using the netrw plugin combined with ":gui" | |
7035 * during the FocusGained event. */ | |
7036 start = time(NULL); | |
7037 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
|
7038 g_main_context_iteration(NULL, TRUE); /* wait for selection_received_cb */ |
7 | 7039 |
7040 if (received_selection != RS_FAIL) | |
7041 return; | |
7042 } | |
7043 | |
7044 /* 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
|
7045 #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
|
7046 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
|
7047 cbd); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7048 #else |
1924 | 7049 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
|
7050 #endif |
7 | 7051 } |
7052 | |
7053 /* | |
7054 * Disown the selection. | |
7055 */ | |
7056 void | |
1884 | 7057 clip_mch_lose_selection(VimClipboard *cbd UNUSED) |
7 | 7058 { |
13503
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7059 if (!in_selection_clear_event) |
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7060 { |
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7061 gtk_selection_owner_set(NULL, cbd->gtk_sel_atom, gui.event_time); |
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7062 gui_mch_update(); |
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7063 } |
7 | 7064 } |
7065 | |
7066 /* | |
7067 * Own the selection and return OK if it worked. | |
7068 */ | |
7069 int | |
7070 clip_mch_own_selection(VimClipboard *cbd) | |
7071 { | |
7072 int success; | |
7073 | |
7074 success = gtk_selection_owner_set(gui.drawarea, cbd->gtk_sel_atom, | |
2923 | 7075 gui.event_time); |
7 | 7076 gui_mch_update(); |
7077 return (success) ? OK : FAIL; | |
7078 } | |
7079 | |
7080 /* | |
7081 * Send the current selection to the clipboard. Do nothing for X because we | |
7082 * will fill in the selection only when requested by another app. | |
7083 */ | |
7084 void | |
1884 | 7085 clip_mch_set_selection(VimClipboard *cbd UNUSED) |
7 | 7086 { |
7087 } | |
7088 | |
4209 | 7089 int |
7090 clip_gtk_owner_exists(VimClipboard *cbd) | |
7091 { | |
7092 return gdk_selection_owner_get(cbd->gtk_sel_atom) != NULL; | |
7093 } | |
7094 | |
7 | 7095 |
7096 #if defined(FEAT_MENU) || defined(PROTO) | |
7097 /* | |
7098 * Make a menu item appear either active or not active (grey or not grey). | |
7099 */ | |
7100 void | |
7101 gui_mch_menu_grey(vimmenu_T *menu, int grey) | |
7102 { | |
7103 if (menu->id == NULL) | |
7104 return; | |
7105 | |
7106 if (menu_is_separator(menu->name)) | |
7107 grey = TRUE; | |
7108 | |
7109 gui_mch_menu_hidden(menu, FALSE); | |
7110 /* 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
|
7111 # 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
|
7112 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
|
7113 # else |
7 | 7114 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
|
7115 # endif |
7 | 7116 { |
7117 gtk_widget_set_sensitive(menu->id, !grey); | |
7118 gui_mch_update(); | |
7119 } | |
7120 } | |
7121 | |
7122 /* | |
7123 * Make menu item hidden or not hidden. | |
7124 */ | |
7125 void | |
7126 gui_mch_menu_hidden(vimmenu_T *menu, int hidden) | |
7127 { | |
7128 if (menu->id == 0) | |
7129 return; | |
7130 | |
7131 if (hidden) | |
7132 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7133 # 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
|
7134 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
|
7135 # else |
7 | 7136 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
|
7137 # endif |
7 | 7138 { |
7139 gtk_widget_hide(menu->id); | |
7140 gui_mch_update(); | |
7141 } | |
7142 } | |
7143 else | |
7144 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7145 # 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
|
7146 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
|
7147 # else |
7 | 7148 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
|
7149 # endif |
7 | 7150 { |
7151 gtk_widget_show(menu->id); | |
7152 gui_mch_update(); | |
7153 } | |
7154 } | |
7155 } | |
7156 | |
7157 /* | |
7158 * This is called after setting all the menus to grey/hidden or not. | |
7159 */ | |
7160 void | |
7161 gui_mch_draw_menubar(void) | |
7162 { | |
7163 /* just make sure that the visual changes get effect immediately */ | |
7164 gui_mch_update(); | |
7165 } | |
7166 #endif /* FEAT_MENU */ | |
7167 | |
7168 /* | |
7169 * Scrollbar stuff. | |
7170 */ | |
7171 void | |
7172 gui_mch_enable_scrollbar(scrollbar_T *sb, int flag) | |
7173 { | |
7174 if (sb->id == NULL) | |
7175 return; | |
7176 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7177 #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
|
7178 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
|
7179 #else |
7 | 7180 if (flag) |
7181 gtk_widget_show(sb->id); | |
7182 else | |
7183 gtk_widget_hide(sb->id); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7184 #endif |
7 | 7185 |
791 | 7186 update_window_manager_hints(0, 0); |
7 | 7187 } |
7188 | |
7189 | |
7190 /* | |
7191 * Return the RGB value of a pixel as long. | |
7192 */ | |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9879
diff
changeset
|
7193 guicolor_T |
7 | 7194 gui_mch_get_rgb(guicolor_T pixel) |
7195 { | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7196 #if GTK_CHECK_VERSION(3,0,0) |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7197 return (long_u)pixel; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7198 #else |
7 | 7199 GdkColor color; |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7200 |
7 | 7201 gdk_colormap_query_color(gtk_widget_get_colormap(gui.drawarea), |
7202 (unsigned long)pixel, &color); | |
7203 | |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9879
diff
changeset
|
7204 return (guicolor_T)( |
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9879
diff
changeset
|
7205 (((unsigned)color.red & 0xff00) << 8) |
7 | 7206 | ((unsigned)color.green & 0xff00) |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9879
diff
changeset
|
7207 | (((unsigned)color.blue & 0xff00) >> 8)); |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7208 #endif |
7 | 7209 } |
7210 | |
7211 /* | |
88 | 7212 * Get current mouse coordinates in text window. |
7 | 7213 */ |
88 | 7214 void |
7215 gui_mch_getmouse(int *x, int *y) | |
7 | 7216 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7217 #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
|
7218 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
|
7219 #else |
88 | 7220 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
|
7221 #endif |
7 | 7222 } |
7223 | |
7224 void | |
7225 gui_mch_setmouse(int x, int y) | |
7226 { | |
7227 /* Sorry for the Xlib call, but we can't avoid it, since there is no | |
7228 * internal GDK mechanism present to accomplish this. (and for good | |
7229 * reason...) */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7230 #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
|
7231 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
|
7232 (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
|
7233 0, 0, 0U, 0U, x, y); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7234 #else |
7 | 7235 XWarpPointer(GDK_WINDOW_XDISPLAY(gui.drawarea->window), |
7236 (Window)0, GDK_WINDOW_XWINDOW(gui.drawarea->window), | |
7237 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
|
7238 #endif |
7 | 7239 } |
7240 | |
7241 | |
7242 #ifdef FEAT_MOUSESHAPE | |
7243 /* The last set mouse pointer shape is remembered, to be used when it goes | |
7244 * from hidden to not hidden. */ | |
7245 static int last_shape = 0; | |
7246 #endif | |
7247 | |
7248 /* | |
7249 * Use the blank mouse pointer or not. | |
7250 * | |
7251 * hide: TRUE = use blank ptr, FALSE = use parent ptr | |
7252 */ | |
7253 void | |
7254 gui_mch_mousehide(int hide) | |
7255 { | |
7256 if (gui.pointer_hidden != hide) | |
7257 { | |
7258 gui.pointer_hidden = hide; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7259 #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
|
7260 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
|
7261 #else |
7 | 7262 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
|
7263 #endif |
7 | 7264 { |
7265 if (hide) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7266 #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
|
7267 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
|
7268 gui.blank_pointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7269 #else |
7 | 7270 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
|
7271 #endif |
7 | 7272 else |
7273 #ifdef FEAT_MOUSESHAPE | |
7274 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
|
7275 #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
|
7276 gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), NULL); |
7 | 7277 #else |
7278 gdk_window_set_cursor(gui.drawarea->window, NULL); | |
7279 #endif | |
7280 } | |
7281 } | |
7282 } | |
7283 | |
7284 #if defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7285 | |
7286 /* Table for shape IDs. Keep in sync with the mshape_names[] table in | |
7287 * misc2.c! */ | |
7288 static const int mshape_ids[] = | |
7289 { | |
7290 GDK_LEFT_PTR, /* arrow */ | |
7291 GDK_CURSOR_IS_PIXMAP, /* blank */ | |
7292 GDK_XTERM, /* beam */ | |
7293 GDK_SB_V_DOUBLE_ARROW, /* updown */ | |
7294 GDK_SIZING, /* udsizing */ | |
7295 GDK_SB_H_DOUBLE_ARROW, /* leftright */ | |
7296 GDK_SIZING, /* lrsizing */ | |
7297 GDK_WATCH, /* busy */ | |
7298 GDK_X_CURSOR, /* no */ | |
7299 GDK_CROSSHAIR, /* crosshair */ | |
7300 GDK_HAND1, /* hand1 */ | |
7301 GDK_HAND2, /* hand2 */ | |
7302 GDK_PENCIL, /* pencil */ | |
7303 GDK_QUESTION_ARROW, /* question */ | |
7304 GDK_RIGHT_PTR, /* right-arrow */ | |
7305 GDK_CENTER_PTR, /* up-arrow */ | |
7306 GDK_LEFT_PTR /* last one */ | |
7307 }; | |
7308 | |
7309 void | |
7310 mch_set_mouse_shape(int shape) | |
7311 { | |
7312 int id; | |
7313 GdkCursor *c; | |
7314 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7315 # 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
|
7316 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
|
7317 # else |
7 | 7318 if (gui.drawarea->window == NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7319 # endif |
7 | 7320 return; |
7321 | |
7322 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
|
7323 # 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
|
7324 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
|
7325 gui.blank_pointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7326 # else |
7 | 7327 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
|
7328 # endif |
7 | 7329 else |
7330 { | |
7331 if (shape >= MSHAPE_NUMBERED) | |
7332 { | |
7333 id = shape - MSHAPE_NUMBERED; | |
7334 if (id >= GDK_LAST_CURSOR) | |
7335 id = GDK_LEFT_PTR; | |
7336 else | |
7337 id &= ~1; /* they are always even (why?) */ | |
7338 } | |
1884 | 7339 else if (shape < (int)(sizeof(mshape_ids) / sizeof(int))) |
7 | 7340 id = mshape_ids[shape]; |
842 | 7341 else |
7342 return; | |
7 | 7343 c = gdk_cursor_new_for_display( |
136 | 7344 gtk_widget_get_display(gui.drawarea), (GdkCursorType)id); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7345 # 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
|
7346 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
|
7347 # else |
7 | 7348 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
|
7349 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7350 # 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
|
7351 g_object_unref(G_OBJECT(c)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7352 # else |
7 | 7353 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
|
7354 # endif |
7 | 7355 } |
7356 if (shape != MSHAPE_HIDE) | |
7357 last_shape = shape; | |
7358 } | |
7359 #endif /* FEAT_MOUSESHAPE */ | |
7360 | |
7361 | |
7362 #if defined(FEAT_SIGN_ICONS) || defined(PROTO) | |
7363 /* | |
7364 * Signs are currently always 2 chars wide. With GTK+ 2, the image will be | |
7365 * scaled down if the current font is not big enough, or scaled up if the image | |
7366 * size is less than 3/4 of the maximum sign size. With GTK+ 1, the pixmap | |
7367 * will be cut off if the current font is not big enough, or centered if it's | |
7368 * too small. | |
7369 */ | |
7370 # define SIGN_WIDTH (2 * gui.char_width) | |
7371 # define SIGN_HEIGHT (gui.char_height) | |
7372 # define SIGN_ASPECT ((double)SIGN_HEIGHT / (double)SIGN_WIDTH) | |
7373 | |
7374 void | |
7375 gui_mch_drawsign(int row, int col, int typenr) | |
7376 { | |
7377 GdkPixbuf *sign; | |
7378 | |
7379 sign = (GdkPixbuf *)sign_get_image(typenr); | |
7380 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7381 # 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
|
7382 if (sign != NULL && gui.drawarea != NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7383 && 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
|
7384 # else |
7 | 7385 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
|
7386 # endif |
7 | 7387 { |
7388 int width; | |
7389 int height; | |
7390 int xoffset; | |
7391 int yoffset; | |
7392 int need_scale; | |
7393 | |
7394 width = gdk_pixbuf_get_width(sign); | |
7395 height = gdk_pixbuf_get_height(sign); | |
7396 /* | |
7397 * Decide whether we need to scale. Allow one pixel of border | |
7398 * width to be cut off, in order to avoid excessive scaling for | |
7399 * tiny differences in font size. | |
5983 | 7400 * Do scale to fit the height to avoid gaps because of linespacing. |
7 | 7401 */ |
7402 need_scale = (width > SIGN_WIDTH + 2 | |
5983 | 7403 || height != SIGN_HEIGHT |
7 | 7404 || (width < 3 * SIGN_WIDTH / 4 |
7405 && height < 3 * SIGN_HEIGHT / 4)); | |
7406 if (need_scale) | |
7407 { | |
5983 | 7408 double aspect; |
7409 int w = width; | |
7410 int h = height; | |
7 | 7411 |
7412 /* Keep the original aspect ratio */ | |
7413 aspect = (double)height / (double)width; | |
7414 width = (double)SIGN_WIDTH * SIGN_ASPECT / aspect; | |
7415 width = MIN(width, SIGN_WIDTH); | |
5983 | 7416 if (((double)(MAX(height, SIGN_HEIGHT)) / |
7417 (double)(MIN(height, SIGN_HEIGHT))) < 1.15) | |
7418 { | |
7419 /* Change the aspect ratio by at most 15% to fill the | |
7420 * available space completly. */ | |
7421 height = (double)SIGN_HEIGHT * SIGN_ASPECT / aspect; | |
7422 height = MIN(height, SIGN_HEIGHT); | |
7423 } | |
7424 else | |
7425 height = (double)width * aspect; | |
7426 | |
7427 if (w == width && h == height) | |
7428 { | |
7429 /* no change in dimensions; don't decrease reference counter | |
7430 * (below) */ | |
7431 need_scale = FALSE; | |
7432 } | |
7433 else | |
7434 { | |
7435 /* This doesn't seem to be worth caching, and doing so would | |
7436 * complicate the code quite a bit. */ | |
7437 sign = gdk_pixbuf_scale_simple(sign, width, height, | |
7438 GDK_INTERP_BILINEAR); | |
7439 if (sign == NULL) | |
7440 return; /* out of memory */ | |
7441 } | |
7 | 7442 } |
7443 | |
7444 /* The origin is the upper-left corner of the pixmap. Therefore | |
7445 * these offset may become negative if the pixmap is smaller than | |
7446 * the 2x1 cells reserved for the sign icon. */ | |
7447 xoffset = (width - SIGN_WIDTH) / 2; | |
7448 yoffset = (height - SIGN_HEIGHT) / 2; | |
7449 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7450 # 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
|
7451 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7452 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7453 cairo_surface_t *bg_surf; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7454 cairo_t *bg_cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7455 cairo_surface_t *sign_surf; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7456 cairo_t *sign_cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7457 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7458 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7459 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7460 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
|
7461 cairo_surface_get_content(gui.surface), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7462 SIGN_WIDTH, SIGN_HEIGHT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7463 bg_cr = cairo_create(bg_surf); |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7464 cairo_set_source_rgba(bg_cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7465 gui.bgcolor->red, gui.bgcolor->green, gui.bgcolor->blue, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7466 gui.bgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7467 cairo_paint(bg_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7468 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7469 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
|
7470 cairo_surface_get_content(gui.surface), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7471 SIGN_WIDTH, SIGN_HEIGHT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7472 sign_cr = cairo_create(sign_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7473 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
|
7474 cairo_paint(sign_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7475 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7476 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
|
7477 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
|
7478 cairo_paint(sign_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7479 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7480 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
|
7481 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7482 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7483 cairo_destroy(sign_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7484 cairo_surface_destroy(sign_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7485 cairo_destroy(bg_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7486 cairo_surface_destroy(bg_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7487 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7488 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7489 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7490 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
|
7491 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
|
7492 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7493 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7494 # else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 7495 gdk_gc_set_foreground(gui.text_gc, gui.bgcolor); |
7496 | |
7497 gdk_draw_rectangle(gui.drawarea->window, | |
7498 gui.text_gc, | |
7499 TRUE, | |
7500 FILL_X(col), | |
7501 FILL_Y(row), | |
7502 SIGN_WIDTH, | |
7503 SIGN_HEIGHT); | |
7504 | |
7505 gdk_pixbuf_render_to_drawable_alpha(sign, | |
7506 gui.drawarea->window, | |
7507 MAX(0, xoffset), | |
7508 MAX(0, yoffset), | |
7509 FILL_X(col) - MIN(0, xoffset), | |
7510 FILL_Y(row) - MIN(0, yoffset), | |
7511 MIN(width, SIGN_WIDTH), | |
7512 MIN(height, SIGN_HEIGHT), | |
7513 GDK_PIXBUF_ALPHA_BILEVEL, | |
7514 127, | |
7515 GDK_RGB_DITHER_NORMAL, | |
7516 0, 0); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7517 # endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 7518 if (need_scale) |
7519 g_object_unref(sign); | |
7520 } | |
7521 } | |
7522 | |
7523 void * | |
7524 gui_mch_register_sign(char_u *signfile) | |
7525 { | |
7526 if (signfile[0] != NUL && signfile[0] != '-' && gui.in_use) | |
7527 { | |
7528 GdkPixbuf *sign; | |
7529 GError *error = NULL; | |
7530 char_u *message; | |
7531 | |
7532 sign = gdk_pixbuf_new_from_file((const char *)signfile, &error); | |
7533 | |
7534 if (error == NULL) | |
7535 return sign; | |
7536 | |
7537 message = (char_u *)error->message; | |
7538 | |
7539 if (message != NULL && input_conv.vc_type != CONV_NONE) | |
7540 message = string_convert(&input_conv, message, NULL); | |
7541 | |
7542 if (message != NULL) | |
7543 { | |
7544 /* The error message is already translated and will be more | |
7545 * descriptive than anything we could possibly do ourselves. */ | |
7546 EMSG2("E255: %s", message); | |
7547 | |
7548 if (input_conv.vc_type != CONV_NONE) | |
7549 vim_free(message); | |
7550 } | |
7551 g_error_free(error); | |
7552 } | |
7553 | |
7554 return NULL; | |
7555 } | |
7556 | |
7557 void | |
7558 gui_mch_destroy_sign(void *sign) | |
7559 { | |
7560 if (sign != NULL) | |
7561 g_object_unref(sign); | |
7562 } | |
7563 | |
7564 #endif /* FEAT_SIGN_ICONS */ |