Mercurial > vim
annotate src/gui_gtk_x11.c @ 10985:09f7827e6d80
Added tag v8.0.0381 for changeset c0d5e8ab1452b5e2981ada563ea223e1b115bf12
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 26 Feb 2017 20:15:04 +0100 |
parents | 687833a3fadc |
children | f4ea50924c6d |
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 | |
10544
a3cef16bea27
patch 8.0.0162: build error on Fedora 23
Christian Brabandt <cb@256bit.org>
parents:
10402
diff
changeset
|
38 # ifdef ngettext |
a3cef16bea27
patch 8.0.0162: build error on Fedora 23
Christian Brabandt <cb@256bit.org>
parents:
10402
diff
changeset
|
39 # undef ngettext |
a3cef16bea27
patch 8.0.0162: build error on Fedora 23
Christian Brabandt <cb@256bit.org>
parents:
10402
diff
changeset
|
40 # endif |
7 | 41 # ifdef N_ |
42 # undef N_ | |
43 # endif | |
44 # ifdef textdomain | |
45 # undef textdomain | |
46 # endif | |
47 # ifdef bindtextdomain | |
48 # undef bindtextdomain | |
49 # endif | |
1286 | 50 # ifdef bind_textdomain_codeset |
51 # undef bind_textdomain_codeset | |
1226 | 52 # endif |
7 | 53 # if defined(FEAT_GETTEXT) && !defined(ENABLE_NLS) |
54 # define ENABLE_NLS /* so the texts in the dialog boxes are translated */ | |
55 # endif | |
56 # include <gnome.h> | |
57 # include "version.h" | |
798 | 58 /* missing prototype in bonobo-dock-item.h */ |
59 extern void bonobo_dock_item_set_behavior(BonoboDockItem *dock_item, BonoboDockItemBehavior beh); | |
7 | 60 #endif |
61 | |
62 #if !defined(FEAT_GUI_GTK) && defined(PROTO) | |
63 /* When generating prototypes we don't want syntax errors. */ | |
64 # define GdkAtom int | |
65 # define GdkEventExpose int | |
66 # define GdkEventFocus int | |
67 # define GdkEventVisibility int | |
68 # define GdkEventProperty int | |
69 # define GtkContainer int | |
70 # define GtkTargetEntry int | |
71 # define GtkType int | |
72 # define GtkWidget int | |
73 # define gint int | |
74 # define gpointer int | |
75 # define guint int | |
76 # define GdkEventKey int | |
77 # define GdkEventSelection int | |
78 # define GtkSelectionData int | |
79 # define GdkEventMotion int | |
80 # define GdkEventButton int | |
81 # define GdkDragContext int | |
82 # define GdkEventConfigure int | |
83 # define GdkEventClient int | |
84 #else | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
85 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
86 # include <gdk/gdkkeysyms-compat.h> |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
87 # include <gtk/gtkx.h> |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
88 # else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
89 # include <gdk/gdkkeysyms.h> |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
90 # endif |
7 | 91 # include <gdk/gdk.h> |
92 # ifdef WIN3264 | |
93 # include <gdk/gdkwin32.h> | |
94 # else | |
95 # include <gdk/gdkx.h> | |
96 # endif | |
97 # include <gtk/gtk.h> | |
98 # include "gui_gtk_f.h" | |
99 #endif | |
100 | |
101 #ifdef HAVE_X11_SUNKEYSYM_H | |
102 # include <X11/Sunkeysym.h> | |
2714 | 103 #endif |
104 | |
7 | 105 /* |
106 * Easy-to-use macro for multihead support. | |
107 */ | |
108 #ifdef HAVE_GTK_MULTIHEAD | |
109 # define GET_X_ATOM(atom) gdk_x11_atom_to_xatom_for_display( \ | |
110 gtk_widget_get_display(gui.mainwin), atom) | |
111 #else | |
112 # define GET_X_ATOM(atom) ((Atom)(atom)) | |
113 #endif | |
114 | |
115 /* Selection type distinguishers */ | |
116 enum | |
117 { | |
118 TARGET_TYPE_NONE, | |
119 TARGET_UTF8_STRING, | |
120 TARGET_STRING, | |
121 TARGET_COMPOUND_TEXT, | |
1904 | 122 TARGET_HTML, |
7 | 123 TARGET_TEXT, |
124 TARGET_TEXT_URI_LIST, | |
125 TARGET_TEXT_PLAIN, | |
126 TARGET_VIM, | |
127 TARGET_VIMENC | |
128 }; | |
129 | |
130 /* | |
131 * Table of selection targets supported by Vim. | |
132 * Note: Order matters, preferred types should come first. | |
133 */ | |
134 static const GtkTargetEntry selection_targets[] = | |
135 { | |
136 {VIMENC_ATOM_NAME, 0, TARGET_VIMENC}, | |
137 {VIM_ATOM_NAME, 0, TARGET_VIM}, | |
1904 | 138 {"text/html", 0, TARGET_HTML}, |
7 | 139 {"UTF8_STRING", 0, TARGET_UTF8_STRING}, |
140 {"COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT}, | |
141 {"TEXT", 0, TARGET_TEXT}, | |
142 {"STRING", 0, TARGET_STRING} | |
143 }; | |
144 #define N_SELECTION_TARGETS (sizeof(selection_targets) / sizeof(selection_targets[0])) | |
145 | |
146 #ifdef FEAT_DND | |
147 /* | |
148 * Table of DnD targets supported by Vim. | |
149 * Note: Order matters, preferred types should come first. | |
150 */ | |
151 static const GtkTargetEntry dnd_targets[] = | |
152 { | |
153 {"text/uri-list", 0, TARGET_TEXT_URI_LIST}, | |
1904 | 154 {"text/html", 0, TARGET_HTML}, |
7 | 155 {"UTF8_STRING", 0, TARGET_UTF8_STRING}, |
156 {"STRING", 0, TARGET_STRING}, | |
157 {"text/plain", 0, TARGET_TEXT_PLAIN} | |
158 }; | |
159 # define N_DND_TARGETS (sizeof(dnd_targets) / sizeof(dnd_targets[0])) | |
160 #endif | |
161 | |
162 | |
163 /* | |
164 * "Monospace" is a standard font alias that should be present | |
165 * on all proper Pango/fontconfig installations. | |
166 */ | |
167 # define DEFAULT_FONT "Monospace 10" | |
168 | |
169 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
170 /* | |
171 * Atoms used to communicate save-yourself from the X11 session manager. There | |
172 * is no need to move them into the GUI struct, since they should be constant. | |
173 */ | |
174 static GdkAtom wm_protocols_atom = GDK_NONE; | |
175 static GdkAtom save_yourself_atom = GDK_NONE; | |
176 #endif | |
177 | |
178 /* | |
179 * Atoms used to control/reference X11 selections. | |
180 */ | |
1904 | 181 static GdkAtom html_atom = GDK_NONE; |
7 | 182 static GdkAtom utf8_string_atom = GDK_NONE; |
183 static GdkAtom vim_atom = GDK_NONE; /* Vim's own special selection format */ | |
184 static GdkAtom vimenc_atom = GDK_NONE; /* Vim's extended selection format */ | |
185 | |
186 /* | |
187 * Keycodes recognized by vim. | |
188 * NOTE: when changing this, the table in gui_x11.c probably needs the same | |
189 * change! | |
190 */ | |
191 static struct special_key | |
192 { | |
193 guint key_sym; | |
194 char_u code0; | |
195 char_u code1; | |
196 } | |
197 const special_keys[] = | |
198 { | |
199 {GDK_Up, 'k', 'u'}, | |
200 {GDK_Down, 'k', 'd'}, | |
201 {GDK_Left, 'k', 'l'}, | |
202 {GDK_Right, 'k', 'r'}, | |
203 {GDK_F1, 'k', '1'}, | |
204 {GDK_F2, 'k', '2'}, | |
205 {GDK_F3, 'k', '3'}, | |
206 {GDK_F4, 'k', '4'}, | |
207 {GDK_F5, 'k', '5'}, | |
208 {GDK_F6, 'k', '6'}, | |
209 {GDK_F7, 'k', '7'}, | |
210 {GDK_F8, 'k', '8'}, | |
211 {GDK_F9, 'k', '9'}, | |
212 {GDK_F10, 'k', ';'}, | |
213 {GDK_F11, 'F', '1'}, | |
214 {GDK_F12, 'F', '2'}, | |
215 {GDK_F13, 'F', '3'}, | |
216 {GDK_F14, 'F', '4'}, | |
217 {GDK_F15, 'F', '5'}, | |
218 {GDK_F16, 'F', '6'}, | |
219 {GDK_F17, 'F', '7'}, | |
220 {GDK_F18, 'F', '8'}, | |
221 {GDK_F19, 'F', '9'}, | |
222 {GDK_F20, 'F', 'A'}, | |
223 {GDK_F21, 'F', 'B'}, | |
224 {GDK_Pause, 'F', 'B'}, /* Pause == F21 according to netbeans.txt */ | |
225 {GDK_F22, 'F', 'C'}, | |
226 {GDK_F23, 'F', 'D'}, | |
227 {GDK_F24, 'F', 'E'}, | |
228 {GDK_F25, 'F', 'F'}, | |
229 {GDK_F26, 'F', 'G'}, | |
230 {GDK_F27, 'F', 'H'}, | |
231 {GDK_F28, 'F', 'I'}, | |
232 {GDK_F29, 'F', 'J'}, | |
233 {GDK_F30, 'F', 'K'}, | |
234 {GDK_F31, 'F', 'L'}, | |
235 {GDK_F32, 'F', 'M'}, | |
236 {GDK_F33, 'F', 'N'}, | |
237 {GDK_F34, 'F', 'O'}, | |
238 {GDK_F35, 'F', 'P'}, | |
239 #ifdef SunXK_F36 | |
240 {SunXK_F36, 'F', 'Q'}, | |
241 {SunXK_F37, 'F', 'R'}, | |
242 #endif | |
243 {GDK_Help, '%', '1'}, | |
244 {GDK_Undo, '&', '8'}, | |
245 {GDK_BackSpace, 'k', 'b'}, | |
246 {GDK_Insert, 'k', 'I'}, | |
247 {GDK_Delete, 'k', 'D'}, | |
248 {GDK_3270_BackTab, 'k', 'B'}, | |
249 {GDK_Clear, 'k', 'C'}, | |
250 {GDK_Home, 'k', 'h'}, | |
251 {GDK_End, '@', '7'}, | |
252 {GDK_Prior, 'k', 'P'}, | |
253 {GDK_Next, 'k', 'N'}, | |
254 {GDK_Print, '%', '9'}, | |
255 /* Keypad keys: */ | |
256 {GDK_KP_Left, 'k', 'l'}, | |
257 {GDK_KP_Right, 'k', 'r'}, | |
258 {GDK_KP_Up, 'k', 'u'}, | |
259 {GDK_KP_Down, 'k', 'd'}, | |
260 {GDK_KP_Insert, KS_EXTRA, (char_u)KE_KINS}, | |
261 {GDK_KP_Delete, KS_EXTRA, (char_u)KE_KDEL}, | |
262 {GDK_KP_Home, 'K', '1'}, | |
263 {GDK_KP_End, 'K', '4'}, | |
264 {GDK_KP_Prior, 'K', '3'}, /* page up */ | |
265 {GDK_KP_Next, 'K', '5'}, /* page down */ | |
266 | |
267 {GDK_KP_Add, 'K', '6'}, | |
268 {GDK_KP_Subtract, 'K', '7'}, | |
269 {GDK_KP_Divide, 'K', '8'}, | |
270 {GDK_KP_Multiply, 'K', '9'}, | |
271 {GDK_KP_Enter, 'K', 'A'}, | |
272 {GDK_KP_Decimal, 'K', 'B'}, | |
273 | |
274 {GDK_KP_0, 'K', 'C'}, | |
275 {GDK_KP_1, 'K', 'D'}, | |
276 {GDK_KP_2, 'K', 'E'}, | |
277 {GDK_KP_3, 'K', 'F'}, | |
278 {GDK_KP_4, 'K', 'G'}, | |
279 {GDK_KP_5, 'K', 'H'}, | |
280 {GDK_KP_6, 'K', 'I'}, | |
281 {GDK_KP_7, 'K', 'J'}, | |
282 {GDK_KP_8, 'K', 'K'}, | |
283 {GDK_KP_9, 'K', 'L'}, | |
284 | |
285 /* End of list marker: */ | |
286 {0, 0, 0} | |
287 }; | |
288 | |
289 /* | |
290 * Flags for command line options table below. | |
291 */ | |
292 #define ARG_FONT 1 | |
293 #define ARG_GEOMETRY 2 | |
294 #define ARG_REVERSE 3 | |
295 #define ARG_NOREVERSE 4 | |
296 #define ARG_BACKGROUND 5 | |
297 #define ARG_FOREGROUND 6 | |
298 #define ARG_ICONIC 7 | |
299 #define ARG_ROLE 8 | |
300 #define ARG_NETBEANS 9 | |
301 #define ARG_XRM 10 /* ignored */ | |
302 #define ARG_MENUFONT 11 /* ignored */ | |
303 #define ARG_INDEX_MASK 0x00ff | |
304 #define ARG_HAS_VALUE 0x0100 /* a value is expected after the argument */ | |
305 #define ARG_NEEDS_GUI 0x0200 /* need to initialize the GUI for this */ | |
306 #define ARG_FOR_GTK 0x0400 /* argument is handled by GTK+ or GNOME */ | |
307 #define ARG_COMPAT_LONG 0x0800 /* accept -foo but substitute with --foo */ | |
308 #define ARG_KEEP 0x1000 /* don't remove argument from argv[] */ | |
309 | |
310 /* | |
311 * This table holds all the X GUI command line options allowed. This includes | |
312 * the standard ones so that we can skip them when Vim is started without the | |
313 * GUI (but the GUI might start up later). | |
314 * | |
315 * When changing this, also update doc/gui_x11.txt and the usage message!!! | |
316 */ | |
317 typedef struct | |
318 { | |
319 const char *name; | |
320 unsigned int flags; | |
321 } | |
322 cmdline_option_T; | |
323 | |
324 static const cmdline_option_T cmdline_options[] = | |
325 { | |
326 /* We handle these options ourselves */ | |
327 {"-fn", ARG_FONT|ARG_HAS_VALUE}, | |
328 {"-font", ARG_FONT|ARG_HAS_VALUE}, | |
329 {"-geom", ARG_GEOMETRY|ARG_HAS_VALUE}, | |
330 {"-geometry", ARG_GEOMETRY|ARG_HAS_VALUE}, | |
331 {"-rv", ARG_REVERSE}, | |
332 {"-reverse", ARG_REVERSE}, | |
333 {"+rv", ARG_NOREVERSE}, | |
334 {"+reverse", ARG_NOREVERSE}, | |
335 {"-bg", ARG_BACKGROUND|ARG_HAS_VALUE}, | |
336 {"-background", ARG_BACKGROUND|ARG_HAS_VALUE}, | |
337 {"-fg", ARG_FOREGROUND|ARG_HAS_VALUE}, | |
338 {"-foreground", ARG_FOREGROUND|ARG_HAS_VALUE}, | |
339 {"-iconic", ARG_ICONIC}, | |
340 {"--role", ARG_ROLE|ARG_HAS_VALUE}, | |
341 #ifdef FEAT_NETBEANS_INTG | |
342 {"-nb", ARG_NETBEANS}, /* non-standard value format */ | |
343 {"-xrm", ARG_XRM|ARG_HAS_VALUE}, /* not implemented */ | |
344 {"-mf", ARG_MENUFONT|ARG_HAS_VALUE}, /* not implemented */ | |
345 {"-menufont", ARG_MENUFONT|ARG_HAS_VALUE}, /* not implemented */ | |
346 #endif | |
347 /* Arguments handled by GTK (and GNOME) internally. */ | |
348 {"--g-fatal-warnings", ARG_FOR_GTK}, | |
349 {"--gdk-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
350 {"--gdk-no-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
351 {"--gtk-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
352 {"--gtk-no-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
353 {"--gtk-module", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
354 {"--sync", ARG_FOR_GTK}, | |
355 {"--display", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
356 {"--name", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
357 {"--class", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
358 {"--screen", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
359 {"--gxid-host", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
360 {"--gxid-port", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
361 #ifdef FEAT_GUI_GNOME | |
362 {"--load-modules", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
363 {"--sm-client-id", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
364 {"--sm-config-prefix", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
365 {"--sm-disable", ARG_FOR_GTK}, | |
366 {"--oaf-ior-fd", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
367 {"--oaf-activate-iid", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
368 {"--oaf-private", ARG_FOR_GTK}, | |
369 {"--enable-sound", ARG_FOR_GTK}, | |
370 {"--disable-sound", ARG_FOR_GTK}, | |
371 {"--espeaker", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
372 {"-?", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
373 {"--help", ARG_FOR_GTK|ARG_NEEDS_GUI|ARG_KEEP}, | |
374 {"--usage", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
375 # if 0 /* conflicts with Vim's own --version argument */ | |
376 {"--version", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
377 # endif | |
378 {"--disable-crash-dialog", ARG_FOR_GTK}, | |
379 #endif | |
380 {NULL, 0} | |
381 }; | |
382 | |
383 static int gui_argc = 0; | |
384 static char **gui_argv = NULL; | |
385 | |
386 static const char *role_argument = NULL; | |
387 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
388 static const char *restart_command = NULL; | |
1898 | 389 static char *abs_restart_command = NULL; |
7 | 390 #endif |
391 static int found_iconic_arg = FALSE; | |
392 | |
393 #ifdef FEAT_GUI_GNOME | |
394 /* | |
395 * Can't use Gnome if --socketid given | |
396 */ | |
397 static int using_gnome = 0; | |
398 #else | |
399 # define using_gnome 0 | |
400 #endif | |
401 | |
402 /* | |
403 * Parse the GUI related command-line arguments. Any arguments used are | |
404 * deleted from argv, and *argc is decremented accordingly. This is called | |
405 * when vim is started, whether or not the GUI has been started. | |
406 */ | |
407 void | |
408 gui_mch_prepare(int *argc, char **argv) | |
409 { | |
410 const cmdline_option_T *option; | |
411 int i = 0; | |
412 int len = 0; | |
413 | |
414 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
415 /* | |
416 * Determine the command used to invoke Vim, to be passed as restart | |
417 * command to the session manager. If argv[0] contains any directory | |
418 * components try building an absolute path, otherwise leave it as is. | |
419 */ | |
420 restart_command = argv[0]; | |
421 | |
422 if (strchr(argv[0], G_DIR_SEPARATOR) != NULL) | |
423 { | |
424 char_u buf[MAXPATHL]; | |
425 | |
426 if (mch_FullName((char_u *)argv[0], buf, (int)sizeof(buf), TRUE) == OK) | |
1898 | 427 { |
428 abs_restart_command = (char *)vim_strsave(buf); | |
429 restart_command = abs_restart_command; | |
430 } | |
7 | 431 } |
432 #endif | |
433 | |
434 /* | |
435 * Move all the entries in argv which are relevant to GTK+ and GNOME | |
436 * into gui_argv. Freed later in gui_mch_init(). | |
437 */ | |
438 gui_argc = 0; | |
439 gui_argv = (char **)alloc((unsigned)((*argc + 1) * sizeof(char *))); | |
440 | |
441 g_return_if_fail(gui_argv != NULL); | |
442 | |
443 gui_argv[gui_argc++] = argv[i++]; | |
444 | |
445 while (i < *argc) | |
446 { | |
447 /* Don't waste CPU cycles on non-option arguments. */ | |
448 if (argv[i][0] != '-' && argv[i][0] != '+') | |
449 { | |
450 ++i; | |
451 continue; | |
452 } | |
453 | |
454 /* Look for argv[i] in cmdline_options[] table. */ | |
455 for (option = &cmdline_options[0]; option->name != NULL; ++option) | |
456 { | |
457 len = strlen(option->name); | |
458 | |
459 if (strncmp(argv[i], option->name, len) == 0) | |
460 { | |
461 if (argv[i][len] == '\0') | |
462 break; | |
463 /* allow --foo=bar style */ | |
464 if (argv[i][len] == '=' && (option->flags & ARG_HAS_VALUE)) | |
465 break; | |
466 #ifdef FEAT_NETBEANS_INTG | |
467 /* darn, -nb has non-standard syntax */ | |
468 if (vim_strchr((char_u *)":=", argv[i][len]) != NULL | |
469 && (option->flags & ARG_INDEX_MASK) == ARG_NETBEANS) | |
470 break; | |
471 #endif | |
472 } | |
473 else if ((option->flags & ARG_COMPAT_LONG) | |
474 && strcmp(argv[i], option->name + 1) == 0) | |
475 { | |
476 /* Replace the standard X arguments "-name" and "-display" | |
477 * with their GNU-style long option counterparts. */ | |
478 argv[i] = (char *)option->name; | |
479 break; | |
480 } | |
481 } | |
482 if (option->name == NULL) /* no match */ | |
483 { | |
484 ++i; | |
485 continue; | |
486 } | |
487 | |
488 if (option->flags & ARG_FOR_GTK) | |
489 { | |
490 /* Move the argument into gui_argv, which | |
491 * will later be passed to gtk_init_check() */ | |
492 gui_argv[gui_argc++] = argv[i]; | |
493 } | |
494 else | |
495 { | |
496 char *value = NULL; | |
497 | |
498 /* Extract the option's value if there is one. | |
499 * Accept both "--foo bar" and "--foo=bar" style. */ | |
500 if (option->flags & ARG_HAS_VALUE) | |
501 { | |
502 if (argv[i][len] == '=') | |
503 value = &argv[i][len + 1]; | |
504 else if (i + 1 < *argc && strcmp(argv[i + 1], "--") != 0) | |
505 value = argv[i + 1]; | |
506 } | |
507 | |
508 /* Check for options handled by Vim itself */ | |
509 switch (option->flags & ARG_INDEX_MASK) | |
510 { | |
511 case ARG_REVERSE: | |
512 found_reverse_arg = TRUE; | |
513 break; | |
514 case ARG_NOREVERSE: | |
515 found_reverse_arg = FALSE; | |
516 break; | |
517 case ARG_FONT: | |
518 font_argument = value; | |
519 break; | |
520 case ARG_GEOMETRY: | |
521 if (value != NULL) | |
522 gui.geom = vim_strsave((char_u *)value); | |
523 break; | |
524 case ARG_BACKGROUND: | |
525 background_argument = value; | |
526 break; | |
527 case ARG_FOREGROUND: | |
528 foreground_argument = value; | |
529 break; | |
530 case ARG_ICONIC: | |
531 found_iconic_arg = TRUE; | |
532 break; | |
533 case ARG_ROLE: | |
534 role_argument = value; /* used later in gui_mch_open() */ | |
535 break; | |
536 #ifdef FEAT_NETBEANS_INTG | |
537 case ARG_NETBEANS: | |
538 gui.dofork = FALSE; /* don't fork() when starting GUI */ | |
539 netbeansArg = argv[i]; | |
540 break; | |
541 #endif | |
542 default: | |
543 break; | |
544 } | |
545 } | |
546 | |
547 /* 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
|
548 * 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
|
549 * Only when the GUI can start. */ |
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
550 if ((option->flags & ARG_NEEDS_GUI) |
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
551 && gui_mch_early_init_check(FALSE) == OK) |
7 | 552 gui.starting = TRUE; |
553 | |
554 if (option->flags & ARG_KEEP) | |
555 ++i; | |
556 else | |
557 { | |
558 /* Remove the flag from the argument vector. */ | |
559 if (--*argc > i) | |
560 { | |
561 int n_strip = 1; | |
562 | |
563 /* Move the argument's value as well, if there is one. */ | |
564 if ((option->flags & ARG_HAS_VALUE) | |
565 && argv[i][len] != '=' | |
566 && strcmp(argv[i + 1], "--") != 0) | |
567 { | |
568 ++n_strip; | |
569 --*argc; | |
570 if (option->flags & ARG_FOR_GTK) | |
571 gui_argv[gui_argc++] = argv[i + 1]; | |
572 } | |
573 | |
574 if (*argc > i) | |
575 mch_memmove(&argv[i], &argv[i + n_strip], | |
576 (*argc - i) * sizeof(char *)); | |
577 } | |
578 argv[*argc] = NULL; | |
579 } | |
580 } | |
581 | |
582 gui_argv[gui_argc] = NULL; | |
583 } | |
584 | |
359 | 585 #if defined(EXITFREE) || defined(PROTO) |
586 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
587 gui_mch_free_all(void) |
359 | 588 { |
589 vim_free(gui_argv); | |
1898 | 590 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) |
591 vim_free(abs_restart_command); | |
592 #endif | |
359 | 593 } |
594 #endif | |
595 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
596 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 597 /* |
598 * This should be maybe completely removed. | |
599 * Doesn't seem possible, since check_copy_area() relies on | |
600 * this information. --danielk | |
601 */ | |
602 static gint | |
1884 | 603 visibility_event(GtkWidget *widget UNUSED, |
604 GdkEventVisibility *event, | |
605 gpointer data UNUSED) | |
7 | 606 { |
607 gui.visibility = event->state; | |
608 /* | |
609 * When we do an gdk_window_copy_area(), and the window is partially | |
610 * obscured, we want to receive an event to tell us whether it worked | |
611 * or not. | |
612 */ | |
613 if (gui.text_gc != NULL) | |
614 gdk_gc_set_exposures(gui.text_gc, | |
615 gui.visibility != GDK_VISIBILITY_UNOBSCURED); | |
616 return FALSE; | |
617 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
618 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 619 |
620 /* | |
621 * Redraw the corresponding portions of the screen. | |
622 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
623 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
624 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
|
625 static gboolean blink_mode = TRUE; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
626 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
627 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
|
628 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
|
629 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
630 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
631 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
|
632 { |
10920
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
633 /* 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
|
634 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
|
635 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
|
636 GUI_MON_NOCLEAR); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
637 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
638 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
639 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
640 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
|
641 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
642 if (gui.row == gui.cursor_row) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
643 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
644 gui.by_signal = TRUE; |
8495
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
645 if (State & CMDLINE) |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
646 gui_update_cursor(TRUE, FALSE); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
647 else |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
648 gui_update_cursor(TRUE, TRUE); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
649 gui.by_signal = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
650 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
651 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
652 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
653 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
654 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
655 gui_gtk3_should_draw_cursor(void) |
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 unsigned int cond = 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
658 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
|
659 if (gui.cursor_col >= gui.col) |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
660 cond |= is_key_pressed; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
661 cond |= gui.in_focus == FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
662 return cond; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
663 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
664 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
665 static gboolean |
9232
a64e2a624fbe
commit https://github.com/vim/vim/commit/8e31fd52ec8be6ef1dc600b637d5f099d55e1715
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
666 draw_event(GtkWidget *widget UNUSED, |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
667 cairo_t *cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
668 gpointer user_data UNUSED) |
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 /* 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
|
671 if (gui.starting) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
672 return FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
673 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
674 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
|
675 /* 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
|
676 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
677 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
|
678 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
679 /* Draw the window without the cursor. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
680 gui.by_signal = TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
681 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
682 cairo_rectangle_list_t *list = NULL; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
683 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
684 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
|
685 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
|
686 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
687 int i; |
10920
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
688 |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
689 /* 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
|
690 * some blocks overlap. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
691 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
|
692 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
693 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
|
694 |
10920
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
695 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
|
696 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
|
697 } |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
698 |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
699 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
|
700 { |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
701 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
|
702 |
8412
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
703 if (blink_mode) |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
704 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
|
705 else |
8510
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
706 { |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
707 if (get_real_state() & VISUAL) |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
708 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
|
709 rect.width, rect.height); |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
710 else |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
711 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
|
712 } |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
713 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
714 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
715 cairo_rectangle_list_destroy(list); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
716 |
8510
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
717 if (get_real_state() & VISUAL) |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
718 { |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
719 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
|
720 gui_update_cursor(TRUE, TRUE); |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
721 } |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
722 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
723 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
724 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
725 gui.by_signal = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
726 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
727 /* 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
|
728 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
|
729 gui_gtk3_update_cursor(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
730 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
731 return FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
732 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
733 #else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 734 static gint |
1884 | 735 expose_event(GtkWidget *widget UNUSED, |
736 GdkEventExpose *event, | |
737 gpointer data UNUSED) | |
7 | 738 { |
739 /* Skip this when the GUI isn't set up yet, will redraw later. */ | |
740 if (gui.starting) | |
741 return FALSE; | |
742 | |
743 out_flush(); /* make sure all output has been processed */ | |
744 gui_redraw(event->area.x, event->area.y, | |
745 event->area.width, event->area.height); | |
746 | |
747 /* Clear the border areas if needed */ | |
748 if (event->area.x < FILL_X(0)) | |
749 gdk_window_clear_area(gui.drawarea->window, 0, 0, FILL_X(0), 0); | |
750 if (event->area.y < FILL_Y(0)) | |
751 gdk_window_clear_area(gui.drawarea->window, 0, 0, 0, FILL_Y(0)); | |
752 if (event->area.x > FILL_X(Columns)) | |
753 gdk_window_clear_area(gui.drawarea->window, | |
754 FILL_X((int)Columns), 0, 0, 0); | |
755 if (event->area.y > FILL_Y(Rows)) | |
756 gdk_window_clear_area(gui.drawarea->window, 0, FILL_Y((int)Rows), 0, 0); | |
757 | |
758 return FALSE; | |
759 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
760 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 761 |
762 #ifdef FEAT_CLIENTSERVER | |
763 /* | |
764 * Handle changes to the "Comm" property | |
765 */ | |
766 static gint | |
1884 | 767 property_event(GtkWidget *widget, |
768 GdkEventProperty *event, | |
769 gpointer data UNUSED) | |
7 | 770 { |
771 if (event->type == GDK_PROPERTY_NOTIFY | |
772 && 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
|
773 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
774 && GDK_WINDOW_XID(event->window) == commWindow |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
775 # else |
7 | 776 && 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
|
777 # endif |
7 | 778 && GET_X_ATOM(event->atom) == commProperty) |
779 { | |
780 XEvent xev; | |
781 | |
782 /* Translate to XLib */ | |
783 xev.xproperty.type = PropertyNotify; | |
784 xev.xproperty.atom = commProperty; | |
785 xev.xproperty.window = commWindow; | |
786 xev.xproperty.state = PropertyNewValue; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
787 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
788 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
|
789 &xev, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
790 # else |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
791 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
|
792 # endif |
7 | 793 } |
794 return FALSE; | |
795 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
796 #endif /* defined(FEAT_CLIENTSERVER) */ |
7 | 797 |
798 | |
799 /**************************************************************************** | |
800 * Focus handlers: | |
801 */ | |
802 | |
803 | |
804 /* | |
805 * This is a simple state machine: | |
806 * BLINK_NONE not blinking at all | |
807 * BLINK_OFF blinking, cursor is not shown | |
808 * BLINK_ON blinking, cursor is shown | |
809 */ | |
810 | |
811 #define BLINK_NONE 0 | |
812 #define BLINK_OFF 1 | |
813 #define BLINK_ON 2 | |
814 | |
815 static int blink_state = BLINK_NONE; | |
816 static long_u blink_waittime = 700; | |
817 static long_u blink_ontime = 400; | |
818 static long_u blink_offtime = 250; | |
819 static guint blink_timer = 0; | |
820 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
821 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
822 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
823 gui_gtk_is_blink_on(void) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
824 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
825 return blink_state == BLINK_ON; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
826 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
827 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
828 |
9213
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
829 int |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
830 gui_mch_is_blinking(void) |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
831 { |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
832 return blink_state != BLINK_NONE; |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
833 } |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
834 |
9428
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
835 int |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
836 gui_mch_is_blink_off(void) |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
837 { |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
838 return blink_state == BLINK_OFF; |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
839 } |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
840 |
7 | 841 void |
842 gui_mch_set_blinking(long waittime, long on, long off) | |
843 { | |
8412
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
844 #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
|
845 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
|
846 { |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
847 blink_mode = FALSE; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
848 |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
849 blink_waittime = 700; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
850 blink_ontime = 400; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
851 blink_offtime = 250; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
852 } |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
853 else |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
854 { |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
855 blink_mode = TRUE; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
856 |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
857 blink_waittime = waittime; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
858 blink_ontime = on; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
859 blink_offtime = off; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
860 } |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
861 #else |
7 | 862 blink_waittime = waittime; |
863 blink_ontime = on; | |
864 blink_offtime = off; | |
8412
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
865 #endif |
7 | 866 } |
867 | |
868 /* | |
869 * Stop the cursor blinking. Show the cursor if it wasn't shown. | |
870 */ | |
871 void | |
872 gui_mch_stop_blink(void) | |
873 { | |
874 if (blink_timer) | |
875 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
876 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
877 g_source_remove(blink_timer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
878 #else |
7 | 879 gtk_timeout_remove(blink_timer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
880 #endif |
7 | 881 blink_timer = 0; |
882 } | |
883 if (blink_state == BLINK_OFF) | |
9489
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
884 { |
7 | 885 gui_update_cursor(TRUE, FALSE); |
9489
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
886 gui_mch_flush(); |
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
887 } |
7 | 888 blink_state = BLINK_NONE; |
889 } | |
890 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
891 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
892 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
893 #else |
7 | 894 static gint |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
895 #endif |
1884 | 896 blink_cb(gpointer data UNUSED) |
7 | 897 { |
898 if (blink_state == BLINK_ON) | |
899 { | |
900 gui_undraw_cursor(); | |
901 blink_state = BLINK_OFF; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
902 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
903 blink_timer = g_timeout_add((guint)blink_offtime, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
904 (GSourceFunc) blink_cb, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
905 #else |
7 | 906 blink_timer = gtk_timeout_add((guint32)blink_offtime, |
907 (GtkFunction) blink_cb, NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
908 #endif |
7 | 909 } |
910 else | |
911 { | |
912 gui_update_cursor(TRUE, FALSE); | |
913 blink_state = BLINK_ON; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
914 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
915 blink_timer = g_timeout_add((guint)blink_ontime, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
916 (GSourceFunc) blink_cb, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
917 #else |
7 | 918 blink_timer = gtk_timeout_add((guint32)blink_ontime, |
919 (GtkFunction) blink_cb, NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
920 #endif |
7 | 921 } |
9489
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
922 gui_mch_flush(); |
7 | 923 |
924 return FALSE; /* don't happen again */ | |
925 } | |
926 | |
927 /* | |
928 * Start the cursor blinking. If it was already blinking, this restarts the | |
929 * waiting time and shows the cursor. | |
930 */ | |
931 void | |
932 gui_mch_start_blink(void) | |
933 { | |
934 if (blink_timer) | |
5818 | 935 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
936 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
937 g_source_remove(blink_timer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
938 #else |
7 | 939 gtk_timeout_remove(blink_timer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
940 #endif |
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 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
946 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
947 blink_timer = g_timeout_add((guint)blink_waittime, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
948 (GSourceFunc) blink_cb, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
949 #else |
7 | 950 blink_timer = gtk_timeout_add((guint32)blink_waittime, |
951 (GtkFunction) blink_cb, NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
952 #endif |
7 | 953 blink_state = BLINK_ON; |
954 gui_update_cursor(TRUE, FALSE); | |
9489
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
955 gui_mch_flush(); |
7 | 956 } |
957 } | |
958 | |
959 static gint | |
1884 | 960 enter_notify_event(GtkWidget *widget UNUSED, |
961 GdkEventCrossing *event UNUSED, | |
962 gpointer data UNUSED) | |
7 | 963 { |
964 if (blink_state == BLINK_NONE) | |
965 gui_mch_start_blink(); | |
966 | |
967 /* 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
|
968 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
969 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
|
970 #else |
7 | 971 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
|
972 #endif |
7 | 973 gtk_widget_grab_focus(gui.drawarea); |
974 | |
975 return FALSE; | |
976 } | |
977 | |
978 static gint | |
1884 | 979 leave_notify_event(GtkWidget *widget UNUSED, |
980 GdkEventCrossing *event UNUSED, | |
981 gpointer data UNUSED) | |
7 | 982 { |
983 if (blink_state != BLINK_NONE) | |
984 gui_mch_stop_blink(); | |
985 | |
986 return FALSE; | |
987 } | |
988 | |
989 static gint | |
1884 | 990 focus_in_event(GtkWidget *widget, |
991 GdkEventFocus *event UNUSED, | |
992 gpointer data UNUSED) | |
7 | 993 { |
994 gui_focus_change(TRUE); | |
995 | |
996 if (blink_state == BLINK_NONE) | |
997 gui_mch_start_blink(); | |
998 | |
1380 | 999 /* make sure keyboard input goes to the draw area (if this is focus for a |
1000 * window) */ | |
791 | 1001 if (widget != gui.drawarea) |
856 | 1002 gtk_widget_grab_focus(gui.drawarea); |
7 | 1003 |
1004 return TRUE; | |
1005 } | |
1006 | |
1007 static gint | |
1884 | 1008 focus_out_event(GtkWidget *widget UNUSED, |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2301
diff
changeset
|
1009 GdkEventFocus *event UNUSED, |
1884 | 1010 gpointer data UNUSED) |
7 | 1011 { |
1012 gui_focus_change(FALSE); | |
1013 | |
1014 if (blink_state != BLINK_NONE) | |
1015 gui_mch_stop_blink(); | |
1016 | |
1017 return TRUE; | |
1018 } | |
1019 | |
1020 | |
1021 /* | |
1022 * Translate a GDK key value to UTF-8 independently of the current locale. | |
1023 * The output is written to string, which must have room for at least 6 bytes | |
1024 * plus the NUL terminator. Returns the length in bytes. | |
1025 * | |
1026 * This function is used in the GTK+ 2 GUI only. The GTK+ 1 code makes use | |
1027 * of GdkEventKey::string instead. But event->string is evil; see here why: | |
1028 * http://developer.gnome.org/doc/API/2.0/gdk/gdk-Event-Structures.html#GdkEventKey | |
1029 */ | |
1030 static int | |
1031 keyval_to_string(unsigned int keyval, unsigned int state, char_u *string) | |
1032 { | |
1033 int len; | |
1034 guint32 uc; | |
1035 | |
1036 uc = gdk_keyval_to_unicode(keyval); | |
1037 if (uc != 0) | |
1038 { | |
1039 /* Check for CTRL-foo */ | |
1040 if ((state & GDK_CONTROL_MASK) && uc >= 0x20 && uc < 0x80) | |
1041 { | |
1042 /* These mappings look arbitrary at the first glance, but in fact | |
1043 * resemble quite exactly the behaviour of the GTK+ 1.2 GUI on my | |
1044 * machine. The only difference is BS vs. DEL for CTRL-8 (makes | |
1045 * more sense and is consistent with usual terminal behaviour). */ | |
1046 if (uc >= '@') | |
1047 string[0] = uc & 0x1F; | |
1048 else if (uc == '2') | |
1049 string[0] = NUL; | |
1050 else if (uc >= '3' && uc <= '7') | |
1051 string[0] = uc ^ 0x28; | |
1052 else if (uc == '8') | |
1053 string[0] = BS; | |
1054 else if (uc == '?') | |
1055 string[0] = DEL; | |
1056 else | |
1057 string[0] = uc; | |
1058 len = 1; | |
1059 } | |
1060 else | |
1061 { | |
1062 /* Translate a normal key to UTF-8. This doesn't work for dead | |
1063 * keys of course, you _have_ to use an input method for that. */ | |
1064 len = utf_char2bytes((int)uc, string); | |
1065 } | |
1066 } | |
1067 else | |
1068 { | |
1069 /* Translate keys which are represented by ASCII control codes in Vim. | |
1070 * There are only a few of those; most control keys are translated to | |
1071 * special terminal-like control sequences. */ | |
1072 len = 1; | |
1073 switch (keyval) | |
1074 { | |
1075 case GDK_Tab: case GDK_KP_Tab: case GDK_ISO_Left_Tab: | |
1076 string[0] = TAB; | |
1077 break; | |
1078 case GDK_Linefeed: | |
1079 string[0] = NL; | |
1080 break; | |
1081 case GDK_Return: case GDK_ISO_Enter: case GDK_3270_Enter: | |
1082 string[0] = CAR; | |
1083 break; | |
1084 case GDK_Escape: | |
1085 string[0] = ESC; | |
1086 break; | |
1087 default: | |
1088 len = 0; | |
1089 break; | |
1090 } | |
1091 } | |
1092 string[len] = NUL; | |
1093 | |
1094 return len; | |
1095 } | |
1096 | |
179 | 1097 static int |
1098 modifiers_gdk2vim(guint state) | |
1099 { | |
1100 int modifiers = 0; | |
1101 | |
1102 if (state & GDK_SHIFT_MASK) | |
1103 modifiers |= MOD_MASK_SHIFT; | |
1104 if (state & GDK_CONTROL_MASK) | |
1105 modifiers |= MOD_MASK_CTRL; | |
1106 if (state & GDK_MOD1_MASK) | |
1107 modifiers |= MOD_MASK_ALT; | |
2550
7c1f73452ea6
Fix #ifdef for GDK_SUPER_MASK.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
1108 #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
|
1109 if (state & GDK_SUPER_MASK) |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1110 modifiers |= MOD_MASK_META; |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1111 #endif |
179 | 1112 if (state & GDK_MOD4_MASK) |
1113 modifiers |= MOD_MASK_META; | |
1114 | |
1115 return modifiers; | |
1116 } | |
1117 | |
1118 static int | |
1119 modifiers_gdk2mouse(guint state) | |
1120 { | |
1121 int modifiers = 0; | |
1122 | |
1123 if (state & GDK_SHIFT_MASK) | |
1124 modifiers |= MOUSE_SHIFT; | |
1125 if (state & GDK_CONTROL_MASK) | |
1126 modifiers |= MOUSE_CTRL; | |
1127 if (state & GDK_MOD1_MASK) | |
1128 modifiers |= MOUSE_ALT; | |
1129 | |
1130 return modifiers; | |
1131 } | |
1132 | |
7 | 1133 /* |
1134 * Main keyboard handler: | |
1135 */ | |
1136 static gint | |
1884 | 1137 key_press_event(GtkWidget *widget UNUSED, |
1138 GdkEventKey *event, | |
1139 gpointer data UNUSED) | |
7 | 1140 { |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1141 /* For GTK+ 2 we know for sure how large the string might get. |
7 | 1142 * (That is, up to 6 bytes + NUL + CSI escapes + safety measure.) */ |
1143 char_u string[32], string2[32]; | |
1144 guint key_sym; | |
1145 int len; | |
1146 int i; | |
1147 int modifiers; | |
1148 int key; | |
1149 guint state; | |
1150 char_u *s, *d; | |
1151 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1152 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1153 is_key_pressed = TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1154 gui_mch_stop_blink(); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1155 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1156 |
2923 | 1157 gui.event_time = event->time; |
7 | 1158 key_sym = event->keyval; |
1159 state = event->state; | |
1160 | |
1161 #ifdef FEAT_XIM | |
1162 if (xim_queue_key_press_event(event, TRUE)) | |
1163 return TRUE; | |
1164 #endif | |
1165 | |
1166 #ifdef FEAT_HANGULIN | |
1167 if (key_sym == GDK_space && (state & GDK_SHIFT_MASK)) | |
1168 { | |
1169 hangul_input_state_toggle(); | |
1170 return TRUE; | |
1171 } | |
1172 #endif | |
1173 | |
1174 #ifdef SunXK_F36 | |
1175 /* | |
1176 * These keys have bogus lookup strings, and trapping them here is | |
1177 * easier than trying to XRebindKeysym() on them with every possible | |
1178 * combination of modifiers. | |
1179 */ | |
1180 if (key_sym == SunXK_F36 || key_sym == SunXK_F37) | |
1181 len = 0; | |
1182 else | |
1183 #endif | |
1184 { | |
1185 len = keyval_to_string(key_sym, state, string2); | |
1186 | |
1187 /* Careful: convert_input() doesn't handle the NUL character. | |
1188 * No need to convert pure ASCII anyway, thus the len > 1 check. */ | |
1189 if (len > 1 && input_conv.vc_type != CONV_NONE) | |
1190 len = convert_input(string2, len, sizeof(string2)); | |
1191 | |
1192 s = string2; | |
1193 d = string; | |
1194 for (i = 0; i < len; ++i) | |
1195 { | |
1196 *d++ = s[i]; | |
1197 if (d[-1] == CSI && d + 2 < string + sizeof(string)) | |
1198 { | |
1199 /* Turn CSI into K_CSI. */ | |
1200 *d++ = KS_EXTRA; | |
1201 *d++ = (int)KE_CSI; | |
1202 } | |
1203 } | |
1204 len = d - string; | |
1205 } | |
1206 | |
1207 /* Shift-Tab results in Left_Tab, but we want <S-Tab> */ | |
1208 if (key_sym == GDK_ISO_Left_Tab) | |
1209 { | |
1210 key_sym = GDK_Tab; | |
1211 state |= GDK_SHIFT_MASK; | |
1212 } | |
1213 | |
1214 #ifdef FEAT_MENU | |
1215 /* If there is a menu and 'wak' is "yes", or 'wak' is "menu" and the key | |
1216 * is a menu shortcut, we ignore everything with the ALT modifier. */ | |
1217 if ((state & GDK_MOD1_MASK) | |
1218 && gui.menu_is_active | |
1219 && (*p_wak == 'y' | |
1220 || (*p_wak == 'm' | |
1221 && len == 1 | |
1222 && gui_is_menu_shortcut(string[0])))) | |
1223 /* For GTK2 we return false to signify that we haven't handled the | |
1224 * keypress, so that gtk will handle the mnemonic or accelerator. */ | |
1225 return FALSE; | |
1226 #endif | |
1227 | |
1228 /* Check for Alt/Meta key (Mod1Mask), but not for a BS, DEL or character | |
1229 * that already has the 8th bit set. | |
1230 * Don't do this for <S-M-Tab>, that should become K_S_TAB with ALT. | |
1231 * Don't do this for double-byte encodings, it turns the char into a lead | |
1232 * byte. */ | |
1233 if (len == 1 | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1234 && ((state & GDK_MOD1_MASK) |
2571
42bdbc2bbb59
Fix #ifdef for GDK_SUPER_MASK. (Stephan Schulz)
Bram Moolenaar <bram@vim.org>
parents:
2550
diff
changeset
|
1235 #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
|
1236 || (state & GDK_SUPER_MASK) |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1237 #endif |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1238 ) |
7 | 1239 && !(key_sym == GDK_BackSpace || key_sym == GDK_Delete) |
1240 && (string[0] & 0x80) == 0 | |
1241 && !(key_sym == GDK_Tab && (state & GDK_SHIFT_MASK)) | |
1242 && !enc_dbcs | |
1243 ) | |
1244 { | |
1245 string[0] |= 0x80; | |
1246 state &= ~GDK_MOD1_MASK; /* don't use it again */ | |
1247 if (enc_utf8) /* convert to utf-8 */ | |
1248 { | |
1249 string[1] = string[0] & 0xbf; | |
1250 string[0] = ((unsigned)string[0] >> 6) + 0xc0; | |
1251 if (string[1] == CSI) | |
1252 { | |
1253 string[2] = KS_EXTRA; | |
1254 string[3] = (int)KE_CSI; | |
1255 len = 4; | |
1256 } | |
1257 else | |
1258 len = 2; | |
1259 } | |
1260 } | |
1261 | |
1262 /* Check for special keys. Also do this when len == 1 (key has an ASCII | |
1263 * value) to detect backspace, delete and keypad keys. */ | |
1264 if (len == 0 || len == 1) | |
1265 { | |
1266 for (i = 0; special_keys[i].key_sym != 0; i++) | |
1267 { | |
1268 if (special_keys[i].key_sym == key_sym) | |
1269 { | |
1270 string[0] = CSI; | |
1271 string[1] = special_keys[i].code0; | |
1272 string[2] = special_keys[i].code1; | |
1273 len = -3; | |
1274 break; | |
1275 } | |
1276 } | |
1277 } | |
1278 | |
1279 if (len == 0) /* Unrecognized key */ | |
1280 return TRUE; | |
1281 | |
1282 /* Special keys (and a few others) may have modifiers. Also when using a | |
1283 * double-byte encoding (can't set the 8th bit). */ | |
1284 if (len == -3 || key_sym == GDK_space || key_sym == GDK_Tab | |
1285 || key_sym == GDK_Return || key_sym == GDK_Linefeed | |
1286 || key_sym == GDK_Escape || key_sym == GDK_KP_Tab | |
1287 || 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
|
1288 || (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
|
1289 #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
|
1290 || (state & GDK_SUPER_MASK) |
7 | 1291 #endif |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1292 ))) |
7 | 1293 { |
179 | 1294 modifiers = modifiers_gdk2vim(state); |
7 | 1295 |
1296 /* | |
1297 * For some keys a shift modifier is translated into another key | |
1298 * code. | |
1299 */ | |
1300 if (len == -3) | |
1301 key = TO_SPECIAL(string[1], string[2]); | |
1302 else | |
1303 key = string[0]; | |
1304 | |
1305 key = simplify_key(key, &modifiers); | |
1306 if (key == CSI) | |
1307 key = K_CSI; | |
1308 if (IS_SPECIAL(key)) | |
1309 { | |
1310 string[0] = CSI; | |
1311 string[1] = K_SECOND(key); | |
1312 string[2] = K_THIRD(key); | |
1313 len = 3; | |
1314 } | |
1315 else | |
1316 { | |
1317 string[0] = key; | |
1318 len = 1; | |
1319 } | |
1320 | |
1321 if (modifiers != 0) | |
1322 { | |
1323 string2[0] = CSI; | |
1324 string2[1] = KS_MODIFIER; | |
1325 string2[2] = modifiers; | |
1326 add_to_input_buf(string2, 3); | |
1327 } | |
1328 } | |
1329 | |
1330 if (len == 1 && ((string[0] == Ctrl_C && ctrl_c_interrupts) | |
1331 || (string[0] == intr_char && intr_char != Ctrl_C))) | |
1332 { | |
1333 trash_input_buf(); | |
1334 got_int = TRUE; | |
1335 } | |
1336 | |
1337 add_to_input_buf(string, len); | |
1338 | |
1339 /* blank out the pointer if necessary */ | |
1340 if (p_mh) | |
1341 gui_mch_mousehide(TRUE); | |
1342 | |
1343 return TRUE; | |
1344 } | |
1345 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1346 #if defined(FEAT_XIM) || GTK_CHECK_VERSION(3,0,0) |
7 | 1347 static gboolean |
1884 | 1348 key_release_event(GtkWidget *widget UNUSED, |
1349 GdkEventKey *event, | |
1350 gpointer data UNUSED) | |
7 | 1351 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1352 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1353 is_key_pressed = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1354 gui_mch_start_blink(); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1355 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1356 # if defined(FEAT_XIM) |
2923 | 1357 gui.event_time = event->time; |
7 | 1358 /* |
1359 * GTK+ 2 input methods may do fancy stuff on key release events too. | |
1360 * With the default IM for instance, you can enter any UCS code point | |
1361 * by holding down CTRL-SHIFT and typing hexadecimal digits. | |
1362 */ | |
1363 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
|
1364 # else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1365 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1366 # endif |
7 | 1367 } |
1368 #endif | |
1369 | |
1370 | |
1371 /**************************************************************************** | |
1372 * Selection handlers: | |
1373 */ | |
1374 | |
1375 static gint | |
1884 | 1376 selection_clear_event(GtkWidget *widget UNUSED, |
7 | 1377 GdkEventSelection *event, |
1884 | 1378 gpointer user_data UNUSED) |
7 | 1379 { |
1380 if (event->selection == clip_plus.gtk_sel_atom) | |
1381 clip_lose_selection(&clip_plus); | |
1382 else | |
1383 clip_lose_selection(&clip_star); | |
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 /**************************************************************************** | |
1745 * Mouse handling callbacks | |
1746 */ | |
1747 | |
1748 | |
1749 static guint mouse_click_timer = 0; | |
1750 static int mouse_timed_out = TRUE; | |
1751 | |
1752 /* | |
1753 * Timer used to recognize multiple clicks of the mouse button | |
1754 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1755 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1756 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1757 #else |
7 | 1758 static gint |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1759 #endif |
7 | 1760 mouse_click_timer_cb(gpointer data) |
1761 { | |
1762 /* we don't use this information currently */ | |
1763 int *timed_out = (int *) data; | |
1764 | |
1765 *timed_out = TRUE; | |
1766 return FALSE; /* don't happen again */ | |
1767 } | |
1768 | |
1769 static guint motion_repeat_timer = 0; | |
1770 static int motion_repeat_offset = FALSE; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1771 #ifdef GTK_DEST_DEFAULT_ALL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1772 static gboolean motion_repeat_timer_cb(gpointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1773 #else |
7 | 1774 static gint motion_repeat_timer_cb(gpointer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1775 #endif |
7 | 1776 |
1777 static void | |
1778 process_motion_notify(int x, int y, GdkModifierType state) | |
1779 { | |
1780 int button; | |
1781 int_u vim_modifiers; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1782 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1783 GtkAllocation allocation; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1784 #endif |
7 | 1785 |
1786 button = (state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | | |
1787 GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | | |
1788 GDK_BUTTON5_MASK)) | |
1789 ? MOUSE_DRAG : ' '; | |
1790 | |
1791 /* If our pointer is currently hidden, then we should show it. */ | |
1792 gui_mch_mousehide(FALSE); | |
1793 | |
1794 /* Just moving the rodent above the drawing area without any button | |
1795 * being pressed. */ | |
1796 if (button != MOUSE_DRAG) | |
1797 { | |
1798 gui_mouse_moved(x, y); | |
1799 return; | |
1800 } | |
1801 | |
1802 /* translate modifier coding between the main engine and GTK */ | |
179 | 1803 vim_modifiers = modifiers_gdk2mouse(state); |
7 | 1804 |
1226 | 1805 /* inform the editor engine about the occurrence of this event */ |
7 | 1806 gui_send_mouse_event(button, x, y, FALSE, vim_modifiers); |
1807 | |
1808 /* | |
1809 * Auto repeat timer handling. | |
1810 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1811 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1812 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
|
1813 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1814 if (x < 0 || y < 0 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1815 || x >= allocation.width |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1816 || y >= allocation.height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1817 #else |
7 | 1818 if (x < 0 || y < 0 |
1819 || x >= gui.drawarea->allocation.width | |
1820 || y >= gui.drawarea->allocation.height) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1821 #endif |
7 | 1822 { |
1823 | |
1824 int dx; | |
1825 int dy; | |
1826 int offshoot; | |
1827 int delay = 10; | |
1828 | |
1829 /* Calculate the maximal distance of the cursor from the drawing area. | |
1830 * (offshoot can't become negative here!). | |
1831 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1832 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1833 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
|
1834 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
|
1835 #else |
7 | 1836 dx = x < 0 ? -x : x - gui.drawarea->allocation.width; |
1837 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
|
1838 #endif |
7 | 1839 |
1840 offshoot = dx > dy ? dx : dy; | |
1841 | |
1884 | 1842 /* Make a linearly decaying timer delay with a threshold of 5 at a |
7 | 1843 * distance of 127 pixels from the main window. |
1844 * | |
1845 * One could think endlessly about the most ergonomic variant here. | |
1846 * For example it could make sense to calculate the distance from the | |
1847 * drags start instead... | |
1848 * | |
1849 * Maybe a parabolic interpolation would suite us better here too... | |
1850 */ | |
1851 if (offshoot > 127) | |
1852 { | |
1853 /* 5 appears to be somehow near to my perceptual limits :-). */ | |
1854 delay = 5; | |
1855 } | |
1856 else | |
1857 { | |
1858 delay = (130 * (127 - offshoot)) / 127 + 5; | |
1859 } | |
1860 | |
1861 /* shoot again */ | |
1862 if (!motion_repeat_timer) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1863 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1864 motion_repeat_timer = g_timeout_add((guint)delay, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1865 motion_repeat_timer_cb, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1866 #else |
7 | 1867 motion_repeat_timer = gtk_timeout_add((guint32)delay, |
1868 motion_repeat_timer_cb, NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1869 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1870 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1871 } |
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 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1874 static GdkDevice * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1875 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
|
1876 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1877 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
|
1878 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
|
1879 # 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
|
1880 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
|
1881 return gdk_seat_get_pointer(seat); |
fc69eed19ba7
commit https://github.com/vim/vim/commit/30e12d259ee78272359f9da2655d0593a4f6a626
Christian Brabandt <cb@256bit.org>
parents:
8851
diff
changeset
|
1882 # else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1883 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
|
1884 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
|
1885 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1886 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1887 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1888 static GdkWindow * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1889 gui_gtk_get_pointer(GtkWidget *widget, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1890 gint *x, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1891 gint *y, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1892 GdkModifierType *state) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1893 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1894 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
|
1895 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
|
1896 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
|
1897 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1898 |
8397
1e58a938aafc
commit https://github.com/vim/vim/commit/2369c15407cf9a730a396ebf9709abb280c5ce48
Christian Brabandt <cb@256bit.org>
parents:
8301
diff
changeset
|
1899 # 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
|
1900 static GdkWindow * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1901 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
|
1902 gint *x, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1903 gint *y) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1904 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1905 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
|
1906 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
|
1907 } |
8397
1e58a938aafc
commit https://github.com/vim/vim/commit/2369c15407cf9a730a396ebf9709abb280c5ce48
Christian Brabandt <cb@256bit.org>
parents:
8301
diff
changeset
|
1908 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1909 #endif |
7 | 1910 |
1911 /* | |
1912 * Timer used to recognize multiple clicks of the mouse button. | |
1913 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1914 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1915 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1916 #else |
7 | 1917 static gint |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1918 #endif |
1884 | 1919 motion_repeat_timer_cb(gpointer data UNUSED) |
7 | 1920 { |
1921 int x; | |
1922 int y; | |
1923 GdkModifierType state; | |
1924 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1925 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1926 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
|
1927 #else |
7 | 1928 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
|
1929 #endif |
7 | 1930 |
1931 if (!(state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | | |
1932 GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | | |
1933 GDK_BUTTON5_MASK))) | |
1934 { | |
1935 motion_repeat_timer = 0; | |
1936 return FALSE; | |
1937 } | |
1938 | |
1939 /* If there already is a mouse click in the input buffer, wait another | |
1940 * time (otherwise we would create a backlog of clicks) */ | |
1941 if (vim_used_in_input_buf() > 10) | |
1942 return TRUE; | |
1943 | |
1944 motion_repeat_timer = 0; | |
1945 | |
1946 /* | |
1947 * Fake a motion event. | |
1948 * Trick: Pretend the mouse moved to the next character on every other | |
1949 * event, otherwise drag events will be discarded, because they are still | |
1950 * in the same character. | |
1951 */ | |
1952 if (motion_repeat_offset) | |
1953 x += gui.char_width; | |
1954 | |
1955 motion_repeat_offset = !motion_repeat_offset; | |
1956 process_motion_notify(x, y, state); | |
1957 | |
1958 /* Don't happen again. We will get reinstalled in the synthetic event | |
1959 * if needed -- thus repeating should still work. */ | |
1960 return FALSE; | |
1961 } | |
1962 | |
1963 static gint | |
1884 | 1964 motion_notify_event(GtkWidget *widget, |
1965 GdkEventMotion *event, | |
1966 gpointer data UNUSED) | |
7 | 1967 { |
1968 if (event->is_hint) | |
1969 { | |
1970 int x; | |
1971 int y; | |
1972 GdkModifierType state; | |
1973 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1974 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1975 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
|
1976 #else |
7 | 1977 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
|
1978 #endif |
7 | 1979 process_motion_notify(x, y, state); |
1980 } | |
1981 else | |
1982 { | |
1983 process_motion_notify((int)event->x, (int)event->y, | |
1984 (GdkModifierType)event->state); | |
1985 } | |
1986 | |
1987 return TRUE; /* handled */ | |
1988 } | |
1989 | |
1990 | |
1991 /* | |
1992 * Mouse button handling. Note please that we are capturing multiple click's | |
1993 * by our own timeout mechanism instead of the one provided by GTK+ itself. | |
1994 * This is due to the way the generic VIM code is recognizing multiple clicks. | |
1995 */ | |
1996 static gint | |
1884 | 1997 button_press_event(GtkWidget *widget, |
1998 GdkEventButton *event, | |
1999 gpointer data UNUSED) | |
7 | 2000 { |
2001 int button; | |
2002 int repeated_click = FALSE; | |
2003 int x, y; | |
2004 int_u vim_modifiers; | |
2005 | |
2923 | 2006 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
|
2007 |
7 | 2008 /* 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
|
2009 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2010 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
|
2011 #else |
7 | 2012 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
|
2013 #endif |
7 | 2014 gtk_widget_grab_focus(widget); |
2015 | |
2016 /* | |
2017 * Don't let additional events about multiple clicks send by GTK to us | |
2018 * after the initial button press event confuse us. | |
2019 */ | |
2020 if (event->type != GDK_BUTTON_PRESS) | |
2021 return FALSE; | |
2022 | |
2023 x = event->x; | |
2024 y = event->y; | |
2025 | |
2026 /* Handle multiple clicks */ | |
2027 if (!mouse_timed_out && mouse_click_timer) | |
2028 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2029 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2030 g_source_remove(mouse_click_timer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2031 #else |
7 | 2032 gtk_timeout_remove(mouse_click_timer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2033 #endif |
7 | 2034 mouse_click_timer = 0; |
2035 repeated_click = TRUE; | |
2036 } | |
2037 | |
2038 mouse_timed_out = FALSE; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2039 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2040 mouse_click_timer = g_timeout_add((guint)p_mouset, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2041 mouse_click_timer_cb, &mouse_timed_out); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2042 #else |
7 | 2043 mouse_click_timer = gtk_timeout_add((guint32)p_mouset, |
2044 mouse_click_timer_cb, &mouse_timed_out); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2045 #endif |
7 | 2046 |
2047 switch (event->button) | |
2048 { | |
7260
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2049 /* 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
|
2050 * 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
|
2051 case 1: button = MOUSE_LEFT; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2052 case 2: button = MOUSE_MIDDLE; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2053 case 3: button = MOUSE_RIGHT; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2054 case 8: button = MOUSE_X1; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2055 case 9: button = MOUSE_X2; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2056 default: |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2057 return FALSE; /* Unknown button */ |
7 | 2058 } |
2059 | |
2060 #ifdef FEAT_XIM | |
2061 /* cancel any preediting */ | |
2062 if (im_is_preediting()) | |
2063 xim_reset(); | |
2064 #endif | |
2065 | |
179 | 2066 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 2067 |
2068 gui_send_mouse_event(button, x, y, repeated_click, vim_modifiers); | |
2069 | |
2070 return TRUE; | |
2071 } | |
2072 | |
2073 /* | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
2074 * GTK+ 2 abstracts scrolling via the GdkEventScroll. |
7 | 2075 */ |
2076 static gboolean | |
1884 | 2077 scroll_event(GtkWidget *widget, |
2078 GdkEventScroll *event, | |
2079 gpointer data UNUSED) | |
7 | 2080 { |
2081 int button; | |
179 | 2082 int_u vim_modifiers; |
7 | 2083 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2084 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2085 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
|
2086 #else |
7 | 2087 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
|
2088 #endif |
7 | 2089 gtk_widget_grab_focus(widget); |
2090 | |
2091 switch (event->direction) | |
2092 { | |
2093 case GDK_SCROLL_UP: | |
2094 button = MOUSE_4; | |
2095 break; | |
2096 case GDK_SCROLL_DOWN: | |
2097 button = MOUSE_5; | |
2098 break; | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2099 case GDK_SCROLL_LEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2100 button = MOUSE_7; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2101 break; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2102 case GDK_SCROLL_RIGHT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2103 button = MOUSE_6; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2104 break; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2105 default: /* This shouldn't happen */ |
7 | 2106 return FALSE; |
2107 } | |
2108 | |
2109 # ifdef FEAT_XIM | |
2110 /* cancel any preediting */ | |
2111 if (im_is_preediting()) | |
2112 xim_reset(); | |
2113 # endif | |
2114 | |
179 | 2115 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 2116 |
2117 gui_send_mouse_event(button, (int)event->x, (int)event->y, | |
2118 FALSE, vim_modifiers); | |
2119 | |
2120 return TRUE; | |
2121 } | |
2122 | |
2123 | |
2124 static gint | |
1884 | 2125 button_release_event(GtkWidget *widget UNUSED, |
2126 GdkEventButton *event, | |
2127 gpointer data UNUSED) | |
7 | 2128 { |
2129 int x, y; | |
2130 int_u vim_modifiers; | |
2131 | |
2923 | 2132 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
|
2133 |
7 | 2134 /* Remove any motion "machine gun" timers used for automatic further |
2135 extension of allocation areas if outside of the applications window | |
2136 area .*/ | |
2137 if (motion_repeat_timer) | |
2138 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2139 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2140 g_source_remove(motion_repeat_timer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2141 #else |
7 | 2142 gtk_timeout_remove(motion_repeat_timer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2143 #endif |
7 | 2144 motion_repeat_timer = 0; |
2145 } | |
2146 | |
2147 x = event->x; | |
2148 y = event->y; | |
2149 | |
179 | 2150 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 2151 |
2152 gui_send_mouse_event(MOUSE_RELEASE, x, y, FALSE, vim_modifiers); | |
2153 | |
2154 return TRUE; | |
2155 } | |
2156 | |
2157 | |
2158 #ifdef FEAT_DND | |
2159 /**************************************************************************** | |
2160 * Drag aNd Drop support handlers. | |
2161 */ | |
2162 | |
2163 /* | |
2164 * Count how many items there may be and separate them with a NUL. | |
2165 * Apparently the items are separated with \r\n. This is not documented, | |
2166 * thus be careful not to go past the end. Also allow separation with | |
2167 * NUL characters. | |
2168 */ | |
2169 static int | |
2170 count_and_decode_uri_list(char_u *out, char_u *raw, int len) | |
2171 { | |
2172 int i; | |
2173 char_u *p = out; | |
2174 int count = 0; | |
2175 | |
2176 for (i = 0; i < len; ++i) | |
2177 { | |
2178 if (raw[i] == NUL || raw[i] == '\n' || raw[i] == '\r') | |
2179 { | |
2180 if (p > out && p[-1] != NUL) | |
2181 { | |
2182 ++count; | |
2183 *p++ = NUL; | |
2184 } | |
2185 } | |
2186 else if (raw[i] == '%' && i + 2 < len && hexhex2nr(raw + i + 1) > 0) | |
2187 { | |
2188 *p++ = hexhex2nr(raw + i + 1); | |
2189 i += 2; | |
2190 } | |
2191 else | |
2192 *p++ = raw[i]; | |
2193 } | |
2194 if (p > out && p[-1] != NUL) | |
2195 { | |
2196 *p = NUL; /* last item didn't have \r or \n */ | |
2197 ++count; | |
2198 } | |
2199 return count; | |
2200 } | |
2201 | |
2202 /* | |
2203 * Parse NUL separated "src" strings. Make it an array "outlist" form. On | |
2204 * this process, URI which protocol is not "file:" are removed. Return | |
2205 * length of array (less than "max"). | |
2206 */ | |
2207 static int | |
2208 filter_uri_list(char_u **outlist, int max, char_u *src) | |
2209 { | |
2210 int i, j; | |
2211 | |
2212 for (i = j = 0; i < max; ++i) | |
2213 { | |
2214 outlist[i] = NULL; | |
2215 if (STRNCMP(src, "file:", 5) == 0) | |
2216 { | |
2217 src += 5; | |
2218 if (STRNCMP(src, "//localhost", 11) == 0) | |
2219 src += 11; | |
2220 while (src[0] == '/' && src[1] == '/') | |
2221 ++src; | |
2222 outlist[j++] = vim_strsave(src); | |
2223 } | |
2224 src += STRLEN(src) + 1; | |
2225 } | |
2226 return j; | |
2227 } | |
2228 | |
2229 static char_u ** | |
2230 parse_uri_list(int *count, char_u *data, int len) | |
2231 { | |
2232 int n = 0; | |
2233 char_u *tmp = NULL; | |
9252
c25898cc99c1
commit https://github.com/vim/vim/commit/945ec093cd4ddefab930239990564b12eb232153
Christian Brabandt <cb@256bit.org>
parents:
9232
diff
changeset
|
2234 char_u **array = NULL; |
7 | 2235 |
2236 if (data != NULL && len > 0 && (tmp = (char_u *)alloc(len + 1)) != NULL) | |
2237 { | |
2238 n = count_and_decode_uri_list(tmp, data, len); | |
2239 if (n > 0 && (array = (char_u **)alloc(n * sizeof(char_u *))) != NULL) | |
2240 n = filter_uri_list(array, n, tmp); | |
2241 } | |
2242 vim_free(tmp); | |
2243 *count = n; | |
2244 return array; | |
2245 } | |
2246 | |
2247 static void | |
2248 drag_handle_uri_list(GdkDragContext *context, | |
2249 GtkSelectionData *data, | |
2250 guint time_, | |
2251 GdkModifierType state, | |
2252 gint x, | |
2253 gint y) | |
2254 { | |
2255 char_u **fnames; | |
2256 int nfiles = 0; | |
2257 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2258 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2259 fnames = parse_uri_list(&nfiles, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2260 (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
|
2261 gtk_selection_data_get_length(data)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2262 # else |
7 | 2263 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
|
2264 # endif |
7 | 2265 |
2266 if (fnames != NULL && nfiles > 0) | |
2267 { | |
179 | 2268 int_u modifiers; |
7 | 2269 |
2270 gtk_drag_finish(context, TRUE, FALSE, time_); /* accept */ | |
2271 | |
179 | 2272 modifiers = modifiers_gdk2mouse(state); |
7 | 2273 |
2274 gui_handle_drop(x, y, modifiers, fnames, nfiles); | |
2275 } | |
840 | 2276 else |
2277 vim_free(fnames); | |
7 | 2278 } |
2279 | |
2280 static void | |
2281 drag_handle_text(GdkDragContext *context, | |
2282 GtkSelectionData *data, | |
2283 guint time_, | |
2284 GdkModifierType state) | |
2285 { | |
2286 char_u dropkey[6] = {CSI, KS_MODIFIER, 0, CSI, KS_EXTRA, (char_u)KE_DROP}; | |
2287 char_u *text; | |
2288 int len; | |
2289 char_u *tmpbuf = NULL; | |
2290 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2291 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2292 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
|
2293 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
|
2294 # else |
7 | 2295 text = data->data; |
2296 len = data->length; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2297 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2298 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2299 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2300 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
|
2301 # else |
7 | 2302 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
|
2303 # endif |
7 | 2304 { |
2305 if (input_conv.vc_type != CONV_NONE) | |
2306 tmpbuf = string_convert(&input_conv, text, &len); | |
2307 if (tmpbuf != NULL) | |
2308 text = tmpbuf; | |
2309 } | |
2310 | |
2311 dnd_yank_drag_data(text, (long)len); | |
2312 gtk_drag_finish(context, TRUE, FALSE, time_); /* accept */ | |
2313 vim_free(tmpbuf); | |
2314 | |
179 | 2315 dropkey[2] = modifiers_gdk2vim(state); |
7 | 2316 |
2317 if (dropkey[2] != 0) | |
2318 add_to_input_buf(dropkey, (int)sizeof(dropkey)); | |
2319 else | |
2320 add_to_input_buf(dropkey + 3, (int)(sizeof(dropkey) - 3)); | |
2321 } | |
2322 | |
2323 /* | |
2324 * DND receiver. | |
2325 */ | |
2326 static void | |
2327 drag_data_received_cb(GtkWidget *widget, | |
2328 GdkDragContext *context, | |
2329 gint x, | |
2330 gint y, | |
2331 GtkSelectionData *data, | |
2332 guint info, | |
2333 guint time_, | |
1884 | 2334 gpointer user_data UNUSED) |
7 | 2335 { |
2336 GdkModifierType state; | |
2337 | |
2338 /* Guard against trash */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2339 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2340 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
|
2341 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
|
2342 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
|
2343 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2344 if (data_data == NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2345 || data_length <= 0 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2346 || data_format != 8 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2347 || data_data[data_length] != '\0') |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2348 # else |
7 | 2349 if (data->data == NULL |
2350 || data->length <= 0 | |
2351 || data->format != 8 | |
2352 || data->data[data->length] != '\0') | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2353 # endif |
7 | 2354 { |
2355 gtk_drag_finish(context, FALSE, FALSE, time_); | |
2356 return; | |
2357 } | |
2358 | |
2359 /* Get the current modifier state for proper distinguishment between | |
2360 * different operations later. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2361 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2362 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
|
2363 # else |
7 | 2364 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
|
2365 # endif |
7 | 2366 |
2367 /* Not sure about the role of "text/plain" here... */ | |
2368 if (info == (guint)TARGET_TEXT_URI_LIST) | |
2369 drag_handle_uri_list(context, data, time_, state, x, y); | |
2370 else | |
2371 drag_handle_text(context, data, time_, state); | |
2372 | |
2373 } | |
2374 #endif /* FEAT_DND */ | |
2375 | |
2376 | |
2377 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
2378 /* | |
2379 * GnomeClient interact callback. Check for unsaved buffers that cannot | |
2380 * be abandoned and pop up a dialog asking the user for confirmation if | |
2381 * necessary. | |
2382 */ | |
2383 static void | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2384 sm_client_check_changed_any(GnomeClient *client UNUSED, |
7 | 2385 gint key, |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2386 GnomeDialogType type UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2387 gpointer data UNUSED) |
7 | 2388 { |
2389 cmdmod_T save_cmdmod; | |
2390 gboolean shutdown_cancelled; | |
2391 | |
2392 save_cmdmod = cmdmod; | |
2393 | |
2394 # ifdef FEAT_BROWSE | |
2395 cmdmod.browse = TRUE; | |
2396 # endif | |
2397 # if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
2398 cmdmod.confirm = TRUE; | |
2399 # endif | |
2400 /* | |
2401 * If there are changed buffers, present the user with | |
2402 * a dialog if possible, otherwise give an error message. | |
2403 */ | |
7469
15eefe1b0dad
commit https://github.com/vim/vim/commit/027387f70c671f62e3e08e0bdd09ec05b0232735
Christian Brabandt <cb@256bit.org>
parents:
7380
diff
changeset
|
2404 shutdown_cancelled = check_changed_any(FALSE, FALSE); |
7 | 2405 |
2406 exiting = FALSE; | |
2407 cmdmod = save_cmdmod; | |
2408 setcursor(); /* position the cursor */ | |
2409 out_flush(); | |
2410 /* | |
2411 * If the user hit the [Cancel] button the whole shutdown | |
2412 * will be cancelled. Wow, quite powerful feature (: | |
2413 */ | |
2414 gnome_interaction_key_return(key, shutdown_cancelled); | |
2415 } | |
2416 | |
2417 /* | |
2418 * Generate a script that can be used to restore the current editing session. | |
2419 * Save the value of v:this_session before running :mksession in order to make | |
2420 * automagic session save fully transparent. Return TRUE on success. | |
2421 */ | |
2422 static int | |
2423 write_session_file(char_u *filename) | |
2424 { | |
2425 char_u *escaped_filename; | |
2426 char *mksession_cmdline; | |
2427 unsigned int save_ssop_flags; | |
2428 int failed; | |
2429 | |
2430 /* | |
2431 * Build an ex command line to create a script that restores the current | |
2432 * session if executed. Escape the filename to avoid nasty surprises. | |
2433 */ | |
2434 escaped_filename = vim_strsave_escaped(filename, escape_chars); | |
2435 if (escaped_filename == NULL) | |
2436 return FALSE; | |
1296 | 2437 mksession_cmdline = g_strconcat("mksession ", (char *)escaped_filename, |
2438 NULL); | |
7 | 2439 vim_free(escaped_filename); |
1296 | 2440 |
7 | 2441 /* |
2442 * Use a reasonable hardcoded set of 'sessionoptions' flags to avoid | |
2443 * unpredictable effects when the session is saved automatically. Also, | |
2444 * we definitely need SSOP_GLOBALS to be able to restore v:this_session. | |
2445 * Don't use SSOP_BUFFERS to prevent the buffer list from becoming | |
2446 * enormously large if the GNOME session feature is used regularly. | |
2447 */ | |
2448 save_ssop_flags = ssop_flags; | |
2449 ssop_flags = (SSOP_BLANK|SSOP_CURDIR|SSOP_FOLDS|SSOP_GLOBALS | |
1296 | 2450 |SSOP_HELP|SSOP_OPTIONS|SSOP_WINSIZE|SSOP_TABPAGES); |
7 | 2451 |
2452 do_cmdline_cmd((char_u *)"let Save_VV_this_session = v:this_session"); | |
2453 failed = (do_cmdline_cmd((char_u *)mksession_cmdline) == FAIL); | |
2454 do_cmdline_cmd((char_u *)"let v:this_session = Save_VV_this_session"); | |
150 | 2455 do_unlet((char_u *)"Save_VV_this_session", TRUE); |
7 | 2456 |
2457 ssop_flags = save_ssop_flags; | |
2458 g_free(mksession_cmdline); | |
5905 | 2459 |
7 | 2460 /* |
2461 * Reopen the file and append a command to restore v:this_session, | |
2462 * as if this save never happened. This is to avoid conflicts with | |
2463 * the user's own sessions. FIXME: It's probably less hackish to add | |
2464 * a "stealth" flag to 'sessionoptions' -- gotta ask Bram. | |
2465 */ | |
2466 if (!failed) | |
2467 { | |
2468 FILE *fd; | |
2469 | |
2470 fd = open_exfile(filename, TRUE, APPENDBIN); | |
2471 | |
2472 failed = (fd == NULL | |
2473 || put_line(fd, "let v:this_session = Save_VV_this_session") == FAIL | |
2474 || put_line(fd, "unlet Save_VV_this_session") == FAIL); | |
2475 | |
2476 if (fd != NULL && fclose(fd) != 0) | |
2477 failed = TRUE; | |
2478 | |
2479 if (failed) | |
2480 mch_remove(filename); | |
2481 } | |
2482 | |
2483 return !failed; | |
2484 } | |
2485 | |
2486 /* | |
2487 * "save_yourself" signal handler. Initiate an interaction to ask the user | |
2488 * for confirmation if necessary. Save the current editing session and tell | |
2489 * the session manager how to restart Vim. | |
2490 */ | |
2491 static gboolean | |
2492 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
|
2493 gint phase UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2494 GnomeSaveStyle save_style UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2495 gboolean shutdown UNUSED, |
7 | 2496 GnomeInteractStyle interact_style, |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2497 gboolean fast UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2498 gpointer data UNUSED) |
7 | 2499 { |
2500 static const char suffix[] = "-session.vim"; | |
2501 char *session_file; | |
2502 unsigned int len; | |
2503 gboolean success; | |
2504 | |
2505 /* Always request an interaction if possible. check_changed_any() | |
2506 * won't actually show a dialog unless any buffers have been modified. | |
2507 * There doesn't seem to be an obvious way to check that without | |
2508 * automatically firing the dialog. Anyway, it works just fine. */ | |
2509 if (interact_style == GNOME_INTERACT_ANY) | |
2510 gnome_client_request_interaction(client, GNOME_DIALOG_NORMAL, | |
2511 &sm_client_check_changed_any, | |
2512 NULL); | |
2513 out_flush(); | |
2514 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
2515 | |
2516 /* The path is unique for each session save. We do neither know nor care | |
2517 * which session script will actually be used later. This decision is in | |
2518 * the domain of the session manager. */ | |
2519 session_file = gnome_config_get_real_path( | |
2520 gnome_client_get_config_prefix(client)); | |
2521 len = strlen(session_file); | |
2522 | |
2523 if (len > 0 && session_file[len-1] == G_DIR_SEPARATOR) | |
2524 --len; /* get rid of the superfluous trailing '/' */ | |
2525 | |
2526 session_file = g_renew(char, session_file, len + sizeof(suffix)); | |
2527 memcpy(session_file + len, suffix, sizeof(suffix)); | |
2528 | |
2529 success = write_session_file((char_u *)session_file); | |
2530 | |
2531 if (success) | |
2532 { | |
2533 const char *argv[8]; | |
2534 int i; | |
2535 | |
2536 /* Tell the session manager how to wipe out the stored session data. | |
2537 * This isn't as dangerous as it looks, don't worry :) session_file | |
2538 * is a unique absolute filename. Usually it'll be something like | |
2539 * `/home/user/.gnome2/vim-XXXXXX-session.vim'. */ | |
2540 i = 0; | |
2541 argv[i++] = "rm"; | |
2542 argv[i++] = session_file; | |
2543 argv[i] = NULL; | |
2544 | |
2545 gnome_client_set_discard_command(client, i, (char **)argv); | |
2546 | |
2547 /* Tell the session manager how to restore the just saved session. | |
2548 * This is easily done thanks to Vim's -S option. Pass the -f flag | |
2549 * since there's no need to fork -- it might even cause confusion. | |
2550 * Also pass the window role to give the WM something to match on. | |
2551 * The role is set in gui_mch_open(), thus should _never_ be NULL. */ | |
2552 i = 0; | |
2553 argv[i++] = restart_command; | |
2554 argv[i++] = "-f"; | |
2555 argv[i++] = "-g"; | |
2556 argv[i++] = "--role"; | |
2557 argv[i++] = gtk_window_get_role(GTK_WINDOW(gui.mainwin)); | |
2558 argv[i++] = "-S"; | |
2559 argv[i++] = session_file; | |
2560 argv[i] = NULL; | |
2561 | |
2562 gnome_client_set_restart_command(client, i, (char **)argv); | |
2563 gnome_client_set_clone_command(client, 0, NULL); | |
2564 } | |
2565 | |
2566 g_free(session_file); | |
2567 | |
2568 return success; | |
2569 } | |
2570 | |
2571 /* | |
2572 * Called when the session manager wants us to die. There isn't much to save | |
2573 * here since "save_yourself" has been emitted before (unless serious trouble | |
2574 * is happening). | |
2575 */ | |
2576 static void | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2577 sm_client_die(GnomeClient *client UNUSED, gpointer data UNUSED) |
7 | 2578 { |
2579 /* Don't write messages to the GUI anymore */ | |
2580 full_screen = FALSE; | |
2581 | |
1666 | 2582 vim_strncpy(IObuff, (char_u *) |
419 | 2583 _("Vim: Received \"die\" request from session manager\n"), |
1666 | 2584 IOSIZE - 1); |
7 | 2585 preserve_exit(); |
2586 } | |
2587 | |
2588 /* | |
2589 * Connect our signal handlers to be notified on session save and shutdown. | |
2590 */ | |
2591 static void | |
2592 setup_save_yourself(void) | |
2593 { | |
2594 GnomeClient *client; | |
2595 | |
2596 client = gnome_master_client(); | |
2597 | |
2598 if (client != NULL) | |
2599 { | |
2600 /* Must use the deprecated gtk_signal_connect() for compatibility | |
2601 * with GNOME 1. Arrgh, zombies! */ | |
2602 gtk_signal_connect(GTK_OBJECT(client), "save_yourself", | |
2603 GTK_SIGNAL_FUNC(&sm_client_save_yourself), NULL); | |
2604 gtk_signal_connect(GTK_OBJECT(client), "die", | |
2605 GTK_SIGNAL_FUNC(&sm_client_die), NULL); | |
2606 } | |
2607 } | |
2608 | |
2609 #else /* !(FEAT_GUI_GNOME && FEAT_SESSION) */ | |
2610 | |
2611 # ifdef USE_XSMP | |
2612 /* | |
2613 * GTK tells us that XSMP needs attention | |
2614 */ | |
2615 static gboolean | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2616 local_xsmp_handle_requests( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2617 GIOChannel *source UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2618 GIOCondition condition, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2619 gpointer data) |
7 | 2620 { |
2621 if (condition == G_IO_IN) | |
2622 { | |
2623 /* Do stuff; maybe close connection */ | |
2624 if (xsmp_handle_requests() == FAIL) | |
2625 g_io_channel_unref((GIOChannel *)data); | |
2626 return TRUE; | |
2627 } | |
2628 /* Error */ | |
2629 g_io_channel_unref((GIOChannel *)data); | |
2630 xsmp_close(); | |
2631 return TRUE; | |
2632 } | |
2633 # endif /* USE_XSMP */ | |
2634 | |
2635 /* | |
2636 * Setup the WM_PROTOCOLS to indicate we want the WM_SAVE_YOURSELF event. | |
2637 * This is an ugly use of X functions. GTK doesn't offer an alternative. | |
2638 */ | |
2639 static void | |
2640 setup_save_yourself(void) | |
2641 { | |
2642 Atom *existing_atoms = NULL; | |
2643 int count = 0; | |
2644 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2645 # ifdef USE_XSMP |
7 | 2646 if (xsmp_icefd != -1) |
2647 { | |
2648 /* | |
2649 * Use XSMP is preference to legacy WM_SAVE_YOURSELF; | |
2650 * set up GTK IO monitor | |
2651 */ | |
2652 GIOChannel *g_io = g_io_channel_unix_new(xsmp_icefd); | |
2653 | |
2654 g_io_add_watch(g_io, G_IO_IN | G_IO_ERR | G_IO_HUP, | |
2655 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
|
2656 g_io_channel_unref(g_io); |
7 | 2657 } |
2658 else | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2659 # endif |
7 | 2660 { |
2661 /* Fall back to old method */ | |
2662 | |
2663 /* first get the existing value */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2664 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2665 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
|
2666 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2667 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
|
2668 GDK_WINDOW_XID(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2669 &existing_atoms, &count)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2670 # else |
7 | 2671 if (XGetWMProtocols(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2672 GDK_WINDOW_XWINDOW(gui.mainwin->window), | |
2673 &existing_atoms, &count)) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2674 # endif |
7 | 2675 { |
2676 Atom *new_atoms; | |
2677 Atom save_yourself_xatom; | |
2678 int i; | |
2679 | |
2680 save_yourself_xatom = GET_X_ATOM(save_yourself_atom); | |
2681 | |
2682 /* check if WM_SAVE_YOURSELF isn't there yet */ | |
2683 for (i = 0; i < count; ++i) | |
2684 if (existing_atoms[i] == save_yourself_xatom) | |
2685 break; | |
2686 | |
2687 if (i == count) | |
2688 { | |
2689 /* allocate an Atoms array which is one item longer */ | |
2690 new_atoms = (Atom *)alloc((unsigned)((count + 1) | |
2691 * sizeof(Atom))); | |
2692 if (new_atoms != NULL) | |
2693 { | |
2694 memcpy(new_atoms, existing_atoms, count * sizeof(Atom)); | |
2695 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
|
2696 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2697 XSetWMProtocols(GDK_WINDOW_XDISPLAY(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2698 GDK_WINDOW_XID(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2699 # else |
7 | 2700 XSetWMProtocols(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2701 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
|
2702 # endif |
7 | 2703 new_atoms, count + 1); |
2704 vim_free(new_atoms); | |
2705 } | |
2706 } | |
2707 XFree(existing_atoms); | |
2708 } | |
2709 } | |
2710 } | |
2711 | |
2712 /* | |
2713 * Installing a global event filter seems to be the only way to catch | |
2714 * client messages of type WM_PROTOCOLS without overriding GDK's own | |
2715 * client message event filter. Well, that's still better than trying | |
2716 * to guess what the GDK filter had done if it had been invoked instead | |
2717 * | |
2718 * GTK2_FIXME: This doesn't seem to work. For some reason we never | |
2719 * receive WM_SAVE_YOURSELF even though everything is set up correctly. | |
2720 * I have the nasty feeling modern session managers just don't send this | |
2721 * deprecated message anymore. Addition: confirmed by several people. | |
2722 * | |
2723 * The GNOME session support is much cooler anyway. Unlike this ugly | |
2724 * WM_SAVE_YOURSELF hack it actually stores the session... And yes, | |
2725 * it should work with KDE as well. | |
2726 */ | |
2727 static GdkFilterReturn | |
1884 | 2728 global_event_filter(GdkXEvent *xev, |
2729 GdkEvent *event UNUSED, | |
2730 gpointer data UNUSED) | |
7 | 2731 { |
2732 XEvent *xevent = (XEvent *)xev; | |
2733 | |
2734 if (xevent != NULL | |
2735 && xevent->type == ClientMessage | |
2736 && xevent->xclient.message_type == GET_X_ATOM(wm_protocols_atom) | |
1884 | 2737 && (long_u)xevent->xclient.data.l[0] |
2738 == GET_X_ATOM(save_yourself_atom)) | |
7 | 2739 { |
2740 out_flush(); | |
2741 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
2742 /* | |
2743 * Set the window's WM_COMMAND property, to let the window manager | |
2744 * know we are done saving ourselves. We don't want to be | |
2745 * restarted, thus set argv to NULL. | |
2746 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2747 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2748 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
|
2749 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
|
2750 # else |
7 | 2751 XSetCommand(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2752 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
|
2753 # endif |
7 | 2754 NULL, 0); |
2755 return GDK_FILTER_REMOVE; | |
2756 } | |
2757 | |
2758 return GDK_FILTER_CONTINUE; | |
2759 } | |
2760 #endif /* !(FEAT_GUI_GNOME && FEAT_SESSION) */ | |
2761 | |
2762 | |
2763 /* | |
2764 * Setup the window icon & xcmdsrv comm after the main window has been realized. | |
2765 */ | |
2766 static void | |
1884 | 2767 mainwin_realize(GtkWidget *widget UNUSED, gpointer data UNUSED) |
7 | 2768 { |
2769 /* If you get an error message here, you still need to unpack the runtime | |
2770 * archive! */ | |
2771 #ifdef magick | |
2772 # undef magick | |
2773 #endif | |
2774 /* A bit hackish, but avoids casting later and allows optimization */ | |
2775 # define static static const | |
2776 #define magick vim32x32 | |
2777 #include "../runtime/vim32x32.xpm" | |
2778 #undef magick | |
2779 #define magick vim16x16 | |
2780 #include "../runtime/vim16x16.xpm" | |
2781 #undef magick | |
2782 #define magick vim48x48 | |
2783 #include "../runtime/vim48x48.xpm" | |
2784 #undef magick | |
2785 # undef static | |
2786 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2787 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2788 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
|
2789 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2790 |
7 | 2791 /* When started with "--echo-wid" argument, write window ID on stdout. */ |
2792 if (echo_wid_arg) | |
2793 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2794 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2795 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
|
2796 #else |
7 | 2797 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
|
2798 #endif |
7 | 2799 fflush(stdout); |
2800 } | |
2801 | |
2802 if (vim_strchr(p_go, GO_ICON) != NULL) | |
2803 { | |
2804 /* | |
2805 * Add an icon to the main window. For fun and convenience of the user. | |
2806 */ | |
2807 GList *icons = NULL; | |
2808 | |
2809 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim16x16)); | |
2810 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim32x32)); | |
2811 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim48x48)); | |
2812 | |
2813 gtk_window_set_icon_list(GTK_WINDOW(gui.mainwin), icons); | |
2814 | |
2815 g_list_foreach(icons, (GFunc)&g_object_unref, NULL); | |
2816 g_list_free(icons); | |
2817 } | |
2818 | |
2819 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
2820 /* Register a handler for WM_SAVE_YOURSELF with GDK's low-level X I/F */ | |
2821 gdk_window_add_filter(NULL, &global_event_filter, NULL); | |
2822 #endif | |
2823 /* Setup to indicate to the window manager that we want to catch the | |
2824 * WM_SAVE_YOURSELF event. For GNOME, this connects to the session | |
2825 * manager instead. */ | |
2826 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
2827 if (using_gnome) | |
2828 #endif | |
2829 setup_save_yourself(); | |
2830 | |
2831 #ifdef FEAT_CLIENTSERVER | |
2832 if (serverName == NULL && serverDelayedStartName != NULL) | |
2833 { | |
2834 /* 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
|
2835 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2836 commWindow = GDK_WINDOW_XID(mainwin_win); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2837 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2838 (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
|
2839 serverDelayedStartName); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2840 # else |
7 | 2841 commWindow = GDK_WINDOW_XWINDOW(gui.mainwin->window); |
2842 | |
2843 (void)serverRegisterName(GDK_WINDOW_XDISPLAY(gui.mainwin->window), | |
2844 serverDelayedStartName); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2845 # endif |
7 | 2846 } |
2847 else | |
2848 { | |
2849 /* | |
2850 * Cannot handle "XLib-only" windows with gtk event routines, we'll | |
2851 * have to change the "server" registration to that of the main window | |
2852 * If we have not registered a name yet, remember the window | |
2853 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2854 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2855 serverChangeRegisteredWindow(GDK_WINDOW_XDISPLAY(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2856 GDK_WINDOW_XID(mainwin_win)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2857 # else |
7 | 2858 serverChangeRegisteredWindow(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2859 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
|
2860 # endif |
7 | 2861 } |
2862 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
|
2863 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2864 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
|
2865 G_CALLBACK(property_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2866 # else |
7 | 2867 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "property_notify_event", |
2868 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
|
2869 # endif |
7 | 2870 #endif |
2871 } | |
2872 | |
2873 static GdkCursor * | |
2874 create_blank_pointer(void) | |
2875 { | |
2876 GdkWindow *root_window = NULL; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2877 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2878 GdkPixbuf *blank_mask; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2879 #else |
7 | 2880 GdkPixmap *blank_mask; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2881 #endif |
7 | 2882 GdkCursor *cursor; |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2883 #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
|
2884 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
|
2885 #else |
7 | 2886 GdkColor color = { 0, 0, 0, 0 }; |
2887 char blank_data[] = { 0x0 }; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2888 #endif |
7 | 2889 |
2890 #ifdef HAVE_GTK_MULTIHEAD | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2891 # if GTK_CHECK_VERSION(3,12,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2892 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2893 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
|
2894 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
|
2895 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
|
2896 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2897 # else |
7 | 2898 root_window = gtk_widget_get_root_window(gui.mainwin); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2899 # endif |
7 | 2900 #endif |
2901 | |
2902 /* Create a pseudo blank pointer, which is in fact one pixel by one pixel | |
2903 * in size. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2904 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2905 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2906 cairo_surface_t *surf; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2907 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2908 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2909 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
|
2910 cr = cairo_create(surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2911 |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2912 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2913 color.red, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2914 color.green, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2915 color.blue, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2916 color.alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2917 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
|
2918 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2919 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2920 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2921 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
|
2922 cairo_surface_destroy(surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2923 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2924 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
|
2925 blank_mask, 0, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2926 g_object_unref(blank_mask); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2927 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2928 #else |
7 | 2929 blank_mask = gdk_bitmap_create_from_data(root_window, blank_data, 1, 1); |
2930 cursor = gdk_cursor_new_from_pixmap(blank_mask, blank_mask, | |
2931 &color, &color, 0, 0); | |
2932 gdk_bitmap_unref(blank_mask); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2933 #endif |
7 | 2934 |
2935 return cursor; | |
2936 } | |
2937 | |
2938 #ifdef HAVE_GTK_MULTIHEAD | |
2939 static void | |
2940 mainwin_screen_changed_cb(GtkWidget *widget, | |
1884 | 2941 GdkScreen *previous_screen UNUSED, |
2942 gpointer data UNUSED) | |
7 | 2943 { |
2944 if (!gtk_widget_has_screen(widget)) | |
2945 return; | |
2946 | |
2947 /* | |
1226 | 2948 * Recreate the invisible mouse cursor. |
7 | 2949 */ |
2950 if (gui.blank_pointer != NULL) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2951 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2952 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
|
2953 # else |
7 | 2954 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
|
2955 # endif |
7 | 2956 |
2957 gui.blank_pointer = create_blank_pointer(); | |
2958 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2959 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2960 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
|
2961 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
|
2962 gui.blank_pointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2963 # else |
7 | 2964 if (gui.pointer_hidden && gui.drawarea->window != NULL) |
2965 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
|
2966 # endif |
7 | 2967 |
2968 /* | |
2969 * Create a new PangoContext for this screen, and initialize it | |
2970 * with the current font if necessary. | |
2971 */ | |
2972 if (gui.text_context != NULL) | |
2973 g_object_unref(gui.text_context); | |
2974 | |
2975 gui.text_context = gtk_widget_create_pango_context(widget); | |
2976 pango_context_set_base_dir(gui.text_context, PANGO_DIRECTION_LTR); | |
2977 | |
2978 if (gui.norm_font != NULL) | |
2979 { | |
38 | 2980 gui_mch_init_font(p_guifont, FALSE); |
814 | 2981 gui_set_shellsize(FALSE, FALSE, RESIZE_BOTH); |
7 | 2982 } |
2983 } | |
2984 #endif /* HAVE_GTK_MULTIHEAD */ | |
2985 | |
2986 /* | |
2987 * After the drawing area comes up, we calculate all colors and create the | |
2988 * dummy blank cursor. | |
2989 * | |
2990 * Don't try to set any VIM scrollbar sizes anywhere here. I'm relying on the | |
2991 * fact that the main VIM engine doesn't take them into account anywhere. | |
2992 */ | |
2993 static void | |
1884 | 2994 drawarea_realize_cb(GtkWidget *widget, gpointer data UNUSED) |
7 | 2995 { |
2996 GtkWidget *sbar; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2997 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2998 GtkAllocation allocation; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2999 #endif |
7 | 3000 |
3001 #ifdef FEAT_XIM | |
3002 xim_init(); | |
3003 #endif | |
3004 gui_mch_new_colors(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3005 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3006 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
|
3007 gtk_widget_get_window(widget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3008 CAIRO_CONTENT_COLOR_ALPHA, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3009 gtk_widget_get_allocated_width(widget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3010 gtk_widget_get_allocated_height(widget)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3011 #else |
7 | 3012 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
|
3013 #endif |
7 | 3014 |
3015 gui.blank_pointer = create_blank_pointer(); | |
3016 if (gui.pointer_hidden) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3017 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3018 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
|
3019 #else |
7 | 3020 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
|
3021 #endif |
7 | 3022 |
3023 /* get the actual size of the scrollbars, if they are realized */ | |
3024 sbar = firstwin->w_scrollbars[SBAR_LEFT].id; | |
3025 if (!sbar || (!gui.which_scrollbars[SBAR_LEFT] | |
3026 && firstwin->w_scrollbars[SBAR_RIGHT].id)) | |
3027 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
|
3028 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3029 gtk_widget_get_allocation(sbar, &allocation); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3030 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
|
3031 gui.scrollbar_width = allocation.width; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3032 #else |
7 | 3033 if (sbar && GTK_WIDGET_REALIZED(sbar) && sbar->allocation.width) |
3034 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
|
3035 #endif |
7 | 3036 |
3037 sbar = gui.bottom_sbar.id; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3038 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3039 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
|
3040 gui.scrollbar_height = allocation.height; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3041 #else |
7 | 3042 if (sbar && GTK_WIDGET_REALIZED(sbar) && sbar->allocation.height) |
3043 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
|
3044 #endif |
7 | 3045 } |
3046 | |
3047 /* | |
3048 * Properly clean up on shutdown. | |
3049 */ | |
3050 static void | |
1884 | 3051 drawarea_unrealize_cb(GtkWidget *widget UNUSED, gpointer data UNUSED) |
7 | 3052 { |
3053 /* Don't write messages to the GUI anymore */ | |
3054 full_screen = FALSE; | |
3055 | |
3056 #ifdef FEAT_XIM | |
3057 im_shutdown(); | |
3058 #endif | |
3059 if (gui.ascii_glyphs != NULL) | |
3060 { | |
3061 pango_glyph_string_free(gui.ascii_glyphs); | |
3062 gui.ascii_glyphs = NULL; | |
3063 } | |
3064 if (gui.ascii_font != NULL) | |
3065 { | |
3066 g_object_unref(gui.ascii_font); | |
3067 gui.ascii_font = NULL; | |
3068 } | |
3069 g_object_unref(gui.text_context); | |
3070 gui.text_context = NULL; | |
3071 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3072 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3073 if (gui.surface != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3074 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3075 cairo_surface_destroy(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3076 gui.surface = NULL; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3077 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3078 #else |
7 | 3079 g_object_unref(gui.text_gc); |
3080 gui.text_gc = NULL; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3081 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3082 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3083 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3084 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
|
3085 #else |
7 | 3086 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
|
3087 #endif |
7 | 3088 gui.blank_pointer = NULL; |
3089 } | |
3090 | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3091 #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
|
3092 static void |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3093 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
|
3094 gpointer data UNUSED) |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3095 #else |
7 | 3096 static void |
1884 | 3097 drawarea_style_set_cb(GtkWidget *widget UNUSED, |
3098 GtkStyle *previous_style UNUSED, | |
3099 gpointer data UNUSED) | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3100 #endif |
7 | 3101 { |
3102 gui_mch_new_colors(); | |
3103 } | |
3104 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3105 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3106 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3107 drawarea_configure_event_cb(GtkWidget *widget, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3108 GdkEventConfigure *event, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3109 gpointer data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3110 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3111 static int cur_width = 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3112 static int cur_height = 0; |
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 g_return_val_if_fail(event |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3115 && 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
|
3116 |
10402
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
3117 # 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
|
3118 /* 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
|
3119 * 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
|
3120 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3121 * 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
|
3122 * 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
|
3123 * 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
|
3124 * "native" one from non-native one. |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3125 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3126 * 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
|
3127 * 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
|
3128 * 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
|
3129 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3130 * 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
|
3131 * 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
|
3132 * configure_native_child(). |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3133 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3134 * 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
|
3135 * 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
|
3136 * 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
|
3137 */ |
10402
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
3138 /* Follow-up |
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
3139 * 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
|
3140 * 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
|
3141 * 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
|
3142 if (event->send_event == FALSE) |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3143 return TRUE; |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3144 # endif |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3145 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3146 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
|
3147 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3148 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3149 cur_width = event->width; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3150 cur_height = event->height; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3151 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3152 if (gui.surface != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3153 cairo_surface_destroy(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3154 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3155 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
|
3156 gtk_widget_get_window(widget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3157 CAIRO_CONTENT_COLOR_ALPHA, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3158 event->width, event->height); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3159 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3160 gtk_widget_queue_draw(widget); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3161 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3162 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3163 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3164 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3165 |
7 | 3166 /* |
3167 * Callback routine for the "delete_event" signal on the toplevel window. | |
3168 * Tries to vim gracefully, or refuses to exit with changed buffers. | |
3169 */ | |
3170 static gint | |
1884 | 3171 delete_event_cb(GtkWidget *widget UNUSED, |
3172 GdkEventAny *event UNUSED, | |
3173 gpointer data UNUSED) | |
7 | 3174 { |
3175 gui_shell_closed(); | |
3176 return TRUE; | |
3177 } | |
3178 | |
685 | 3179 #if defined(FEAT_MENU) || defined(FEAT_TOOLBAR) || defined(FEAT_GUI_TABLINE) |
3180 static int | |
3181 get_item_dimensions(GtkWidget *widget, GtkOrientation orientation) | |
3182 { | |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3183 # ifdef FEAT_GUI_GNOME |
685 | 3184 GtkOrientation item_orientation = GTK_ORIENTATION_HORIZONTAL; |
3185 | |
3186 if (using_gnome && widget != NULL) | |
3187 { | |
856 | 3188 GtkWidget *parent; |
685 | 3189 BonoboDockItem *dockitem; |
3190 | |
791 | 3191 parent = gtk_widget_get_parent(widget); |
856 | 3192 if (G_TYPE_FROM_INSTANCE(parent) == BONOBO_TYPE_DOCK_ITEM) |
3193 { | |
3194 /* Only menu & toolbar are dock items. Could tabline be? | |
3195 * Seem to be only the 2 defined in GNOME */ | |
3196 widget = parent; | |
3197 dockitem = BONOBO_DOCK_ITEM(widget); | |
3198 | |
3199 if (dockitem == NULL || dockitem->is_floating) | |
3200 return 0; | |
3201 item_orientation = bonobo_dock_item_get_orientation(dockitem); | |
3202 } | |
685 | 3203 } |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3204 # else |
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3205 # 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
|
3206 # endif |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3207 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3208 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3209 if (widget != NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3210 && item_orientation == orientation |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3211 && gtk_widget_get_realized(widget) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3212 && gtk_widget_get_visible(widget)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3213 # else |
685 | 3214 if (widget != NULL |
3215 && item_orientation == orientation | |
3216 && GTK_WIDGET_REALIZED(widget) | |
3217 && GTK_WIDGET_VISIBLE(widget)) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3218 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3219 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3220 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3221 GtkAllocation allocation; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3222 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3223 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
|
3224 return allocation.height; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3225 # else |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3226 # ifdef FEAT_GUI_GNOME |
685 | 3227 if (orientation == GTK_ORIENTATION_HORIZONTAL) |
3228 return widget->allocation.height; | |
3229 else | |
3230 return widget->allocation.width; | |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3231 # else |
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3232 return widget->allocation.height; |
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3233 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3234 # endif |
685 | 3235 } |
3236 return 0; | |
3237 } | |
3238 #endif | |
3239 | |
3240 static int | |
3241 get_menu_tool_width(void) | |
3242 { | |
3243 int width = 0; | |
3244 | |
3245 #ifdef FEAT_GUI_GNOME /* these are never vertical without GNOME */ | |
3246 # ifdef FEAT_MENU | |
3247 width += get_item_dimensions(gui.menubar, GTK_ORIENTATION_VERTICAL); | |
3248 # endif | |
3249 # ifdef FEAT_TOOLBAR | |
3250 width += get_item_dimensions(gui.toolbar, GTK_ORIENTATION_VERTICAL); | |
3251 # endif | |
3252 # ifdef FEAT_GUI_TABLINE | |
782 | 3253 if (gui.tabline != NULL) |
3254 width += get_item_dimensions(gui.tabline, GTK_ORIENTATION_VERTICAL); | |
685 | 3255 # endif |
3256 #endif | |
3257 | |
3258 return width; | |
3259 } | |
3260 | |
3261 static int | |
3262 get_menu_tool_height(void) | |
3263 { | |
3264 int height = 0; | |
3265 | |
3266 #ifdef FEAT_MENU | |
3267 height += get_item_dimensions(gui.menubar, GTK_ORIENTATION_HORIZONTAL); | |
3268 #endif | |
3269 #ifdef FEAT_TOOLBAR | |
3270 height += get_item_dimensions(gui.toolbar, GTK_ORIENTATION_HORIZONTAL); | |
3271 #endif | |
3272 #ifdef FEAT_GUI_TABLINE | |
782 | 3273 if (gui.tabline != NULL) |
3274 height += get_item_dimensions(gui.tabline, GTK_ORIENTATION_HORIZONTAL); | |
685 | 3275 #endif |
3276 | |
3277 return height; | |
3278 } | |
3279 | |
791 | 3280 /* This controls whether we can set the real window hints at |
3281 * start-up when in a GtkPlug. | |
3282 * 0 = normal processing (default) | |
3283 * 1 = init. hints set, no-one's tried to reset since last check | |
3284 * 2 = init. hints set, attempt made to change hints | |
3285 */ | |
3286 static int init_window_hints_state = 0; | |
3287 | |
685 | 3288 static void |
791 | 3289 update_window_manager_hints(int force_width, int force_height) |
685 | 3290 { |
3291 static int old_width = 0; | |
3292 static int old_height = 0; | |
791 | 3293 static int old_min_width = 0; |
3294 static int old_min_height = 0; | |
685 | 3295 static int old_char_width = 0; |
3296 static int old_char_height = 0; | |
3297 | |
3298 int width; | |
3299 int height; | |
791 | 3300 int min_width; |
3301 int min_height; | |
3302 | |
3303 /* At start-up, don't try to set the hints until the initial | |
3304 * values have been used (those that dictate our initial size) | |
1884 | 3305 * Let forced (i.e., correct) values through always. |
791 | 3306 */ |
3307 if (!(force_width && force_height) && init_window_hints_state > 0) | |
3308 { | |
856 | 3309 /* Don't do it! */ |
3310 init_window_hints_state = 2; | |
3311 return; | |
791 | 3312 } |
685 | 3313 |
3314 /* This also needs to be done when the main window isn't there yet, | |
3315 * otherwise the hints don't work. */ | |
3316 width = gui_get_base_width(); | |
3317 height = gui_get_base_height(); | |
3318 # ifdef FEAT_MENU | |
3319 height += tabline_height() * gui.char_height; | |
3320 # endif | |
3321 width += get_menu_tool_width(); | |
3322 height += get_menu_tool_height(); | |
3323 | |
791 | 3324 /* GtkSockets use GtkPlug's [gui,mainwin] min-size hints to determine |
1226 | 3325 * their actual widget size. When we set our size ourselves (e.g., |
791 | 3326 * 'set columns=' or init. -geom) we briefly set the min. to the size |
3327 * we wish to be instead of the legitimate minimum so that we actually | |
3328 * resize correctly. | |
3329 */ | |
3330 if (force_width && force_height) | |
3331 { | |
856 | 3332 min_width = force_width; |
3333 min_height = force_height; | |
791 | 3334 } |
3335 else | |
3336 { | |
856 | 3337 min_width = width + MIN_COLUMNS * gui.char_width; |
3338 min_height = height + MIN_LINES * gui.char_height; | |
791 | 3339 } |
3340 | |
685 | 3341 /* Avoid an expose event when the size didn't change. */ |
3342 if (width != old_width | |
3343 || height != old_height | |
856 | 3344 || min_width != old_min_width |
791 | 3345 || min_height != old_min_height |
685 | 3346 || gui.char_width != old_char_width |
3347 || gui.char_height != old_char_height) | |
3348 { | |
3349 GdkGeometry geometry; | |
3350 GdkWindowHints geometry_mask; | |
3351 | |
3352 geometry.width_inc = gui.char_width; | |
3353 geometry.height_inc = gui.char_height; | |
3354 geometry.base_width = width; | |
3355 geometry.base_height = height; | |
856 | 3356 geometry.min_width = min_width; |
3357 geometry.min_height = min_height; | |
685 | 3358 geometry_mask = GDK_HINT_BASE_SIZE|GDK_HINT_RESIZE_INC |
3359 |GDK_HINT_MIN_SIZE; | |
3360 /* Using gui.formwin as geometry widget doesn't work as expected | |
3361 * with GTK+ 2 -- dunno why. Presumably all the resizing hacks | |
3362 * in Vim confuse GTK+. */ | |
3363 gtk_window_set_geometry_hints(GTK_WINDOW(gui.mainwin), gui.mainwin, | |
3364 &geometry, geometry_mask); | |
856 | 3365 old_width = width; |
3366 old_height = height; | |
3367 old_min_width = min_width; | |
3368 old_min_height = min_height; | |
3369 old_char_width = gui.char_width; | |
3370 old_char_height = gui.char_height; | |
685 | 3371 } |
3372 } | |
3373 | |
7 | 3374 #ifdef FEAT_TOOLBAR |
3375 | |
3376 /* | |
3377 * This extra effort wouldn't be necessary if we only used stock icons in the | |
3378 * toolbar, as we do for all builtin icons. But user-defined toolbar icons | |
3379 * shouldn't be treated differently, thus we do need this. | |
3380 */ | |
3381 static void | |
3382 icon_size_changed_foreach(GtkWidget *widget, gpointer user_data) | |
3383 { | |
3384 if (GTK_IS_IMAGE(widget)) | |
3385 { | |
3386 GtkImage *image = (GtkImage *)widget; | |
3387 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3388 # 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
|
3389 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
|
3390 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3391 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
|
3392 const gchar *icon_name; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3393 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3394 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
|
3395 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3396 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
|
3397 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3398 # else |
7 | 3399 /* User-defined icons are stored in a GtkIconSet */ |
3400 if (gtk_image_get_storage_type(image) == GTK_IMAGE_ICON_SET) | |
3401 { | |
3402 GtkIconSet *icon_set; | |
3403 GtkIconSize icon_size; | |
3404 | |
3405 gtk_image_get_icon_set(image, &icon_set, &icon_size); | |
3406 icon_size = (GtkIconSize)(long)user_data; | |
3407 | |
3408 gtk_icon_set_ref(icon_set); | |
3409 gtk_image_set_from_icon_set(image, icon_set, icon_size); | |
3410 gtk_icon_set_unref(icon_set); | |
3411 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3412 # endif |
7 | 3413 } |
3414 else if (GTK_IS_CONTAINER(widget)) | |
3415 { | |
3416 gtk_container_foreach((GtkContainer *)widget, | |
3417 &icon_size_changed_foreach, | |
3418 user_data); | |
3419 } | |
3420 } | |
3421 | |
3422 static void | |
3423 set_toolbar_style(GtkToolbar *toolbar) | |
3424 { | |
3425 GtkToolbarStyle style; | |
3426 GtkIconSize size; | |
3427 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
|
3428 |
7 | 3429 if ((toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS | TOOLBAR_HORIZ)) |
3430 == (TOOLBAR_TEXT | TOOLBAR_ICONS | TOOLBAR_HORIZ)) | |
3431 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
|
3432 else if ((toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS)) |
7 | 3433 == (TOOLBAR_TEXT | TOOLBAR_ICONS)) |
3434 style = GTK_TOOLBAR_BOTH; | |
3435 else if (toolbar_flags & TOOLBAR_TEXT) | |
3436 style = GTK_TOOLBAR_TEXT; | |
3437 else | |
3438 style = GTK_TOOLBAR_ICONS; | |
3439 | |
3440 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
|
3441 # if !GTK_CHECK_VERSION(3,0,0) |
7 | 3442 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
|
3443 # endif |
7 | 3444 |
3445 switch (tbis_flags) | |
3446 { | |
3447 case TBIS_TINY: size = GTK_ICON_SIZE_MENU; break; | |
3448 case TBIS_SMALL: size = GTK_ICON_SIZE_SMALL_TOOLBAR; break; | |
3449 case TBIS_MEDIUM: size = GTK_ICON_SIZE_BUTTON; break; | |
3450 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
|
3451 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
|
3452 case TBIS_GIANT: size = GTK_ICON_SIZE_DIALOG; break; |
7 | 3453 default: size = GTK_ICON_SIZE_INVALID; break; |
3454 } | |
3455 oldsize = gtk_toolbar_get_icon_size(toolbar); | |
3456 | |
3457 if (size == GTK_ICON_SIZE_INVALID) | |
3458 { | |
3459 /* Let global user preferences decide the icon size. */ | |
3460 gtk_toolbar_unset_icon_size(toolbar); | |
3461 size = gtk_toolbar_get_icon_size(toolbar); | |
3462 } | |
3463 if (size != oldsize) | |
3464 { | |
3465 gtk_container_foreach(GTK_CONTAINER(toolbar), | |
3466 &icon_size_changed_foreach, | |
3467 GINT_TO_POINTER((int)size)); | |
3468 } | |
3469 gtk_toolbar_set_icon_size(toolbar, size); | |
3470 } | |
3471 | |
3472 #endif /* FEAT_TOOLBAR */ | |
3473 | |
685 | 3474 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
3475 static int ignore_tabline_evt = FALSE; | |
689 | 3476 static GtkWidget *tabline_menu; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3477 # if !GTK_CHECK_VERSION(3,0,0) |
846 | 3478 static GtkTooltips *tabline_tooltip; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3479 # endif |
689 | 3480 static int clicked_page; /* page clicked in tab line */ |
3481 | |
3482 /* | |
3483 * Handle selecting an item in the tab line popup menu. | |
3484 */ | |
3485 static void | |
1884 | 3486 tabline_menu_handler(GtkMenuItem *item UNUSED, gpointer user_data) |
689 | 3487 { |
3488 /* Add the string cmd into input buffer */ | |
824 | 3489 send_tabline_menu_event(clicked_page, (int)(long)user_data); |
689 | 3490 } |
3491 | |
851 | 3492 static void |
3493 add_tabline_menu_item(GtkWidget *menu, char_u *text, int resp) | |
3494 { | |
3495 GtkWidget *item; | |
3496 char_u *utf_text; | |
3497 | |
3498 utf_text = CONVERT_TO_UTF8(text); | |
3499 item = gtk_menu_item_new_with_label((const char *)utf_text); | |
3500 gtk_widget_show(item); | |
3501 CONVERT_TO_UTF8_FREE(utf_text); | |
3502 | |
3503 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
|
3504 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3505 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
|
3506 G_CALLBACK(tabline_menu_handler), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3507 GINT_TO_POINTER(resp)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3508 # else |
851 | 3509 gtk_signal_connect(GTK_OBJECT(item), "activate", |
3510 GTK_SIGNAL_FUNC(tabline_menu_handler), | |
1660 | 3511 (gpointer)(long)resp); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3512 # endif |
851 | 3513 } |
3514 | |
689 | 3515 /* |
3516 * Create a menu for the tab line. | |
3517 */ | |
3518 static GtkWidget * | |
3519 create_tabline_menu(void) | |
3520 { | |
851 | 3521 GtkWidget *menu; |
689 | 3522 |
3523 menu = gtk_menu_new(); | |
6819 | 3524 if (first_tabpage->tp_next != NULL) |
3525 add_tabline_menu_item(menu, (char_u *)_("Close tab"), | |
3526 TABLINE_MENU_CLOSE); | |
851 | 3527 add_tabline_menu_item(menu, (char_u *)_("New tab"), TABLINE_MENU_NEW); |
3528 add_tabline_menu_item(menu, (char_u *)_("Open Tab..."), TABLINE_MENU_OPEN); | |
689 | 3529 |
3530 return menu; | |
3531 } | |
3532 | |
3533 static gboolean | |
3534 on_tabline_menu(GtkWidget *widget, GdkEvent *event) | |
3535 { | |
3536 /* Was this button press event ? */ | |
3537 if (event->type == GDK_BUTTON_PRESS) | |
3538 { | |
3539 GdkEventButton *bevent = (GdkEventButton *)event; | |
3540 int x = bevent->x; | |
851 | 3541 int y = bevent->y; |
3542 GtkWidget *tabwidget; | |
3543 GdkWindow *tabwin; | |
689 | 3544 |
844 | 3545 /* When ignoring events return TRUE so that the selected page doesn't |
3546 * change. */ | |
3547 if (hold_gui_events | |
3548 # ifdef FEAT_CMDWIN | |
3549 || cmdwin_type != 0 | |
3550 # endif | |
3551 ) | |
3552 return TRUE; | |
3553 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3554 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3555 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
|
3556 # else |
851 | 3557 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
|
3558 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3559 |
851 | 3560 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
|
3561 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3562 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
|
3563 "tab_num")); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3564 # else |
851 | 3565 clicked_page = (int)(long)gtk_object_get_user_data( |
3566 GTK_OBJECT(tabwidget)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3567 # endif |
689 | 3568 |
3569 /* If the event was generated for 3rd button popup the menu. */ | |
3570 if (bevent->button == 3) | |
3571 { | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3572 # 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
|
3573 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
|
3574 # else |
689 | 3575 gtk_menu_popup(GTK_MENU(widget), NULL, NULL, NULL, NULL, |
3576 bevent->button, bevent->time); | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3577 # endif |
689 | 3578 /* We handled the event. */ |
3579 return TRUE; | |
3580 } | |
868 | 3581 else if (bevent->button == 1) |
693 | 3582 { |
868 | 3583 if (clicked_page == 0) |
3584 { | |
1394 | 3585 /* Click after all tabs moves to next tab page. When "x" is |
3586 * 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
|
3587 send_tabline_event(x < 50 ? -1 : 0); |
868 | 3588 } |
693 | 3589 } |
689 | 3590 } |
844 | 3591 |
689 | 3592 /* We didn't handle the event. */ |
3593 return FALSE; | |
3594 } | |
685 | 3595 |
3596 /* | |
3597 * Handle selecting one of the tabs. | |
3598 */ | |
3599 static void | |
3600 on_select_tab( | |
1884 | 3601 GtkNotebook *notebook UNUSED, |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3602 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3603 gpointer *page UNUSED, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3604 # else |
1884 | 3605 GtkNotebookPage *page UNUSED, |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3606 # endif |
944 | 3607 gint idx, |
1884 | 3608 gpointer data UNUSED) |
685 | 3609 { |
3610 if (!ignore_tabline_evt) | |
693 | 3611 { |
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
|
3612 send_tabline_event(idx + 1); |
693 | 3613 } |
685 | 3614 } |
3615 | |
3616 /* | |
3617 * Show or hide the tabline. | |
3618 */ | |
3619 void | |
3620 gui_mch_show_tabline(int showit) | |
3621 { | |
3622 if (gui.tabline == NULL) | |
3623 return; | |
3624 | |
3625 if (!showit != !gtk_notebook_get_show_tabs(GTK_NOTEBOOK(gui.tabline))) | |
3626 { | |
708 | 3627 /* Note: this may cause a resize event */ |
685 | 3628 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gui.tabline), showit); |
791 | 3629 update_window_manager_hints(0, 0); |
868 | 3630 if (showit) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3631 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3632 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
|
3633 # else |
868 | 3634 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
|
3635 # endif |
868 | 3636 } |
3637 | |
3638 gui_mch_update(); | |
685 | 3639 } |
3640 | |
3641 /* | |
708 | 3642 * Return TRUE when tabline is displayed. |
3643 */ | |
3644 int | |
3645 gui_mch_showing_tabline(void) | |
3646 { | |
3647 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
|
3648 && gtk_notebook_get_show_tabs(GTK_NOTEBOOK(gui.tabline)); |
708 | 3649 } |
3650 | |
3651 /* | |
685 | 3652 * Update the labels of the tabline. |
3653 */ | |
3654 void | |
3655 gui_mch_update_tabline(void) | |
3656 { | |
3657 GtkWidget *page; | |
846 | 3658 GtkWidget *event_box; |
685 | 3659 GtkWidget *label; |
3660 tabpage_T *tp; | |
3661 int nr = 0; | |
851 | 3662 int tab_num; |
685 | 3663 int curtabidx = 0; |
836 | 3664 char_u *labeltext; |
685 | 3665 |
3666 if (gui.tabline == NULL) | |
3667 return; | |
3668 | |
3669 ignore_tabline_evt = TRUE; | |
3670 | |
3671 /* Add a label for each tab page. They all contain the same text area. */ | |
3672 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr) | |
3673 { | |
3674 if (tp == curtab) | |
3675 curtabidx = nr; | |
3676 | |
851 | 3677 tab_num = nr + 1; |
3678 | |
685 | 3679 page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr); |
3680 if (page == NULL) | |
3681 { | |
3682 /* Add notebook page */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3683 # 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
|
3684 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
|
3685 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
|
3686 # else |
685 | 3687 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
|
3688 # endif |
685 | 3689 gtk_widget_show(page); |
846 | 3690 event_box = gtk_event_box_new(); |
3691 gtk_widget_show(event_box); | |
685 | 3692 label = gtk_label_new("-Empty-"); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3693 # if !GTK_CHECK_VERSION(3,14,0) |
851 | 3694 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
|
3695 # endif |
846 | 3696 gtk_container_add(GTK_CONTAINER(event_box), label); |
685 | 3697 gtk_widget_show(label); |
3698 gtk_notebook_insert_page(GTK_NOTEBOOK(gui.tabline), | |
3699 page, | |
846 | 3700 event_box, |
685 | 3701 nr++); |
3702 } | |
3703 | |
846 | 3704 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
|
3705 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3706 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
|
3707 GINT_TO_POINTER(tab_num)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3708 # else |
1660 | 3709 gtk_object_set_user_data(GTK_OBJECT(event_box), |
3710 (gpointer)(long)tab_num); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3711 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3712 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3713 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
|
3714 # else |
846 | 3715 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
|
3716 # endif |
839 | 3717 get_tabline_label(tp, FALSE); |
836 | 3718 labeltext = CONVERT_TO_UTF8(NameBuff); |
846 | 3719 gtk_label_set_text(GTK_LABEL(label), (const char *)labeltext); |
836 | 3720 CONVERT_TO_UTF8_FREE(labeltext); |
846 | 3721 |
3722 get_tabline_label(tp, TRUE); | |
3723 labeltext = CONVERT_TO_UTF8(NameBuff); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3724 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3725 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
|
3726 # else |
846 | 3727 gtk_tooltips_set_tip(GTK_TOOLTIPS(tabline_tooltip), event_box, |
3728 (const char *)labeltext, NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3729 # endif |
846 | 3730 CONVERT_TO_UTF8_FREE(labeltext); |
685 | 3731 } |
3732 | |
3733 /* Remove any old labels. */ | |
3734 while (gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr) != NULL) | |
3735 gtk_notebook_remove_page(GTK_NOTEBOOK(gui.tabline), nr); | |
3736 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3737 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3738 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
|
3739 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
|
3740 # else |
685 | 3741 if (gtk_notebook_current_page(GTK_NOTEBOOK(gui.tabline)) != curtabidx) |
856 | 3742 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
|
3743 # endif |
685 | 3744 |
851 | 3745 /* Make sure everything is in place before drawing text. */ |
3746 gui_mch_update(); | |
3747 | |
685 | 3748 ignore_tabline_evt = FALSE; |
3749 } | |
3750 | |
3751 /* | |
3752 * Set the current tab to "nr". First tab is 1. | |
3753 */ | |
3754 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
3755 gui_mch_set_curtab(int nr) |
685 | 3756 { |
3757 if (gui.tabline == NULL) | |
3758 return; | |
3759 | |
3760 ignore_tabline_evt = TRUE; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3761 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3762 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
|
3763 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
|
3764 # else |
685 | 3765 if (gtk_notebook_current_page(GTK_NOTEBOOK(gui.tabline)) != nr - 1) |
856 | 3766 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
|
3767 # endif |
685 | 3768 ignore_tabline_evt = FALSE; |
3769 } | |
3770 | |
3771 #endif /* FEAT_GUI_TABLINE */ | |
3772 | |
7 | 3773 /* |
2183 | 3774 * Add selection targets for PRIMARY and CLIPBOARD selections. |
3775 */ | |
3776 void | |
3777 gui_gtk_set_selection_targets(void) | |
3778 { | |
3779 int i, j = 0; | |
3780 int n_targets = N_SELECTION_TARGETS; | |
3781 GtkTargetEntry targets[N_SELECTION_TARGETS]; | |
3782 | |
3783 for (i = 0; i < (int)N_SELECTION_TARGETS; ++i) | |
3784 { | |
3518 | 3785 /* OpenOffice tries to use TARGET_HTML and fails when we don't |
2183 | 3786 * return something, instead of trying another target. Therefore only |
3787 * offer TARGET_HTML when it works. */ | |
3788 if (!clip_html && selection_targets[i].info == TARGET_HTML) | |
3789 n_targets--; | |
3790 else | |
3791 targets[j++] = selection_targets[i]; | |
3792 } | |
3793 | |
3794 gtk_selection_clear_targets(gui.drawarea, (GdkAtom)GDK_SELECTION_PRIMARY); | |
3795 gtk_selection_clear_targets(gui.drawarea, (GdkAtom)clip_plus.gtk_sel_atom); | |
3796 gtk_selection_add_targets(gui.drawarea, | |
3797 (GdkAtom)GDK_SELECTION_PRIMARY, | |
3798 targets, n_targets); | |
3799 gtk_selection_add_targets(gui.drawarea, | |
3800 (GdkAtom)clip_plus.gtk_sel_atom, | |
3801 targets, n_targets); | |
3802 } | |
3803 | |
3804 /* | |
3805 * Set up for receiving DND items. | |
3806 */ | |
3807 void | |
3808 gui_gtk_set_dnd_targets(void) | |
3809 { | |
3810 int i, j = 0; | |
3811 int n_targets = N_DND_TARGETS; | |
3812 GtkTargetEntry targets[N_DND_TARGETS]; | |
3813 | |
3814 for (i = 0; i < (int)N_DND_TARGETS; ++i) | |
3815 { | |
3154 | 3816 if (!clip_html && dnd_targets[i].info == TARGET_HTML) |
2183 | 3817 n_targets--; |
3818 else | |
3819 targets[j++] = dnd_targets[i]; | |
3820 } | |
3821 | |
3822 gtk_drag_dest_unset(gui.drawarea); | |
3823 gtk_drag_dest_set(gui.drawarea, | |
3824 GTK_DEST_DEFAULT_ALL, | |
3825 targets, n_targets, | |
2718 | 3826 GDK_ACTION_COPY | GDK_ACTION_MOVE); |
2183 | 3827 } |
3828 | |
3829 /* | |
7 | 3830 * Initialize the GUI. Create all the windows, set up all the callbacks etc. |
3831 * Returns OK for success, FAIL when the GUI can't be started. | |
3832 */ | |
3833 int | |
3834 gui_mch_init(void) | |
3835 { | |
3836 GtkWidget *vbox; | |
3837 | |
3838 #ifdef FEAT_GUI_GNOME | |
3839 /* Initialize the GNOME libraries. gnome_program_init()/gnome_init() | |
3840 * exits on failure, but that's a non-issue because we already called | |
3841 * gtk_init_check() in gui_mch_init_check(). */ | |
3842 if (using_gnome) | |
4045 | 3843 { |
7 | 3844 gnome_program_init(VIMPACKAGE, VIM_VERSION_SHORT, |
3845 LIBGNOMEUI_MODULE, gui_argc, gui_argv, NULL); | |
4045 | 3846 # if defined(FEAT_FLOAT) && defined(LC_NUMERIC) |
5854 | 3847 { |
3848 char *p = setlocale(LC_NUMERIC, NULL); | |
3849 | |
3850 /* Make sure strtod() uses a decimal point, not a comma. Gnome | |
3851 * init may change it. */ | |
3852 if (p == NULL || strcmp(p, "C") != 0) | |
3853 setlocale(LC_NUMERIC, "C"); | |
3854 } | |
4045 | 3855 # endif |
3856 } | |
7 | 3857 #endif |
3858 vim_free(gui_argv); | |
3859 gui_argv = NULL; | |
3860 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3861 #if GLIB_CHECK_VERSION(2,1,3) |
7 | 3862 /* Set the human-readable application name */ |
3863 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
|
3864 #endif |
7 | 3865 /* |
3866 * Force UTF-8 output no matter what the value of 'encoding' is. | |
3867 * did_set_string_option() in option.c prohibits changing 'termencoding' | |
3868 * to something else than UTF-8 if the GUI is in use. | |
3869 */ | |
3870 set_option_value((char_u *)"termencoding", 0L, (char_u *)"utf-8", 0); | |
3871 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3872 #ifdef FEAT_TOOLBAR |
7 | 3873 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
|
3874 #endif |
7 | 3875 /* FIXME: Need to install the classic icons and a gtkrc.classic file. |
3876 * 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
|
3877 #if !GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3878 # if 0 |
7 | 3879 gtk_rc_parse("gtkrc"); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3880 # endif |
7 | 3881 #endif |
3882 | |
3883 /* Initialize values */ | |
3884 gui.border_width = 2; | |
3885 gui.scrollbar_width = SB_DEFAULT_WIDTH; | |
3886 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
|
3887 #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
|
3888 gui.fgcolor = g_new(GdkRGBA, 1); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
3889 gui.bgcolor = g_new(GdkRGBA, 1); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
3890 gui.spcolor = g_new(GdkRGBA, 1); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
3891 #else |
136 | 3892 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
7 | 3893 gui.fgcolor = g_new0(GdkColor, 1); |
136 | 3894 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
7 | 3895 gui.bgcolor = g_new0(GdkColor, 1); |
207 | 3896 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
3897 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
|
3898 #endif |
7 | 3899 |
3900 /* Initialise atoms */ | |
1904 | 3901 html_atom = gdk_atom_intern("text/html", FALSE); |
7 | 3902 utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE); |
3903 | |
3904 /* Set default foreground and background colors. */ | |
3905 gui.norm_pixel = gui.def_norm_pixel; | |
3906 gui.back_pixel = gui.def_back_pixel; | |
3907 | |
3908 if (gtk_socket_id != 0) | |
3909 { | |
3910 GtkWidget *plug; | |
3911 | |
3912 /* Use GtkSocket from another app. */ | |
3913 #ifdef HAVE_GTK_MULTIHEAD | |
3914 plug = gtk_plug_new_for_display(gdk_display_get_default(), | |
3915 gtk_socket_id); | |
3916 #else | |
3917 plug = gtk_plug_new(gtk_socket_id); | |
3918 #endif | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3919 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3920 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
|
3921 #else |
7 | 3922 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
|
3923 #endif |
7 | 3924 { |
3925 gui.mainwin = plug; | |
3926 } | |
3927 else | |
3928 { | |
3929 g_warning("Connection to GTK+ socket (ID %u) failed", | |
3930 (unsigned int)gtk_socket_id); | |
3931 /* Pretend we never wanted it if it failed (get own window) */ | |
3932 gtk_socket_id = 0; | |
3933 } | |
3934 } | |
3935 | |
3936 if (gtk_socket_id == 0) | |
3937 { | |
3938 #ifdef FEAT_GUI_GNOME | |
3939 if (using_gnome) | |
3940 { | |
3941 gui.mainwin = gnome_app_new("Vim", NULL); | |
3942 # ifdef USE_XSMP | |
3943 /* Use the GNOME save-yourself functionality now. */ | |
3944 xsmp_close(); | |
3945 # endif | |
3946 } | |
3947 else | |
3948 #endif | |
3949 gui.mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
3950 } | |
3951 | |
3952 gtk_widget_set_name(gui.mainwin, "vim-main-window"); | |
3953 | |
3954 /* Create the PangoContext used for drawing all text. */ | |
3955 gui.text_context = gtk_widget_create_pango_context(gui.mainwin); | |
3956 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
|
3957 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3958 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3959 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
|
3960 #else |
7 | 3961 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
|
3962 #endif |
7 | 3963 gtk_widget_add_events(gui.mainwin, GDK_VISIBILITY_NOTIFY_MASK); |
3964 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3965 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3966 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
|
3967 G_CALLBACK(&delete_event_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3968 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3969 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
|
3970 G_CALLBACK(&mainwin_realize), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3971 #else |
7 | 3972 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "delete_event", |
3973 GTK_SIGNAL_FUNC(&delete_event_cb), NULL); | |
3974 | |
3975 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "realize", | |
3976 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
|
3977 #endif |
7 | 3978 #ifdef HAVE_GTK_MULTIHEAD |
3979 g_signal_connect(G_OBJECT(gui.mainwin), "screen_changed", | |
3980 G_CALLBACK(&mainwin_screen_changed_cb), NULL); | |
3981 #endif | |
3982 gui.accel_group = gtk_accel_group_new(); | |
3983 gtk_window_add_accel_group(GTK_WINDOW(gui.mainwin), gui.accel_group); | |
3984 | |
685 | 3985 /* 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
|
3986 #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
|
3987 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
|
3988 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
|
3989 #else |
7 | 3990 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
|
3991 #endif |
7 | 3992 |
3993 #ifdef FEAT_GUI_GNOME | |
3994 if (using_gnome) | |
3995 { | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3996 # if defined(FEAT_MENU) |
7 | 3997 /* automagically restore menubar/toolbar placement */ |
3998 gnome_app_enable_layout_config(GNOME_APP(gui.mainwin), TRUE); | |
3999 # endif | |
4000 gnome_app_set_contents(GNOME_APP(gui.mainwin), vbox); | |
4001 } | |
4002 else | |
4003 #endif | |
4004 { | |
4005 gtk_container_add(GTK_CONTAINER(gui.mainwin), vbox); | |
4006 gtk_widget_show(vbox); | |
4007 } | |
4008 | |
4009 #ifdef FEAT_MENU | |
4010 /* | |
4011 * Create the menubar and handle | |
4012 */ | |
4013 gui.menubar = gtk_menu_bar_new(); | |
4014 gtk_widget_set_name(gui.menubar, "vim-menubar"); | |
4015 | |
36 | 4016 /* Avoid that GTK takes <F10> away from us. */ |
4017 { | |
4018 GtkSettings *gtk_settings; | |
4019 | |
4020 gtk_settings = gtk_settings_get_for_screen(gdk_screen_get_default()); | |
4021 g_object_set(gtk_settings, "gtk-menu-bar-accel", NULL, NULL); | |
4022 } | |
4023 | |
4024 | |
7 | 4025 # ifdef FEAT_GUI_GNOME |
4026 if (using_gnome) | |
4027 { | |
4028 BonoboDockItem *dockitem; | |
4029 | |
4030 gnome_app_set_menus(GNOME_APP(gui.mainwin), GTK_MENU_BAR(gui.menubar)); | |
4031 dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), | |
4032 GNOME_APP_MENUBAR_NAME); | |
798 | 4033 /* We don't want the menu to float. */ |
4034 bonobo_dock_item_set_behavior(dockitem, | |
4035 bonobo_dock_item_get_behavior(dockitem) | |
4036 | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); | |
7 | 4037 gui.menubar_h = GTK_WIDGET(dockitem); |
4038 } | |
4039 else | |
4040 # endif /* FEAT_GUI_GNOME */ | |
4041 { | |
827 | 4042 /* Always show the menubar, otherwise <F10> doesn't work. It may be |
4043 * disabled in gui_init() later. */ | |
4044 gtk_widget_show(gui.menubar); | |
7 | 4045 gtk_box_pack_start(GTK_BOX(vbox), gui.menubar, FALSE, FALSE, 0); |
4046 } | |
4047 #endif /* FEAT_MENU */ | |
4048 | |
4049 #ifdef FEAT_TOOLBAR | |
4050 /* | |
4051 * Create the toolbar and handle | |
4052 */ | |
4053 /* some aesthetics on the toolbar */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4054 # ifdef USE_GTK3 |
8301
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4055 /* 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
|
4056 /* 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
|
4057 * 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
|
4058 # else |
7 | 4059 gtk_rc_parse_string( |
4060 "style \"vim-toolbar-style\" {\n" | |
4061 " GtkToolbar::button_relief = GTK_RELIEF_NONE\n" | |
4062 "}\n" | |
4063 "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
|
4064 # endif |
7 | 4065 gui.toolbar = gtk_toolbar_new(); |
4066 gtk_widget_set_name(gui.toolbar, "vim-toolbar"); | |
4067 set_toolbar_style(GTK_TOOLBAR(gui.toolbar)); | |
4068 | |
4069 # ifdef FEAT_GUI_GNOME | |
4070 if (using_gnome) | |
4071 { | |
4072 BonoboDockItem *dockitem; | |
4073 | |
4074 gnome_app_set_toolbar(GNOME_APP(gui.mainwin), GTK_TOOLBAR(gui.toolbar)); | |
4075 dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), | |
4076 GNOME_APP_TOOLBAR_NAME); | |
4077 gui.toolbar_h = GTK_WIDGET(dockitem); | |
795 | 4078 /* When the toolbar is floating it gets stuck. So long as that isn't |
798 | 4079 * fixed let's disallow floating. */ |
795 | 4080 bonobo_dock_item_set_behavior(dockitem, |
798 | 4081 bonobo_dock_item_get_behavior(dockitem) |
4082 | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); | |
7 | 4083 gtk_container_set_border_width(GTK_CONTAINER(gui.toolbar), 0); |
4084 } | |
4085 else | |
4086 # endif /* FEAT_GUI_GNOME */ | |
4087 { | |
4088 if (vim_strchr(p_go, GO_TOOLBAR) != NULL | |
4089 && (toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS))) | |
4090 gtk_widget_show(gui.toolbar); | |
4091 gtk_box_pack_start(GTK_BOX(vbox), gui.toolbar, FALSE, FALSE, 0); | |
4092 } | |
4093 #endif /* FEAT_TOOLBAR */ | |
4094 | |
685 | 4095 #ifdef FEAT_GUI_TABLINE |
782 | 4096 /* |
4097 * Use a Notebook for the tab pages labels. The labels are hidden by | |
4098 * default. | |
4099 */ | |
791 | 4100 gui.tabline = gtk_notebook_new(); |
4101 gtk_widget_show(gui.tabline); | |
4102 gtk_box_pack_start(GTK_BOX(vbox), gui.tabline, FALSE, FALSE, 0); | |
4103 gtk_notebook_set_show_border(GTK_NOTEBOOK(gui.tabline), FALSE); | |
4104 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gui.tabline), FALSE); | |
841 | 4105 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
|
4106 # if !GTK_CHECK_VERSION(3,0,0) |
868 | 4107 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
|
4108 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4109 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4110 # if !GTK_CHECK_VERSION(3,0,0) |
846 | 4111 tabline_tooltip = gtk_tooltips_new(); |
4112 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
|
4113 # endif |
846 | 4114 |
4115 { | |
4116 GtkWidget *page, *label, *event_box; | |
791 | 4117 |
856 | 4118 /* Add the first tab. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4119 # 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
|
4120 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
|
4121 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
|
4122 # else |
846 | 4123 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
|
4124 # endif |
846 | 4125 gtk_widget_show(page); |
4126 gtk_container_add(GTK_CONTAINER(gui.tabline), page); | |
4127 label = gtk_label_new("-Empty-"); | |
4128 gtk_widget_show(label); | |
4129 event_box = gtk_event_box_new(); | |
4130 gtk_widget_show(event_box); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4131 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4132 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
|
4133 # else |
1660 | 4134 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
|
4135 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4136 # if !GTK_CHECK_VERSION(3,14,0) |
851 | 4137 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
|
4138 # endif |
846 | 4139 gtk_container_add(GTK_CONTAINER(event_box), label); |
4140 gtk_notebook_set_tab_label(GTK_NOTEBOOK(gui.tabline), page, event_box); | |
791 | 4141 } |
865 | 4142 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4143 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4144 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
|
4145 G_CALLBACK(on_select_tab), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4146 # else |
791 | 4147 gtk_signal_connect(GTK_OBJECT(gui.tabline), "switch_page", |
856 | 4148 GTK_SIGNAL_FUNC(on_select_tab), NULL); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4149 # endif |
791 | 4150 |
4151 /* Create a popup menu for the tab line and connect it. */ | |
4152 tabline_menu = create_tabline_menu(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4153 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4154 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
|
4155 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
|
4156 # else |
791 | 4157 gtk_signal_connect_object(GTK_OBJECT(gui.tabline), "button_press_event", |
856 | 4158 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
|
4159 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4160 #endif /* FEAT_GUI_TABLINE */ |
685 | 4161 |
7 | 4162 gui.formwin = gtk_form_new(); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4163 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4164 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
|
4165 #else |
7 | 4166 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
|
4167 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4168 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 4169 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
|
4170 #endif |
7 | 4171 |
4172 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
|
4173 #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
|
4174 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
|
4175 #endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4176 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4177 gui.surface = NULL; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4178 gui.by_signal = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4179 #endif |
7 | 4180 |
4181 /* Determine which events we will filter. */ | |
4182 gtk_widget_set_events(gui.drawarea, | |
4183 GDK_EXPOSURE_MASK | | |
4184 GDK_ENTER_NOTIFY_MASK | | |
4185 GDK_LEAVE_NOTIFY_MASK | | |
4186 GDK_BUTTON_PRESS_MASK | | |
4187 GDK_BUTTON_RELEASE_MASK | | |
4188 GDK_SCROLL_MASK | | |
4189 GDK_KEY_PRESS_MASK | | |
4190 GDK_KEY_RELEASE_MASK | | |
4191 GDK_POINTER_MOTION_MASK | | |
4192 GDK_POINTER_MOTION_HINT_MASK); | |
4193 | |
4194 gtk_widget_show(gui.drawarea); | |
4195 gtk_form_put(GTK_FORM(gui.formwin), gui.drawarea, 0, 0); | |
4196 gtk_widget_show(gui.formwin); | |
4197 gtk_box_pack_start(GTK_BOX(vbox), gui.formwin, TRUE, TRUE, 0); | |
4198 | |
4199 /* For GtkSockets, key-presses must go to the focus widget (drawarea) | |
4200 * and not the window. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4201 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4202 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
|
4203 : G_OBJECT(gui.drawarea), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4204 "key-press-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4205 G_CALLBACK(key_press_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4206 #else |
7 | 4207 gtk_signal_connect((gtk_socket_id == 0) ? GTK_OBJECT(gui.mainwin) |
4208 : GTK_OBJECT(gui.drawarea), | |
4209 "key_press_event", | |
4210 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
|
4211 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4212 #if defined(FEAT_XIM) || GTK_CHECK_VERSION(3,0,0) |
7 | 4213 /* Also forward key release events for the benefit of GTK+ 2 input |
4214 * modules. Try CTRL-SHIFT-xdigits to enter a Unicode code point. */ | |
4215 g_signal_connect((gtk_socket_id == 0) ? G_OBJECT(gui.mainwin) | |
4216 : G_OBJECT(gui.drawarea), | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4217 "key-release-event", |
7 | 4218 G_CALLBACK(&key_release_event), NULL); |
4219 #endif | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4220 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4221 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
|
4222 G_CALLBACK(drawarea_realize_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4223 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
|
4224 G_CALLBACK(drawarea_unrealize_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4225 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
|
4226 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
|
4227 # 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
|
4228 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
|
4229 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
|
4230 # else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4231 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
|
4232 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
|
4233 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4234 #else |
7 | 4235 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "realize", |
4236 GTK_SIGNAL_FUNC(drawarea_realize_cb), NULL); | |
4237 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "unrealize", | |
4238 GTK_SIGNAL_FUNC(drawarea_unrealize_cb), NULL); | |
4239 | |
4240 gtk_signal_connect_after(GTK_OBJECT(gui.drawarea), "style_set", | |
4241 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
|
4242 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4243 |
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) |
7 | 4245 gui.visibility = GDK_VISIBILITY_UNOBSCURED; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4246 #endif |
7 | 4247 |
4248 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
4249 wm_protocols_atom = gdk_atom_intern("WM_PROTOCOLS", FALSE); | |
4250 save_yourself_atom = gdk_atom_intern("WM_SAVE_YOURSELF", FALSE); | |
4251 #endif | |
4252 | |
4253 if (gtk_socket_id != 0) | |
1884 | 4254 /* 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
|
4255 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4256 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
|
4257 #else |
7 | 4258 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
|
4259 #endif |
7 | 4260 |
4261 /* | |
4262 * Set clipboard specific atoms | |
4263 */ | |
4264 vim_atom = gdk_atom_intern(VIM_ATOM_NAME, FALSE); | |
4265 vimenc_atom = gdk_atom_intern(VIMENC_ATOM_NAME, FALSE); | |
4266 clip_star.gtk_sel_atom = GDK_SELECTION_PRIMARY; | |
4267 clip_plus.gtk_sel_atom = gdk_atom_intern("CLIPBOARD", FALSE); | |
4268 | |
4269 /* | |
4270 * Start out by adding the configured border width into the border offset. | |
4271 */ | |
4272 gui.border_offset = gui.border_width; | |
4273 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4274 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4275 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
|
4276 G_CALLBACK(draw_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4277 #else |
7 | 4278 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "visibility_notify_event", |
4279 GTK_SIGNAL_FUNC(visibility_event), NULL); | |
4280 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "expose_event", | |
4281 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
|
4282 #endif |
7 | 4283 |
4284 /* | |
4285 * Only install these enter/leave callbacks when 'p' in 'guioptions'. | |
4286 * Only needed for some window managers. | |
4287 */ | |
4288 if (vim_strchr(p_go, GO_POINTER) != NULL) | |
4289 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4290 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4291 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
|
4292 G_CALLBACK(leave_notify_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4293 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
|
4294 G_CALLBACK(enter_notify_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4295 #else |
7 | 4296 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "leave_notify_event", |
4297 GTK_SIGNAL_FUNC(leave_notify_event), NULL); | |
4298 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "enter_notify_event", | |
4299 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
|
4300 #endif |
7 | 4301 } |
4302 | |
791 | 4303 /* Real windows can get focus ... GtkPlug, being a mere container can't, |
4304 * only its widgets. Arguably, this could be common code and we not use | |
4305 * the window focus at all, but let's be safe. | |
4306 */ | |
4307 if (gtk_socket_id == 0) | |
4308 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4309 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4310 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
|
4311 G_CALLBACK(focus_out_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4312 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
|
4313 G_CALLBACK(focus_in_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4314 #else |
856 | 4315 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "focus_out_event", |
4316 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
4317 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "focus_in_event", | |
4318 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
|
4319 #endif |
791 | 4320 } |
4321 else | |
4322 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4323 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4324 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
|
4325 G_CALLBACK(focus_out_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4326 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
|
4327 G_CALLBACK(focus_in_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4328 #else |
856 | 4329 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "focus_out_event", |
4330 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
4331 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "focus_in_event", | |
4332 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
|
4333 #endif |
791 | 4334 #ifdef FEAT_GUI_TABLINE |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4335 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4336 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
|
4337 G_CALLBACK(focus_out_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4338 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
|
4339 G_CALLBACK(focus_in_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4340 # else |
856 | 4341 gtk_signal_connect(GTK_OBJECT(gui.tabline), "focus_out_event", |
4342 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
4343 gtk_signal_connect(GTK_OBJECT(gui.tabline), "focus_in_event", | |
4344 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
|
4345 # endif |
791 | 4346 #endif /* FEAT_GUI_TABLINE */ |
4347 } | |
7 | 4348 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4349 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4350 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
|
4351 G_CALLBACK(motion_notify_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4352 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
|
4353 G_CALLBACK(button_press_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4354 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
|
4355 G_CALLBACK(button_release_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4356 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
|
4357 G_CALLBACK(&scroll_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4358 #else |
7 | 4359 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "motion_notify_event", |
4360 GTK_SIGNAL_FUNC(motion_notify_event), NULL); | |
4361 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "button_press_event", | |
4362 GTK_SIGNAL_FUNC(button_press_event), NULL); | |
4363 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "button_release_event", | |
4364 GTK_SIGNAL_FUNC(button_release_event), NULL); | |
4365 g_signal_connect(G_OBJECT(gui.drawarea), "scroll_event", | |
4366 G_CALLBACK(&scroll_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4367 #endif |
7 | 4368 |
4369 /* | |
4370 * Add selection handler functions. | |
4371 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4372 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4373 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
|
4374 G_CALLBACK(selection_clear_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4375 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
|
4376 G_CALLBACK(selection_received_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4377 #else |
7 | 4378 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_clear_event", |
4379 GTK_SIGNAL_FUNC(selection_clear_event), NULL); | |
4380 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_received", | |
4381 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
|
4382 #endif |
7 | 4383 |
2183 | 4384 gui_gtk_set_selection_targets(); |
7 | 4385 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4386 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4387 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
|
4388 G_CALLBACK(selection_get_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4389 #else |
7 | 4390 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_get", |
4391 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
|
4392 #endif |
7 | 4393 |
4394 /* Pretend we don't have input focus, we will get an event if we do. */ | |
4395 gui.in_focus = FALSE; | |
4396 | |
4397 return OK; | |
4398 } | |
4399 | |
4400 #if (defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) || defined(PROTO) | |
4401 /* | |
4402 * This is called from gui_start() after a fork() has been done. | |
4403 * We have to tell the session manager our new PID. | |
4404 */ | |
4405 void | |
4406 gui_mch_forked(void) | |
4407 { | |
4408 if (using_gnome) | |
4409 { | |
4410 GnomeClient *client; | |
4411 | |
4412 client = gnome_master_client(); | |
4413 | |
4414 if (client != NULL) | |
4415 gnome_client_set_process_id(client, getpid()); | |
4416 } | |
4417 } | |
4418 #endif /* FEAT_GUI_GNOME && FEAT_SESSION */ | |
4419 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4420 #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
|
4421 static GdkRGBA |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4422 color_to_rgba(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 GdkRGBA rgba; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4425 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
|
4426 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
|
4427 rgba.blue = ((color & 0xff)) / 255.0; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4428 rgba.alpha = 1.0; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4429 return rgba; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4430 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4431 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4432 static void |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4433 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
|
4434 { |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4435 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
|
4436 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
|
4437 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4438 #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
|
4439 |
7 | 4440 /* |
4441 * Called when the foreground or background color has been changed. | |
4442 * This used to change the graphics contexts directly but we are | |
4443 * currently manipulating them where desired. | |
4444 */ | |
4445 void | |
4446 gui_mch_new_colors(void) | |
4447 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4448 #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
|
4449 # 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
|
4450 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
|
4451 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4452 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4453 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
|
4454 #else |
7 | 4455 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
|
4456 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4457 { |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4458 #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
|
4459 GtkStyleContext * const context |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4460 = 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
|
4461 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
|
4462 gchar * const css = g_strdup_printf( |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4463 "widget#vim-gui-drawarea {\n" |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4464 " background-color: #%.2lx%.2lx%.2lx;\n" |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4465 "}\n", |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4466 (gui.back_pixel >> 16) & 0xff, |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4467 (gui.back_pixel >> 8) & 0xff, |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4468 gui.back_pixel & 0xff); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4469 |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4470 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
|
4471 gtk_style_context_add_provider(context, |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4472 GTK_STYLE_PROVIDER(provider), G_MAXUINT); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4473 |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4474 g_free(css); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4475 g_object_unref(provider); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4476 #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
|
4477 GdkRGBA rgba; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4478 |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4479 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
|
4480 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4481 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
|
4482 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
|
4483 if (pat != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4484 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4485 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
|
4486 cairo_pattern_destroy(pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4487 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4488 else |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4489 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
|
4490 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4491 #else /* !GTK_CHECK_VERSION(3,4,0) */ |
7 | 4492 GdkColor color = { 0, 0, 0, 0 }; |
4493 | |
4494 color.pixel = gui.back_pixel; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4495 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4496 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
|
4497 # else |
7 | 4498 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
|
4499 # endif |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4500 #endif /* !GTK_CHECK_VERSION(3,22,2) */ |
7 | 4501 } |
4502 } | |
4503 | |
4504 /* | |
4505 * This signal informs us about the need to rearrange our sub-widgets. | |
4506 */ | |
4507 static gint | |
1884 | 4508 form_configure_event(GtkWidget *widget UNUSED, |
4509 GdkEventConfigure *event, | |
4510 gpointer data UNUSED) | |
7 | 4511 { |
791 | 4512 int usable_height = event->height; |
4513 | |
10402
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
4514 #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
|
4515 /* 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
|
4516 * 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
|
4517 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4518 * 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
|
4519 * 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
|
4520 * 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
|
4521 * "native" one from non-native one. |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4522 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4523 * 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
|
4524 * 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
|
4525 * gui.formwin. |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4526 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4527 * 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
|
4528 * 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
|
4529 */ |
10402
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
4530 /* Follow-up |
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
4531 * 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
|
4532 * 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
|
4533 * 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
|
4534 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
|
4535 return TRUE; |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4536 #endif |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4537 |
791 | 4538 /* When in a GtkPlug, we can't guarantee valid heights (as a round |
4539 * no. of char-heights), so we have to manually sanitise them. | |
4540 * Widths seem to sort themselves out, don't ask me why. | |
4541 */ | |
4542 if (gtk_socket_id != 0) | |
856 | 4543 usable_height -= (gui.char_height - (gui.char_height/2)); /* sic. */ |
791 | 4544 |
7 | 4545 gtk_form_freeze(GTK_FORM(gui.formwin)); |
791 | 4546 gui_resize_shell(event->width, usable_height); |
7 | 4547 gtk_form_thaw(GTK_FORM(gui.formwin)); |
4548 | |
4549 return TRUE; | |
4550 } | |
4551 | |
4552 /* | |
4553 * Function called when window already closed. | |
4554 * We can't do much more here than to trying to preserve what had been done, | |
4555 * since the window is already inevitably going away. | |
4556 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4557 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4558 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4559 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
|
4560 #else |
7 | 4561 static void |
1884 | 4562 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
|
4563 #endif |
7 | 4564 { |
4565 /* Don't write messages to the GUI anymore */ | |
4566 full_screen = FALSE; | |
4567 | |
4568 gui.mainwin = NULL; | |
4569 gui.drawarea = NULL; | |
4570 | |
4571 if (!exiting) /* only do anything if the destroy was unexpected */ | |
4572 { | |
419 | 4573 vim_strncpy(IObuff, |
4574 (char_u *)_("Vim: Main window unexpectedly destroyed\n"), | |
4575 IOSIZE - 1); | |
7 | 4576 preserve_exit(); |
4577 } | |
7380
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
4578 #ifdef USE_GRESOURCE |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
4579 gui_gtk_unregister_resource(); |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
4580 #endif |
7 | 4581 } |
4582 | |
791 | 4583 |
4584 /* | |
4585 * Bit of a hack to ensure we start GtkPlug windows with the correct window | |
4586 * hints (and thus the required size from -geom), but that after that we | |
4587 * put the hints back to normal (the actual minimum size) so we may | |
4588 * subsequently be resized smaller. GtkSocket (the parent end) uses the | |
1226 | 4589 * plug's window 'min hints to set *it's* minimum size, but that's also the |
791 | 4590 * only way we have of making ourselves bigger (by set lines/columns). |
4591 * 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
|
4592 * 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
|
4593 * scrollbar init.), actually do the standard hints and stop the timer. |
791 | 4594 * We'll not let the default hints be set while this timer's active. |
4595 */ | |
4596 static gboolean | |
1884 | 4597 check_startup_plug_hints(gpointer data UNUSED) |
791 | 4598 { |
4599 if (init_window_hints_state == 1) | |
4600 { | |
856 | 4601 /* Safe to use normal hints now */ |
4602 init_window_hints_state = 0; | |
4603 update_window_manager_hints(0, 0); | |
4604 return FALSE; /* stop timer */ | |
791 | 4605 } |
4606 | |
4607 /* Keep on trying */ | |
4608 init_window_hints_state = 1; | |
4609 return TRUE; | |
4610 } | |
4611 | |
7 | 4612 /* |
4613 * Open the GUI window which was created by a call to gui_mch_init(). | |
4614 */ | |
4615 int | |
4616 gui_mch_open(void) | |
4617 { | |
4618 guicolor_T fg_pixel = INVALCOLOR; | |
4619 guicolor_T bg_pixel = INVALCOLOR; | |
1966 | 4620 guint pixel_width; |
4621 guint pixel_height; | |
7 | 4622 |
4623 /* | |
4624 * Allow setting a window role on the command line, or invent one | |
4625 * if none was specified. This is mainly useful for GNOME session | |
4626 * support; allowing the WM to restore window placement. | |
4627 */ | |
4628 if (role_argument != NULL) | |
4629 { | |
4630 gtk_window_set_role(GTK_WINDOW(gui.mainwin), role_argument); | |
4631 } | |
4632 else | |
4633 { | |
4634 char *role; | |
4635 | |
4636 /* Invent a unique-enough ID string for the role */ | |
4637 role = g_strdup_printf("vim-%u-%u-%u", | |
4638 (unsigned)mch_get_pid(), | |
4639 (unsigned)g_random_int(), | |
4640 (unsigned)time(NULL)); | |
4641 | |
4642 gtk_window_set_role(GTK_WINDOW(gui.mainwin), role); | |
4643 g_free(role); | |
4644 } | |
4645 | |
4646 if (gui_win_x != -1 && gui_win_y != -1) | |
4647 gtk_window_move(GTK_WINDOW(gui.mainwin), gui_win_x, gui_win_y); | |
4648 | |
4649 /* Determine user specified geometry, if present. */ | |
4650 if (gui.geom != NULL) | |
4651 { | |
4652 int mask; | |
4653 unsigned int w, h; | |
4654 int x = 0; | |
4655 int y = 0; | |
4656 | |
4657 mask = XParseGeometry((char *)gui.geom, &x, &y, &w, &h); | |
4658 | |
4659 if (mask & WidthValue) | |
4660 Columns = w; | |
4661 if (mask & HeightValue) | |
857 | 4662 { |
1884 | 4663 if (p_window > (long)h - 1 || !option_was_set((char_u *)"window")) |
857 | 4664 p_window = h - 1; |
7 | 4665 Rows = h; |
857 | 4666 } |
5070
cf52d2a8c05c
updated for version 7.3.1278
Bram Moolenaar <bram@vim.org>
parents:
4474
diff
changeset
|
4667 limit_screen_size(); |
1426 | 4668 |
4669 pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width); | |
4670 pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height); | |
4671 | |
4672 pixel_width += get_menu_tool_width(); | |
4673 pixel_height += get_menu_tool_height(); | |
4674 | |
7 | 4675 if (mask & (XValue | YValue)) |
1426 | 4676 { |
1757 | 4677 int ww, hh; |
4678 gui_mch_get_screen_dimensions(&ww, &hh); | |
4679 hh += p_ghr + get_menu_tool_height(); | |
4680 ww += get_menu_tool_width(); | |
1426 | 4681 if (mask & XNegative) |
1757 | 4682 x += ww - pixel_width; |
1426 | 4683 if (mask & YNegative) |
1757 | 4684 y += hh - pixel_height; |
7 | 4685 gtk_window_move(GTK_WINDOW(gui.mainwin), x, y); |
1426 | 4686 } |
7 | 4687 vim_free(gui.geom); |
4688 gui.geom = NULL; | |
791 | 4689 |
856 | 4690 /* From now until everyone's stopped trying to set the window hints |
4691 * to their correct minimum values, stop them being set as we need | |
4692 * them to remain at our required size for the parent GtkSocket to | |
4693 * give us the right initial size. | |
4694 */ | |
791 | 4695 if (gtk_socket_id != 0 && (mask & WidthValue || mask & HeightValue)) |
856 | 4696 { |
4697 update_window_manager_hints(pixel_width, pixel_height); | |
4698 init_window_hints_state = 1; | |
4699 g_timeout_add(1000, check_startup_plug_hints, NULL); | |
4700 } | |
7 | 4701 } |
4702 | |
1966 | 4703 pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width); |
4704 pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height); | |
4705 /* For GTK2 changing the size of the form widget doesn't cause window | |
4706 * resizing. */ | |
2254
4620acaf4814
One more fix for conceal patch.
Bram Moolenaar <bram@vim.org>
parents:
2248
diff
changeset
|
4707 if (gtk_socket_id == 0) |
1966 | 4708 gtk_window_resize(GTK_WINDOW(gui.mainwin), pixel_width, pixel_height); |
791 | 4709 update_window_manager_hints(0, 0); |
7 | 4710 |
4711 if (foreground_argument != NULL) | |
4712 fg_pixel = gui_get_color((char_u *)foreground_argument); | |
4713 if (fg_pixel == INVALCOLOR) | |
4714 fg_pixel = gui_get_color((char_u *)"Black"); | |
4715 | |
4716 if (background_argument != NULL) | |
4717 bg_pixel = gui_get_color((char_u *)background_argument); | |
4718 if (bg_pixel == INVALCOLOR) | |
4719 bg_pixel = gui_get_color((char_u *)"White"); | |
4720 | |
4721 if (found_reverse_arg) | |
4722 { | |
4723 gui.def_norm_pixel = bg_pixel; | |
4724 gui.def_back_pixel = fg_pixel; | |
4725 } | |
4726 else | |
4727 { | |
4728 gui.def_norm_pixel = fg_pixel; | |
4729 gui.def_back_pixel = bg_pixel; | |
4730 } | |
4731 | |
4732 /* Get the colors from the "Normal" and "Menu" group (set in syntax.c or | |
4733 * in a vimrc file) */ | |
4734 set_normal_colors(); | |
4735 | |
4736 /* Check that none of the colors are the same as the background color */ | |
4737 gui_check_colors(); | |
4738 | |
4739 /* Get the colors for the highlight groups (gui_check_colors() might have | |
4740 * changed them). */ | |
4741 highlight_gui_started(); /* re-init colors and fonts */ | |
4742 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4743 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4744 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
|
4745 G_CALLBACK(mainwin_destroy_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4746 #else |
7 | 4747 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "destroy", |
4748 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
|
4749 #endif |
7 | 4750 |
4751 #ifdef FEAT_HANGULIN | |
4752 hangul_keyboard_set(); | |
4753 #endif | |
4754 | |
4755 /* | |
4756 * Notify the fixed area about the need to resize the contents of the | |
4757 * gui.formwin, which we use for random positioning of the included | |
4758 * components. | |
4759 * | |
4760 * We connect this signal deferred finally after anything is in place, | |
4761 * since this is intended to handle resizements coming from the window | |
4762 * manager upon us and should not interfere with what VIM is requesting | |
4763 * upon startup. | |
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.formwin), "configure-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4767 G_CALLBACK(form_configure_event), 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.formwin), "configure_event", |
4770 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
|
4771 #endif |
7 | 4772 |
4773 #ifdef FEAT_DND | |
2183 | 4774 /* Set up for receiving DND items. */ |
4775 gui_gtk_set_dnd_targets(); | |
7 | 4776 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4777 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4778 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
|
4779 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
|
4780 # else |
7 | 4781 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "drag_data_received", |
4782 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
|
4783 # endif |
7 | 4784 #endif |
4785 | |
4786 /* 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
|
4787 * to avoid mapping the window for a short time. */ |
7 | 4788 if (found_iconic_arg && gtk_socket_id == 0) |
4789 gui_mch_iconify(); | |
4790 | |
4791 { | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
4792 #if defined(FEAT_GUI_GNOME) && defined(FEAT_MENU) |
7 | 4793 unsigned long menu_handler = 0; |
4794 # ifdef FEAT_TOOLBAR | |
4795 unsigned long tool_handler = 0; | |
4796 # endif | |
4797 /* | |
4798 * Urgh hackish :/ For some reason BonoboDockLayout always forces a | |
4799 * show when restoring the saved layout configuration. We can't just | |
4800 * hide the widgets again after gtk_widget_show(gui.mainwin) since it's | |
4801 * a toplevel window and thus will be realized immediately. Instead, | |
4802 * connect signal handlers to hide the widgets just after they've been | |
4803 * marked visible, but before the main window is realized. | |
4804 */ | |
4805 if (using_gnome && vim_strchr(p_go, GO_MENUS) == NULL) | |
4806 menu_handler = g_signal_connect_after(gui.menubar_h, "show", | |
4807 G_CALLBACK(>k_widget_hide), | |
4808 NULL); | |
4809 # ifdef FEAT_TOOLBAR | |
4810 if (using_gnome && vim_strchr(p_go, GO_TOOLBAR) == NULL | |
4811 && (toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS))) | |
4812 tool_handler = g_signal_connect_after(gui.toolbar_h, "show", | |
4813 G_CALLBACK(>k_widget_hide), | |
4814 NULL); | |
4815 # endif | |
4816 #endif | |
4817 gtk_widget_show(gui.mainwin); | |
4818 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
4819 #if defined(FEAT_GUI_GNOME) && defined(FEAT_MENU) |
7 | 4820 if (menu_handler != 0) |
4821 g_signal_handler_disconnect(gui.menubar_h, menu_handler); | |
4822 # ifdef FEAT_TOOLBAR | |
4823 if (tool_handler != 0) | |
4824 g_signal_handler_disconnect(gui.toolbar_h, tool_handler); | |
4825 # endif | |
4826 #endif | |
4827 } | |
4828 | |
4829 return OK; | |
4830 } | |
4831 | |
4832 | |
4833 void | |
1884 | 4834 gui_mch_exit(int rc UNUSED) |
7 | 4835 { |
4836 if (gui.mainwin != NULL) | |
4837 gtk_widget_destroy(gui.mainwin); | |
4838 } | |
4839 | |
4840 /* | |
4841 * Get the position of the top left corner of the window. | |
4842 */ | |
4843 int | |
4844 gui_mch_get_winpos(int *x, int *y) | |
4845 { | |
4846 gtk_window_get_position(GTK_WINDOW(gui.mainwin), x, y); | |
4847 return OK; | |
4848 } | |
4849 | |
4850 /* | |
4851 * Set the position of the top left corner of the window to the given | |
4852 * coordinates. | |
4853 */ | |
4854 void | |
4855 gui_mch_set_winpos(int x, int y) | |
4856 { | |
4857 gtk_window_move(GTK_WINDOW(gui.mainwin), x, y); | |
4858 } | |
4859 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4860 #if !GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4861 # if 0 |
7 | 4862 static int resize_idle_installed = FALSE; |
4863 /* | |
4864 * Idle handler to force resize. Used by gui_mch_set_shellsize() to ensure | |
4865 * the shell size doesn't exceed the window size, i.e. if the window manager | |
4866 * ignored our size request. Usually this happens if the window is maximized. | |
4867 * | |
4868 * FIXME: It'd be nice if we could find a little more orthodox solution. | |
4869 * See also the remark below in gui_mch_set_shellsize(). | |
4870 * | |
4871 * DISABLED: When doing ":set lines+=1" this function would first invoke | |
4872 * gui_resize_shell() with the old size, then the normal callback would | |
4873 * report the new size through form_configure_event(). That caused the window | |
4874 * layout to be messed up. | |
4875 */ | |
4876 static gboolean | |
4877 force_shell_resize_idle(gpointer data) | |
4878 { | |
4879 if (gui.mainwin != NULL | |
4880 && GTK_WIDGET_REALIZED(gui.mainwin) | |
4881 && GTK_WIDGET_VISIBLE(gui.mainwin)) | |
4882 { | |
4883 int width; | |
4884 int height; | |
4885 | |
4886 gtk_window_get_size(GTK_WINDOW(gui.mainwin), &width, &height); | |
4887 | |
4888 width -= get_menu_tool_width(); | |
4889 height -= get_menu_tool_height(); | |
4890 | |
4891 gui_resize_shell(width, height); | |
4892 } | |
4893 | |
4894 resize_idle_installed = FALSE; | |
4895 return FALSE; /* don't call me again */ | |
4896 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4897 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4898 #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
|
4899 |
1967 | 4900 /* |
4901 * Return TRUE if the main window is maximized. | |
4902 */ | |
4903 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
4904 gui_mch_maximized(void) |
1967 | 4905 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4906 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4907 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
|
4908 && (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
|
4909 & GDK_WINDOW_STATE_MAXIMIZED)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4910 #else |
1967 | 4911 return (gui.mainwin != NULL && gui.mainwin->window != NULL |
4912 && (gdk_window_get_state(gui.mainwin->window) | |
4913 & GDK_WINDOW_STATE_MAXIMIZED)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4914 #endif |
1967 | 4915 } |
4916 | |
4917 /* | |
4918 * Unmaximize the main window | |
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_unmaximize(void) |
1967 | 4922 { |
4923 if (gui.mainwin != NULL) | |
4924 gtk_window_unmaximize(GTK_WINDOW(gui.mainwin)); | |
4925 } | |
4926 | |
7 | 4927 /* |
3014 | 4928 * Called when the font changed while the window is maximized. Compute the |
4929 * new Rows and Columns. This is like resizing the window. | |
4930 */ | |
4931 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
4932 gui_mch_newfont(void) |
3014 | 4933 { |
4934 int w, h; | |
4935 | |
4936 gtk_window_get_size(GTK_WINDOW(gui.mainwin), &w, &h); | |
4937 w -= get_menu_tool_width(); | |
4938 h -= get_menu_tool_height(); | |
4939 gui_resize_shell(w, h); | |
4940 } | |
4941 | |
4942 /* | |
7 | 4943 * Set the windows size. |
4944 */ | |
4945 void | |
4946 gui_mch_set_shellsize(int width, int height, | |
1884 | 4947 int min_width UNUSED, int min_height UNUSED, |
4948 int base_width UNUSED, int base_height UNUSED, | |
4949 int direction UNUSED) | |
7 | 4950 { |
4951 /* give GTK+ a chance to put all widget's into place */ | |
4952 gui_mch_update(); | |
4953 | |
791 | 4954 /* this will cause the proper resizement to happen too */ |
4955 if (gtk_socket_id == 0) | |
856 | 4956 update_window_manager_hints(0, 0); |
791 | 4957 |
7 | 4958 /* With GTK+ 2, changing the size of the form widget doesn't resize |
791 | 4959 * the window. So let's do it the other way around and resize the |
7 | 4960 * main window instead. */ |
4961 width += get_menu_tool_width(); | |
4962 height += get_menu_tool_height(); | |
4963 | |
791 | 4964 if (gtk_socket_id == 0) |
856 | 4965 gtk_window_resize(GTK_WINDOW(gui.mainwin), width, height); |
791 | 4966 else |
856 | 4967 update_window_manager_hints(width, height); |
7 | 4968 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4969 # if !GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4970 # if 0 |
7 | 4971 if (!resize_idle_installed) |
4972 { | |
4973 g_idle_add_full(GDK_PRIORITY_EVENTS + 10, | |
4974 &force_shell_resize_idle, NULL, NULL); | |
4975 resize_idle_installed = TRUE; | |
4976 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4977 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4978 # endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 4979 /* |
4980 * Wait until all events are processed to prevent a crash because the | |
4981 * real size of the drawing area doesn't reflect Vim's internal ideas. | |
4982 * | |
4983 * This is a bit of a hack, since Vim is a terminal application with a GUI | |
4984 * on top, while the GUI expects to be the boss. | |
4985 */ | |
4986 gui_mch_update(); | |
4987 } | |
4988 | |
4989 | |
4990 /* | |
4991 * The screen size is used to make sure the initial window doesn't get bigger | |
4992 * than the screen. This subtracts some room for menubar, toolbar and window | |
4993 * decorations. | |
4994 */ | |
4995 void | |
4996 gui_mch_get_screen_dimensions(int *screen_w, int *screen_h) | |
4997 { | |
4998 #ifdef HAVE_GTK_MULTIHEAD | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4999 # 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
|
5000 GdkRectangle rect; |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5001 GdkMonitor * const mon = gdk_display_get_monitor_at_window( |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5002 gtk_widget_get_display(gui.mainwin), |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5003 gtk_widget_get_window(gui.mainwin)); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5004 gdk_monitor_get_geometry(mon, &rect); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5005 |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5006 *screen_w = rect.width; |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5007 *screen_h = rect.height - p_ghr; |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5008 # else |
7 | 5009 GdkScreen* screen; |
5010 | |
5011 if (gui.mainwin != NULL && gtk_widget_has_screen(gui.mainwin)) | |
5012 screen = gtk_widget_get_screen(gui.mainwin); | |
5013 else | |
5014 screen = gdk_screen_get_default(); | |
5015 | |
5016 *screen_w = gdk_screen_get_width(screen); | |
5017 *screen_h = gdk_screen_get_height(screen) - p_ghr; | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5018 # endif |
7 | 5019 #else |
5020 *screen_w = gdk_screen_width(); | |
5021 /* Subtract 'guiheadroom' from the height to allow some room for the | |
5022 * window manager (task list and window title bar). */ | |
5023 *screen_h = gdk_screen_height() - p_ghr; | |
5024 #endif | |
5025 | |
5026 /* | |
5027 * FIXME: dirty trick: Because the gui_get_base_height() doesn't include | |
5028 * 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
|
5029 * height, so that the window size can be made to fit on the screen. |
7 | 5030 * This should be completely changed later. |
5031 */ | |
5032 *screen_w -= get_menu_tool_width(); | |
5033 *screen_h -= get_menu_tool_height(); | |
5034 } | |
5035 | |
5036 #if defined(FEAT_TITLE) || defined(PROTO) | |
5037 void | |
1884 | 5038 gui_mch_settitle(char_u *title, char_u *icon UNUSED) |
7 | 5039 { |
5040 if (title != NULL && output_conv.vc_type != CONV_NONE) | |
5041 title = string_convert(&output_conv, title, NULL); | |
5042 | |
5043 gtk_window_set_title(GTK_WINDOW(gui.mainwin), (const char *)title); | |
5044 | |
5045 if (output_conv.vc_type != CONV_NONE) | |
5046 vim_free(title); | |
5047 } | |
5048 #endif /* FEAT_TITLE */ | |
5049 | |
5050 #if defined(FEAT_MENU) || defined(PROTO) | |
5051 void | |
5052 gui_mch_enable_menu(int showit) | |
5053 { | |
5054 GtkWidget *widget; | |
5055 | |
5056 # ifdef FEAT_GUI_GNOME | |
5057 if (using_gnome) | |
5058 widget = gui.menubar_h; | |
5059 else | |
5060 # endif | |
5061 widget = gui.menubar; | |
5062 | |
827 | 5063 /* 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
|
5064 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5065 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
|
5066 # else |
827 | 5067 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
|
5068 # endif |
7 | 5069 { |
5070 if (showit) | |
5071 gtk_widget_show(widget); | |
5072 else | |
5073 gtk_widget_hide(widget); | |
5074 | |
791 | 5075 update_window_manager_hints(0, 0); |
7 | 5076 } |
5077 } | |
5078 #endif /* FEAT_MENU */ | |
5079 | |
5080 #if defined(FEAT_TOOLBAR) || defined(PROTO) | |
5081 void | |
5082 gui_mch_show_toolbar(int showit) | |
5083 { | |
5084 GtkWidget *widget; | |
5085 | |
5086 if (gui.toolbar == NULL) | |
5087 return; | |
5088 | |
5089 # ifdef FEAT_GUI_GNOME | |
5090 if (using_gnome) | |
5091 widget = gui.toolbar_h; | |
5092 else | |
5093 # endif | |
5094 widget = gui.toolbar; | |
5095 | |
5096 if (showit) | |
5097 set_toolbar_style(GTK_TOOLBAR(gui.toolbar)); | |
5098 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5099 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5100 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
|
5101 # else |
7 | 5102 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
|
5103 # endif |
7 | 5104 { |
5105 if (showit) | |
5106 gtk_widget_show(widget); | |
5107 else | |
5108 gtk_widget_hide(widget); | |
5109 | |
791 | 5110 update_window_manager_hints(0, 0); |
7 | 5111 } |
5112 } | |
5113 #endif /* FEAT_TOOLBAR */ | |
5114 | |
5115 /* | |
5116 * Check if a given font is a CJK font. This is done in a very crude manner. It | |
5117 * just see if U+04E00 for zh and ja and U+AC00 for ko are covered in a given | |
5118 * font. Consequently, this function cannot be used as a general purpose check | |
5119 * for CJK-ness for which fontconfig APIs should be used. This is only used by | |
5120 * gui_mch_init_font() to deal with 'CJK fixed width fonts'. | |
5121 */ | |
5122 static int | |
5123 is_cjk_font(PangoFontDescription *font_desc) | |
5124 { | |
5125 static const char * const cjk_langs[] = | |
5126 {"zh_CN", "zh_TW", "zh_HK", "ja", "ko"}; | |
5127 | |
5128 PangoFont *font; | |
5129 unsigned i; | |
5130 int is_cjk = FALSE; | |
5131 | |
5132 font = pango_context_load_font(gui.text_context, font_desc); | |
5133 | |
5134 if (font == NULL) | |
5135 return FALSE; | |
5136 | |
5137 for (i = 0; !is_cjk && i < G_N_ELEMENTS(cjk_langs); ++i) | |
5138 { | |
5139 PangoCoverage *coverage; | |
5140 gunichar uc; | |
5141 | |
5142 coverage = pango_font_get_coverage( | |
5143 font, pango_language_from_string(cjk_langs[i])); | |
5144 | |
5145 if (coverage != NULL) | |
5146 { | |
5147 uc = (cjk_langs[i][0] == 'k') ? 0xAC00 : 0x4E00; | |
5148 is_cjk = (pango_coverage_get(coverage, uc) == PANGO_COVERAGE_EXACT); | |
5149 pango_coverage_unref(coverage); | |
5150 } | |
5151 } | |
5152 | |
5153 g_object_unref(font); | |
5154 | |
5155 return is_cjk; | |
5156 } | |
5157 | |
445 | 5158 /* |
5159 * Adjust gui.char_height (after 'linespace' was changed). | |
5160 */ | |
7 | 5161 int |
445 | 5162 gui_mch_adjust_charheight(void) |
7 | 5163 { |
5164 PangoFontMetrics *metrics; | |
5165 int ascent; | |
5166 int descent; | |
5167 | |
5168 metrics = pango_context_get_metrics(gui.text_context, gui.norm_font, | |
5169 pango_context_get_language(gui.text_context)); | |
5170 ascent = pango_font_metrics_get_ascent(metrics); | |
5171 descent = pango_font_metrics_get_descent(metrics); | |
5172 | |
5173 pango_font_metrics_unref(metrics); | |
5174 | |
5175 gui.char_height = (ascent + descent + PANGO_SCALE - 1) / PANGO_SCALE | |
445 | 5176 + p_linespace; |
136 | 5177 /* LINTED: avoid warning: bitwise operation on signed value */ |
7 | 5178 gui.char_ascent = PANGO_PIXELS(ascent + p_linespace * PANGO_SCALE / 2); |
5179 | |
5180 /* A not-positive value of char_height may crash Vim. Only happens | |
5181 * if 'linespace' is negative (which does make sense sometimes). */ | |
5182 gui.char_ascent = MAX(gui.char_ascent, 0); | |
5183 gui.char_height = MAX(gui.char_height, gui.char_ascent + 1); | |
5184 | |
5185 return OK; | |
5186 } | |
5187 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5188 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5189 /* 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
|
5190 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5191 font_filter(const PangoFontFamily *family, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5192 const PangoFontFace *face UNUSED, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5193 gpointer data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5194 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5195 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
|
5196 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5197 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5198 |
7 | 5199 /* |
5200 * Put up a font dialog and return the selected font name in allocated memory. | |
5201 * "oldval" is the previous value. Return NULL when cancelled. | |
5202 * This should probably go into gui_gtk.c. Hmm. | |
5203 * FIXME: | |
5204 * The GTK2 font selection dialog has no filtering API. So we could either | |
5205 * a) implement our own (possibly copying the code from somewhere else) or | |
5206 * b) just live with it. | |
5207 */ | |
5208 char_u * | |
5209 gui_mch_font_dialog(char_u *oldval) | |
5210 { | |
5211 GtkWidget *dialog; | |
5212 int response; | |
5213 char_u *fontname = NULL; | |
5214 char_u *oldname; | |
5215 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5216 #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
|
5217 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
|
5218 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
|
5219 NULL, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5220 #else |
7 | 5221 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
|
5222 #endif |
7 | 5223 |
5224 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gui.mainwin)); | |
5225 gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); | |
5226 | |
5227 if (oldval != NULL && oldval[0] != NUL) | |
5228 { | |
5229 if (output_conv.vc_type != CONV_NONE) | |
5230 oldname = string_convert(&output_conv, oldval, NULL); | |
5231 else | |
5232 oldname = oldval; | |
5233 | |
5234 /* Annoying bug in GTK (or Pango): if the font name does not include a | |
5235 * size, zero is used. Use default point size ten. */ | |
5236 if (!vim_isdigit(oldname[STRLEN(oldname) - 1])) | |
5237 { | |
5238 char_u *p = vim_strnsave(oldname, STRLEN(oldname) + 3); | |
5239 | |
5240 if (p != NULL) | |
5241 { | |
5242 STRCPY(p + STRLEN(p), " 10"); | |
5243 if (oldname != oldval) | |
5244 vim_free(oldname); | |
5245 oldname = p; | |
5246 } | |
5247 } | |
5248 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5249 #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
|
5250 gtk_font_chooser_set_font( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5251 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
|
5252 #else |
7 | 5253 gtk_font_selection_dialog_set_font_name( |
5254 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
|
5255 #endif |
7 | 5256 |
5257 if (oldname != oldval) | |
100 | 5258 vim_free(oldname); |
7 | 5259 } |
1959 | 5260 else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5261 #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
|
5262 gtk_font_chooser_set_font( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5263 GTK_FONT_CHOOSER(dialog), DEFAULT_FONT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5264 #else |
1959 | 5265 gtk_font_selection_dialog_set_font_name( |
5266 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
|
5267 #endif |
7 | 5268 |
5269 response = gtk_dialog_run(GTK_DIALOG(dialog)); | |
5270 | |
5271 if (response == GTK_RESPONSE_OK) | |
5272 { | |
5273 char *name; | |
5274 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5275 #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
|
5276 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
|
5277 #else |
7 | 5278 name = gtk_font_selection_dialog_get_font_name( |
5279 GTK_FONT_SELECTION_DIALOG(dialog)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5280 #endif |
7 | 5281 if (name != NULL) |
5282 { | |
714 | 5283 char_u *p; |
5284 | |
5285 /* Apparently some font names include a comma, need to escape | |
5286 * that, because in 'guifont' it separates names. */ | |
5287 p = vim_strsave_escaped((char_u *)name, (char_u *)","); | |
5288 g_free(name); | |
840 | 5289 if (p != NULL && input_conv.vc_type != CONV_NONE) |
714 | 5290 { |
5291 fontname = string_convert(&input_conv, p, NULL); | |
5292 vim_free(p); | |
5293 } | |
7 | 5294 else |
714 | 5295 fontname = p; |
7 | 5296 } |
5297 } | |
5298 | |
5299 if (response != GTK_RESPONSE_NONE) | |
5300 gtk_widget_destroy(dialog); | |
5301 | |
5302 return fontname; | |
5303 } | |
5304 | |
5305 /* | |
5306 * Some monospace fonts don't support a bold weight, and fall back | |
5307 * silently to the regular weight. But this is no good since our text | |
5308 * drawing function can emulate bold by overstriking. So let's try | |
5309 * to detect whether bold weight is actually available and emulate it | |
5310 * otherwise. | |
5311 * | |
5312 * Note that we don't need to check for italic style since Xft can | |
5313 * emulate italic on its own, provided you have a proper fontconfig | |
5314 * setup. We wouldn't be able to emulate it in Vim anyway. | |
5315 */ | |
5316 static void | |
5317 get_styled_font_variants(void) | |
5318 { | |
5319 PangoFontDescription *bold_font_desc; | |
5320 PangoFont *plain_font; | |
5321 PangoFont *bold_font; | |
5322 | |
5323 gui.font_can_bold = FALSE; | |
5324 | |
5325 plain_font = pango_context_load_font(gui.text_context, gui.norm_font); | |
5326 | |
5327 if (plain_font == NULL) | |
5328 return; | |
5329 | |
5330 bold_font_desc = pango_font_description_copy_static(gui.norm_font); | |
5331 pango_font_description_set_weight(bold_font_desc, PANGO_WEIGHT_BOLD); | |
5332 | |
5333 bold_font = pango_context_load_font(gui.text_context, bold_font_desc); | |
5334 /* | |
5335 * The comparison relies on the unique handle nature of a PangoFont*, | |
5336 * i.e. it's assumed that a different PangoFont* won't refer to the | |
5337 * same font. Seems to work, and failing here isn't critical anyway. | |
5338 */ | |
5339 if (bold_font != NULL) | |
5340 { | |
5341 gui.font_can_bold = (bold_font != plain_font); | |
5342 g_object_unref(bold_font); | |
5343 } | |
5344 | |
5345 pango_font_description_free(bold_font_desc); | |
5346 g_object_unref(plain_font); | |
5347 } | |
5348 | |
5349 static PangoEngineShape *default_shape_engine = NULL; | |
5350 | |
5351 /* | |
5352 * Create a map from ASCII characters in the range [32,126] to glyphs | |
5353 * of the current font. This is used by gui_gtk2_draw_string() to skip | |
5354 * the itemize and shaping process for the most common case. | |
5355 */ | |
5356 static void | |
5357 ascii_glyph_table_init(void) | |
5358 { | |
9879
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5359 char_u ascii_chars[2 * 128]; |
7 | 5360 PangoAttrList *attr_list; |
5361 GList *item_list; | |
5362 int i; | |
5363 | |
5364 if (gui.ascii_glyphs != NULL) | |
5365 pango_glyph_string_free(gui.ascii_glyphs); | |
5366 if (gui.ascii_font != NULL) | |
5367 g_object_unref(gui.ascii_font); | |
5368 | |
5369 gui.ascii_glyphs = NULL; | |
5370 gui.ascii_font = NULL; | |
5371 | |
9879
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5372 /* 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
|
5373 * 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
|
5374 for (i = 0; i < 128; ++i) |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5375 { |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5376 if (i >= 32 && i < 127) |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5377 ascii_chars[2 * i] = i; |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5378 else |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5379 ascii_chars[2 * i] = '?'; |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5380 ascii_chars[2 * i + 1] = ' '; |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5381 } |
7 | 5382 |
5383 attr_list = pango_attr_list_new(); | |
5384 item_list = pango_itemize(gui.text_context, (const char *)ascii_chars, | |
5385 0, sizeof(ascii_chars), attr_list, NULL); | |
5386 | |
5387 if (item_list != NULL && item_list->next == NULL) /* play safe */ | |
5388 { | |
5389 PangoItem *item; | |
5390 int width; | |
5391 | |
5392 item = (PangoItem *)item_list->data; | |
5393 width = gui.char_width * PANGO_SCALE; | |
5394 | |
5395 /* Remember the shape engine used for ASCII. */ | |
5396 default_shape_engine = item->analysis.shape_engine; | |
5397 | |
5398 gui.ascii_font = item->analysis.font; | |
5399 g_object_ref(gui.ascii_font); | |
5400 | |
5401 gui.ascii_glyphs = pango_glyph_string_new(); | |
5402 | |
5403 pango_shape((const char *)ascii_chars, sizeof(ascii_chars), | |
5404 &item->analysis, gui.ascii_glyphs); | |
5405 | |
5406 g_return_if_fail(gui.ascii_glyphs->num_glyphs == sizeof(ascii_chars)); | |
5407 | |
5408 for (i = 0; i < gui.ascii_glyphs->num_glyphs; ++i) | |
5409 { | |
5410 PangoGlyphGeometry *geom; | |
5411 | |
5412 geom = &gui.ascii_glyphs->glyphs[i].geometry; | |
5413 geom->x_offset += MAX(0, width - geom->width) / 2; | |
5414 geom->width = width; | |
5415 } | |
5416 } | |
5417 | |
5418 g_list_foreach(item_list, (GFunc)&pango_item_free, NULL); | |
5419 g_list_free(item_list); | |
5420 pango_attr_list_unref(attr_list); | |
5421 } | |
5422 | |
5423 /* | |
5424 * Initialize Vim to use the font or fontset with the given name. | |
5425 * Return FAIL if the font could not be loaded, OK otherwise. | |
5426 */ | |
5427 int | |
1884 | 5428 gui_mch_init_font(char_u *font_name, int fontset UNUSED) |
7 | 5429 { |
5430 PangoFontDescription *font_desc; | |
5431 PangoLayout *layout; | |
5432 int width; | |
5433 | |
5434 /* If font_name is NULL, this means to use the default, which should | |
5435 * be present on all proper Pango/fontconfig installations. */ | |
5436 if (font_name == NULL) | |
5437 font_name = (char_u *)DEFAULT_FONT; | |
5438 | |
5439 font_desc = gui_mch_get_font(font_name, FALSE); | |
5440 | |
5441 if (font_desc == NULL) | |
5442 return FAIL; | |
5443 | |
5444 gui_mch_free_font(gui.norm_font); | |
5445 gui.norm_font = font_desc; | |
5446 | |
5447 pango_context_set_font_description(gui.text_context, font_desc); | |
5448 | |
5449 layout = pango_layout_new(gui.text_context); | |
5450 pango_layout_set_text(layout, "MW", 2); | |
5451 pango_layout_get_size(layout, &width, NULL); | |
5452 /* | |
5453 * Set char_width to half the width obtained from pango_layout_get_size() | |
5454 * for CJK fixed_width/bi-width fonts. An unpatched version of Xft leads | |
5455 * Pango to use the same width for both non-CJK characters (e.g. Latin | |
5456 * letters and numbers) and CJK characters. This results in 's p a c e d | |
5457 * o u t' rendering when a CJK 'fixed width' font is used. To work around | |
5458 * that, divide the width returned by Pango by 2 if cjk_width is equal to | |
5459 * width for CJK fonts. | |
5460 * | |
5461 * For related bugs, see: | |
5462 * http://bugzilla.gnome.org/show_bug.cgi?id=106618 | |
5463 * http://bugzilla.gnome.org/show_bug.cgi?id=106624 | |
5464 * | |
5465 * With this, for all four of the following cases, Vim works fine: | |
5466 * guifont=CJK_fixed_width_font | |
5467 * guifont=Non_CJK_fixed_font | |
5468 * guifont=Non_CJK_fixed_font,CJK_Fixed_font | |
5469 * guifont=Non_CJK_fixed_font guifontwide=CJK_fixed_font | |
5470 */ | |
5471 if (is_cjk_font(gui.norm_font)) | |
5472 { | |
5473 int cjk_width; | |
5474 | |
5475 /* Measure the text extent of U+4E00 and U+4E8C */ | |
5476 pango_layout_set_text(layout, "\344\270\200\344\272\214", -1); | |
5477 pango_layout_get_size(layout, &cjk_width, NULL); | |
5478 | |
5479 if (width == cjk_width) /* Xft not patched */ | |
5480 width /= 2; | |
5481 } | |
5482 g_object_unref(layout); | |
5483 | |
5484 gui.char_width = (width / 2 + PANGO_SCALE - 1) / PANGO_SCALE; | |
5485 | |
5486 /* A zero width may cause a crash. Happens for semi-invalid fontsets. */ | |
5487 if (gui.char_width <= 0) | |
5488 gui.char_width = 8; | |
5489 | |
445 | 5490 gui_mch_adjust_charheight(); |
7 | 5491 |
5492 /* Set the fontname, which will be used for information purposes */ | |
5493 hl_set_font_name(font_name); | |
5494 | |
5495 get_styled_font_variants(); | |
5496 ascii_glyph_table_init(); | |
5497 | |
5498 /* Avoid unnecessary overhead if 'guifontwide' is equal to 'guifont'. */ | |
5499 if (gui.wide_font != NULL | |
5500 && pango_font_description_equal(gui.norm_font, gui.wide_font)) | |
5501 { | |
5502 pango_font_description_free(gui.wide_font); | |
5503 gui.wide_font = NULL; | |
5504 } | |
5505 | |
1986 | 5506 if (gui_mch_maximized()) |
5507 { | |
5508 /* Update lines and columns in accordance with the new font, keep the | |
5509 * window maximized. */ | |
3014 | 5510 gui_mch_newfont(); |
1986 | 5511 } |
5512 else | |
5513 { | |
5514 /* Preserve the logical dimensions of the screen. */ | |
5515 update_window_manager_hints(0, 0); | |
5516 } | |
7 | 5517 |
5518 return OK; | |
5519 } | |
5520 | |
5521 /* | |
5522 * Get a reference to the font "name". | |
5523 * Return zero for failure. | |
5524 */ | |
5525 GuiFont | |
5526 gui_mch_get_font(char_u *name, int report_error) | |
5527 { | |
5528 PangoFontDescription *font; | |
5529 | |
5530 /* can't do this when GUI is not running */ | |
5531 if (!gui.in_use || name == NULL) | |
5532 return NULL; | |
5533 | |
5534 if (output_conv.vc_type != CONV_NONE) | |
5535 { | |
5536 char_u *buf; | |
5537 | |
5538 buf = string_convert(&output_conv, name, NULL); | |
5539 if (buf != NULL) | |
5540 { | |
5541 font = pango_font_description_from_string((const char *)buf); | |
5542 vim_free(buf); | |
5543 } | |
5544 else | |
5545 font = NULL; | |
5546 } | |
5547 else | |
5548 font = pango_font_description_from_string((const char *)name); | |
5549 | |
5550 if (font != NULL) | |
5551 { | |
5552 PangoFont *real_font; | |
5553 | |
5554 /* pango_context_load_font() bails out if no font size is set */ | |
5555 if (pango_font_description_get_size(font) <= 0) | |
5556 pango_font_description_set_size(font, 10 * PANGO_SCALE); | |
5557 | |
5558 real_font = pango_context_load_font(gui.text_context, font); | |
5559 | |
5560 if (real_font == NULL) | |
5561 { | |
5562 pango_font_description_free(font); | |
5563 font = NULL; | |
5564 } | |
5565 else | |
5566 g_object_unref(real_font); | |
5567 } | |
5568 | |
5569 if (font == NULL) | |
5570 { | |
5571 if (report_error) | |
1666 | 5572 EMSG2(_((char *)e_font), name); |
7 | 5573 return NULL; |
5574 } | |
5575 | |
5576 return font; | |
5577 } | |
5578 | |
39 | 5579 #if defined(FEAT_EVAL) || defined(PROTO) |
38 | 5580 /* |
5581 * Return the name of font "font" in allocated memory. | |
5582 */ | |
5583 char_u * | |
1884 | 5584 gui_mch_get_fontname(GuiFont font, char_u *name UNUSED) |
38 | 5585 { |
5586 if (font != NOFONT) | |
5587 { | |
944 | 5588 char *pangoname = pango_font_description_to_string(font); |
5589 | |
5590 if (pangoname != NULL) | |
38 | 5591 { |
944 | 5592 char_u *s = vim_strsave((char_u *)pangoname); |
5593 | |
5594 g_free(pangoname); | |
38 | 5595 return s; |
5596 } | |
5597 } | |
5598 return NULL; | |
5599 } | |
39 | 5600 #endif |
38 | 5601 |
7 | 5602 /* |
5603 * If a font is not going to be used, free its structure. | |
5604 */ | |
5605 void | |
5606 gui_mch_free_font(GuiFont font) | |
5607 { | |
5608 if (font != NOFONT) | |
5609 pango_font_description_free(font); | |
5610 } | |
5611 | |
5612 /* | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5613 * 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
|
5614 * |
7 | 5615 * Return INVALCOLOR for error. |
5616 */ | |
5617 guicolor_T | |
5618 gui_mch_get_color(char_u *name) | |
5619 { | |
5620 if (!gui.in_use) /* can't do this when GUI not running */ | |
5621 return INVALCOLOR; | |
5622 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5623 #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
|
5624 return name != NULL ? gui_get_color_cmn(name) : INVALCOLOR; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5625 #else |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5626 guicolor_T color; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5627 GdkColor gcolor; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5628 int ret; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5629 |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5630 color = (name != NULL) ? gui_get_color_cmn(name) : INVALCOLOR; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5631 if (color == INVALCOLOR) |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5632 return INVALCOLOR; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5633 |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5634 gcolor.red = (guint16)(((color & 0xff0000) >> 16) / 255.0 * 65535 + 0.5); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5635 gcolor.green = (guint16)(((color & 0xff00) >> 8) / 255.0 * 65535 + 0.5); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5636 gcolor.blue = (guint16)((color & 0xff) / 255.0 * 65535 + 0.5); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5637 |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5638 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
|
5639 &gcolor, FALSE, TRUE); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5640 |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5641 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
|
5642 #endif |
7 | 5643 } |
5644 | |
5645 /* | |
5646 * Set the current text foreground color. | |
5647 */ | |
5648 void | |
5649 gui_mch_set_fg_color(guicolor_T color) | |
5650 { | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5651 #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
|
5652 *gui.fgcolor = color_to_rgba(color); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5653 #else |
7 | 5654 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
|
5655 #endif |
7 | 5656 } |
5657 | |
5658 /* | |
5659 * Set the current text background color. | |
5660 */ | |
5661 void | |
5662 gui_mch_set_bg_color(guicolor_T color) | |
5663 { | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5664 #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
|
5665 *gui.bgcolor = color_to_rgba(color); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5666 #else |
7 | 5667 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
|
5668 #endif |
7 | 5669 } |
5670 | |
207 | 5671 /* |
5672 * Set the current text special color. | |
5673 */ | |
5674 void | |
5675 gui_mch_set_sp_color(guicolor_T color) | |
5676 { | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5677 #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
|
5678 *gui.spcolor = color_to_rgba(color); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5679 #else |
207 | 5680 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
|
5681 #endif |
207 | 5682 } |
5683 | |
7 | 5684 /* |
5685 * Function-like convenience macro for the sake of efficiency. | |
5686 */ | |
5687 #define INSERT_PANGO_ATTR(Attribute, AttrList, Start, End) \ | |
5688 G_STMT_START{ \ | |
5689 PangoAttribute *tmp_attr_; \ | |
5690 tmp_attr_ = (Attribute); \ | |
5691 tmp_attr_->start_index = (Start); \ | |
5692 tmp_attr_->end_index = (End); \ | |
5693 pango_attr_list_insert((AttrList), tmp_attr_); \ | |
5694 }G_STMT_END | |
5695 | |
5696 static void | |
5697 apply_wide_font_attr(char_u *s, int len, PangoAttrList *attr_list) | |
5698 { | |
5699 char_u *start = NULL; | |
5700 char_u *p; | |
5701 int uc; | |
5702 | |
5703 for (p = s; p < s + len; p += utf_byte2len(*p)) | |
5704 { | |
5705 uc = utf_ptr2char(p); | |
5706 | |
5707 if (start == NULL) | |
5708 { | |
5709 if (uc >= 0x80 && utf_char2cells(uc) == 2) | |
5710 start = p; | |
5711 } | |
5712 else if (uc < 0x80 /* optimization shortcut */ | |
5713 || (utf_char2cells(uc) != 2 && !utf_iscomposing(uc))) | |
5714 { | |
5715 INSERT_PANGO_ATTR(pango_attr_font_desc_new(gui.wide_font), | |
5716 attr_list, start - s, p - s); | |
5717 start = NULL; | |
5718 } | |
5719 } | |
5720 | |
5721 if (start != NULL) | |
5722 INSERT_PANGO_ATTR(pango_attr_font_desc_new(gui.wide_font), | |
5723 attr_list, start - s, len); | |
5724 } | |
5725 | |
5726 static int | |
5727 count_cluster_cells(char_u *s, PangoItem *item, | |
5728 PangoGlyphString* glyphs, int i, | |
5729 int *cluster_width, | |
5730 int *last_glyph_rbearing) | |
5731 { | |
5732 char_u *p; | |
5733 int next; /* glyph start index of next cluster */ | |
5734 int start, end; /* string segment of current cluster */ | |
5735 int width; /* real cluster width in Pango units */ | |
5736 int uc; | |
5737 int cellcount = 0; | |
5738 | |
5739 width = glyphs->glyphs[i].geometry.width; | |
5740 | |
5741 for (next = i + 1; next < glyphs->num_glyphs; ++next) | |
5742 { | |
5743 if (glyphs->glyphs[next].attr.is_cluster_start) | |
5744 break; | |
5745 else if (glyphs->glyphs[next].geometry.width > width) | |
5746 width = glyphs->glyphs[next].geometry.width; | |
5747 } | |
5748 | |
5749 start = item->offset + glyphs->log_clusters[i]; | |
5750 end = item->offset + ((next < glyphs->num_glyphs) ? | |
5751 glyphs->log_clusters[next] : item->length); | |
5752 | |
5753 for (p = s + start; p < s + end; p += utf_byte2len(*p)) | |
5754 { | |
5755 uc = utf_ptr2char(p); | |
5756 if (uc < 0x80) | |
5757 ++cellcount; | |
5758 else if (!utf_iscomposing(uc)) | |
5759 cellcount += utf_char2cells(uc); | |
5760 } | |
5761 | |
5762 if (last_glyph_rbearing != NULL | |
5763 && cellcount > 0 && next == glyphs->num_glyphs) | |
5764 { | |
5765 PangoRectangle ink_rect; | |
5766 /* | |
5767 * If a certain combining mark had to be taken from a non-monospace | |
5768 * font, we have to compensate manually by adapting x_offset according | |
5769 * to the ink extents of the previous glyph. | |
5770 */ | |
5771 pango_font_get_glyph_extents(item->analysis.font, | |
5772 glyphs->glyphs[i].glyph, | |
5773 &ink_rect, NULL); | |
5774 | |
5775 if (PANGO_RBEARING(ink_rect) > 0) | |
5776 *last_glyph_rbearing = PANGO_RBEARING(ink_rect); | |
5777 } | |
5778 | |
5779 if (cellcount > 0) | |
5780 *cluster_width = width; | |
5781 | |
5782 return cellcount; | |
5783 } | |
5784 | |
5785 /* | |
5786 * If there are only combining characters in the cluster, we cannot just | |
5787 * change the width of the previous glyph since there is none. Therefore | |
5788 * some guesswork is needed. | |
5789 * | |
5790 * If ink_rect.x is negative Pango apparently has taken care of the composing | |
5791 * by itself. Actually setting x_offset = 0 should be sufficient then, but due | |
5792 * 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
|
5793 * x_offset to avoid ugliness. |
7 | 5794 * |
5795 * If ink_rect.x is not negative, force overstriking by pointing x_offset to | |
5796 * the position of the previous glyph. Apparently this happens only with old | |
5797 * X fonts which don't provide the special combining information needed by | |
5798 * Pango. | |
5799 */ | |
5800 static void | |
5801 setup_zero_width_cluster(PangoItem *item, PangoGlyphInfo *glyph, | |
5802 int last_cellcount, int last_cluster_width, | |
5803 int last_glyph_rbearing) | |
5804 { | |
5805 PangoRectangle ink_rect; | |
5806 PangoRectangle logical_rect; | |
5807 int width; | |
5808 | |
5809 width = last_cellcount * gui.char_width * PANGO_SCALE; | |
5810 glyph->geometry.x_offset = -width + MAX(0, width - last_cluster_width) / 2; | |
5811 glyph->geometry.width = 0; | |
5812 | |
5813 pango_font_get_glyph_extents(item->analysis.font, | |
5814 glyph->glyph, | |
5815 &ink_rect, &logical_rect); | |
5816 if (ink_rect.x < 0) | |
5817 { | |
5818 glyph->geometry.x_offset += last_glyph_rbearing; | |
5819 glyph->geometry.y_offset = logical_rect.height | |
5820 - (gui.char_height - p_linespace) * PANGO_SCALE; | |
5821 } | |
2507
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
5822 else |
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
5823 /* 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
|
5824 * 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
|
5825 glyph->geometry.x_offset = -width + MAX(0, width - ink_rect.width) / 2; |
7 | 5826 } |
5827 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5828 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5829 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5830 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
|
5831 PangoFont *font, PangoGlyphString *glyphs, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5832 cairo_t *cr) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5833 #else |
7 | 5834 static void |
5835 draw_glyph_string(int row, int col, int num_cells, int flags, | |
5836 PangoFont *font, PangoGlyphString *glyphs) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5837 #endif |
7 | 5838 { |
5839 if (!(flags & DRAW_TRANSP)) | |
5840 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5841 #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
|
5842 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5843 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
|
5844 gui.bgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5845 cairo_rectangle(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5846 FILL_X(col), FILL_Y(row), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5847 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
|
5848 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5849 #else |
7 | 5850 gdk_gc_set_foreground(gui.text_gc, gui.bgcolor); |
5851 | |
5852 gdk_draw_rectangle(gui.drawarea->window, | |
5853 gui.text_gc, | |
5854 TRUE, | |
5855 FILL_X(col), | |
5856 FILL_Y(row), | |
5857 num_cells * gui.char_width, | |
5858 gui.char_height); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5859 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5860 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5861 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5862 #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
|
5863 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5864 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
|
5865 gui.fgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5866 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
|
5867 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
|
5868 #else |
7 | 5869 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
5870 | |
5871 gdk_draw_glyphs(gui.drawarea->window, | |
5872 gui.text_gc, | |
5873 font, | |
5874 TEXT_X(col), | |
5875 TEXT_Y(row), | |
5876 glyphs); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5877 #endif |
7 | 5878 |
5879 /* redraw the contents with an offset of 1 to emulate bold */ | |
5880 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
|
5881 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5882 { |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5883 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5884 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
|
5885 gui.fgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5886 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
|
5887 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
|
5888 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5889 #else |
7 | 5890 gdk_draw_glyphs(gui.drawarea->window, |
5891 gui.text_gc, | |
5892 font, | |
5893 TEXT_X(col) + 1, | |
5894 TEXT_Y(row), | |
5895 glyphs); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5896 #endif |
7 | 5897 } |
5898 | |
207 | 5899 /* |
5900 * Draw underline and undercurl at the bottom of the character cell. | |
5901 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5902 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5903 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5904 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
|
5905 #else |
207 | 5906 static void |
5907 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
|
5908 #endif |
207 | 5909 { |
5910 int i; | |
5911 int offset; | |
1884 | 5912 static const int val[8] = {1, 0, 0, 0, 1, 2, 2, 2 }; |
207 | 5913 int y = FILL_Y(row + 1) - 1; |
5914 | |
5915 /* Undercurl: draw curl at the bottom of the character cell. */ | |
5916 if (flags & DRAW_UNDERC) | |
5917 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5918 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5919 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
|
5920 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
|
5921 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5922 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
|
5923 gui.spcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5924 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
|
5925 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5926 offset = val[i % 8]; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5927 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
|
5928 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5929 cairo_stroke(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5930 #else |
207 | 5931 gdk_gc_set_foreground(gui.text_gc, gui.spcolor); |
5932 for (i = FILL_X(col); i < FILL_X(col + cells); ++i) | |
5933 { | |
5934 offset = val[i % 8]; | |
5935 gdk_draw_point(gui.drawarea->window, gui.text_gc, i, y - offset); | |
5936 } | |
5937 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
|
5938 #endif |
207 | 5939 } |
5940 | |
5941 /* Underline: draw a line at the bottom of the character cell. */ | |
5942 if (flags & DRAW_UNDERL) | |
5943 { | |
5944 /* When p_linespace is 0, overwrite the bottom row of pixels. | |
5945 * Otherwise put the line just below the character. */ | |
5946 if (p_linespace > 1) | |
5947 y -= p_linespace - 1; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5948 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5949 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5950 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
|
5951 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
|
5952 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5953 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
|
5954 gui.fgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5955 cairo_move_to(cr, FILL_X(col), y + 0.5); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5956 cairo_line_to(cr, FILL_X(col + cells), y + 0.5); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5957 cairo_stroke(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5958 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5959 #else |
207 | 5960 gdk_draw_line(gui.drawarea->window, gui.text_gc, |
5961 FILL_X(col), y, | |
5962 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
|
5963 #endif |
207 | 5964 } |
5965 } | |
5966 | |
7 | 5967 int |
5968 gui_gtk2_draw_string(int row, int col, char_u *s, int len, int flags) | |
5969 { | |
5970 GdkRectangle area; /* area for clip mask */ | |
5971 PangoGlyphString *glyphs; /* glyphs of current item */ | |
5972 int column_offset = 0; /* column offset in cells */ | |
5973 int i; | |
5974 char_u *conv_buf = NULL; /* result of UTF-8 conversion */ | |
5975 char_u *new_conv_buf; | |
5976 int convlen; | |
5977 char_u *sp, *bp; | |
5978 int plen; | |
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) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5980 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5981 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5982 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5983 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5984 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
|
5985 #else |
7 | 5986 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
|
5987 #endif |
7 | 5988 return len; |
5989 | |
5990 if (output_conv.vc_type != CONV_NONE) | |
5991 { | |
5992 /* | |
5993 * Convert characters from 'encoding' to 'termencoding', which is set | |
5994 * to UTF-8 by gui_mch_init(). did_set_string_option() in option.c | |
5995 * prohibits changing this to something else than UTF-8 if the GUI is | |
5996 * in use. | |
5997 */ | |
5998 convlen = len; | |
5999 conv_buf = string_convert(&output_conv, s, &convlen); | |
6000 g_return_val_if_fail(conv_buf != NULL, len); | |
6001 | |
6002 /* Correct for differences in char width: some chars are | |
6003 * double-wide in 'encoding' but single-wide in utf-8. Add a space to | |
6004 * compensate for that. */ | |
6005 for (sp = s, bp = conv_buf; sp < s + len && bp < conv_buf + convlen; ) | |
6006 { | |
474 | 6007 plen = utf_ptr2len(bp); |
7 | 6008 if ((*mb_ptr2cells)(sp) == 2 && utf_ptr2cells(bp) == 1) |
6009 { | |
6010 new_conv_buf = alloc(convlen + 2); | |
6011 if (new_conv_buf == NULL) | |
6012 return len; | |
6013 plen += bp - conv_buf; | |
6014 mch_memmove(new_conv_buf, conv_buf, plen); | |
6015 new_conv_buf[plen] = ' '; | |
6016 mch_memmove(new_conv_buf + plen + 1, conv_buf + plen, | |
6017 convlen - plen + 1); | |
6018 vim_free(conv_buf); | |
6019 conv_buf = new_conv_buf; | |
6020 ++convlen; | |
6021 bp = conv_buf + plen; | |
6022 plen = 1; | |
6023 } | |
474 | 6024 sp += (*mb_ptr2len)(sp); |
7 | 6025 bp += plen; |
6026 } | |
6027 s = conv_buf; | |
6028 len = convlen; | |
6029 } | |
6030 | |
6031 /* | |
6032 * Restrict all drawing to the current screen line in order to prevent | |
6033 * fuzzy font lookups from messing up the screen. | |
6034 */ | |
6035 area.x = gui.border_offset; | |
6036 area.y = FILL_Y(row); | |
6037 area.width = gui.num_cols * gui.char_width; | |
6038 area.height = gui.char_height; | |
6039 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6040 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6041 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6042 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
|
6043 cairo_clip(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6044 #else |
7 | 6045 gdk_gc_set_clip_origin(gui.text_gc, 0, 0); |
6046 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
|
6047 #endif |
7 | 6048 |
6049 glyphs = pango_glyph_string_new(); | |
6050 | |
6051 /* | |
6052 * Optimization hack: If possible, skip the itemize and shaping process | |
6053 * for pure ASCII strings. This optimization is particularly effective | |
6054 * because Vim draws space characters to clear parts of the screen. | |
6055 */ | |
6056 if (!(flags & DRAW_ITALIC) | |
6057 && !((flags & DRAW_BOLD) && gui.font_can_bold) | |
6058 && gui.ascii_glyphs != NULL) | |
6059 { | |
6060 char_u *p; | |
6061 | |
6062 for (p = s; p < s + len; ++p) | |
6063 if (*p & 0x80) | |
6064 goto not_ascii; | |
6065 | |
6066 pango_glyph_string_set_size(glyphs, len); | |
6067 | |
6068 for (i = 0; i < len; ++i) | |
6069 { | |
9879
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
6070 glyphs->glyphs[i] = gui.ascii_glyphs->glyphs[2 * s[i]]; |
7 | 6071 glyphs->log_clusters[i] = i; |
6072 } | |
6073 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6074 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6075 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
|
6076 #else |
7 | 6077 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
|
6078 #endif |
7 | 6079 |
6080 column_offset = len; | |
6081 } | |
6082 else | |
6083 not_ascii: | |
6084 { | |
6085 PangoAttrList *attr_list; | |
6086 GList *item_list; | |
6087 int cluster_width; | |
6088 int last_glyph_rbearing; | |
6089 int cells = 0; /* cells occupied by current cluster */ | |
6090 | |
26 | 6091 /* Safety check: pango crashes when invoked with invalid utf-8 |
6092 * characters. */ | |
6093 if (!utf_valid_string(s, s + len)) | |
6094 { | |
6095 column_offset = len; | |
6096 goto skipitall; | |
6097 } | |
6098 | |
7 | 6099 /* original width of the current cluster */ |
6100 cluster_width = PANGO_SCALE * gui.char_width; | |
6101 | |
6102 /* right bearing of the last non-composing glyph */ | |
6103 last_glyph_rbearing = PANGO_SCALE * gui.char_width; | |
6104 | |
6105 attr_list = pango_attr_list_new(); | |
6106 | |
6107 /* If 'guifontwide' is set then use that for double-width characters. | |
6108 * Otherwise just go with 'guifont' and let Pango do its thing. */ | |
6109 if (gui.wide_font != NULL) | |
6110 apply_wide_font_attr(s, len, attr_list); | |
6111 | |
6112 if ((flags & DRAW_BOLD) && gui.font_can_bold) | |
6113 INSERT_PANGO_ATTR(pango_attr_weight_new(PANGO_WEIGHT_BOLD), | |
6114 attr_list, 0, len); | |
6115 if (flags & DRAW_ITALIC) | |
6116 INSERT_PANGO_ATTR(pango_attr_style_new(PANGO_STYLE_ITALIC), | |
6117 attr_list, 0, len); | |
6118 /* | |
6119 * Break the text into segments with consistent directional level | |
6120 * and shaping engine. Pure Latin text needs only a single segment, | |
6121 * so there's no need to worry about the loop's efficiency. Better | |
6122 * try to optimize elsewhere, e.g. reducing exposes and stuff :) | |
6123 */ | |
6124 item_list = pango_itemize(gui.text_context, | |
6125 (const char *)s, 0, len, attr_list, NULL); | |
6126 | |
6127 while (item_list != NULL) | |
6128 { | |
6129 PangoItem *item; | |
6130 int item_cells = 0; /* item length in cells */ | |
6131 | |
6132 item = (PangoItem *)item_list->data; | |
6133 item_list = g_list_delete_link(item_list, item_list); | |
6134 /* | |
6135 * Increment the bidirectional embedding level by 1 if it is not | |
6136 * even. An odd number means the output will be RTL, but we don't | |
6137 * want that since Vim handles right-to-left text on its own. It | |
6138 * would probably be sufficient to just set level = 0, but you can | |
6139 * never know :) | |
6140 * | |
6141 * Unfortunately we can't take advantage of Pango's ability to | |
6142 * render both LTR and RTL at the same time. In order to support | |
6143 * that, Vim's main screen engine would have to make use of Pango | |
6144 * functionality. | |
6145 */ | |
6146 item->analysis.level = (item->analysis.level + 1) & (~1U); | |
6147 | |
6148 /* HACK: Overrule the shape engine, we don't want shaping to be | |
6149 * done, because drawing the cursor would change the display. */ | |
6150 item->analysis.shape_engine = default_shape_engine; | |
6151 | |
7098
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6152 #ifdef HAVE_PANGO_SHAPE_FULL |
7086
3825da022231
commit https://github.com/vim/vim/commit/7e2ec008f5c5152205d0b8a7d88177b374225d8d
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
6153 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
|
6154 (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
|
6155 #else |
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6156 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
|
6157 &item->analysis, glyphs); |
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6158 #endif |
7 | 6159 /* |
6160 * Fixed-width hack: iterate over the array and assign a fixed | |
6161 * width to each glyph, thus overriding the choice made by the | |
6162 * shaping engine. We use utf_char2cells() to determine the | |
6163 * number of cells needed. | |
6164 * | |
6165 * Also perform all kind of dark magic to get composing | |
6166 * characters right (and pretty too of course). | |
6167 */ | |
6168 for (i = 0; i < glyphs->num_glyphs; ++i) | |
6169 { | |
6170 PangoGlyphInfo *glyph; | |
6171 | |
6172 glyph = &glyphs->glyphs[i]; | |
6173 | |
6174 if (glyph->attr.is_cluster_start) | |
6175 { | |
6176 int cellcount; | |
6177 | |
6178 cellcount = count_cluster_cells( | |
6179 s, item, glyphs, i, &cluster_width, | |
6180 (item_list != NULL) ? &last_glyph_rbearing : NULL); | |
6181 | |
6182 if (cellcount > 0) | |
6183 { | |
6184 int width; | |
6185 | |
6186 width = cellcount * gui.char_width * PANGO_SCALE; | |
6187 glyph->geometry.x_offset += | |
6188 MAX(0, width - cluster_width) / 2; | |
6189 glyph->geometry.width = width; | |
6190 } | |
6191 else | |
6192 { | |
6193 /* If there are only combining characters in the | |
6194 * cluster, we cannot just change the width of the | |
6195 * previous glyph since there is none. Therefore | |
6196 * some guesswork is needed. */ | |
6197 setup_zero_width_cluster(item, glyph, cells, | |
6198 cluster_width, | |
6199 last_glyph_rbearing); | |
6200 } | |
6201 | |
6202 item_cells += cellcount; | |
6203 cells = cellcount; | |
6204 } | |
6205 else if (i > 0) | |
6206 { | |
6207 int width; | |
6208 | |
6209 /* 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
|
6210 * characters the canonical way. |
2517
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6211 * 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
|
6212 * 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
|
6213 * and set the previous width to zero. |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6214 * 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
|
6215 * 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
|
6216 * 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
|
6217 * 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
|
6218 * 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
|
6219 if (glyph->geometry.x_offset >= 0) |
2517
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6220 { |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6221 glyphs->glyphs[i].geometry.width = |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6222 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
|
6223 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
|
6224 } |
7 | 6225 width = cells * gui.char_width * PANGO_SCALE; |
6226 glyph->geometry.x_offset += | |
6227 MAX(0, width - cluster_width) / 2; | |
6228 } | |
6229 else /* i == 0 "cannot happen" */ | |
6230 { | |
6231 glyph->geometry.width = 0; | |
6232 } | |
6233 } | |
6234 | |
6235 /*** Aaaaand action! ***/ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6236 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6237 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
|
6238 flags, item->analysis.font, glyphs, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6239 cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6240 #else |
7 | 6241 draw_glyph_string(row, col + column_offset, item_cells, |
6242 flags, item->analysis.font, glyphs); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6243 #endif |
7 | 6244 |
6245 pango_item_free(item); | |
6246 | |
6247 column_offset += item_cells; | |
6248 } | |
6249 | |
6250 pango_attr_list_unref(attr_list); | |
6251 } | |
6252 | |
26 | 6253 skipitall: |
207 | 6254 /* Draw underline and undercurl. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6255 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6256 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
|
6257 #else |
207 | 6258 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
|
6259 #endif |
7 | 6260 |
6261 pango_glyph_string_free(glyphs); | |
6262 vim_free(conv_buf); | |
6263 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6264 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6265 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6266 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6267 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
|
6268 &area, FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6269 #else |
7 | 6270 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
|
6271 #endif |
7 | 6272 |
6273 return column_offset; | |
6274 } | |
6275 | |
6276 /* | |
6277 * Return OK if the key with the termcap name "name" is supported. | |
6278 */ | |
6279 int | |
6280 gui_mch_haskey(char_u *name) | |
6281 { | |
6282 int i; | |
6283 | |
6284 for (i = 0; special_keys[i].key_sym != 0; i++) | |
6285 if (name[0] == special_keys[i].code0 | |
6286 && name[1] == special_keys[i].code1) | |
6287 return OK; | |
6288 return FAIL; | |
6289 } | |
6290 | |
4133 | 6291 #if defined(FEAT_TITLE) || defined(FEAT_EVAL) || defined(PROTO) |
7 | 6292 /* |
6293 * Return the text window-id and display. Only required for X-based GUI's | |
6294 */ | |
6295 int | |
6296 gui_get_x11_windis(Window *win, Display **dis) | |
6297 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6298 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6299 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
|
6300 #else |
7 | 6301 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
|
6302 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6303 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6304 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6305 *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
|
6306 *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
|
6307 #else |
7 | 6308 *dis = GDK_WINDOW_XDISPLAY(gui.mainwin->window); |
6309 *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
|
6310 #endif |
7 | 6311 return OK; |
6312 } | |
6313 | |
6314 *dis = NULL; | |
6315 *win = 0; | |
6316 return FAIL; | |
6317 } | |
6318 #endif | |
6319 | |
6320 #if defined(FEAT_CLIENTSERVER) \ | |
6321 || (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO) | |
6322 | |
6323 Display * | |
6324 gui_mch_get_display(void) | |
6325 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6326 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6327 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
|
6328 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
|
6329 #else |
7 | 6330 if (gui.mainwin != NULL && gui.mainwin->window != NULL) |
6331 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
|
6332 #endif |
7 | 6333 else |
6334 return NULL; | |
6335 } | |
6336 #endif | |
6337 | |
6338 void | |
6339 gui_mch_beep(void) | |
6340 { | |
6341 #ifdef HAVE_GTK_MULTIHEAD | |
6342 GdkDisplay *display; | |
6343 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6344 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6345 if (gui.mainwin != NULL && gtk_widget_get_realized(gui.mainwin)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6346 # else |
7 | 6347 if (gui.mainwin != NULL && GTK_WIDGET_REALIZED(gui.mainwin)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6348 # endif |
7 | 6349 display = gtk_widget_get_display(gui.mainwin); |
6350 else | |
6351 display = gdk_display_get_default(); | |
6352 | |
6353 if (display != NULL) | |
6354 gdk_display_beep(display); | |
6355 #else | |
6356 gdk_beep(); | |
6357 #endif | |
6358 } | |
6359 | |
6360 void | |
6361 gui_mch_flash(int msec) | |
6362 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6363 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6364 /* TODO Replace GdkGC with Cairo */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6365 (void)msec; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6366 #else |
7 | 6367 GdkGCValues values; |
6368 GdkGC *invert_gc; | |
6369 | |
6370 if (gui.drawarea->window == NULL) | |
6371 return; | |
6372 | |
6373 values.foreground.pixel = gui.norm_pixel ^ gui.back_pixel; | |
6374 values.background.pixel = gui.norm_pixel ^ gui.back_pixel; | |
6375 values.function = GDK_XOR; | |
6376 invert_gc = gdk_gc_new_with_values(gui.drawarea->window, | |
6377 &values, | |
6378 GDK_GC_FOREGROUND | | |
6379 GDK_GC_BACKGROUND | | |
6380 GDK_GC_FUNCTION); | |
6381 gdk_gc_set_exposures(invert_gc, | |
6382 gui.visibility != GDK_VISIBILITY_UNOBSCURED); | |
6383 /* | |
6384 * Do a visual beep by changing back and forth in some undetermined way, | |
6385 * the foreground and background colors. This is due to the fact that | |
6386 * there can't be really any prediction about the effects of XOR on | |
6387 * arbitrary X11 servers. However this seems to be enough for what we | |
6388 * intend it to do. | |
6389 */ | |
6390 gdk_draw_rectangle(gui.drawarea->window, invert_gc, | |
6391 TRUE, | |
6392 0, 0, | |
6393 FILL_X((int)Columns) + gui.border_offset, | |
6394 FILL_Y((int)Rows) + gui.border_offset); | |
6395 | |
6396 gui_mch_flush(); | |
6397 ui_delay((long)msec, TRUE); /* wait so many msec */ | |
6398 | |
6399 gdk_draw_rectangle(gui.drawarea->window, invert_gc, | |
6400 TRUE, | |
6401 0, 0, | |
6402 FILL_X((int)Columns) + gui.border_offset, | |
6403 FILL_Y((int)Rows) + gui.border_offset); | |
6404 | |
6405 gdk_gc_destroy(invert_gc); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6406 #endif |
7 | 6407 } |
6408 | |
6409 /* | |
6410 * Invert a rectangle from row r, column c, for nr rows and nc columns. | |
6411 */ | |
6412 void | |
6413 gui_mch_invert_rectangle(int r, int c, int nr, int nc) | |
6414 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6415 #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
|
6416 const GdkRectangle rect = { |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6417 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
|
6418 }; |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6419 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
|
6420 |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6421 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
|
6422 # 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
|
6423 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
|
6424 # else |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6425 /* 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
|
6426 # endif |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6427 gdk_cairo_rectangle(cr, &rect); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6428 cairo_fill(cr); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6429 |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6430 cairo_destroy(cr); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6431 |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6432 if (!gui.by_signal) |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6433 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
|
6434 rect.width, rect.height); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6435 #else |
7 | 6436 GdkGCValues values; |
6437 GdkGC *invert_gc; | |
6438 | |
6439 if (gui.drawarea->window == NULL) | |
6440 return; | |
6441 | |
944 | 6442 values.foreground.pixel = gui.norm_pixel ^ gui.back_pixel; |
6443 values.background.pixel = gui.norm_pixel ^ gui.back_pixel; | |
7 | 6444 values.function = GDK_XOR; |
6445 invert_gc = gdk_gc_new_with_values(gui.drawarea->window, | |
6446 &values, | |
6447 GDK_GC_FOREGROUND | | |
6448 GDK_GC_BACKGROUND | | |
6449 GDK_GC_FUNCTION); | |
944 | 6450 gdk_gc_set_exposures(invert_gc, gui.visibility != |
6451 GDK_VISIBILITY_UNOBSCURED); | |
7 | 6452 gdk_draw_rectangle(gui.drawarea->window, invert_gc, |
6453 TRUE, | |
6454 FILL_X(c), FILL_Y(r), | |
6455 (nc) * gui.char_width, (nr) * gui.char_height); | |
6456 gdk_gc_destroy(invert_gc); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6457 #endif |
7 | 6458 } |
6459 | |
6460 /* | |
6461 * Iconify the GUI window. | |
6462 */ | |
6463 void | |
6464 gui_mch_iconify(void) | |
6465 { | |
6466 gtk_window_iconify(GTK_WINDOW(gui.mainwin)); | |
6467 } | |
6468 | |
6469 #if defined(FEAT_EVAL) || defined(PROTO) | |
6470 /* | |
6471 * Bring the Vim window to the foreground. | |
6472 */ | |
6473 void | |
6474 gui_mch_set_foreground(void) | |
6475 { | |
6476 gtk_window_present(GTK_WINDOW(gui.mainwin)); | |
6477 } | |
6478 #endif | |
6479 | |
6480 /* | |
6481 * Draw a cursor without focus. | |
6482 */ | |
6483 void | |
6484 gui_mch_draw_hollow_cursor(guicolor_T color) | |
6485 { | |
6486 int i = 1; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6487 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6488 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6489 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6490 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6491 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6492 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
|
6493 #else |
7 | 6494 if (gui.drawarea->window == NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6495 #endif |
7 | 6496 return; |
6497 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6498 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6499 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6500 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6501 |
7 | 6502 gui_mch_set_fg_color(color); |
6503 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6504 #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
|
6505 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6506 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
|
6507 gui.fgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6508 #else |
7 | 6509 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
|
6510 #endif |
7 | 6511 if (mb_lefthalve(gui.row, gui.col)) |
6512 i = 2; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6513 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6514 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
|
6515 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
|
6516 cairo_rectangle(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6517 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
|
6518 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
|
6519 cairo_stroke(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6520 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6521 #else |
7 | 6522 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, |
6523 FALSE, | |
6524 FILL_X(gui.col), FILL_Y(gui.row), | |
6525 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
|
6526 #endif |
7 | 6527 } |
6528 | |
6529 /* | |
6530 * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using | |
6531 * color "color". | |
6532 */ | |
6533 void | |
6534 gui_mch_draw_part_cursor(int w, int h, guicolor_T color) | |
6535 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6536 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6537 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
|
6538 #else |
7 | 6539 if (gui.drawarea->window == NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6540 #endif |
7 | 6541 return; |
6542 | |
6543 gui_mch_set_fg_color(color); | |
6544 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6545 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6546 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6547 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6548 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6549 cr = cairo_create(gui.surface); |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6550 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6551 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
|
6552 gui.fgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6553 cairo_rectangle(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6554 # ifdef FEAT_RIGHTLEFT |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6555 /* 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
|
6556 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
|
6557 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6558 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
|
6559 w, h); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6560 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6561 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6562 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6563 #else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6564 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
6565 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, | |
6566 TRUE, | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6567 # ifdef FEAT_RIGHTLEFT |
7 | 6568 /* vertical line should be on the right of current point */ |
6569 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
|
6570 # endif |
7 | 6571 FILL_X(gui.col), |
6572 FILL_Y(gui.row) + gui.char_height - h, | |
6573 w, h); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6574 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6575 } |
6576 | |
6577 | |
6578 /* | |
6579 * Catch up with any queued X11 events. This may put keyboard input into the | |
6580 * input buffer, call resize call-backs, trigger timers etc. If there is | |
6581 * nothing in the X11 event queue (& no timers pending), then we return | |
6582 * immediately. | |
6583 */ | |
6584 void | |
6585 gui_mch_update(void) | |
6586 { | |
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
|
6587 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
|
6588 g_main_context_iteration(NULL, TRUE); |
7 | 6589 } |
6590 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6591 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6592 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6593 #else |
7 | 6594 static gint |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6595 #endif |
7 | 6596 input_timer_cb(gpointer data) |
6597 { | |
6598 int *timed_out = (int *) data; | |
6599 | |
1226 | 6600 /* Just inform the caller about the occurrence of it */ |
7 | 6601 *timed_out = TRUE; |
6602 | |
6603 return FALSE; /* don't happen again */ | |
6604 } | |
6605 | |
6606 /* | |
6607 * GUI input routine called by gui_wait_for_chars(). Waits for a character | |
6608 * from the keyboard. | |
6609 * wtime == -1 Wait forever. | |
6610 * wtime == 0 This should never happen. | |
6611 * wtime > 0 Wait wtime milliseconds for a character. | |
6612 * Returns OK if a character was found to be available within the given time, | |
6613 * or FAIL otherwise. | |
6614 */ | |
6615 int | |
6616 gui_mch_wait_for_chars(long wtime) | |
6617 { | |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6618 int focus; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6619 guint timer; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6620 static int timed_out; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6621 int retval = FAIL; |
7 | 6622 |
6623 timed_out = FALSE; | |
6624 | |
6625 /* this timeout makes sure that we will return if no characters arrived in | |
6626 * time */ | |
6627 if (wtime > 0) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6628 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6629 timer = g_timeout_add((guint)wtime, input_timer_cb, &timed_out); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6630 #else |
7 | 6631 timer = gtk_timeout_add((guint32)wtime, input_timer_cb, &timed_out); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6632 #endif |
7 | 6633 else |
6634 timer = 0; | |
6635 | |
6636 focus = gui.in_focus; | |
6637 | |
6638 do | |
6639 { | |
6640 /* Stop or start blinking when focus changes */ | |
6641 if (gui.in_focus != focus) | |
6642 { | |
6643 if (gui.in_focus) | |
6644 gui_mch_start_blink(); | |
6645 else | |
6646 gui_mch_stop_blink(); | |
6647 focus = gui.in_focus; | |
6648 } | |
6649 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
6650 #ifdef MESSAGE_QUEUE |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6651 # ifdef FEAT_TIMERS |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6652 did_add_timer = FALSE; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6653 # endif |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
6654 parse_queued_messages(); |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6655 # ifdef FEAT_TIMERS |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6656 if (did_add_timer) |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6657 /* Need to recompute the waiting time. */ |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6658 goto theend; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6659 # endif |
1624 | 6660 #endif |
6661 | |
7 | 6662 /* |
6663 * Loop in GTK+ processing until a timeout or input occurs. | |
22 | 6664 * Skip this if input is available anyway (can happen in rare |
6665 * situations, sort of race condition). | |
7 | 6666 */ |
22 | 6667 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
|
6668 g_main_context_iteration(NULL, TRUE); |
7 | 6669 |
6670 /* Got char, return immediately */ | |
6671 if (input_available()) | |
6672 { | |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6673 retval = OK; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6674 goto theend; |
7 | 6675 } |
6676 } while (wtime < 0 || !timed_out); | |
6677 | |
6678 /* | |
6679 * Flush all eventually pending (drawing) events. | |
6680 */ | |
6681 gui_mch_update(); | |
6682 | |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6683 theend: |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6684 if (timer != 0 && !timed_out) |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6685 #if GTK_CHECK_VERSION(3,0,0) |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6686 g_source_remove(timer); |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6687 #else |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6688 gtk_timeout_remove(timer); |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6689 #endif |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6690 |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6691 return retval; |
7 | 6692 } |
6693 | |
6694 | |
6695 /**************************************************************************** | |
6696 * Output drawing routines. | |
6697 ****************************************************************************/ | |
6698 | |
6699 | |
6700 /* Flush any output to the screen */ | |
6701 void | |
6702 gui_mch_flush(void) | |
6703 { | |
6704 #ifdef HAVE_GTK_MULTIHEAD | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6705 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6706 if (gui.mainwin != NULL && gtk_widget_get_realized(gui.mainwin)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6707 # else |
7 | 6708 if (gui.mainwin != NULL && GTK_WIDGET_REALIZED(gui.mainwin)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6709 # endif |
9523
9d1abad90d6c
commit https://github.com/vim/vim/commit/fdadad994a6e8f6cc8b11519082e23200b96d0ba
Christian Brabandt <cb@256bit.org>
parents:
9489
diff
changeset
|
6710 gdk_display_flush(gtk_widget_get_display(gui.mainwin)); |
7 | 6711 #else |
6712 gdk_flush(); /* historical misnomer: calls XSync(), not XFlush() */ | |
6713 #endif | |
6714 } | |
6715 | |
6716 /* | |
6717 * Clear a rectangular region of the screen from text pos (row1, col1) to | |
6718 * (row2, col2) inclusive. | |
6719 */ | |
6720 void | |
10920
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6721 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
|
6722 { |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6723 |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6724 int col1 = check_col(col1arg); |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6725 int col2 = check_col(col2arg); |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6726 int row1 = check_row(row1arg); |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6727 int row2 = check_row(row2arg); |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6728 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6729 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6730 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
|
6731 return; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6732 #else |
7 | 6733 GdkColor color; |
6734 | |
6735 if (gui.drawarea->window == NULL) | |
6736 return; | |
6737 | |
6738 color.pixel = gui.back_pixel; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6739 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6740 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6741 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6742 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6743 /* 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
|
6744 * bold glyph may sit there. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6745 const GdkRectangle rect = { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6746 FILL_X(col1), FILL_Y(row1), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6747 (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
|
6748 (row2 - row1 + 1) * gui.char_height |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6749 }; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6750 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
|
6751 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
|
6752 # 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
|
6753 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
|
6754 # else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6755 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
|
6756 if (pat != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6757 cairo_set_source(cr, pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6758 else |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6759 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
|
6760 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6761 gdk_cairo_rectangle(cr, &rect); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6762 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6763 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6764 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6765 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6766 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
|
6767 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6768 #else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6769 gdk_gc_set_foreground(gui.text_gc, &color); |
6770 | |
6771 /* Clear one extra pixel at the far right, for when bold characters have | |
6772 * spilled over to the window border. */ | |
6773 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, TRUE, | |
6774 FILL_X(col1), FILL_Y(row1), | |
6775 (col2 - col1 + 1) * gui.char_width | |
6776 + (col2 == Columns - 1), | |
6777 (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
|
6778 #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
|
6779 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6780 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6781 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6782 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6783 gui_gtk_window_clear(GdkWindow *win) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6784 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6785 const GdkRectangle rect = { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6786 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
|
6787 }; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6788 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
|
6789 # 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
|
6790 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
|
6791 # else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6792 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
|
6793 if (pat != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6794 cairo_set_source(cr, pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6795 else |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6796 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
|
6797 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6798 gdk_cairo_rectangle(cr, &rect); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6799 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6800 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6801 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6802 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6803 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
|
6804 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6805 #endif |
7 | 6806 |
6807 void | |
6808 gui_mch_clear_all(void) | |
6809 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6810 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6811 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
|
6812 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
|
6813 #else |
7 | 6814 if (gui.drawarea->window != NULL) |
6815 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
|
6816 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6817 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6818 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6819 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 6820 /* |
6821 * Redraw any text revealed by scrolling up/down. | |
6822 */ | |
6823 static void | |
6824 check_copy_area(void) | |
6825 { | |
6826 GdkEvent *event; | |
6827 int expose_count; | |
6828 | |
6829 if (gui.visibility != GDK_VISIBILITY_PARTIAL) | |
6830 return; | |
6831 | |
6832 /* Avoid redrawing the cursor while scrolling or it'll end up where | |
6833 * we don't want it to be. I'm not sure if it's correct to call | |
6834 * gui_dont_update_cursor() at this point but it works as a quick | |
6835 * fix for now. */ | |
9848
664276833670
commit https://github.com/vim/vim/commit/107abd2ca53c31fd3bb40d77ff296e98eaae2975
Christian Brabandt <cb@256bit.org>
parents:
9836
diff
changeset
|
6836 gui_dont_update_cursor(TRUE); |
7 | 6837 |
6838 do | |
6839 { | |
6840 /* Wait to check whether the scroll worked or not. */ | |
6841 event = gdk_event_get_graphics_expose(gui.drawarea->window); | |
6842 | |
6843 if (event == NULL) | |
6844 break; /* received NoExpose event */ | |
6845 | |
6846 gui_redraw(event->expose.area.x, event->expose.area.y, | |
6847 event->expose.area.width, event->expose.area.height); | |
6848 | |
6849 expose_count = event->expose.count; | |
6850 gdk_event_free(event); | |
6851 } | |
6852 while (expose_count > 0); /* more events follow */ | |
6853 | |
6854 gui_can_update_cursor(); | |
6855 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6856 #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
|
6857 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6858 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6859 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6860 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
|
6861 int src_x, int src_y, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6862 int width, int height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6863 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6864 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
|
6865 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6866 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
|
6867 cairo_clip(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6868 cairo_push_group(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6869 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
|
6870 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6871 cairo_pop_group_to_source(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6872 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6873 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6874 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6875 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6876 #endif |
7 | 6877 |
6878 /* | |
6879 * Delete the given number of lines from the given row, scrolling up any | |
6880 * text further down within the scroll region. | |
6881 */ | |
6882 void | |
6883 gui_mch_delete_lines(int row, int num_lines) | |
6884 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6885 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6886 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
|
6887 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
|
6888 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
|
6889 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6890 gui_gtk_surface_copy_rect( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6891 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
|
6892 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
|
6893 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
|
6894 gui_clear_block( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6895 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
|
6896 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
|
6897 gui_gtk3_redraw( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6898 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
|
6899 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
|
6900 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6901 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
|
6902 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
|
6903 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
|
6904 #else |
7 | 6905 if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) |
6906 return; /* Can't see the window */ | |
6907 | |
6908 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
6909 gdk_gc_set_background(gui.text_gc, gui.bgcolor); | |
6910 | |
6911 /* copy one extra pixel, for when bold has spilled over */ | |
6912 gdk_window_copy_area(gui.drawarea->window, gui.text_gc, | |
6913 FILL_X(gui.scroll_region_left), FILL_Y(row), | |
6914 gui.drawarea->window, | |
6915 FILL_X(gui.scroll_region_left), | |
6916 FILL_Y(row + num_lines), | |
6917 gui.char_width * (gui.scroll_region_right | |
6918 - gui.scroll_region_left + 1) + 1, | |
6919 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1)); | |
6920 | |
6921 gui_clear_block(gui.scroll_region_bot - num_lines + 1, | |
6922 gui.scroll_region_left, | |
6923 gui.scroll_region_bot, gui.scroll_region_right); | |
6924 check_copy_area(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6925 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6926 } |
6927 | |
6928 /* | |
6929 * Insert the given number of lines before the given row, scrolling down any | |
6930 * following text within the scroll region. | |
6931 */ | |
6932 void | |
6933 gui_mch_insert_lines(int row, int num_lines) | |
6934 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6935 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6936 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
|
6937 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
|
6938 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
|
6939 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6940 gui_gtk_surface_copy_rect( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6941 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
|
6942 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
|
6943 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
|
6944 gui_mch_clear_block( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6945 row, gui.scroll_region_left, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6946 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
|
6947 gui_gtk3_redraw( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6948 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
|
6949 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
|
6950 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6951 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
|
6952 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
|
6953 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
|
6954 #else |
7 | 6955 if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) |
6956 return; /* Can't see the window */ | |
6957 | |
6958 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
6959 gdk_gc_set_background(gui.text_gc, gui.bgcolor); | |
6960 | |
6961 /* copy one extra pixel, for when bold has spilled over */ | |
6962 gdk_window_copy_area(gui.drawarea->window, gui.text_gc, | |
6963 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), | |
6964 gui.drawarea->window, | |
6965 FILL_X(gui.scroll_region_left), FILL_Y(row), | |
6966 gui.char_width * (gui.scroll_region_right | |
6967 - gui.scroll_region_left + 1) + 1, | |
6968 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1)); | |
6969 | |
6970 gui_clear_block(row, gui.scroll_region_left, | |
6971 row + num_lines - 1, gui.scroll_region_right); | |
6972 check_copy_area(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6973 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6974 } |
6975 | |
6976 /* | |
6977 * X Selection stuff, for cutting and pasting text to other windows. | |
6978 */ | |
6979 void | |
6980 clip_mch_request_selection(VimClipboard *cbd) | |
6981 { | |
6982 GdkAtom target; | |
6983 unsigned i; | |
1494 | 6984 time_t start; |
7 | 6985 |
6986 for (i = 0; i < N_SELECTION_TARGETS; ++i) | |
6987 { | |
1904 | 6988 if (!clip_html && selection_targets[i].info == TARGET_HTML) |
6989 continue; | |
7 | 6990 received_selection = RS_NONE; |
6991 target = gdk_atom_intern(selection_targets[i].target, FALSE); | |
6992 | |
6993 gtk_selection_convert(gui.drawarea, | |
6994 cbd->gtk_sel_atom, target, | |
6995 (guint32)GDK_CURRENT_TIME); | |
6996 | |
1494 | 6997 /* Hack: Wait up to three seconds for the selection. A hang was |
6998 * noticed here when using the netrw plugin combined with ":gui" | |
6999 * during the FocusGained event. */ | |
7000 start = time(NULL); | |
7001 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
|
7002 g_main_context_iteration(NULL, TRUE); /* wait for selection_received_cb */ |
7 | 7003 |
7004 if (received_selection != RS_FAIL) | |
7005 return; | |
7006 } | |
7007 | |
7008 /* 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
|
7009 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7010 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
|
7011 cbd); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7012 #else |
1924 | 7013 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
|
7014 #endif |
7 | 7015 } |
7016 | |
7017 /* | |
7018 * Disown the selection. | |
7019 */ | |
7020 void | |
1884 | 7021 clip_mch_lose_selection(VimClipboard *cbd UNUSED) |
7 | 7022 { |
4209 | 7023 gtk_selection_owner_set(NULL, cbd->gtk_sel_atom, gui.event_time); |
7 | 7024 gui_mch_update(); |
7025 } | |
7026 | |
7027 /* | |
7028 * Own the selection and return OK if it worked. | |
7029 */ | |
7030 int | |
7031 clip_mch_own_selection(VimClipboard *cbd) | |
7032 { | |
7033 int success; | |
7034 | |
7035 success = gtk_selection_owner_set(gui.drawarea, cbd->gtk_sel_atom, | |
2923 | 7036 gui.event_time); |
7 | 7037 gui_mch_update(); |
7038 return (success) ? OK : FAIL; | |
7039 } | |
7040 | |
7041 /* | |
7042 * Send the current selection to the clipboard. Do nothing for X because we | |
7043 * will fill in the selection only when requested by another app. | |
7044 */ | |
7045 void | |
1884 | 7046 clip_mch_set_selection(VimClipboard *cbd UNUSED) |
7 | 7047 { |
7048 } | |
7049 | |
4209 | 7050 int |
7051 clip_gtk_owner_exists(VimClipboard *cbd) | |
7052 { | |
7053 return gdk_selection_owner_get(cbd->gtk_sel_atom) != NULL; | |
7054 } | |
7055 | |
7 | 7056 |
7057 #if defined(FEAT_MENU) || defined(PROTO) | |
7058 /* | |
7059 * Make a menu item appear either active or not active (grey or not grey). | |
7060 */ | |
7061 void | |
7062 gui_mch_menu_grey(vimmenu_T *menu, int grey) | |
7063 { | |
7064 if (menu->id == NULL) | |
7065 return; | |
7066 | |
7067 if (menu_is_separator(menu->name)) | |
7068 grey = TRUE; | |
7069 | |
7070 gui_mch_menu_hidden(menu, FALSE); | |
7071 /* 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
|
7072 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7073 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
|
7074 # else |
7 | 7075 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
|
7076 # endif |
7 | 7077 { |
7078 gtk_widget_set_sensitive(menu->id, !grey); | |
7079 gui_mch_update(); | |
7080 } | |
7081 } | |
7082 | |
7083 /* | |
7084 * Make menu item hidden or not hidden. | |
7085 */ | |
7086 void | |
7087 gui_mch_menu_hidden(vimmenu_T *menu, int hidden) | |
7088 { | |
7089 if (menu->id == 0) | |
7090 return; | |
7091 | |
7092 if (hidden) | |
7093 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7094 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7095 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
|
7096 # else |
7 | 7097 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
|
7098 # endif |
7 | 7099 { |
7100 gtk_widget_hide(menu->id); | |
7101 gui_mch_update(); | |
7102 } | |
7103 } | |
7104 else | |
7105 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7106 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7107 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
|
7108 # else |
7 | 7109 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
|
7110 # endif |
7 | 7111 { |
7112 gtk_widget_show(menu->id); | |
7113 gui_mch_update(); | |
7114 } | |
7115 } | |
7116 } | |
7117 | |
7118 /* | |
7119 * This is called after setting all the menus to grey/hidden or not. | |
7120 */ | |
7121 void | |
7122 gui_mch_draw_menubar(void) | |
7123 { | |
7124 /* just make sure that the visual changes get effect immediately */ | |
7125 gui_mch_update(); | |
7126 } | |
7127 #endif /* FEAT_MENU */ | |
7128 | |
7129 /* | |
7130 * Scrollbar stuff. | |
7131 */ | |
7132 void | |
7133 gui_mch_enable_scrollbar(scrollbar_T *sb, int flag) | |
7134 { | |
7135 if (sb->id == NULL) | |
7136 return; | |
7137 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7138 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7139 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
|
7140 #else |
7 | 7141 if (flag) |
7142 gtk_widget_show(sb->id); | |
7143 else | |
7144 gtk_widget_hide(sb->id); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7145 #endif |
7 | 7146 |
791 | 7147 update_window_manager_hints(0, 0); |
7 | 7148 } |
7149 | |
7150 | |
7151 /* | |
7152 * Return the RGB value of a pixel as long. | |
7153 */ | |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9879
diff
changeset
|
7154 guicolor_T |
7 | 7155 gui_mch_get_rgb(guicolor_T pixel) |
7156 { | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7157 #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
|
7158 return (long_u)pixel; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7159 #else |
7 | 7160 GdkColor color; |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7161 |
7 | 7162 gdk_colormap_query_color(gtk_widget_get_colormap(gui.drawarea), |
7163 (unsigned long)pixel, &color); | |
7164 | |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9879
diff
changeset
|
7165 return (guicolor_T)( |
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9879
diff
changeset
|
7166 (((unsigned)color.red & 0xff00) << 8) |
7 | 7167 | ((unsigned)color.green & 0xff00) |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9879
diff
changeset
|
7168 | (((unsigned)color.blue & 0xff00) >> 8)); |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7169 #endif |
7 | 7170 } |
7171 | |
7172 /* | |
88 | 7173 * Get current mouse coordinates in text window. |
7 | 7174 */ |
88 | 7175 void |
7176 gui_mch_getmouse(int *x, int *y) | |
7 | 7177 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7178 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7179 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
|
7180 #else |
88 | 7181 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
|
7182 #endif |
7 | 7183 } |
7184 | |
7185 void | |
7186 gui_mch_setmouse(int x, int y) | |
7187 { | |
7188 /* Sorry for the Xlib call, but we can't avoid it, since there is no | |
7189 * internal GDK mechanism present to accomplish this. (and for good | |
7190 * reason...) */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7191 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7192 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
|
7193 (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
|
7194 0, 0, 0U, 0U, x, y); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7195 #else |
7 | 7196 XWarpPointer(GDK_WINDOW_XDISPLAY(gui.drawarea->window), |
7197 (Window)0, GDK_WINDOW_XWINDOW(gui.drawarea->window), | |
7198 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
|
7199 #endif |
7 | 7200 } |
7201 | |
7202 | |
7203 #ifdef FEAT_MOUSESHAPE | |
7204 /* The last set mouse pointer shape is remembered, to be used when it goes | |
7205 * from hidden to not hidden. */ | |
7206 static int last_shape = 0; | |
7207 #endif | |
7208 | |
7209 /* | |
7210 * Use the blank mouse pointer or not. | |
7211 * | |
7212 * hide: TRUE = use blank ptr, FALSE = use parent ptr | |
7213 */ | |
7214 void | |
7215 gui_mch_mousehide(int hide) | |
7216 { | |
7217 if (gui.pointer_hidden != hide) | |
7218 { | |
7219 gui.pointer_hidden = hide; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7220 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7221 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
|
7222 #else |
7 | 7223 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
|
7224 #endif |
7 | 7225 { |
7226 if (hide) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7227 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7228 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
|
7229 gui.blank_pointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7230 #else |
7 | 7231 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
|
7232 #endif |
7 | 7233 else |
7234 #ifdef FEAT_MOUSESHAPE | |
7235 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
|
7236 #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
|
7237 gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), NULL); |
7 | 7238 #else |
7239 gdk_window_set_cursor(gui.drawarea->window, NULL); | |
7240 #endif | |
7241 } | |
7242 } | |
7243 } | |
7244 | |
7245 #if defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7246 | |
7247 /* Table for shape IDs. Keep in sync with the mshape_names[] table in | |
7248 * misc2.c! */ | |
7249 static const int mshape_ids[] = | |
7250 { | |
7251 GDK_LEFT_PTR, /* arrow */ | |
7252 GDK_CURSOR_IS_PIXMAP, /* blank */ | |
7253 GDK_XTERM, /* beam */ | |
7254 GDK_SB_V_DOUBLE_ARROW, /* updown */ | |
7255 GDK_SIZING, /* udsizing */ | |
7256 GDK_SB_H_DOUBLE_ARROW, /* leftright */ | |
7257 GDK_SIZING, /* lrsizing */ | |
7258 GDK_WATCH, /* busy */ | |
7259 GDK_X_CURSOR, /* no */ | |
7260 GDK_CROSSHAIR, /* crosshair */ | |
7261 GDK_HAND1, /* hand1 */ | |
7262 GDK_HAND2, /* hand2 */ | |
7263 GDK_PENCIL, /* pencil */ | |
7264 GDK_QUESTION_ARROW, /* question */ | |
7265 GDK_RIGHT_PTR, /* right-arrow */ | |
7266 GDK_CENTER_PTR, /* up-arrow */ | |
7267 GDK_LEFT_PTR /* last one */ | |
7268 }; | |
7269 | |
7270 void | |
7271 mch_set_mouse_shape(int shape) | |
7272 { | |
7273 int id; | |
7274 GdkCursor *c; | |
7275 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7276 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7277 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
|
7278 # else |
7 | 7279 if (gui.drawarea->window == NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7280 # endif |
7 | 7281 return; |
7282 | |
7283 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
|
7284 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7285 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
|
7286 gui.blank_pointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7287 # else |
7 | 7288 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
|
7289 # endif |
7 | 7290 else |
7291 { | |
7292 if (shape >= MSHAPE_NUMBERED) | |
7293 { | |
7294 id = shape - MSHAPE_NUMBERED; | |
7295 if (id >= GDK_LAST_CURSOR) | |
7296 id = GDK_LEFT_PTR; | |
7297 else | |
7298 id &= ~1; /* they are always even (why?) */ | |
7299 } | |
1884 | 7300 else if (shape < (int)(sizeof(mshape_ids) / sizeof(int))) |
7 | 7301 id = mshape_ids[shape]; |
842 | 7302 else |
7303 return; | |
7 | 7304 # ifdef HAVE_GTK_MULTIHEAD |
7305 c = gdk_cursor_new_for_display( | |
136 | 7306 gtk_widget_get_display(gui.drawarea), (GdkCursorType)id); |
7 | 7307 # else |
136 | 7308 c = gdk_cursor_new((GdkCursorType)id); |
7 | 7309 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7310 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7311 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
|
7312 # else |
7 | 7313 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
|
7314 # endif |
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 g_object_unref(G_OBJECT(c)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7317 # else |
7 | 7318 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
|
7319 # endif |
7 | 7320 } |
7321 if (shape != MSHAPE_HIDE) | |
7322 last_shape = shape; | |
7323 } | |
7324 #endif /* FEAT_MOUSESHAPE */ | |
7325 | |
7326 | |
7327 #if defined(FEAT_SIGN_ICONS) || defined(PROTO) | |
7328 /* | |
7329 * Signs are currently always 2 chars wide. With GTK+ 2, the image will be | |
7330 * scaled down if the current font is not big enough, or scaled up if the image | |
7331 * size is less than 3/4 of the maximum sign size. With GTK+ 1, the pixmap | |
7332 * will be cut off if the current font is not big enough, or centered if it's | |
7333 * too small. | |
7334 */ | |
7335 # define SIGN_WIDTH (2 * gui.char_width) | |
7336 # define SIGN_HEIGHT (gui.char_height) | |
7337 # define SIGN_ASPECT ((double)SIGN_HEIGHT / (double)SIGN_WIDTH) | |
7338 | |
7339 void | |
7340 gui_mch_drawsign(int row, int col, int typenr) | |
7341 { | |
7342 GdkPixbuf *sign; | |
7343 | |
7344 sign = (GdkPixbuf *)sign_get_image(typenr); | |
7345 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7346 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7347 if (sign != NULL && gui.drawarea != NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7348 && 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
|
7349 # else |
7 | 7350 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
|
7351 # endif |
7 | 7352 { |
7353 int width; | |
7354 int height; | |
7355 int xoffset; | |
7356 int yoffset; | |
7357 int need_scale; | |
7358 | |
7359 width = gdk_pixbuf_get_width(sign); | |
7360 height = gdk_pixbuf_get_height(sign); | |
7361 /* | |
7362 * Decide whether we need to scale. Allow one pixel of border | |
7363 * width to be cut off, in order to avoid excessive scaling for | |
7364 * tiny differences in font size. | |
5983 | 7365 * Do scale to fit the height to avoid gaps because of linespacing. |
7 | 7366 */ |
7367 need_scale = (width > SIGN_WIDTH + 2 | |
5983 | 7368 || height != SIGN_HEIGHT |
7 | 7369 || (width < 3 * SIGN_WIDTH / 4 |
7370 && height < 3 * SIGN_HEIGHT / 4)); | |
7371 if (need_scale) | |
7372 { | |
5983 | 7373 double aspect; |
7374 int w = width; | |
7375 int h = height; | |
7 | 7376 |
7377 /* Keep the original aspect ratio */ | |
7378 aspect = (double)height / (double)width; | |
7379 width = (double)SIGN_WIDTH * SIGN_ASPECT / aspect; | |
7380 width = MIN(width, SIGN_WIDTH); | |
5983 | 7381 if (((double)(MAX(height, SIGN_HEIGHT)) / |
7382 (double)(MIN(height, SIGN_HEIGHT))) < 1.15) | |
7383 { | |
7384 /* Change the aspect ratio by at most 15% to fill the | |
7385 * available space completly. */ | |
7386 height = (double)SIGN_HEIGHT * SIGN_ASPECT / aspect; | |
7387 height = MIN(height, SIGN_HEIGHT); | |
7388 } | |
7389 else | |
7390 height = (double)width * aspect; | |
7391 | |
7392 if (w == width && h == height) | |
7393 { | |
7394 /* no change in dimensions; don't decrease reference counter | |
7395 * (below) */ | |
7396 need_scale = FALSE; | |
7397 } | |
7398 else | |
7399 { | |
7400 /* This doesn't seem to be worth caching, and doing so would | |
7401 * complicate the code quite a bit. */ | |
7402 sign = gdk_pixbuf_scale_simple(sign, width, height, | |
7403 GDK_INTERP_BILINEAR); | |
7404 if (sign == NULL) | |
7405 return; /* out of memory */ | |
7406 } | |
7 | 7407 } |
7408 | |
7409 /* The origin is the upper-left corner of the pixmap. Therefore | |
7410 * these offset may become negative if the pixmap is smaller than | |
7411 * the 2x1 cells reserved for the sign icon. */ | |
7412 xoffset = (width - SIGN_WIDTH) / 2; | |
7413 yoffset = (height - SIGN_HEIGHT) / 2; | |
7414 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7415 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7416 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7417 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7418 cairo_surface_t *bg_surf; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7419 cairo_t *bg_cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7420 cairo_surface_t *sign_surf; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7421 cairo_t *sign_cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7422 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7423 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7424 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7425 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
|
7426 cairo_surface_get_content(gui.surface), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7427 SIGN_WIDTH, SIGN_HEIGHT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7428 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
|
7429 cairo_set_source_rgba(bg_cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7430 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
|
7431 gui.bgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7432 cairo_paint(bg_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7433 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7434 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
|
7435 cairo_surface_get_content(gui.surface), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7436 SIGN_WIDTH, SIGN_HEIGHT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7437 sign_cr = cairo_create(sign_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7438 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
|
7439 cairo_paint(sign_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7440 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7441 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
|
7442 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
|
7443 cairo_paint(sign_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7444 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7445 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
|
7446 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7447 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7448 cairo_destroy(sign_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7449 cairo_surface_destroy(sign_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7450 cairo_destroy(bg_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7451 cairo_surface_destroy(bg_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7452 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7453 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7454 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7455 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
|
7456 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
|
7457 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7458 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7459 # else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 7460 gdk_gc_set_foreground(gui.text_gc, gui.bgcolor); |
7461 | |
7462 gdk_draw_rectangle(gui.drawarea->window, | |
7463 gui.text_gc, | |
7464 TRUE, | |
7465 FILL_X(col), | |
7466 FILL_Y(row), | |
7467 SIGN_WIDTH, | |
7468 SIGN_HEIGHT); | |
7469 | |
7470 gdk_pixbuf_render_to_drawable_alpha(sign, | |
7471 gui.drawarea->window, | |
7472 MAX(0, xoffset), | |
7473 MAX(0, yoffset), | |
7474 FILL_X(col) - MIN(0, xoffset), | |
7475 FILL_Y(row) - MIN(0, yoffset), | |
7476 MIN(width, SIGN_WIDTH), | |
7477 MIN(height, SIGN_HEIGHT), | |
7478 GDK_PIXBUF_ALPHA_BILEVEL, | |
7479 127, | |
7480 GDK_RGB_DITHER_NORMAL, | |
7481 0, 0); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7482 # endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 7483 if (need_scale) |
7484 g_object_unref(sign); | |
7485 } | |
7486 } | |
7487 | |
7488 void * | |
7489 gui_mch_register_sign(char_u *signfile) | |
7490 { | |
7491 if (signfile[0] != NUL && signfile[0] != '-' && gui.in_use) | |
7492 { | |
7493 GdkPixbuf *sign; | |
7494 GError *error = NULL; | |
7495 char_u *message; | |
7496 | |
7497 sign = gdk_pixbuf_new_from_file((const char *)signfile, &error); | |
7498 | |
7499 if (error == NULL) | |
7500 return sign; | |
7501 | |
7502 message = (char_u *)error->message; | |
7503 | |
7504 if (message != NULL && input_conv.vc_type != CONV_NONE) | |
7505 message = string_convert(&input_conv, message, NULL); | |
7506 | |
7507 if (message != NULL) | |
7508 { | |
7509 /* The error message is already translated and will be more | |
7510 * descriptive than anything we could possibly do ourselves. */ | |
7511 EMSG2("E255: %s", message); | |
7512 | |
7513 if (input_conv.vc_type != CONV_NONE) | |
7514 vim_free(message); | |
7515 } | |
7516 g_error_free(error); | |
7517 } | |
7518 | |
7519 return NULL; | |
7520 } | |
7521 | |
7522 void | |
7523 gui_mch_destroy_sign(void *sign) | |
7524 { | |
7525 if (sign != NULL) | |
7526 g_object_unref(sign); | |
7527 } | |
7528 | |
7529 #endif /* FEAT_SIGN_ICONS */ |