Mercurial > vim
annotate src/gui_gtk_x11.c @ 14712:82e7ce311065 v8.1.0368
patch 8.1.0368: GTK code has too many #ifdefs and GTK 2.10 building fails
commit https://github.com/vim/vim/commit/25328e39d2a6e3ded82bf282a2e248ce7209f1b4
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Sep 11 21:30:09 2018 +0200
patch 8.1.0368: GTK code has too many #ifdefs and GTK 2.10 building fails
Problem: GTK code has too many #ifdefs and building fails with GTK 2.10.
Solution: Always use gtk_widget_get_window() and define it for older GTK
versions. (Ken Takata, closes #3421)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 11 Sep 2018 21:45:06 +0200 |
parents | f8cd07a1cbb5 |
children | 11978f68a8c3 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9939
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * Porting to GTK+ was done by: | |
12 * | |
70 | 13 * (C) 1998,1999,2000 by Marcin Dalecki <martin@dalecki.de> |
7 | 14 * |
15 * With GREAT support and continuous encouragements by Andy Kahn and of | |
16 * course Bram Moolenaar! | |
17 * | |
18 * Support for GTK+ 2 was added by: | |
19 * | |
20 * (C) 2002,2003 Jason Hildebrand <jason@peaceworks.ca> | |
21 * Daniel Elstner <daniel.elstner@gmx.net> | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
22 * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
23 * Support for GTK+ 3 was added by: |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
24 * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
25 * 2016 Kazunobu Kuriyama <kazunobu.kuriyama@gmail.com> |
7 | 26 */ |
27 | |
28 #include "vim.h" | |
7380
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
29 #ifdef USE_GRESOURCE |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
30 #include "auto/gui_gtk_gresources.h" |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
31 #endif |
1666 | 32 |
7 | 33 #ifdef FEAT_GUI_GNOME |
34 /* Gnome redefines _() and N_(). Grrr... */ | |
35 # ifdef _ | |
36 # undef _ | |
37 # endif | |
38 # ifdef N_ | |
39 # undef N_ | |
40 # endif | |
41 # ifdef textdomain | |
42 # undef textdomain | |
43 # endif | |
44 # ifdef bindtextdomain | |
45 # undef bindtextdomain | |
46 # endif | |
1286 | 47 # ifdef bind_textdomain_codeset |
48 # undef bind_textdomain_codeset | |
1226 | 49 # endif |
7 | 50 # if defined(FEAT_GETTEXT) && !defined(ENABLE_NLS) |
51 # define ENABLE_NLS /* so the texts in the dialog boxes are translated */ | |
52 # endif | |
53 # include <gnome.h> | |
54 # include "version.h" | |
798 | 55 /* missing prototype in bonobo-dock-item.h */ |
56 extern void bonobo_dock_item_set_behavior(BonoboDockItem *dock_item, BonoboDockItemBehavior beh); | |
7 | 57 #endif |
58 | |
59 #if !defined(FEAT_GUI_GTK) && defined(PROTO) | |
60 /* When generating prototypes we don't want syntax errors. */ | |
61 # define GdkAtom int | |
62 # define GdkEventExpose int | |
63 # define GdkEventFocus int | |
64 # define GdkEventVisibility int | |
65 # define GdkEventProperty int | |
66 # define GtkContainer int | |
67 # define GtkTargetEntry int | |
68 # define GtkType int | |
69 # define GtkWidget int | |
70 # define gint int | |
71 # define gpointer int | |
72 # define guint int | |
73 # define GdkEventKey int | |
74 # define GdkEventSelection int | |
75 # define GtkSelectionData int | |
76 # define GdkEventMotion int | |
77 # define GdkEventButton int | |
78 # define GdkDragContext int | |
79 # define GdkEventConfigure int | |
80 # define GdkEventClient int | |
81 #else | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
82 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
83 # include <gdk/gdkkeysyms-compat.h> |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
84 # include <gtk/gtkx.h> |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
85 # else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
86 # include <gdk/gdkkeysyms.h> |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
87 # endif |
7 | 88 # include <gdk/gdk.h> |
89 # ifdef WIN3264 | |
90 # include <gdk/gdkwin32.h> | |
91 # else | |
92 # include <gdk/gdkx.h> | |
93 # endif | |
94 # include <gtk/gtk.h> | |
95 # include "gui_gtk_f.h" | |
96 #endif | |
97 | |
98 #ifdef HAVE_X11_SUNKEYSYM_H | |
99 # include <X11/Sunkeysym.h> | |
2714 | 100 #endif |
101 | |
7 | 102 /* |
103 * Easy-to-use macro for multihead support. | |
104 */ | |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
105 #define GET_X_ATOM(atom) gdk_x11_atom_to_xatom_for_display( \ |
7 | 106 gtk_widget_get_display(gui.mainwin), atom) |
107 | |
108 /* Selection type distinguishers */ | |
109 enum | |
110 { | |
111 TARGET_TYPE_NONE, | |
112 TARGET_UTF8_STRING, | |
113 TARGET_STRING, | |
114 TARGET_COMPOUND_TEXT, | |
1904 | 115 TARGET_HTML, |
7 | 116 TARGET_TEXT, |
117 TARGET_TEXT_URI_LIST, | |
118 TARGET_TEXT_PLAIN, | |
119 TARGET_VIM, | |
120 TARGET_VIMENC | |
121 }; | |
122 | |
123 /* | |
124 * Table of selection targets supported by Vim. | |
125 * Note: Order matters, preferred types should come first. | |
126 */ | |
127 static const GtkTargetEntry selection_targets[] = | |
128 { | |
129 {VIMENC_ATOM_NAME, 0, TARGET_VIMENC}, | |
130 {VIM_ATOM_NAME, 0, TARGET_VIM}, | |
1904 | 131 {"text/html", 0, TARGET_HTML}, |
7 | 132 {"UTF8_STRING", 0, TARGET_UTF8_STRING}, |
133 {"COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT}, | |
134 {"TEXT", 0, TARGET_TEXT}, | |
135 {"STRING", 0, TARGET_STRING} | |
136 }; | |
137 #define N_SELECTION_TARGETS (sizeof(selection_targets) / sizeof(selection_targets[0])) | |
138 | |
139 #ifdef FEAT_DND | |
140 /* | |
141 * Table of DnD targets supported by Vim. | |
142 * Note: Order matters, preferred types should come first. | |
143 */ | |
144 static const GtkTargetEntry dnd_targets[] = | |
145 { | |
146 {"text/uri-list", 0, TARGET_TEXT_URI_LIST}, | |
1904 | 147 {"text/html", 0, TARGET_HTML}, |
7 | 148 {"UTF8_STRING", 0, TARGET_UTF8_STRING}, |
149 {"STRING", 0, TARGET_STRING}, | |
150 {"text/plain", 0, TARGET_TEXT_PLAIN} | |
151 }; | |
152 # define N_DND_TARGETS (sizeof(dnd_targets) / sizeof(dnd_targets[0])) | |
153 #endif | |
154 | |
155 | |
156 /* | |
157 * "Monospace" is a standard font alias that should be present | |
158 * on all proper Pango/fontconfig installations. | |
159 */ | |
160 # define DEFAULT_FONT "Monospace 10" | |
161 | |
162 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
163 /* | |
164 * Atoms used to communicate save-yourself from the X11 session manager. There | |
165 * is no need to move them into the GUI struct, since they should be constant. | |
166 */ | |
167 static GdkAtom wm_protocols_atom = GDK_NONE; | |
168 static GdkAtom save_yourself_atom = GDK_NONE; | |
169 #endif | |
170 | |
171 /* | |
172 * Atoms used to control/reference X11 selections. | |
173 */ | |
1904 | 174 static GdkAtom html_atom = GDK_NONE; |
7 | 175 static GdkAtom utf8_string_atom = GDK_NONE; |
176 static GdkAtom vim_atom = GDK_NONE; /* Vim's own special selection format */ | |
177 static GdkAtom vimenc_atom = GDK_NONE; /* Vim's extended selection format */ | |
178 | |
179 /* | |
180 * Keycodes recognized by vim. | |
181 * NOTE: when changing this, the table in gui_x11.c probably needs the same | |
182 * change! | |
183 */ | |
184 static struct special_key | |
185 { | |
186 guint key_sym; | |
187 char_u code0; | |
188 char_u code1; | |
189 } | |
190 const special_keys[] = | |
191 { | |
192 {GDK_Up, 'k', 'u'}, | |
193 {GDK_Down, 'k', 'd'}, | |
194 {GDK_Left, 'k', 'l'}, | |
195 {GDK_Right, 'k', 'r'}, | |
196 {GDK_F1, 'k', '1'}, | |
197 {GDK_F2, 'k', '2'}, | |
198 {GDK_F3, 'k', '3'}, | |
199 {GDK_F4, 'k', '4'}, | |
200 {GDK_F5, 'k', '5'}, | |
201 {GDK_F6, 'k', '6'}, | |
202 {GDK_F7, 'k', '7'}, | |
203 {GDK_F8, 'k', '8'}, | |
204 {GDK_F9, 'k', '9'}, | |
205 {GDK_F10, 'k', ';'}, | |
206 {GDK_F11, 'F', '1'}, | |
207 {GDK_F12, 'F', '2'}, | |
208 {GDK_F13, 'F', '3'}, | |
209 {GDK_F14, 'F', '4'}, | |
210 {GDK_F15, 'F', '5'}, | |
211 {GDK_F16, 'F', '6'}, | |
212 {GDK_F17, 'F', '7'}, | |
213 {GDK_F18, 'F', '8'}, | |
214 {GDK_F19, 'F', '9'}, | |
215 {GDK_F20, 'F', 'A'}, | |
216 {GDK_F21, 'F', 'B'}, | |
217 {GDK_Pause, 'F', 'B'}, /* Pause == F21 according to netbeans.txt */ | |
218 {GDK_F22, 'F', 'C'}, | |
219 {GDK_F23, 'F', 'D'}, | |
220 {GDK_F24, 'F', 'E'}, | |
221 {GDK_F25, 'F', 'F'}, | |
222 {GDK_F26, 'F', 'G'}, | |
223 {GDK_F27, 'F', 'H'}, | |
224 {GDK_F28, 'F', 'I'}, | |
225 {GDK_F29, 'F', 'J'}, | |
226 {GDK_F30, 'F', 'K'}, | |
227 {GDK_F31, 'F', 'L'}, | |
228 {GDK_F32, 'F', 'M'}, | |
229 {GDK_F33, 'F', 'N'}, | |
230 {GDK_F34, 'F', 'O'}, | |
231 {GDK_F35, 'F', 'P'}, | |
232 #ifdef SunXK_F36 | |
233 {SunXK_F36, 'F', 'Q'}, | |
234 {SunXK_F37, 'F', 'R'}, | |
235 #endif | |
236 {GDK_Help, '%', '1'}, | |
237 {GDK_Undo, '&', '8'}, | |
238 {GDK_BackSpace, 'k', 'b'}, | |
239 {GDK_Insert, 'k', 'I'}, | |
240 {GDK_Delete, 'k', 'D'}, | |
241 {GDK_3270_BackTab, 'k', 'B'}, | |
242 {GDK_Clear, 'k', 'C'}, | |
243 {GDK_Home, 'k', 'h'}, | |
244 {GDK_End, '@', '7'}, | |
245 {GDK_Prior, 'k', 'P'}, | |
246 {GDK_Next, 'k', 'N'}, | |
247 {GDK_Print, '%', '9'}, | |
248 /* Keypad keys: */ | |
249 {GDK_KP_Left, 'k', 'l'}, | |
250 {GDK_KP_Right, 'k', 'r'}, | |
251 {GDK_KP_Up, 'k', 'u'}, | |
252 {GDK_KP_Down, 'k', 'd'}, | |
253 {GDK_KP_Insert, KS_EXTRA, (char_u)KE_KINS}, | |
254 {GDK_KP_Delete, KS_EXTRA, (char_u)KE_KDEL}, | |
255 {GDK_KP_Home, 'K', '1'}, | |
256 {GDK_KP_End, 'K', '4'}, | |
257 {GDK_KP_Prior, 'K', '3'}, /* page up */ | |
258 {GDK_KP_Next, 'K', '5'}, /* page down */ | |
259 | |
260 {GDK_KP_Add, 'K', '6'}, | |
261 {GDK_KP_Subtract, 'K', '7'}, | |
262 {GDK_KP_Divide, 'K', '8'}, | |
263 {GDK_KP_Multiply, 'K', '9'}, | |
264 {GDK_KP_Enter, 'K', 'A'}, | |
265 {GDK_KP_Decimal, 'K', 'B'}, | |
266 | |
267 {GDK_KP_0, 'K', 'C'}, | |
268 {GDK_KP_1, 'K', 'D'}, | |
269 {GDK_KP_2, 'K', 'E'}, | |
270 {GDK_KP_3, 'K', 'F'}, | |
271 {GDK_KP_4, 'K', 'G'}, | |
272 {GDK_KP_5, 'K', 'H'}, | |
273 {GDK_KP_6, 'K', 'I'}, | |
274 {GDK_KP_7, 'K', 'J'}, | |
275 {GDK_KP_8, 'K', 'K'}, | |
276 {GDK_KP_9, 'K', 'L'}, | |
277 | |
278 /* End of list marker: */ | |
279 {0, 0, 0} | |
280 }; | |
281 | |
282 /* | |
283 * Flags for command line options table below. | |
284 */ | |
285 #define ARG_FONT 1 | |
286 #define ARG_GEOMETRY 2 | |
287 #define ARG_REVERSE 3 | |
288 #define ARG_NOREVERSE 4 | |
289 #define ARG_BACKGROUND 5 | |
290 #define ARG_FOREGROUND 6 | |
291 #define ARG_ICONIC 7 | |
292 #define ARG_ROLE 8 | |
293 #define ARG_NETBEANS 9 | |
294 #define ARG_XRM 10 /* ignored */ | |
295 #define ARG_MENUFONT 11 /* ignored */ | |
296 #define ARG_INDEX_MASK 0x00ff | |
297 #define ARG_HAS_VALUE 0x0100 /* a value is expected after the argument */ | |
298 #define ARG_NEEDS_GUI 0x0200 /* need to initialize the GUI for this */ | |
299 #define ARG_FOR_GTK 0x0400 /* argument is handled by GTK+ or GNOME */ | |
300 #define ARG_COMPAT_LONG 0x0800 /* accept -foo but substitute with --foo */ | |
301 #define ARG_KEEP 0x1000 /* don't remove argument from argv[] */ | |
302 | |
303 /* | |
304 * This table holds all the X GUI command line options allowed. This includes | |
305 * the standard ones so that we can skip them when Vim is started without the | |
306 * GUI (but the GUI might start up later). | |
307 * | |
308 * When changing this, also update doc/gui_x11.txt and the usage message!!! | |
309 */ | |
310 typedef struct | |
311 { | |
312 const char *name; | |
313 unsigned int flags; | |
314 } | |
315 cmdline_option_T; | |
316 | |
317 static const cmdline_option_T cmdline_options[] = | |
318 { | |
319 /* We handle these options ourselves */ | |
320 {"-fn", ARG_FONT|ARG_HAS_VALUE}, | |
321 {"-font", ARG_FONT|ARG_HAS_VALUE}, | |
322 {"-geom", ARG_GEOMETRY|ARG_HAS_VALUE}, | |
323 {"-geometry", ARG_GEOMETRY|ARG_HAS_VALUE}, | |
324 {"-rv", ARG_REVERSE}, | |
325 {"-reverse", ARG_REVERSE}, | |
326 {"+rv", ARG_NOREVERSE}, | |
327 {"+reverse", ARG_NOREVERSE}, | |
328 {"-bg", ARG_BACKGROUND|ARG_HAS_VALUE}, | |
329 {"-background", ARG_BACKGROUND|ARG_HAS_VALUE}, | |
330 {"-fg", ARG_FOREGROUND|ARG_HAS_VALUE}, | |
331 {"-foreground", ARG_FOREGROUND|ARG_HAS_VALUE}, | |
332 {"-iconic", ARG_ICONIC}, | |
333 {"--role", ARG_ROLE|ARG_HAS_VALUE}, | |
334 #ifdef FEAT_NETBEANS_INTG | |
335 {"-nb", ARG_NETBEANS}, /* non-standard value format */ | |
336 {"-xrm", ARG_XRM|ARG_HAS_VALUE}, /* not implemented */ | |
337 {"-mf", ARG_MENUFONT|ARG_HAS_VALUE}, /* not implemented */ | |
338 {"-menufont", ARG_MENUFONT|ARG_HAS_VALUE}, /* not implemented */ | |
339 #endif | |
340 /* Arguments handled by GTK (and GNOME) internally. */ | |
341 {"--g-fatal-warnings", ARG_FOR_GTK}, | |
342 {"--gdk-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
343 {"--gdk-no-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
344 {"--gtk-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
345 {"--gtk-no-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
346 {"--gtk-module", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
347 {"--sync", ARG_FOR_GTK}, | |
348 {"--display", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
349 {"--name", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
350 {"--class", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
351 {"--screen", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
352 {"--gxid-host", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
353 {"--gxid-port", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
354 #ifdef FEAT_GUI_GNOME | |
355 {"--load-modules", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
356 {"--sm-client-id", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
357 {"--sm-config-prefix", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
358 {"--sm-disable", ARG_FOR_GTK}, | |
359 {"--oaf-ior-fd", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
360 {"--oaf-activate-iid", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
361 {"--oaf-private", ARG_FOR_GTK}, | |
362 {"--enable-sound", ARG_FOR_GTK}, | |
363 {"--disable-sound", ARG_FOR_GTK}, | |
364 {"--espeaker", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
365 {"-?", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
366 {"--help", ARG_FOR_GTK|ARG_NEEDS_GUI|ARG_KEEP}, | |
367 {"--usage", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
368 # if 0 /* conflicts with Vim's own --version argument */ | |
369 {"--version", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
370 # endif | |
371 {"--disable-crash-dialog", ARG_FOR_GTK}, | |
372 #endif | |
373 {NULL, 0} | |
374 }; | |
375 | |
376 static int gui_argc = 0; | |
377 static char **gui_argv = NULL; | |
378 | |
379 static const char *role_argument = NULL; | |
380 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
381 static const char *restart_command = NULL; | |
1898 | 382 static char *abs_restart_command = NULL; |
7 | 383 #endif |
384 static int found_iconic_arg = FALSE; | |
385 | |
386 #ifdef FEAT_GUI_GNOME | |
387 /* | |
388 * Can't use Gnome if --socketid given | |
389 */ | |
390 static int using_gnome = 0; | |
391 #else | |
392 # define using_gnome 0 | |
393 #endif | |
394 | |
395 /* | |
396 * Parse the GUI related command-line arguments. Any arguments used are | |
397 * deleted from argv, and *argc is decremented accordingly. This is called | |
398 * when vim is started, whether or not the GUI has been started. | |
399 */ | |
400 void | |
401 gui_mch_prepare(int *argc, char **argv) | |
402 { | |
403 const cmdline_option_T *option; | |
404 int i = 0; | |
405 int len = 0; | |
406 | |
407 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
408 /* | |
409 * Determine the command used to invoke Vim, to be passed as restart | |
410 * command to the session manager. If argv[0] contains any directory | |
411 * components try building an absolute path, otherwise leave it as is. | |
412 */ | |
413 restart_command = argv[0]; | |
414 | |
415 if (strchr(argv[0], G_DIR_SEPARATOR) != NULL) | |
416 { | |
417 char_u buf[MAXPATHL]; | |
418 | |
419 if (mch_FullName((char_u *)argv[0], buf, (int)sizeof(buf), TRUE) == OK) | |
1898 | 420 { |
421 abs_restart_command = (char *)vim_strsave(buf); | |
422 restart_command = abs_restart_command; | |
423 } | |
7 | 424 } |
425 #endif | |
426 | |
427 /* | |
428 * Move all the entries in argv which are relevant to GTK+ and GNOME | |
429 * into gui_argv. Freed later in gui_mch_init(). | |
430 */ | |
431 gui_argc = 0; | |
432 gui_argv = (char **)alloc((unsigned)((*argc + 1) * sizeof(char *))); | |
433 | |
434 g_return_if_fail(gui_argv != NULL); | |
435 | |
436 gui_argv[gui_argc++] = argv[i++]; | |
437 | |
438 while (i < *argc) | |
439 { | |
440 /* Don't waste CPU cycles on non-option arguments. */ | |
441 if (argv[i][0] != '-' && argv[i][0] != '+') | |
442 { | |
443 ++i; | |
444 continue; | |
445 } | |
446 | |
447 /* Look for argv[i] in cmdline_options[] table. */ | |
448 for (option = &cmdline_options[0]; option->name != NULL; ++option) | |
449 { | |
450 len = strlen(option->name); | |
451 | |
452 if (strncmp(argv[i], option->name, len) == 0) | |
453 { | |
454 if (argv[i][len] == '\0') | |
455 break; | |
456 /* allow --foo=bar style */ | |
457 if (argv[i][len] == '=' && (option->flags & ARG_HAS_VALUE)) | |
458 break; | |
459 #ifdef FEAT_NETBEANS_INTG | |
460 /* darn, -nb has non-standard syntax */ | |
461 if (vim_strchr((char_u *)":=", argv[i][len]) != NULL | |
462 && (option->flags & ARG_INDEX_MASK) == ARG_NETBEANS) | |
463 break; | |
464 #endif | |
465 } | |
466 else if ((option->flags & ARG_COMPAT_LONG) | |
467 && strcmp(argv[i], option->name + 1) == 0) | |
468 { | |
469 /* Replace the standard X arguments "-name" and "-display" | |
470 * with their GNU-style long option counterparts. */ | |
471 argv[i] = (char *)option->name; | |
472 break; | |
473 } | |
474 } | |
475 if (option->name == NULL) /* no match */ | |
476 { | |
477 ++i; | |
478 continue; | |
479 } | |
480 | |
481 if (option->flags & ARG_FOR_GTK) | |
482 { | |
483 /* Move the argument into gui_argv, which | |
484 * will later be passed to gtk_init_check() */ | |
485 gui_argv[gui_argc++] = argv[i]; | |
486 } | |
487 else | |
488 { | |
489 char *value = NULL; | |
490 | |
491 /* Extract the option's value if there is one. | |
492 * Accept both "--foo bar" and "--foo=bar" style. */ | |
493 if (option->flags & ARG_HAS_VALUE) | |
494 { | |
495 if (argv[i][len] == '=') | |
496 value = &argv[i][len + 1]; | |
497 else if (i + 1 < *argc && strcmp(argv[i + 1], "--") != 0) | |
498 value = argv[i + 1]; | |
499 } | |
500 | |
501 /* Check for options handled by Vim itself */ | |
502 switch (option->flags & ARG_INDEX_MASK) | |
503 { | |
504 case ARG_REVERSE: | |
505 found_reverse_arg = TRUE; | |
506 break; | |
507 case ARG_NOREVERSE: | |
508 found_reverse_arg = FALSE; | |
509 break; | |
510 case ARG_FONT: | |
511 font_argument = value; | |
512 break; | |
513 case ARG_GEOMETRY: | |
514 if (value != NULL) | |
515 gui.geom = vim_strsave((char_u *)value); | |
516 break; | |
517 case ARG_BACKGROUND: | |
518 background_argument = value; | |
519 break; | |
520 case ARG_FOREGROUND: | |
521 foreground_argument = value; | |
522 break; | |
523 case ARG_ICONIC: | |
524 found_iconic_arg = TRUE; | |
525 break; | |
526 case ARG_ROLE: | |
527 role_argument = value; /* used later in gui_mch_open() */ | |
528 break; | |
529 #ifdef FEAT_NETBEANS_INTG | |
530 case ARG_NETBEANS: | |
531 gui.dofork = FALSE; /* don't fork() when starting GUI */ | |
532 netbeansArg = argv[i]; | |
533 break; | |
534 #endif | |
535 default: | |
536 break; | |
537 } | |
538 } | |
539 | |
540 /* These arguments make gnome_program_init() print a message and exit. | |
9836
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
541 * Must start the GUI for this, otherwise ":gui" will exit later! |
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
542 * Only when the GUI can start. */ |
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
543 if ((option->flags & ARG_NEEDS_GUI) |
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
544 && gui_mch_early_init_check(FALSE) == OK) |
7 | 545 gui.starting = TRUE; |
546 | |
547 if (option->flags & ARG_KEEP) | |
548 ++i; | |
549 else | |
550 { | |
551 /* Remove the flag from the argument vector. */ | |
552 if (--*argc > i) | |
553 { | |
554 int n_strip = 1; | |
555 | |
556 /* Move the argument's value as well, if there is one. */ | |
557 if ((option->flags & ARG_HAS_VALUE) | |
558 && argv[i][len] != '=' | |
559 && strcmp(argv[i + 1], "--") != 0) | |
560 { | |
561 ++n_strip; | |
562 --*argc; | |
563 if (option->flags & ARG_FOR_GTK) | |
564 gui_argv[gui_argc++] = argv[i + 1]; | |
565 } | |
566 | |
567 if (*argc > i) | |
568 mch_memmove(&argv[i], &argv[i + n_strip], | |
569 (*argc - i) * sizeof(char *)); | |
570 } | |
571 argv[*argc] = NULL; | |
572 } | |
573 } | |
574 | |
575 gui_argv[gui_argc] = NULL; | |
576 } | |
577 | |
359 | 578 #if defined(EXITFREE) || defined(PROTO) |
579 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
580 gui_mch_free_all(void) |
359 | 581 { |
582 vim_free(gui_argv); | |
1898 | 583 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) |
584 vim_free(abs_restart_command); | |
585 #endif | |
359 | 586 } |
587 #endif | |
588 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
589 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 590 /* |
591 * This should be maybe completely removed. | |
592 * Doesn't seem possible, since check_copy_area() relies on | |
593 * this information. --danielk | |
594 */ | |
595 static gint | |
1884 | 596 visibility_event(GtkWidget *widget UNUSED, |
597 GdkEventVisibility *event, | |
598 gpointer data UNUSED) | |
7 | 599 { |
600 gui.visibility = event->state; | |
601 /* | |
602 * When we do an gdk_window_copy_area(), and the window is partially | |
603 * obscured, we want to receive an event to tell us whether it worked | |
604 * or not. | |
605 */ | |
606 if (gui.text_gc != NULL) | |
607 gdk_gc_set_exposures(gui.text_gc, | |
608 gui.visibility != GDK_VISIBILITY_UNOBSCURED); | |
609 return FALSE; | |
610 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
611 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 612 |
613 /* | |
614 * Redraw the corresponding portions of the screen. | |
615 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
616 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
617 static gboolean is_key_pressed = FALSE; |
8412
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
618 static gboolean blink_mode = TRUE; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
619 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
620 static gboolean gui_gtk_is_blink_on(void); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
621 static void gui_gtk_window_clear(GdkWindow *win); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
622 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
623 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
624 gui_gtk3_redraw(int x, int y, int width, int height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
625 { |
10920
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
626 /* Range checks are left to gui_redraw_block() */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
627 gui_redraw_block(Y_2_ROW(y), X_2_COL(x), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
628 Y_2_ROW(y + height - 1), X_2_COL(x + width - 1), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
629 GUI_MON_NOCLEAR); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
630 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
631 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
632 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
633 gui_gtk3_update_cursor(cairo_t *cr) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
634 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
635 if (gui.row == gui.cursor_row) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
636 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
637 gui.by_signal = TRUE; |
8495
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
638 if (State & CMDLINE) |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
639 gui_update_cursor(TRUE, FALSE); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
640 else |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
641 gui_update_cursor(TRUE, TRUE); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
642 gui.by_signal = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
643 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
644 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
645 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
646 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
647 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
648 gui_gtk3_should_draw_cursor(void) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
649 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
650 unsigned int cond = 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
651 cond |= gui_gtk_is_blink_on(); |
8510
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
652 if (gui.cursor_col >= gui.col) |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
653 cond |= is_key_pressed; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
654 cond |= gui.in_focus == FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
655 return cond; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
656 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
657 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
658 static gboolean |
9232
a64e2a624fbe
commit https://github.com/vim/vim/commit/8e31fd52ec8be6ef1dc600b637d5f099d55e1715
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
659 draw_event(GtkWidget *widget UNUSED, |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
660 cairo_t *cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
661 gpointer user_data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
662 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
663 /* Skip this when the GUI isn't set up yet, will redraw later. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
664 if (gui.starting) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
665 return FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
666 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
667 out_flush(); /* make sure all output has been processed */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
668 /* for GTK+ 3, may induce other draw events. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
669 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
670 cairo_set_source_surface(cr, gui.surface, 0, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
671 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
672 /* Draw the window without the cursor. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
673 gui.by_signal = TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
674 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
675 cairo_rectangle_list_t *list = NULL; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
676 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
677 list = cairo_copy_clip_rectangle_list(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
678 if (list->status != CAIRO_STATUS_CLIP_NOT_REPRESENTABLE) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
679 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
680 int i; |
10920
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
681 |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
682 /* First clear all the blocks and then redraw them. Just in case |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
683 * some blocks overlap. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
684 for (i = 0; i < list->num_rectangles; i++) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
685 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
686 const cairo_rectangle_t rect = list->rectangles[i]; |
9232
a64e2a624fbe
commit https://github.com/vim/vim/commit/8e31fd52ec8be6ef1dc600b637d5f099d55e1715
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
687 |
10920
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
688 gui_mch_clear_block(Y_2_ROW((int)rect.y), 0, |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
689 Y_2_ROW((int)(rect.y + rect.height)) - 1, Columns - 1); |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
690 } |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
691 |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
692 for (i = 0; i < list->num_rectangles; i++) |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
693 { |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
694 const cairo_rectangle_t rect = list->rectangles[i]; |
9232
a64e2a624fbe
commit https://github.com/vim/vim/commit/8e31fd52ec8be6ef1dc600b637d5f099d55e1715
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
695 |
8412
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
696 if (blink_mode) |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
697 gui_gtk3_redraw(rect.x, rect.y, rect.width, rect.height); |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
698 else |
8510
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
699 { |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
700 if (get_real_state() & VISUAL) |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
701 gui_gtk3_redraw(rect.x, rect.y, |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
702 rect.width, rect.height); |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
703 else |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
704 gui_redraw(rect.x, rect.y, rect.width, rect.height); |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
705 } |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
706 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
707 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
708 cairo_rectangle_list_destroy(list); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
709 |
8510
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
710 if (get_real_state() & VISUAL) |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
711 { |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
712 if (gui.cursor_row == gui.row && gui.cursor_col >= gui.col) |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
713 gui_update_cursor(TRUE, TRUE); |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
714 } |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
715 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
716 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
717 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
718 gui.by_signal = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
719 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
720 /* Add the cursor to the window if necessary.*/ |
8510
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
721 if (gui_gtk3_should_draw_cursor() && blink_mode) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
722 gui_gtk3_update_cursor(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
723 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
724 return FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
725 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
726 #else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 727 static gint |
1884 | 728 expose_event(GtkWidget *widget UNUSED, |
729 GdkEventExpose *event, | |
730 gpointer data UNUSED) | |
7 | 731 { |
732 /* Skip this when the GUI isn't set up yet, will redraw later. */ | |
733 if (gui.starting) | |
734 return FALSE; | |
735 | |
736 out_flush(); /* make sure all output has been processed */ | |
737 gui_redraw(event->area.x, event->area.y, | |
738 event->area.width, event->area.height); | |
739 | |
740 /* Clear the border areas if needed */ | |
741 if (event->area.x < FILL_X(0)) | |
742 gdk_window_clear_area(gui.drawarea->window, 0, 0, FILL_X(0), 0); | |
743 if (event->area.y < FILL_Y(0)) | |
744 gdk_window_clear_area(gui.drawarea->window, 0, 0, 0, FILL_Y(0)); | |
745 if (event->area.x > FILL_X(Columns)) | |
746 gdk_window_clear_area(gui.drawarea->window, | |
747 FILL_X((int)Columns), 0, 0, 0); | |
748 if (event->area.y > FILL_Y(Rows)) | |
749 gdk_window_clear_area(gui.drawarea->window, 0, FILL_Y((int)Rows), 0, 0); | |
750 | |
751 return FALSE; | |
752 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
753 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 754 |
755 #ifdef FEAT_CLIENTSERVER | |
756 /* | |
757 * Handle changes to the "Comm" property | |
758 */ | |
759 static gint | |
1884 | 760 property_event(GtkWidget *widget, |
761 GdkEventProperty *event, | |
762 gpointer data UNUSED) | |
7 | 763 { |
764 if (event->type == GDK_PROPERTY_NOTIFY | |
765 && event->state == (int)GDK_PROPERTY_NEW_VALUE | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
766 && GDK_WINDOW_XID(event->window) == commWindow |
7 | 767 && GET_X_ATOM(event->atom) == commProperty) |
768 { | |
769 XEvent xev; | |
770 | |
771 /* Translate to XLib */ | |
772 xev.xproperty.type = PropertyNotify; | |
773 xev.xproperty.atom = commProperty; | |
774 xev.xproperty.window = commWindow; | |
775 xev.xproperty.state = PropertyNewValue; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
776 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
|
777 &xev, 0); |
7 | 778 } |
779 return FALSE; | |
780 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
781 #endif /* defined(FEAT_CLIENTSERVER) */ |
7 | 782 |
14471
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
783 /* |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
784 * Handle changes to the "Xft/DPI" setting |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
785 */ |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
786 static void |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
787 gtk_settings_xft_dpi_changed_cb(GtkSettings *gtk_settings UNUSED, |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
788 GParamSpec *pspec UNUSED, |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
789 gpointer data UNUSED) |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
790 { |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
791 // Create a new PangoContext for this screen, and initialize it |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
792 // with the current font if necessary. |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
793 if (gui.text_context != NULL) |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
794 g_object_unref(gui.text_context); |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
795 |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
796 gui.text_context = gtk_widget_create_pango_context(gui.mainwin); |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
797 pango_context_set_base_dir(gui.text_context, PANGO_DIRECTION_LTR); |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
798 |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
799 if (gui.norm_font != NULL) |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
800 { |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
801 // force default font |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
802 gui_mch_init_font(*p_guifont == NUL ? NULL : p_guifont, FALSE); |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
803 gui_set_shellsize(TRUE, FALSE, RESIZE_BOTH); |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
804 } |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
805 } |
7 | 806 |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
807 #if GTK_CHECK_VERSION(3,0,0) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
808 typedef gboolean timeout_cb_type; |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
809 #else |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
810 typedef gint timeout_cb_type; |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
811 #endif |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
812 |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
813 /* |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
814 * Start a timer that will invoke the specified callback. |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
815 * Returns the ID of the timer. |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
816 */ |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
817 static guint |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
818 timeout_add(int time, timeout_cb_type (*callback)(gpointer), int *flagp) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
819 { |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
820 #if GTK_CHECK_VERSION(3,0,0) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
821 return g_timeout_add((guint)time, (GSourceFunc)callback, flagp); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
822 #else |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
823 return gtk_timeout_add((guint32)time, (GtkFunction)callback, flagp); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
824 #endif |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
825 } |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
826 |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
827 static void |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
828 timeout_remove(guint timer) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
829 { |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
830 #if GTK_CHECK_VERSION(3,0,0) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
831 g_source_remove(timer); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
832 #else |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
833 gtk_timeout_remove(timer); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
834 #endif |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
835 } |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
836 |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
837 |
7 | 838 /**************************************************************************** |
839 * Focus handlers: | |
840 */ | |
841 | |
842 | |
843 /* | |
844 * This is a simple state machine: | |
845 * BLINK_NONE not blinking at all | |
846 * BLINK_OFF blinking, cursor is not shown | |
847 * BLINK_ON blinking, cursor is shown | |
848 */ | |
849 | |
850 #define BLINK_NONE 0 | |
851 #define BLINK_OFF 1 | |
852 #define BLINK_ON 2 | |
853 | |
854 static int blink_state = BLINK_NONE; | |
855 static long_u blink_waittime = 700; | |
856 static long_u blink_ontime = 400; | |
857 static long_u blink_offtime = 250; | |
858 static guint blink_timer = 0; | |
859 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
860 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
861 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
862 gui_gtk_is_blink_on(void) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
863 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
864 return blink_state == BLINK_ON; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
865 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
866 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
867 |
9213
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
868 int |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
869 gui_mch_is_blinking(void) |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
870 { |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
871 return blink_state != BLINK_NONE; |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
872 } |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
873 |
9428
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
874 int |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
875 gui_mch_is_blink_off(void) |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
876 { |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
877 return blink_state == BLINK_OFF; |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
878 } |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
879 |
7 | 880 void |
881 gui_mch_set_blinking(long waittime, long on, long off) | |
882 { | |
8412
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
883 #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
|
884 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
|
885 { |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
886 blink_mode = FALSE; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
887 |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
888 blink_waittime = 700; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
889 blink_ontime = 400; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
890 blink_offtime = 250; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
891 } |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
892 else |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
893 { |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
894 blink_mode = TRUE; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
895 |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
896 blink_waittime = waittime; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
897 blink_ontime = on; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
898 blink_offtime = off; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
899 } |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
900 #else |
7 | 901 blink_waittime = waittime; |
902 blink_ontime = on; | |
903 blink_offtime = off; | |
8412
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
904 #endif |
7 | 905 } |
906 | |
907 /* | |
908 * Stop the cursor blinking. Show the cursor if it wasn't shown. | |
909 */ | |
910 void | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
911 gui_mch_stop_blink(int may_call_gui_update_cursor) |
7 | 912 { |
913 if (blink_timer) | |
914 { | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
915 timeout_remove(blink_timer); |
7 | 916 blink_timer = 0; |
917 } | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
918 if (blink_state == BLINK_OFF && may_call_gui_update_cursor) |
9489
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
919 { |
7 | 920 gui_update_cursor(TRUE, FALSE); |
9489
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
921 gui_mch_flush(); |
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
922 } |
7 | 923 blink_state = BLINK_NONE; |
924 } | |
925 | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
926 static timeout_cb_type |
1884 | 927 blink_cb(gpointer data UNUSED) |
7 | 928 { |
929 if (blink_state == BLINK_ON) | |
930 { | |
931 gui_undraw_cursor(); | |
932 blink_state = BLINK_OFF; | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
933 blink_timer = timeout_add(blink_offtime, blink_cb, NULL); |
7 | 934 } |
935 else | |
936 { | |
937 gui_update_cursor(TRUE, FALSE); | |
938 blink_state = BLINK_ON; | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
939 blink_timer = timeout_add(blink_ontime, blink_cb, NULL); |
7 | 940 } |
9489
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
941 gui_mch_flush(); |
7 | 942 |
943 return FALSE; /* don't happen again */ | |
944 } | |
945 | |
946 /* | |
947 * Start the cursor blinking. If it was already blinking, this restarts the | |
948 * waiting time and shows the cursor. | |
949 */ | |
950 void | |
951 gui_mch_start_blink(void) | |
952 { | |
953 if (blink_timer) | |
5818 | 954 { |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
955 timeout_remove(blink_timer); |
5818 | 956 blink_timer = 0; |
957 } | |
7 | 958 /* Only switch blinking on if none of the times is zero */ |
959 if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus) | |
960 { | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
961 blink_timer = timeout_add(blink_waittime, blink_cb, NULL); |
7 | 962 blink_state = BLINK_ON; |
963 gui_update_cursor(TRUE, FALSE); | |
9489
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
964 gui_mch_flush(); |
7 | 965 } |
966 } | |
967 | |
968 static gint | |
1884 | 969 enter_notify_event(GtkWidget *widget UNUSED, |
970 GdkEventCrossing *event UNUSED, | |
971 gpointer data UNUSED) | |
7 | 972 { |
973 if (blink_state == BLINK_NONE) | |
974 gui_mch_start_blink(); | |
975 | |
976 /* 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
|
977 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
978 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
|
979 #else |
7 | 980 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
|
981 #endif |
7 | 982 gtk_widget_grab_focus(gui.drawarea); |
983 | |
984 return FALSE; | |
985 } | |
986 | |
987 static gint | |
1884 | 988 leave_notify_event(GtkWidget *widget UNUSED, |
989 GdkEventCrossing *event UNUSED, | |
990 gpointer data UNUSED) | |
7 | 991 { |
992 if (blink_state != BLINK_NONE) | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
993 gui_mch_stop_blink(TRUE); |
7 | 994 |
995 return FALSE; | |
996 } | |
997 | |
998 static gint | |
1884 | 999 focus_in_event(GtkWidget *widget, |
1000 GdkEventFocus *event UNUSED, | |
1001 gpointer data UNUSED) | |
7 | 1002 { |
1003 gui_focus_change(TRUE); | |
1004 | |
1005 if (blink_state == BLINK_NONE) | |
1006 gui_mch_start_blink(); | |
1007 | |
1380 | 1008 /* make sure keyboard input goes to the draw area (if this is focus for a |
1009 * window) */ | |
791 | 1010 if (widget != gui.drawarea) |
856 | 1011 gtk_widget_grab_focus(gui.drawarea); |
7 | 1012 |
1013 return TRUE; | |
1014 } | |
1015 | |
1016 static gint | |
1884 | 1017 focus_out_event(GtkWidget *widget UNUSED, |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2301
diff
changeset
|
1018 GdkEventFocus *event UNUSED, |
1884 | 1019 gpointer data UNUSED) |
7 | 1020 { |
1021 gui_focus_change(FALSE); | |
1022 | |
1023 if (blink_state != BLINK_NONE) | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
1024 gui_mch_stop_blink(TRUE); |
7 | 1025 |
1026 return TRUE; | |
1027 } | |
1028 | |
1029 | |
1030 /* | |
1031 * Translate a GDK key value to UTF-8 independently of the current locale. | |
1032 * The output is written to string, which must have room for at least 6 bytes | |
1033 * plus the NUL terminator. Returns the length in bytes. | |
1034 * | |
1035 * This function is used in the GTK+ 2 GUI only. The GTK+ 1 code makes use | |
1036 * of GdkEventKey::string instead. But event->string is evil; see here why: | |
1037 * http://developer.gnome.org/doc/API/2.0/gdk/gdk-Event-Structures.html#GdkEventKey | |
1038 */ | |
1039 static int | |
1040 keyval_to_string(unsigned int keyval, unsigned int state, char_u *string) | |
1041 { | |
1042 int len; | |
1043 guint32 uc; | |
1044 | |
1045 uc = gdk_keyval_to_unicode(keyval); | |
1046 if (uc != 0) | |
1047 { | |
1048 /* Check for CTRL-foo */ | |
1049 if ((state & GDK_CONTROL_MASK) && uc >= 0x20 && uc < 0x80) | |
1050 { | |
1051 /* These mappings look arbitrary at the first glance, but in fact | |
1052 * resemble quite exactly the behaviour of the GTK+ 1.2 GUI on my | |
1053 * machine. The only difference is BS vs. DEL for CTRL-8 (makes | |
1054 * more sense and is consistent with usual terminal behaviour). */ | |
1055 if (uc >= '@') | |
1056 string[0] = uc & 0x1F; | |
1057 else if (uc == '2') | |
1058 string[0] = NUL; | |
1059 else if (uc >= '3' && uc <= '7') | |
1060 string[0] = uc ^ 0x28; | |
1061 else if (uc == '8') | |
1062 string[0] = BS; | |
1063 else if (uc == '?') | |
1064 string[0] = DEL; | |
1065 else | |
1066 string[0] = uc; | |
1067 len = 1; | |
1068 } | |
1069 else | |
1070 { | |
1071 /* Translate a normal key to UTF-8. This doesn't work for dead | |
1072 * keys of course, you _have_ to use an input method for that. */ | |
1073 len = utf_char2bytes((int)uc, string); | |
1074 } | |
1075 } | |
1076 else | |
1077 { | |
1078 /* Translate keys which are represented by ASCII control codes in Vim. | |
1079 * There are only a few of those; most control keys are translated to | |
1080 * special terminal-like control sequences. */ | |
1081 len = 1; | |
1082 switch (keyval) | |
1083 { | |
1084 case GDK_Tab: case GDK_KP_Tab: case GDK_ISO_Left_Tab: | |
1085 string[0] = TAB; | |
1086 break; | |
1087 case GDK_Linefeed: | |
1088 string[0] = NL; | |
1089 break; | |
1090 case GDK_Return: case GDK_ISO_Enter: case GDK_3270_Enter: | |
1091 string[0] = CAR; | |
1092 break; | |
1093 case GDK_Escape: | |
1094 string[0] = ESC; | |
1095 break; | |
1096 default: | |
1097 len = 0; | |
1098 break; | |
1099 } | |
1100 } | |
1101 string[len] = NUL; | |
1102 | |
1103 return len; | |
1104 } | |
1105 | |
179 | 1106 static int |
1107 modifiers_gdk2vim(guint state) | |
1108 { | |
1109 int modifiers = 0; | |
1110 | |
1111 if (state & GDK_SHIFT_MASK) | |
1112 modifiers |= MOD_MASK_SHIFT; | |
1113 if (state & GDK_CONTROL_MASK) | |
1114 modifiers |= MOD_MASK_CTRL; | |
1115 if (state & GDK_MOD1_MASK) | |
1116 modifiers |= MOD_MASK_ALT; | |
2550
7c1f73452ea6
Fix #ifdef for GDK_SUPER_MASK.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
1117 #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
|
1118 if (state & GDK_SUPER_MASK) |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1119 modifiers |= MOD_MASK_META; |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1120 #endif |
179 | 1121 if (state & GDK_MOD4_MASK) |
1122 modifiers |= MOD_MASK_META; | |
1123 | |
1124 return modifiers; | |
1125 } | |
1126 | |
1127 static int | |
1128 modifiers_gdk2mouse(guint state) | |
1129 { | |
1130 int modifiers = 0; | |
1131 | |
1132 if (state & GDK_SHIFT_MASK) | |
1133 modifiers |= MOUSE_SHIFT; | |
1134 if (state & GDK_CONTROL_MASK) | |
1135 modifiers |= MOUSE_CTRL; | |
1136 if (state & GDK_MOD1_MASK) | |
1137 modifiers |= MOUSE_ALT; | |
1138 | |
1139 return modifiers; | |
1140 } | |
1141 | |
7 | 1142 /* |
1143 * Main keyboard handler: | |
1144 */ | |
1145 static gint | |
1884 | 1146 key_press_event(GtkWidget *widget UNUSED, |
1147 GdkEventKey *event, | |
1148 gpointer data UNUSED) | |
7 | 1149 { |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1150 /* For GTK+ 2 we know for sure how large the string might get. |
7 | 1151 * (That is, up to 6 bytes + NUL + CSI escapes + safety measure.) */ |
1152 char_u string[32], string2[32]; | |
1153 guint key_sym; | |
1154 int len; | |
1155 int i; | |
1156 int modifiers; | |
1157 int key; | |
1158 guint state; | |
1159 char_u *s, *d; | |
1160 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1161 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1162 is_key_pressed = TRUE; |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
1163 gui_mch_stop_blink(TRUE); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1164 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1165 |
2923 | 1166 gui.event_time = event->time; |
7 | 1167 key_sym = event->keyval; |
1168 state = event->state; | |
1169 | |
1170 #ifdef FEAT_XIM | |
1171 if (xim_queue_key_press_event(event, TRUE)) | |
1172 return TRUE; | |
1173 #endif | |
1174 | |
1175 #ifdef FEAT_HANGULIN | |
1176 if (key_sym == GDK_space && (state & GDK_SHIFT_MASK)) | |
1177 { | |
1178 hangul_input_state_toggle(); | |
1179 return TRUE; | |
1180 } | |
1181 #endif | |
1182 | |
1183 #ifdef SunXK_F36 | |
1184 /* | |
1185 * These keys have bogus lookup strings, and trapping them here is | |
1186 * easier than trying to XRebindKeysym() on them with every possible | |
1187 * combination of modifiers. | |
1188 */ | |
1189 if (key_sym == SunXK_F36 || key_sym == SunXK_F37) | |
1190 len = 0; | |
1191 else | |
1192 #endif | |
1193 { | |
1194 len = keyval_to_string(key_sym, state, string2); | |
1195 | |
1196 /* Careful: convert_input() doesn't handle the NUL character. | |
1197 * No need to convert pure ASCII anyway, thus the len > 1 check. */ | |
1198 if (len > 1 && input_conv.vc_type != CONV_NONE) | |
1199 len = convert_input(string2, len, sizeof(string2)); | |
1200 | |
1201 s = string2; | |
1202 d = string; | |
1203 for (i = 0; i < len; ++i) | |
1204 { | |
1205 *d++ = s[i]; | |
1206 if (d[-1] == CSI && d + 2 < string + sizeof(string)) | |
1207 { | |
1208 /* Turn CSI into K_CSI. */ | |
1209 *d++ = KS_EXTRA; | |
1210 *d++ = (int)KE_CSI; | |
1211 } | |
1212 } | |
1213 len = d - string; | |
1214 } | |
1215 | |
1216 /* Shift-Tab results in Left_Tab, but we want <S-Tab> */ | |
1217 if (key_sym == GDK_ISO_Left_Tab) | |
1218 { | |
1219 key_sym = GDK_Tab; | |
1220 state |= GDK_SHIFT_MASK; | |
1221 } | |
1222 | |
1223 #ifdef FEAT_MENU | |
1224 /* If there is a menu and 'wak' is "yes", or 'wak' is "menu" and the key | |
1225 * is a menu shortcut, we ignore everything with the ALT modifier. */ | |
1226 if ((state & GDK_MOD1_MASK) | |
1227 && gui.menu_is_active | |
1228 && (*p_wak == 'y' | |
1229 || (*p_wak == 'm' | |
1230 && len == 1 | |
1231 && gui_is_menu_shortcut(string[0])))) | |
1232 /* For GTK2 we return false to signify that we haven't handled the | |
1233 * keypress, so that gtk will handle the mnemonic or accelerator. */ | |
1234 return FALSE; | |
1235 #endif | |
1236 | |
1237 /* Check for Alt/Meta key (Mod1Mask), but not for a BS, DEL or character | |
1238 * that already has the 8th bit set. | |
1239 * Don't do this for <S-M-Tab>, that should become K_S_TAB with ALT. | |
1240 * Don't do this for double-byte encodings, it turns the char into a lead | |
1241 * byte. */ | |
1242 if (len == 1 | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1243 && ((state & GDK_MOD1_MASK) |
2571
42bdbc2bbb59
Fix #ifdef for GDK_SUPER_MASK. (Stephan Schulz)
Bram Moolenaar <bram@vim.org>
parents:
2550
diff
changeset
|
1244 #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
|
1245 || (state & GDK_SUPER_MASK) |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1246 #endif |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1247 ) |
7 | 1248 && !(key_sym == GDK_BackSpace || key_sym == GDK_Delete) |
1249 && (string[0] & 0x80) == 0 | |
1250 && !(key_sym == GDK_Tab && (state & GDK_SHIFT_MASK)) | |
1251 && !enc_dbcs | |
1252 ) | |
1253 { | |
1254 string[0] |= 0x80; | |
1255 state &= ~GDK_MOD1_MASK; /* don't use it again */ | |
1256 if (enc_utf8) /* convert to utf-8 */ | |
1257 { | |
1258 string[1] = string[0] & 0xbf; | |
1259 string[0] = ((unsigned)string[0] >> 6) + 0xc0; | |
1260 if (string[1] == CSI) | |
1261 { | |
1262 string[2] = KS_EXTRA; | |
1263 string[3] = (int)KE_CSI; | |
1264 len = 4; | |
1265 } | |
1266 else | |
1267 len = 2; | |
1268 } | |
1269 } | |
1270 | |
1271 /* Check for special keys. Also do this when len == 1 (key has an ASCII | |
1272 * value) to detect backspace, delete and keypad keys. */ | |
1273 if (len == 0 || len == 1) | |
1274 { | |
1275 for (i = 0; special_keys[i].key_sym != 0; i++) | |
1276 { | |
1277 if (special_keys[i].key_sym == key_sym) | |
1278 { | |
1279 string[0] = CSI; | |
1280 string[1] = special_keys[i].code0; | |
1281 string[2] = special_keys[i].code1; | |
1282 len = -3; | |
1283 break; | |
1284 } | |
1285 } | |
1286 } | |
1287 | |
1288 if (len == 0) /* Unrecognized key */ | |
1289 return TRUE; | |
1290 | |
1291 /* Special keys (and a few others) may have modifiers. Also when using a | |
1292 * double-byte encoding (can't set the 8th bit). */ | |
1293 if (len == -3 || key_sym == GDK_space || key_sym == GDK_Tab | |
1294 || key_sym == GDK_Return || key_sym == GDK_Linefeed | |
1295 || key_sym == GDK_Escape || key_sym == GDK_KP_Tab | |
1296 || 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
|
1297 || (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
|
1298 #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
|
1299 || (state & GDK_SUPER_MASK) |
7 | 1300 #endif |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1301 ))) |
7 | 1302 { |
179 | 1303 modifiers = modifiers_gdk2vim(state); |
7 | 1304 |
1305 /* | |
1306 * For some keys a shift modifier is translated into another key | |
1307 * code. | |
1308 */ | |
1309 if (len == -3) | |
1310 key = TO_SPECIAL(string[1], string[2]); | |
1311 else | |
1312 key = string[0]; | |
1313 | |
1314 key = simplify_key(key, &modifiers); | |
1315 if (key == CSI) | |
1316 key = K_CSI; | |
1317 if (IS_SPECIAL(key)) | |
1318 { | |
1319 string[0] = CSI; | |
1320 string[1] = K_SECOND(key); | |
1321 string[2] = K_THIRD(key); | |
1322 len = 3; | |
1323 } | |
1324 else | |
1325 { | |
1326 string[0] = key; | |
1327 len = 1; | |
1328 } | |
1329 | |
1330 if (modifiers != 0) | |
1331 { | |
1332 string2[0] = CSI; | |
1333 string2[1] = KS_MODIFIER; | |
1334 string2[2] = modifiers; | |
1335 add_to_input_buf(string2, 3); | |
1336 } | |
1337 } | |
1338 | |
1339 if (len == 1 && ((string[0] == Ctrl_C && ctrl_c_interrupts) | |
1340 || (string[0] == intr_char && intr_char != Ctrl_C))) | |
1341 { | |
1342 trash_input_buf(); | |
1343 got_int = TRUE; | |
1344 } | |
1345 | |
1346 add_to_input_buf(string, len); | |
1347 | |
1348 /* blank out the pointer if necessary */ | |
1349 if (p_mh) | |
1350 gui_mch_mousehide(TRUE); | |
1351 | |
1352 return TRUE; | |
1353 } | |
1354 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1355 #if defined(FEAT_XIM) || GTK_CHECK_VERSION(3,0,0) |
7 | 1356 static gboolean |
1884 | 1357 key_release_event(GtkWidget *widget UNUSED, |
1358 GdkEventKey *event, | |
1359 gpointer data UNUSED) | |
7 | 1360 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1361 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1362 is_key_pressed = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1363 gui_mch_start_blink(); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1364 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1365 # if defined(FEAT_XIM) |
2923 | 1366 gui.event_time = event->time; |
7 | 1367 /* |
1368 * GTK+ 2 input methods may do fancy stuff on key release events too. | |
1369 * With the default IM for instance, you can enter any UCS code point | |
1370 * by holding down CTRL-SHIFT and typing hexadecimal digits. | |
1371 */ | |
1372 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
|
1373 # else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1374 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1375 # endif |
7 | 1376 } |
1377 #endif | |
1378 | |
1379 | |
1380 /**************************************************************************** | |
1381 * Selection handlers: | |
1382 */ | |
1383 | |
13503
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1384 /* Remember when clip_lose_selection was called from here, we must not call |
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1385 * gtk_selection_owner_set() then. */ |
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1386 static int in_selection_clear_event = FALSE; |
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1387 |
7 | 1388 static gint |
1884 | 1389 selection_clear_event(GtkWidget *widget UNUSED, |
7 | 1390 GdkEventSelection *event, |
1884 | 1391 gpointer user_data UNUSED) |
7 | 1392 { |
13503
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1393 in_selection_clear_event = TRUE; |
7 | 1394 if (event->selection == clip_plus.gtk_sel_atom) |
1395 clip_lose_selection(&clip_plus); | |
1396 else | |
1397 clip_lose_selection(&clip_star); | |
13503
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1398 in_selection_clear_event = FALSE; |
7 | 1399 |
1400 return TRUE; | |
1401 } | |
1402 | |
1403 #define RS_NONE 0 /* selection_received_cb() not called yet */ | |
1404 #define RS_OK 1 /* selection_received_cb() called and OK */ | |
1405 #define RS_FAIL 2 /* selection_received_cb() called and failed */ | |
1406 static int received_selection = RS_NONE; | |
1407 | |
1408 static void | |
1884 | 1409 selection_received_cb(GtkWidget *widget UNUSED, |
7 | 1410 GtkSelectionData *data, |
1884 | 1411 guint time_ UNUSED, |
1412 gpointer user_data UNUSED) | |
7 | 1413 { |
1414 VimClipboard *cbd; | |
1415 char_u *text; | |
1416 char_u *tmpbuf = NULL; | |
1417 guchar *tmpbuf_utf8 = NULL; | |
1418 int len; | |
2896 | 1419 int motion_type = MAUTO; |
7 | 1420 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1421 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1422 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
|
1423 #else |
7 | 1424 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
|
1425 #endif |
7 | 1426 cbd = &clip_plus; |
1427 else | |
1428 cbd = &clip_star; | |
1429 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1430 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1431 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
|
1432 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
|
1433 #else |
7 | 1434 text = (char_u *)data->data; |
1435 len = data->length; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1436 #endif |
7 | 1437 |
1438 if (text == NULL || len <= 0) | |
1439 { | |
1440 received_selection = RS_FAIL; | |
1441 /* clip_free_selection(cbd); ??? */ | |
1442 | |
1443 return; | |
1444 } | |
1445 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1446 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1447 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
|
1448 #else |
7 | 1449 if (data->type == vim_atom) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1450 #endif |
7 | 1451 { |
1452 motion_type = *text++; | |
1453 --len; | |
1454 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1455 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1456 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
|
1457 #else |
7 | 1458 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
|
1459 #endif |
7 | 1460 { |
1461 char_u *enc; | |
1462 vimconv_T conv; | |
1463 | |
1464 motion_type = *text++; | |
1465 --len; | |
1466 | |
1467 enc = text; | |
1468 text += STRLEN(text) + 1; | |
1469 len -= text - enc; | |
1470 | |
1471 /* If the encoding of the text is different from 'encoding', attempt | |
1472 * converting it. */ | |
1473 conv.vc_type = CONV_NONE; | |
1474 convert_setup(&conv, enc, p_enc); | |
1475 if (conv.vc_type != CONV_NONE) | |
1476 { | |
1477 tmpbuf = string_convert(&conv, text, &len); | |
1478 if (tmpbuf != NULL) | |
1479 text = tmpbuf; | |
1480 convert_setup(&conv, NULL, NULL); | |
1481 } | |
1482 } | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1483 |
7 | 1484 /* gtk_selection_data_get_text() handles all the nasty details |
1485 * and targets and encodings etc. This rocks so hard. */ | |
1486 else | |
1487 { | |
1488 tmpbuf_utf8 = gtk_selection_data_get_text(data); | |
1489 if (tmpbuf_utf8 != NULL) | |
1490 { | |
1491 len = STRLEN(tmpbuf_utf8); | |
1492 if (input_conv.vc_type != CONV_NONE) | |
1493 { | |
1494 tmpbuf = string_convert(&input_conv, tmpbuf_utf8, &len); | |
1495 if (tmpbuf != NULL) | |
1496 text = tmpbuf; | |
1497 } | |
1498 else | |
1499 text = tmpbuf_utf8; | |
1500 } | |
1904 | 1501 else if (len >= 2 && text[0] == 0xff && text[1] == 0xfe) |
1502 { | |
1503 vimconv_T conv; | |
1504 | |
1505 /* UTF-16, we get this for HTML */ | |
1506 conv.vc_type = CONV_NONE; | |
1507 convert_setup_ext(&conv, (char_u *)"utf-16le", FALSE, p_enc, TRUE); | |
1508 | |
1509 if (conv.vc_type != CONV_NONE) | |
1510 { | |
1511 text += 2; | |
1512 len -= 2; | |
1513 tmpbuf = string_convert(&conv, text, &len); | |
1514 convert_setup(&conv, NULL, NULL); | |
1515 } | |
1516 if (tmpbuf != NULL) | |
1517 text = tmpbuf; | |
1518 } | |
7 | 1519 } |
1520 | |
4352 | 1521 /* Chop off any trailing NUL bytes. OpenOffice sends these. */ |
2183 | 1522 while (len > 0 && text[len - 1] == NUL) |
1523 --len; | |
1524 | |
7 | 1525 clip_yank_selection(motion_type, text, (long)len, cbd); |
1526 received_selection = RS_OK; | |
1527 vim_free(tmpbuf); | |
1528 g_free(tmpbuf_utf8); | |
1529 } | |
1530 | |
1531 /* | |
1532 * Prepare our selection data for passing it to the external selection | |
1533 * client. | |
1534 */ | |
1535 static void | |
1884 | 1536 selection_get_cb(GtkWidget *widget UNUSED, |
7 | 1537 GtkSelectionData *selection_data, |
1538 guint info, | |
1884 | 1539 guint time_ UNUSED, |
1540 gpointer user_data UNUSED) | |
7 | 1541 { |
1542 char_u *string; | |
1543 char_u *tmpbuf; | |
1544 long_u tmplen; | |
1545 int length; | |
1546 int motion_type; | |
1547 GdkAtom type; | |
1548 VimClipboard *cbd; | |
1549 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1550 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1551 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
|
1552 == clip_plus.gtk_sel_atom) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1553 #else |
7 | 1554 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
|
1555 #endif |
7 | 1556 cbd = &clip_plus; |
1557 else | |
1558 cbd = &clip_star; | |
1559 | |
1560 if (!cbd->owned) | |
1561 return; /* Shouldn't ever happen */ | |
1562 | |
1563 if (info != (guint)TARGET_STRING | |
1904 | 1564 && (!clip_html || info != (guint)TARGET_HTML) |
7 | 1565 && info != (guint)TARGET_UTF8_STRING |
1566 && info != (guint)TARGET_VIMENC | |
1567 && info != (guint)TARGET_VIM | |
1568 && info != (guint)TARGET_COMPOUND_TEXT | |
1569 && info != (guint)TARGET_TEXT) | |
1570 return; | |
1571 | |
1572 /* get the selection from the '*'/'+' register */ | |
1573 clip_get_selection(cbd); | |
1574 | |
1575 motion_type = clip_convert_selection(&string, &tmplen, cbd); | |
1576 if (motion_type < 0 || string == NULL) | |
1577 return; | |
1578 /* Due to int arguments we can't handle more than G_MAXINT. Also | |
1579 * reserve one extra byte for NUL or the motion type; just in case. | |
1580 * (Not that pasting 2G of text is ever going to work, but... ;-) */ | |
1581 length = MIN(tmplen, (long_u)(G_MAXINT - 1)); | |
1582 | |
1583 if (info == (guint)TARGET_VIM) | |
1584 { | |
1585 tmpbuf = alloc((unsigned)length + 1); | |
1586 if (tmpbuf != NULL) | |
1587 { | |
1588 tmpbuf[0] = motion_type; | |
1589 mch_memmove(tmpbuf + 1, string, (size_t)length); | |
1590 } | |
1591 /* For our own format, the first byte contains the motion type */ | |
1592 ++length; | |
1593 vim_free(string); | |
1594 string = tmpbuf; | |
1595 type = vim_atom; | |
1596 } | |
1597 | |
1904 | 1598 else if (info == (guint)TARGET_HTML) |
1599 { | |
1600 vimconv_T conv; | |
1601 | |
1602 /* Since we get utf-16, we probably should set it as well. */ | |
1603 conv.vc_type = CONV_NONE; | |
1604 convert_setup_ext(&conv, p_enc, TRUE, (char_u *)"utf-16le", FALSE); | |
1605 if (conv.vc_type != CONV_NONE) | |
1606 { | |
1607 tmpbuf = string_convert(&conv, string, &length); | |
1608 convert_setup(&conv, NULL, NULL); | |
1609 vim_free(string); | |
1610 string = tmpbuf; | |
1611 } | |
1612 | |
1613 /* Prepend the BOM: "fffe" */ | |
1614 if (string != NULL) | |
1615 { | |
1616 tmpbuf = alloc(length + 2); | |
1617 tmpbuf[0] = 0xff; | |
1618 tmpbuf[1] = 0xfe; | |
1619 mch_memmove(tmpbuf + 2, string, (size_t)length); | |
1620 vim_free(string); | |
1621 string = tmpbuf; | |
1622 length += 2; | |
1623 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1624 #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
|
1625 /* 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
|
1626 * overwritten by gtk_selection_data_set() that follows. */ |
1904 | 1627 selection_data->type = selection_data->target; |
1628 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
|
1629 #endif |
1904 | 1630 gtk_selection_data_set(selection_data, html_atom, 16, |
1631 string, length); | |
1632 vim_free(string); | |
1633 } | |
1634 return; | |
1635 } | |
7 | 1636 else if (info == (guint)TARGET_VIMENC) |
1637 { | |
1638 int l = STRLEN(p_enc); | |
1639 | |
1640 /* contents: motion_type 'encoding' NUL text */ | |
1641 tmpbuf = alloc((unsigned)length + l + 2); | |
1642 if (tmpbuf != NULL) | |
1643 { | |
1644 tmpbuf[0] = motion_type; | |
1645 STRCPY(tmpbuf + 1, p_enc); | |
1646 mch_memmove(tmpbuf + l + 2, string, (size_t)length); | |
1647 } | |
1648 length += l + 2; | |
1649 vim_free(string); | |
1650 string = tmpbuf; | |
1651 type = vimenc_atom; | |
1652 } | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1653 |
7 | 1654 /* gtk_selection_data_set_text() handles everything for us. This is |
1655 * so easy and simple and cool, it'd be insane not to use it. */ | |
1656 else | |
1657 { | |
1658 if (output_conv.vc_type != CONV_NONE) | |
1659 { | |
1660 tmpbuf = string_convert(&output_conv, string, &length); | |
1661 vim_free(string); | |
1662 if (tmpbuf == NULL) | |
1663 return; | |
1664 string = tmpbuf; | |
1665 } | |
1666 /* Validate the string to avoid runtime warnings */ | |
1667 if (g_utf8_validate((const char *)string, (gssize)length, NULL)) | |
1668 { | |
1669 gtk_selection_data_set_text(selection_data, | |
1670 (const char *)string, length); | |
1671 } | |
1672 vim_free(string); | |
1673 return; | |
1674 } | |
1675 | |
1676 if (string != NULL) | |
1677 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1678 #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
|
1679 /* 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
|
1680 * overwritten by gtk_selection_data_set() that follows. */ |
7 | 1681 selection_data->type = selection_data->target; |
1682 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
|
1683 #endif |
7 | 1684 gtk_selection_data_set(selection_data, type, 8, string, length); |
1685 vim_free(string); | |
1686 } | |
1687 } | |
1688 | |
1689 /* | |
3518 | 1690 * Check if the GUI can be started. Called before gvimrc is sourced and |
1691 * before fork(). | |
1692 * Return OK or FAIL. | |
1693 */ | |
1694 int | |
9836
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
1695 gui_mch_early_init_check(int give_message) |
3518 | 1696 { |
1697 char_u *p; | |
1698 | |
1699 /* Guess that when $DISPLAY isn't set the GUI can't start. */ | |
1700 p = mch_getenv((char_u *)"DISPLAY"); | |
1701 if (p == NULL || *p == NUL) | |
1702 { | |
1703 gui.dying = TRUE; | |
9836
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
1704 if (give_message) |
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
1705 EMSG(_((char *)e_opendisp)); |
3518 | 1706 return FAIL; |
1707 } | |
1708 return OK; | |
1709 } | |
1710 | |
1711 /* | |
1712 * Check if the GUI can be started. Called before gvimrc is sourced but after | |
1713 * fork(). | |
7 | 1714 * Return OK or FAIL. |
1715 */ | |
1716 int | |
1717 gui_mch_init_check(void) | |
1718 { | |
7679
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1719 #ifdef USE_GRESOURCE |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1720 static int res_registered = FALSE; |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1721 |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1722 if (!res_registered) |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1723 { |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1724 /* 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
|
1725 * 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
|
1726 res_registered = TRUE; |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1727 gui_gtk_register_resource(); |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1728 } |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1729 #endif |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1730 |
8851
1b38596644ba
commit https://github.com/vim/vim/commit/f80663f17b2f2499b45eb4467088704c8298c385
Christian Brabandt <cb@256bit.org>
parents:
8510
diff
changeset
|
1731 #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
|
1732 /* 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
|
1733 * 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
|
1734 gdk_set_allowed_backends ("x11"); |
1b38596644ba
commit https://github.com/vim/vim/commit/f80663f17b2f2499b45eb4467088704c8298c385
Christian Brabandt <cb@256bit.org>
parents:
8510
diff
changeset
|
1735 #endif |
1b38596644ba
commit https://github.com/vim/vim/commit/f80663f17b2f2499b45eb4467088704c8298c385
Christian Brabandt <cb@256bit.org>
parents:
8510
diff
changeset
|
1736 |
7 | 1737 #ifdef FEAT_GUI_GNOME |
1738 if (gtk_socket_id == 0) | |
1739 using_gnome = 1; | |
1740 #endif | |
1741 | |
4474 | 1742 /* This defaults to argv[0], but we want it to match the name of the |
1743 * shipped gvim.desktop so that Vim's windows can be associated with this | |
1744 * file. */ | |
1745 g_set_prgname("gvim"); | |
1746 | |
7 | 1747 /* Don't use gtk_init() or gnome_init(), it exits on failure. */ |
1748 if (!gtk_init_check(&gui_argc, &gui_argv)) | |
1749 { | |
1750 gui.dying = TRUE; | |
1666 | 1751 EMSG(_((char *)e_opendisp)); |
7 | 1752 return FAIL; |
1753 } | |
1754 | |
1755 return OK; | |
1756 } | |
1757 | |
1758 /**************************************************************************** | |
1759 * Mouse handling callbacks | |
1760 */ | |
1761 | |
1762 | |
1763 static guint mouse_click_timer = 0; | |
1764 static int mouse_timed_out = TRUE; | |
1765 | |
1766 /* | |
1767 * Timer used to recognize multiple clicks of the mouse button | |
1768 */ | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
1769 static timeout_cb_type |
7 | 1770 mouse_click_timer_cb(gpointer data) |
1771 { | |
1772 /* we don't use this information currently */ | |
1773 int *timed_out = (int *) data; | |
1774 | |
1775 *timed_out = TRUE; | |
1776 return FALSE; /* don't happen again */ | |
1777 } | |
1778 | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
1779 static guint motion_repeat_timer = 0; |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
1780 static int motion_repeat_offset = FALSE; |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
1781 static timeout_cb_type motion_repeat_timer_cb(gpointer); |
7 | 1782 |
1783 static void | |
1784 process_motion_notify(int x, int y, GdkModifierType state) | |
1785 { | |
1786 int button; | |
1787 int_u vim_modifiers; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1788 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1789 GtkAllocation allocation; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1790 #endif |
7 | 1791 |
1792 button = (state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | | |
1793 GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | | |
1794 GDK_BUTTON5_MASK)) | |
1795 ? MOUSE_DRAG : ' '; | |
1796 | |
1797 /* If our pointer is currently hidden, then we should show it. */ | |
1798 gui_mch_mousehide(FALSE); | |
1799 | |
1800 /* Just moving the rodent above the drawing area without any button | |
1801 * being pressed. */ | |
1802 if (button != MOUSE_DRAG) | |
1803 { | |
1804 gui_mouse_moved(x, y); | |
1805 return; | |
1806 } | |
1807 | |
1808 /* translate modifier coding between the main engine and GTK */ | |
179 | 1809 vim_modifiers = modifiers_gdk2mouse(state); |
7 | 1810 |
1226 | 1811 /* inform the editor engine about the occurrence of this event */ |
7 | 1812 gui_send_mouse_event(button, x, y, FALSE, vim_modifiers); |
1813 | |
1814 /* | |
1815 * Auto repeat timer handling. | |
1816 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1817 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1818 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
|
1819 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1820 if (x < 0 || y < 0 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1821 || x >= allocation.width |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1822 || y >= allocation.height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1823 #else |
7 | 1824 if (x < 0 || y < 0 |
1825 || x >= gui.drawarea->allocation.width | |
1826 || y >= gui.drawarea->allocation.height) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1827 #endif |
7 | 1828 { |
1829 | |
1830 int dx; | |
1831 int dy; | |
1832 int offshoot; | |
1833 int delay = 10; | |
1834 | |
1835 /* Calculate the maximal distance of the cursor from the drawing area. | |
1836 * (offshoot can't become negative here!). | |
1837 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1838 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1839 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
|
1840 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
|
1841 #else |
7 | 1842 dx = x < 0 ? -x : x - gui.drawarea->allocation.width; |
1843 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
|
1844 #endif |
7 | 1845 |
1846 offshoot = dx > dy ? dx : dy; | |
1847 | |
1884 | 1848 /* Make a linearly decaying timer delay with a threshold of 5 at a |
7 | 1849 * distance of 127 pixels from the main window. |
1850 * | |
1851 * One could think endlessly about the most ergonomic variant here. | |
1852 * For example it could make sense to calculate the distance from the | |
1853 * drags start instead... | |
1854 * | |
1855 * Maybe a parabolic interpolation would suite us better here too... | |
1856 */ | |
1857 if (offshoot > 127) | |
1858 { | |
1859 /* 5 appears to be somehow near to my perceptual limits :-). */ | |
1860 delay = 5; | |
1861 } | |
1862 else | |
1863 { | |
1864 delay = (130 * (127 - offshoot)) / 127 + 5; | |
1865 } | |
1866 | |
1867 /* shoot again */ | |
1868 if (!motion_repeat_timer) | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
1869 motion_repeat_timer = timeout_add(delay, motion_repeat_timer_cb, |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
1870 NULL); |
8218
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 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1874 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1875 static GdkDevice * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1876 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
|
1877 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1878 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
|
1879 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
|
1880 # 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
|
1881 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
|
1882 return gdk_seat_get_pointer(seat); |
fc69eed19ba7
commit https://github.com/vim/vim/commit/30e12d259ee78272359f9da2655d0593a4f6a626
Christian Brabandt <cb@256bit.org>
parents:
8851
diff
changeset
|
1883 # else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1884 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
|
1885 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
|
1886 # endif |
8218
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 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1889 static GdkWindow * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1890 gui_gtk_get_pointer(GtkWidget *widget, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1891 gint *x, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1892 gint *y, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1893 GdkModifierType *state) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1894 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1895 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
|
1896 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
|
1897 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
|
1898 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1899 |
8397
1e58a938aafc
commit https://github.com/vim/vim/commit/2369c15407cf9a730a396ebf9709abb280c5ce48
Christian Brabandt <cb@256bit.org>
parents:
8301
diff
changeset
|
1900 # 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
|
1901 static GdkWindow * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1902 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
|
1903 gint *x, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1904 gint *y) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1905 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1906 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
|
1907 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
|
1908 } |
8397
1e58a938aafc
commit https://github.com/vim/vim/commit/2369c15407cf9a730a396ebf9709abb280c5ce48
Christian Brabandt <cb@256bit.org>
parents:
8301
diff
changeset
|
1909 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1910 #endif |
7 | 1911 |
1912 /* | |
1913 * Timer used to recognize multiple clicks of the mouse button. | |
1914 */ | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
1915 static timeout_cb_type |
1884 | 1916 motion_repeat_timer_cb(gpointer data UNUSED) |
7 | 1917 { |
1918 int x; | |
1919 int y; | |
1920 GdkModifierType state; | |
1921 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1922 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1923 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
|
1924 #else |
7 | 1925 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
|
1926 #endif |
7 | 1927 |
1928 if (!(state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | | |
1929 GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | | |
1930 GDK_BUTTON5_MASK))) | |
1931 { | |
1932 motion_repeat_timer = 0; | |
1933 return FALSE; | |
1934 } | |
1935 | |
1936 /* If there already is a mouse click in the input buffer, wait another | |
1937 * time (otherwise we would create a backlog of clicks) */ | |
1938 if (vim_used_in_input_buf() > 10) | |
1939 return TRUE; | |
1940 | |
1941 motion_repeat_timer = 0; | |
1942 | |
1943 /* | |
1944 * Fake a motion event. | |
1945 * Trick: Pretend the mouse moved to the next character on every other | |
1946 * event, otherwise drag events will be discarded, because they are still | |
1947 * in the same character. | |
1948 */ | |
1949 if (motion_repeat_offset) | |
1950 x += gui.char_width; | |
1951 | |
1952 motion_repeat_offset = !motion_repeat_offset; | |
1953 process_motion_notify(x, y, state); | |
1954 | |
1955 /* Don't happen again. We will get reinstalled in the synthetic event | |
1956 * if needed -- thus repeating should still work. */ | |
1957 return FALSE; | |
1958 } | |
1959 | |
1960 static gint | |
1884 | 1961 motion_notify_event(GtkWidget *widget, |
1962 GdkEventMotion *event, | |
1963 gpointer data UNUSED) | |
7 | 1964 { |
1965 if (event->is_hint) | |
1966 { | |
1967 int x; | |
1968 int y; | |
1969 GdkModifierType state; | |
1970 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1971 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1972 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
|
1973 #else |
7 | 1974 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
|
1975 #endif |
7 | 1976 process_motion_notify(x, y, state); |
1977 } | |
1978 else | |
1979 { | |
1980 process_motion_notify((int)event->x, (int)event->y, | |
1981 (GdkModifierType)event->state); | |
1982 } | |
1983 | |
1984 return TRUE; /* handled */ | |
1985 } | |
1986 | |
1987 | |
1988 /* | |
1989 * Mouse button handling. Note please that we are capturing multiple click's | |
1990 * by our own timeout mechanism instead of the one provided by GTK+ itself. | |
1991 * This is due to the way the generic VIM code is recognizing multiple clicks. | |
1992 */ | |
1993 static gint | |
1884 | 1994 button_press_event(GtkWidget *widget, |
1995 GdkEventButton *event, | |
1996 gpointer data UNUSED) | |
7 | 1997 { |
1998 int button; | |
1999 int repeated_click = FALSE; | |
2000 int x, y; | |
2001 int_u vim_modifiers; | |
2002 | |
2923 | 2003 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
|
2004 |
7 | 2005 /* 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
|
2006 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2007 if (gtk_socket_id != 0 && !gtk_widget_has_focus(widget)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2008 #else |
7 | 2009 if (gtk_socket_id != 0 && !GTK_WIDGET_HAS_FOCUS(widget)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2010 #endif |
7 | 2011 gtk_widget_grab_focus(widget); |
2012 | |
2013 /* | |
2014 * Don't let additional events about multiple clicks send by GTK to us | |
2015 * after the initial button press event confuse us. | |
2016 */ | |
2017 if (event->type != GDK_BUTTON_PRESS) | |
2018 return FALSE; | |
2019 | |
2020 x = event->x; | |
2021 y = event->y; | |
2022 | |
2023 /* Handle multiple clicks */ | |
2024 if (!mouse_timed_out && mouse_click_timer) | |
2025 { | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
2026 timeout_remove(mouse_click_timer); |
7 | 2027 mouse_click_timer = 0; |
2028 repeated_click = TRUE; | |
2029 } | |
2030 | |
2031 mouse_timed_out = FALSE; | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
2032 mouse_click_timer = timeout_add(p_mouset, mouse_click_timer_cb, |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
2033 &mouse_timed_out); |
7 | 2034 |
2035 switch (event->button) | |
2036 { | |
7260
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2037 /* 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
|
2038 * 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
|
2039 case 1: button = MOUSE_LEFT; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2040 case 2: button = MOUSE_MIDDLE; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2041 case 3: button = MOUSE_RIGHT; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2042 case 8: button = MOUSE_X1; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2043 case 9: button = MOUSE_X2; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2044 default: |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2045 return FALSE; /* Unknown button */ |
7 | 2046 } |
2047 | |
2048 #ifdef FEAT_XIM | |
2049 /* cancel any preediting */ | |
2050 if (im_is_preediting()) | |
2051 xim_reset(); | |
2052 #endif | |
2053 | |
179 | 2054 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 2055 |
2056 gui_send_mouse_event(button, x, y, repeated_click, vim_modifiers); | |
2057 | |
2058 return TRUE; | |
2059 } | |
2060 | |
2061 /* | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
2062 * GTK+ 2 abstracts scrolling via the GdkEventScroll. |
7 | 2063 */ |
2064 static gboolean | |
1884 | 2065 scroll_event(GtkWidget *widget, |
2066 GdkEventScroll *event, | |
2067 gpointer data UNUSED) | |
7 | 2068 { |
2069 int button; | |
179 | 2070 int_u vim_modifiers; |
7 | 2071 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2072 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2073 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
|
2074 #else |
7 | 2075 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
|
2076 #endif |
7 | 2077 gtk_widget_grab_focus(widget); |
2078 | |
2079 switch (event->direction) | |
2080 { | |
2081 case GDK_SCROLL_UP: | |
2082 button = MOUSE_4; | |
2083 break; | |
2084 case GDK_SCROLL_DOWN: | |
2085 button = MOUSE_5; | |
2086 break; | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2087 case GDK_SCROLL_LEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2088 button = MOUSE_7; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2089 break; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2090 case GDK_SCROLL_RIGHT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2091 button = MOUSE_6; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2092 break; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2093 default: /* This shouldn't happen */ |
7 | 2094 return FALSE; |
2095 } | |
2096 | |
2097 # ifdef FEAT_XIM | |
2098 /* cancel any preediting */ | |
2099 if (im_is_preediting()) | |
2100 xim_reset(); | |
2101 # endif | |
2102 | |
179 | 2103 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 2104 |
2105 gui_send_mouse_event(button, (int)event->x, (int)event->y, | |
2106 FALSE, vim_modifiers); | |
2107 | |
2108 return TRUE; | |
2109 } | |
2110 | |
2111 | |
2112 static gint | |
1884 | 2113 button_release_event(GtkWidget *widget UNUSED, |
2114 GdkEventButton *event, | |
2115 gpointer data UNUSED) | |
7 | 2116 { |
2117 int x, y; | |
2118 int_u vim_modifiers; | |
2119 | |
2923 | 2120 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
|
2121 |
7 | 2122 /* Remove any motion "machine gun" timers used for automatic further |
2123 extension of allocation areas if outside of the applications window | |
2124 area .*/ | |
2125 if (motion_repeat_timer) | |
2126 { | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
2127 timeout_remove(motion_repeat_timer); |
7 | 2128 motion_repeat_timer = 0; |
2129 } | |
2130 | |
2131 x = event->x; | |
2132 y = event->y; | |
2133 | |
179 | 2134 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 2135 |
2136 gui_send_mouse_event(MOUSE_RELEASE, x, y, FALSE, vim_modifiers); | |
2137 | |
2138 return TRUE; | |
2139 } | |
2140 | |
2141 | |
2142 #ifdef FEAT_DND | |
2143 /**************************************************************************** | |
2144 * Drag aNd Drop support handlers. | |
2145 */ | |
2146 | |
2147 /* | |
2148 * Count how many items there may be and separate them with a NUL. | |
2149 * Apparently the items are separated with \r\n. This is not documented, | |
2150 * thus be careful not to go past the end. Also allow separation with | |
2151 * NUL characters. | |
2152 */ | |
2153 static int | |
2154 count_and_decode_uri_list(char_u *out, char_u *raw, int len) | |
2155 { | |
2156 int i; | |
2157 char_u *p = out; | |
2158 int count = 0; | |
2159 | |
2160 for (i = 0; i < len; ++i) | |
2161 { | |
2162 if (raw[i] == NUL || raw[i] == '\n' || raw[i] == '\r') | |
2163 { | |
2164 if (p > out && p[-1] != NUL) | |
2165 { | |
2166 ++count; | |
2167 *p++ = NUL; | |
2168 } | |
2169 } | |
2170 else if (raw[i] == '%' && i + 2 < len && hexhex2nr(raw + i + 1) > 0) | |
2171 { | |
2172 *p++ = hexhex2nr(raw + i + 1); | |
2173 i += 2; | |
2174 } | |
2175 else | |
2176 *p++ = raw[i]; | |
2177 } | |
2178 if (p > out && p[-1] != NUL) | |
2179 { | |
2180 *p = NUL; /* last item didn't have \r or \n */ | |
2181 ++count; | |
2182 } | |
2183 return count; | |
2184 } | |
2185 | |
2186 /* | |
2187 * Parse NUL separated "src" strings. Make it an array "outlist" form. On | |
2188 * this process, URI which protocol is not "file:" are removed. Return | |
2189 * length of array (less than "max"). | |
2190 */ | |
2191 static int | |
2192 filter_uri_list(char_u **outlist, int max, char_u *src) | |
2193 { | |
2194 int i, j; | |
2195 | |
2196 for (i = j = 0; i < max; ++i) | |
2197 { | |
2198 outlist[i] = NULL; | |
2199 if (STRNCMP(src, "file:", 5) == 0) | |
2200 { | |
2201 src += 5; | |
2202 if (STRNCMP(src, "//localhost", 11) == 0) | |
2203 src += 11; | |
2204 while (src[0] == '/' && src[1] == '/') | |
2205 ++src; | |
2206 outlist[j++] = vim_strsave(src); | |
2207 } | |
2208 src += STRLEN(src) + 1; | |
2209 } | |
2210 return j; | |
2211 } | |
2212 | |
2213 static char_u ** | |
2214 parse_uri_list(int *count, char_u *data, int len) | |
2215 { | |
2216 int n = 0; | |
2217 char_u *tmp = NULL; | |
9252
c25898cc99c1
commit https://github.com/vim/vim/commit/945ec093cd4ddefab930239990564b12eb232153
Christian Brabandt <cb@256bit.org>
parents:
9232
diff
changeset
|
2218 char_u **array = NULL; |
7 | 2219 |
2220 if (data != NULL && len > 0 && (tmp = (char_u *)alloc(len + 1)) != NULL) | |
2221 { | |
2222 n = count_and_decode_uri_list(tmp, data, len); | |
2223 if (n > 0 && (array = (char_u **)alloc(n * sizeof(char_u *))) != NULL) | |
2224 n = filter_uri_list(array, n, tmp); | |
2225 } | |
2226 vim_free(tmp); | |
2227 *count = n; | |
2228 return array; | |
2229 } | |
2230 | |
2231 static void | |
2232 drag_handle_uri_list(GdkDragContext *context, | |
2233 GtkSelectionData *data, | |
2234 guint time_, | |
2235 GdkModifierType state, | |
2236 gint x, | |
2237 gint y) | |
2238 { | |
2239 char_u **fnames; | |
2240 int nfiles = 0; | |
2241 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2242 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2243 fnames = parse_uri_list(&nfiles, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2244 (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
|
2245 gtk_selection_data_get_length(data)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2246 # else |
7 | 2247 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
|
2248 # endif |
7 | 2249 |
2250 if (fnames != NULL && nfiles > 0) | |
2251 { | |
179 | 2252 int_u modifiers; |
7 | 2253 |
2254 gtk_drag_finish(context, TRUE, FALSE, time_); /* accept */ | |
2255 | |
179 | 2256 modifiers = modifiers_gdk2mouse(state); |
7 | 2257 |
2258 gui_handle_drop(x, y, modifiers, fnames, nfiles); | |
2259 } | |
840 | 2260 else |
2261 vim_free(fnames); | |
7 | 2262 } |
2263 | |
2264 static void | |
2265 drag_handle_text(GdkDragContext *context, | |
2266 GtkSelectionData *data, | |
2267 guint time_, | |
2268 GdkModifierType state) | |
2269 { | |
2270 char_u dropkey[6] = {CSI, KS_MODIFIER, 0, CSI, KS_EXTRA, (char_u)KE_DROP}; | |
2271 char_u *text; | |
2272 int len; | |
2273 char_u *tmpbuf = NULL; | |
2274 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2275 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2276 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
|
2277 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
|
2278 # else |
7 | 2279 text = data->data; |
2280 len = data->length; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2281 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2282 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2283 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2284 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
|
2285 # else |
7 | 2286 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
|
2287 # endif |
7 | 2288 { |
2289 if (input_conv.vc_type != CONV_NONE) | |
2290 tmpbuf = string_convert(&input_conv, text, &len); | |
2291 if (tmpbuf != NULL) | |
2292 text = tmpbuf; | |
2293 } | |
2294 | |
2295 dnd_yank_drag_data(text, (long)len); | |
2296 gtk_drag_finish(context, TRUE, FALSE, time_); /* accept */ | |
2297 vim_free(tmpbuf); | |
2298 | |
179 | 2299 dropkey[2] = modifiers_gdk2vim(state); |
7 | 2300 |
2301 if (dropkey[2] != 0) | |
2302 add_to_input_buf(dropkey, (int)sizeof(dropkey)); | |
2303 else | |
2304 add_to_input_buf(dropkey + 3, (int)(sizeof(dropkey) - 3)); | |
2305 } | |
2306 | |
2307 /* | |
2308 * DND receiver. | |
2309 */ | |
2310 static void | |
2311 drag_data_received_cb(GtkWidget *widget, | |
2312 GdkDragContext *context, | |
2313 gint x, | |
2314 gint y, | |
2315 GtkSelectionData *data, | |
2316 guint info, | |
2317 guint time_, | |
1884 | 2318 gpointer user_data UNUSED) |
7 | 2319 { |
2320 GdkModifierType state; | |
2321 | |
2322 /* Guard against trash */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2323 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2324 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
|
2325 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
|
2326 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
|
2327 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2328 if (data_data == NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2329 || data_length <= 0 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2330 || data_format != 8 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2331 || data_data[data_length] != '\0') |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2332 # else |
7 | 2333 if (data->data == NULL |
2334 || data->length <= 0 | |
2335 || data->format != 8 | |
2336 || data->data[data->length] != '\0') | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2337 # endif |
7 | 2338 { |
2339 gtk_drag_finish(context, FALSE, FALSE, time_); | |
2340 return; | |
2341 } | |
2342 | |
2343 /* Get the current modifier state for proper distinguishment between | |
2344 * different operations later. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2345 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2346 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
|
2347 # else |
7 | 2348 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
|
2349 # endif |
7 | 2350 |
2351 /* Not sure about the role of "text/plain" here... */ | |
2352 if (info == (guint)TARGET_TEXT_URI_LIST) | |
2353 drag_handle_uri_list(context, data, time_, state, x, y); | |
2354 else | |
2355 drag_handle_text(context, data, time_, state); | |
2356 | |
2357 } | |
2358 #endif /* FEAT_DND */ | |
2359 | |
2360 | |
2361 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
2362 /* | |
2363 * GnomeClient interact callback. Check for unsaved buffers that cannot | |
2364 * be abandoned and pop up a dialog asking the user for confirmation if | |
2365 * necessary. | |
2366 */ | |
2367 static void | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2368 sm_client_check_changed_any(GnomeClient *client UNUSED, |
7 | 2369 gint key, |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2370 GnomeDialogType type UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2371 gpointer data UNUSED) |
7 | 2372 { |
2373 cmdmod_T save_cmdmod; | |
2374 gboolean shutdown_cancelled; | |
2375 | |
2376 save_cmdmod = cmdmod; | |
2377 | |
2378 # ifdef FEAT_BROWSE | |
2379 cmdmod.browse = TRUE; | |
2380 # endif | |
2381 # if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
2382 cmdmod.confirm = TRUE; | |
2383 # endif | |
2384 /* | |
2385 * If there are changed buffers, present the user with | |
2386 * a dialog if possible, otherwise give an error message. | |
2387 */ | |
7469
15eefe1b0dad
commit https://github.com/vim/vim/commit/027387f70c671f62e3e08e0bdd09ec05b0232735
Christian Brabandt <cb@256bit.org>
parents:
7380
diff
changeset
|
2388 shutdown_cancelled = check_changed_any(FALSE, FALSE); |
7 | 2389 |
2390 exiting = FALSE; | |
2391 cmdmod = save_cmdmod; | |
2392 setcursor(); /* position the cursor */ | |
2393 out_flush(); | |
2394 /* | |
2395 * If the user hit the [Cancel] button the whole shutdown | |
2396 * will be cancelled. Wow, quite powerful feature (: | |
2397 */ | |
2398 gnome_interaction_key_return(key, shutdown_cancelled); | |
2399 } | |
2400 | |
2401 /* | |
2402 * Generate a script that can be used to restore the current editing session. | |
2403 * Save the value of v:this_session before running :mksession in order to make | |
2404 * automagic session save fully transparent. Return TRUE on success. | |
2405 */ | |
2406 static int | |
2407 write_session_file(char_u *filename) | |
2408 { | |
2409 char_u *escaped_filename; | |
2410 char *mksession_cmdline; | |
2411 unsigned int save_ssop_flags; | |
2412 int failed; | |
2413 | |
2414 /* | |
2415 * Build an ex command line to create a script that restores the current | |
2416 * session if executed. Escape the filename to avoid nasty surprises. | |
2417 */ | |
2418 escaped_filename = vim_strsave_escaped(filename, escape_chars); | |
2419 if (escaped_filename == NULL) | |
2420 return FALSE; | |
1296 | 2421 mksession_cmdline = g_strconcat("mksession ", (char *)escaped_filename, |
2422 NULL); | |
7 | 2423 vim_free(escaped_filename); |
1296 | 2424 |
7 | 2425 /* |
2426 * Use a reasonable hardcoded set of 'sessionoptions' flags to avoid | |
2427 * unpredictable effects when the session is saved automatically. Also, | |
2428 * we definitely need SSOP_GLOBALS to be able to restore v:this_session. | |
2429 * Don't use SSOP_BUFFERS to prevent the buffer list from becoming | |
2430 * enormously large if the GNOME session feature is used regularly. | |
2431 */ | |
2432 save_ssop_flags = ssop_flags; | |
2433 ssop_flags = (SSOP_BLANK|SSOP_CURDIR|SSOP_FOLDS|SSOP_GLOBALS | |
1296 | 2434 |SSOP_HELP|SSOP_OPTIONS|SSOP_WINSIZE|SSOP_TABPAGES); |
7 | 2435 |
2436 do_cmdline_cmd((char_u *)"let Save_VV_this_session = v:this_session"); | |
2437 failed = (do_cmdline_cmd((char_u *)mksession_cmdline) == FAIL); | |
2438 do_cmdline_cmd((char_u *)"let v:this_session = Save_VV_this_session"); | |
150 | 2439 do_unlet((char_u *)"Save_VV_this_session", TRUE); |
7 | 2440 |
2441 ssop_flags = save_ssop_flags; | |
2442 g_free(mksession_cmdline); | |
5905 | 2443 |
7 | 2444 /* |
2445 * Reopen the file and append a command to restore v:this_session, | |
2446 * as if this save never happened. This is to avoid conflicts with | |
2447 * the user's own sessions. FIXME: It's probably less hackish to add | |
2448 * a "stealth" flag to 'sessionoptions' -- gotta ask Bram. | |
2449 */ | |
2450 if (!failed) | |
2451 { | |
2452 FILE *fd; | |
2453 | |
2454 fd = open_exfile(filename, TRUE, APPENDBIN); | |
2455 | |
2456 failed = (fd == NULL | |
2457 || put_line(fd, "let v:this_session = Save_VV_this_session") == FAIL | |
2458 || put_line(fd, "unlet Save_VV_this_session") == FAIL); | |
2459 | |
2460 if (fd != NULL && fclose(fd) != 0) | |
2461 failed = TRUE; | |
2462 | |
2463 if (failed) | |
2464 mch_remove(filename); | |
2465 } | |
2466 | |
2467 return !failed; | |
2468 } | |
2469 | |
2470 /* | |
2471 * "save_yourself" signal handler. Initiate an interaction to ask the user | |
2472 * for confirmation if necessary. Save the current editing session and tell | |
2473 * the session manager how to restart Vim. | |
2474 */ | |
2475 static gboolean | |
2476 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
|
2477 gint phase UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2478 GnomeSaveStyle save_style UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2479 gboolean shutdown UNUSED, |
7 | 2480 GnomeInteractStyle interact_style, |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2481 gboolean fast UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2482 gpointer data UNUSED) |
7 | 2483 { |
2484 static const char suffix[] = "-session.vim"; | |
2485 char *session_file; | |
2486 unsigned int len; | |
2487 gboolean success; | |
2488 | |
2489 /* Always request an interaction if possible. check_changed_any() | |
2490 * won't actually show a dialog unless any buffers have been modified. | |
2491 * There doesn't seem to be an obvious way to check that without | |
2492 * automatically firing the dialog. Anyway, it works just fine. */ | |
2493 if (interact_style == GNOME_INTERACT_ANY) | |
2494 gnome_client_request_interaction(client, GNOME_DIALOG_NORMAL, | |
2495 &sm_client_check_changed_any, | |
2496 NULL); | |
2497 out_flush(); | |
2498 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
2499 | |
2500 /* The path is unique for each session save. We do neither know nor care | |
2501 * which session script will actually be used later. This decision is in | |
2502 * the domain of the session manager. */ | |
2503 session_file = gnome_config_get_real_path( | |
2504 gnome_client_get_config_prefix(client)); | |
2505 len = strlen(session_file); | |
2506 | |
2507 if (len > 0 && session_file[len-1] == G_DIR_SEPARATOR) | |
2508 --len; /* get rid of the superfluous trailing '/' */ | |
2509 | |
2510 session_file = g_renew(char, session_file, len + sizeof(suffix)); | |
2511 memcpy(session_file + len, suffix, sizeof(suffix)); | |
2512 | |
2513 success = write_session_file((char_u *)session_file); | |
2514 | |
2515 if (success) | |
2516 { | |
2517 const char *argv[8]; | |
2518 int i; | |
2519 | |
2520 /* Tell the session manager how to wipe out the stored session data. | |
2521 * This isn't as dangerous as it looks, don't worry :) session_file | |
2522 * is a unique absolute filename. Usually it'll be something like | |
2523 * `/home/user/.gnome2/vim-XXXXXX-session.vim'. */ | |
2524 i = 0; | |
2525 argv[i++] = "rm"; | |
2526 argv[i++] = session_file; | |
2527 argv[i] = NULL; | |
2528 | |
2529 gnome_client_set_discard_command(client, i, (char **)argv); | |
2530 | |
2531 /* Tell the session manager how to restore the just saved session. | |
2532 * This is easily done thanks to Vim's -S option. Pass the -f flag | |
2533 * since there's no need to fork -- it might even cause confusion. | |
2534 * Also pass the window role to give the WM something to match on. | |
2535 * The role is set in gui_mch_open(), thus should _never_ be NULL. */ | |
2536 i = 0; | |
2537 argv[i++] = restart_command; | |
2538 argv[i++] = "-f"; | |
2539 argv[i++] = "-g"; | |
2540 argv[i++] = "--role"; | |
2541 argv[i++] = gtk_window_get_role(GTK_WINDOW(gui.mainwin)); | |
2542 argv[i++] = "-S"; | |
2543 argv[i++] = session_file; | |
2544 argv[i] = NULL; | |
2545 | |
2546 gnome_client_set_restart_command(client, i, (char **)argv); | |
2547 gnome_client_set_clone_command(client, 0, NULL); | |
2548 } | |
2549 | |
2550 g_free(session_file); | |
2551 | |
2552 return success; | |
2553 } | |
2554 | |
2555 /* | |
2556 * Called when the session manager wants us to die. There isn't much to save | |
2557 * here since "save_yourself" has been emitted before (unless serious trouble | |
2558 * is happening). | |
2559 */ | |
2560 static void | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2561 sm_client_die(GnomeClient *client UNUSED, gpointer data UNUSED) |
7 | 2562 { |
2563 /* Don't write messages to the GUI anymore */ | |
2564 full_screen = FALSE; | |
2565 | |
1666 | 2566 vim_strncpy(IObuff, (char_u *) |
419 | 2567 _("Vim: Received \"die\" request from session manager\n"), |
1666 | 2568 IOSIZE - 1); |
7 | 2569 preserve_exit(); |
2570 } | |
2571 | |
2572 /* | |
2573 * Connect our signal handlers to be notified on session save and shutdown. | |
2574 */ | |
2575 static void | |
2576 setup_save_yourself(void) | |
2577 { | |
2578 GnomeClient *client; | |
2579 | |
2580 client = gnome_master_client(); | |
2581 | |
2582 if (client != NULL) | |
2583 { | |
2584 /* Must use the deprecated gtk_signal_connect() for compatibility | |
2585 * with GNOME 1. Arrgh, zombies! */ | |
2586 gtk_signal_connect(GTK_OBJECT(client), "save_yourself", | |
2587 GTK_SIGNAL_FUNC(&sm_client_save_yourself), NULL); | |
2588 gtk_signal_connect(GTK_OBJECT(client), "die", | |
2589 GTK_SIGNAL_FUNC(&sm_client_die), NULL); | |
2590 } | |
2591 } | |
2592 | |
2593 #else /* !(FEAT_GUI_GNOME && FEAT_SESSION) */ | |
2594 | |
2595 # ifdef USE_XSMP | |
2596 /* | |
2597 * GTK tells us that XSMP needs attention | |
2598 */ | |
2599 static gboolean | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2600 local_xsmp_handle_requests( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2601 GIOChannel *source UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2602 GIOCondition condition, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2603 gpointer data) |
7 | 2604 { |
2605 if (condition == G_IO_IN) | |
2606 { | |
2607 /* Do stuff; maybe close connection */ | |
2608 if (xsmp_handle_requests() == FAIL) | |
2609 g_io_channel_unref((GIOChannel *)data); | |
2610 return TRUE; | |
2611 } | |
2612 /* Error */ | |
2613 g_io_channel_unref((GIOChannel *)data); | |
2614 xsmp_close(); | |
2615 return TRUE; | |
2616 } | |
2617 # endif /* USE_XSMP */ | |
2618 | |
2619 /* | |
2620 * Setup the WM_PROTOCOLS to indicate we want the WM_SAVE_YOURSELF event. | |
2621 * This is an ugly use of X functions. GTK doesn't offer an alternative. | |
2622 */ | |
2623 static void | |
2624 setup_save_yourself(void) | |
2625 { | |
2626 Atom *existing_atoms = NULL; | |
2627 int count = 0; | |
2628 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2629 # ifdef USE_XSMP |
7 | 2630 if (xsmp_icefd != -1) |
2631 { | |
2632 /* | |
2633 * Use XSMP is preference to legacy WM_SAVE_YOURSELF; | |
2634 * set up GTK IO monitor | |
2635 */ | |
2636 GIOChannel *g_io = g_io_channel_unix_new(xsmp_icefd); | |
2637 | |
2638 g_io_add_watch(g_io, G_IO_IN | G_IO_ERR | G_IO_HUP, | |
2639 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
|
2640 g_io_channel_unref(g_io); |
7 | 2641 } |
2642 else | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2643 # endif |
7 | 2644 { |
2645 /* Fall back to old method */ | |
2646 | |
2647 /* first get the existing value */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2648 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
|
2649 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2650 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
|
2651 GDK_WINDOW_XID(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2652 &existing_atoms, &count)) |
7 | 2653 { |
2654 Atom *new_atoms; | |
2655 Atom save_yourself_xatom; | |
2656 int i; | |
2657 | |
2658 save_yourself_xatom = GET_X_ATOM(save_yourself_atom); | |
2659 | |
2660 /* check if WM_SAVE_YOURSELF isn't there yet */ | |
2661 for (i = 0; i < count; ++i) | |
2662 if (existing_atoms[i] == save_yourself_xatom) | |
2663 break; | |
2664 | |
2665 if (i == count) | |
2666 { | |
2667 /* allocate an Atoms array which is one item longer */ | |
2668 new_atoms = (Atom *)alloc((unsigned)((count + 1) | |
2669 * sizeof(Atom))); | |
2670 if (new_atoms != NULL) | |
2671 { | |
2672 memcpy(new_atoms, existing_atoms, count * sizeof(Atom)); | |
2673 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
|
2674 XSetWMProtocols(GDK_WINDOW_XDISPLAY(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2675 GDK_WINDOW_XID(mainwin_win), |
7 | 2676 new_atoms, count + 1); |
2677 vim_free(new_atoms); | |
2678 } | |
2679 } | |
2680 XFree(existing_atoms); | |
2681 } | |
2682 } | |
2683 } | |
2684 | |
2685 /* | |
2686 * Installing a global event filter seems to be the only way to catch | |
2687 * client messages of type WM_PROTOCOLS without overriding GDK's own | |
2688 * client message event filter. Well, that's still better than trying | |
2689 * to guess what the GDK filter had done if it had been invoked instead | |
2690 * | |
2691 * GTK2_FIXME: This doesn't seem to work. For some reason we never | |
2692 * receive WM_SAVE_YOURSELF even though everything is set up correctly. | |
2693 * I have the nasty feeling modern session managers just don't send this | |
2694 * deprecated message anymore. Addition: confirmed by several people. | |
2695 * | |
2696 * The GNOME session support is much cooler anyway. Unlike this ugly | |
2697 * WM_SAVE_YOURSELF hack it actually stores the session... And yes, | |
2698 * it should work with KDE as well. | |
2699 */ | |
2700 static GdkFilterReturn | |
1884 | 2701 global_event_filter(GdkXEvent *xev, |
2702 GdkEvent *event UNUSED, | |
2703 gpointer data UNUSED) | |
7 | 2704 { |
2705 XEvent *xevent = (XEvent *)xev; | |
2706 | |
2707 if (xevent != NULL | |
2708 && xevent->type == ClientMessage | |
2709 && xevent->xclient.message_type == GET_X_ATOM(wm_protocols_atom) | |
1884 | 2710 && (long_u)xevent->xclient.data.l[0] |
2711 == GET_X_ATOM(save_yourself_atom)) | |
7 | 2712 { |
2713 out_flush(); | |
2714 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
2715 /* | |
2716 * Set the window's WM_COMMAND property, to let the window manager | |
2717 * know we are done saving ourselves. We don't want to be | |
2718 * restarted, thus set argv to NULL. | |
2719 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2720 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
|
2721 GDK_WINDOW_XID(gtk_widget_get_window(gui.mainwin)), |
7 | 2722 NULL, 0); |
2723 return GDK_FILTER_REMOVE; | |
2724 } | |
2725 | |
2726 return GDK_FILTER_CONTINUE; | |
2727 } | |
2728 #endif /* !(FEAT_GUI_GNOME && FEAT_SESSION) */ | |
2729 | |
2730 | |
2731 /* | |
2732 * Setup the window icon & xcmdsrv comm after the main window has been realized. | |
2733 */ | |
2734 static void | |
1884 | 2735 mainwin_realize(GtkWidget *widget UNUSED, gpointer data UNUSED) |
7 | 2736 { |
2737 /* If you get an error message here, you still need to unpack the runtime | |
2738 * archive! */ | |
2739 #ifdef magick | |
2740 # undef magick | |
2741 #endif | |
2742 /* A bit hackish, but avoids casting later and allows optimization */ | |
2743 # define static static const | |
2744 #define magick vim32x32 | |
2745 #include "../runtime/vim32x32.xpm" | |
2746 #undef magick | |
2747 #define magick vim16x16 | |
2748 #include "../runtime/vim16x16.xpm" | |
2749 #undef magick | |
2750 #define magick vim48x48 | |
2751 #include "../runtime/vim48x48.xpm" | |
2752 #undef magick | |
2753 # undef static | |
2754 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2755 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
|
2756 |
7 | 2757 /* When started with "--echo-wid" argument, write window ID on stdout. */ |
2758 if (echo_wid_arg) | |
2759 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2760 printf("WID: %ld\n", (long)GDK_WINDOW_XID(mainwin_win)); |
7 | 2761 fflush(stdout); |
2762 } | |
2763 | |
2764 if (vim_strchr(p_go, GO_ICON) != NULL) | |
2765 { | |
2766 /* | |
2767 * Add an icon to the main window. For fun and convenience of the user. | |
2768 */ | |
2769 GList *icons = NULL; | |
2770 | |
2771 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim16x16)); | |
2772 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim32x32)); | |
2773 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim48x48)); | |
2774 | |
2775 gtk_window_set_icon_list(GTK_WINDOW(gui.mainwin), icons); | |
2776 | |
2777 g_list_foreach(icons, (GFunc)&g_object_unref, NULL); | |
2778 g_list_free(icons); | |
2779 } | |
2780 | |
2781 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
2782 /* Register a handler for WM_SAVE_YOURSELF with GDK's low-level X I/F */ | |
2783 gdk_window_add_filter(NULL, &global_event_filter, NULL); | |
2784 #endif | |
2785 /* Setup to indicate to the window manager that we want to catch the | |
2786 * WM_SAVE_YOURSELF event. For GNOME, this connects to the session | |
2787 * manager instead. */ | |
2788 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
2789 if (using_gnome) | |
2790 #endif | |
2791 setup_save_yourself(); | |
2792 | |
2793 #ifdef FEAT_CLIENTSERVER | |
2794 if (serverName == NULL && serverDelayedStartName != NULL) | |
2795 { | |
2796 /* 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
|
2797 commWindow = GDK_WINDOW_XID(mainwin_win); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2798 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2799 (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
|
2800 serverDelayedStartName); |
7 | 2801 } |
2802 else | |
2803 { | |
2804 /* | |
2805 * Cannot handle "XLib-only" windows with gtk event routines, we'll | |
2806 * have to change the "server" registration to that of the main window | |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2807 * If we have not registered a name yet, remember the window. |
7 | 2808 */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2809 serverChangeRegisteredWindow(GDK_WINDOW_XDISPLAY(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2810 GDK_WINDOW_XID(mainwin_win)); |
7 | 2811 } |
2812 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
|
2813 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2814 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
|
2815 G_CALLBACK(property_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2816 # else |
7 | 2817 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "property_notify_event", |
2818 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
|
2819 # endif |
7 | 2820 #endif |
2821 } | |
2822 | |
2823 static GdkCursor * | |
2824 create_blank_pointer(void) | |
2825 { | |
2826 GdkWindow *root_window = NULL; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2827 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2828 GdkPixbuf *blank_mask; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2829 #else |
7 | 2830 GdkPixmap *blank_mask; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2831 #endif |
7 | 2832 GdkCursor *cursor; |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2833 #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
|
2834 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
|
2835 #else |
7 | 2836 GdkColor color = { 0, 0, 0, 0 }; |
2837 char blank_data[] = { 0x0 }; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2838 #endif |
7 | 2839 |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2840 #if GTK_CHECK_VERSION(3,12,0) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2841 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2842 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
|
2843 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
|
2844 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
|
2845 } |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2846 #else |
7 | 2847 root_window = gtk_widget_get_root_window(gui.mainwin); |
2848 #endif | |
2849 | |
2850 /* Create a pseudo blank pointer, which is in fact one pixel by one pixel | |
2851 * in size. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2852 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2853 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2854 cairo_surface_t *surf; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2855 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2856 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2857 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
|
2858 cr = cairo_create(surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2859 |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2860 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2861 color.red, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2862 color.green, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2863 color.blue, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2864 color.alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2865 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
|
2866 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2867 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2868 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2869 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
|
2870 cairo_surface_destroy(surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2871 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2872 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
|
2873 blank_mask, 0, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2874 g_object_unref(blank_mask); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2875 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2876 #else |
7 | 2877 blank_mask = gdk_bitmap_create_from_data(root_window, blank_data, 1, 1); |
2878 cursor = gdk_cursor_new_from_pixmap(blank_mask, blank_mask, | |
2879 &color, &color, 0, 0); | |
2880 gdk_bitmap_unref(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 |
2883 return cursor; | |
2884 } | |
2885 | |
2886 static void | |
2887 mainwin_screen_changed_cb(GtkWidget *widget, | |
1884 | 2888 GdkScreen *previous_screen UNUSED, |
2889 gpointer data UNUSED) | |
7 | 2890 { |
2891 if (!gtk_widget_has_screen(widget)) | |
2892 return; | |
2893 | |
2894 /* | |
1226 | 2895 * Recreate the invisible mouse cursor. |
7 | 2896 */ |
2897 if (gui.blank_pointer != NULL) | |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2898 #if GTK_CHECK_VERSION(3,0,0) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2899 g_object_unref(G_OBJECT(gui.blank_pointer)); |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2900 #else |
7 | 2901 gdk_cursor_unref(gui.blank_pointer); |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2902 #endif |
7 | 2903 |
2904 gui.blank_pointer = create_blank_pointer(); | |
2905 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2906 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
|
2907 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
|
2908 gui.blank_pointer); |
7 | 2909 |
2910 /* | |
2911 * Create a new PangoContext for this screen, and initialize it | |
2912 * with the current font if necessary. | |
2913 */ | |
2914 if (gui.text_context != NULL) | |
2915 g_object_unref(gui.text_context); | |
2916 | |
2917 gui.text_context = gtk_widget_create_pango_context(widget); | |
2918 pango_context_set_base_dir(gui.text_context, PANGO_DIRECTION_LTR); | |
2919 | |
2920 if (gui.norm_font != NULL) | |
2921 { | |
38 | 2922 gui_mch_init_font(p_guifont, FALSE); |
12802
29a728529f92
patch 8.0.1278: GUI window always resizes when adding scrollbar
Christian Brabandt <cb@256bit.org>
parents:
12666
diff
changeset
|
2923 gui_set_shellsize(TRUE, FALSE, RESIZE_BOTH); |
7 | 2924 } |
2925 } | |
2926 | |
2927 /* | |
2928 * After the drawing area comes up, we calculate all colors and create the | |
2929 * dummy blank cursor. | |
2930 * | |
2931 * Don't try to set any VIM scrollbar sizes anywhere here. I'm relying on the | |
2932 * fact that the main VIM engine doesn't take them into account anywhere. | |
2933 */ | |
2934 static void | |
1884 | 2935 drawarea_realize_cb(GtkWidget *widget, gpointer data UNUSED) |
7 | 2936 { |
2937 GtkWidget *sbar; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2938 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2939 GtkAllocation allocation; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2940 #endif |
7 | 2941 |
2942 #ifdef FEAT_XIM | |
2943 xim_init(); | |
2944 #endif | |
2945 gui_mch_new_colors(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2946 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2947 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
|
2948 gtk_widget_get_window(widget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2949 CAIRO_CONTENT_COLOR_ALPHA, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2950 gtk_widget_get_allocated_width(widget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2951 gtk_widget_get_allocated_height(widget)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2952 #else |
7 | 2953 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
|
2954 #endif |
7 | 2955 |
2956 gui.blank_pointer = create_blank_pointer(); | |
2957 if (gui.pointer_hidden) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2958 gdk_window_set_cursor(gtk_widget_get_window(widget), gui.blank_pointer); |
7 | 2959 |
2960 /* get the actual size of the scrollbars, if they are realized */ | |
2961 sbar = firstwin->w_scrollbars[SBAR_LEFT].id; | |
2962 if (!sbar || (!gui.which_scrollbars[SBAR_LEFT] | |
2963 && firstwin->w_scrollbars[SBAR_RIGHT].id)) | |
2964 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
|
2965 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2966 gtk_widget_get_allocation(sbar, &allocation); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2967 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
|
2968 gui.scrollbar_width = allocation.width; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2969 #else |
7 | 2970 if (sbar && GTK_WIDGET_REALIZED(sbar) && sbar->allocation.width) |
2971 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
|
2972 #endif |
7 | 2973 |
2974 sbar = gui.bottom_sbar.id; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2975 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2976 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
|
2977 gui.scrollbar_height = allocation.height; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2978 #else |
7 | 2979 if (sbar && GTK_WIDGET_REALIZED(sbar) && sbar->allocation.height) |
2980 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
|
2981 #endif |
7 | 2982 } |
2983 | |
2984 /* | |
2985 * Properly clean up on shutdown. | |
2986 */ | |
2987 static void | |
1884 | 2988 drawarea_unrealize_cb(GtkWidget *widget UNUSED, gpointer data UNUSED) |
7 | 2989 { |
2990 /* Don't write messages to the GUI anymore */ | |
2991 full_screen = FALSE; | |
2992 | |
2993 #ifdef FEAT_XIM | |
2994 im_shutdown(); | |
2995 #endif | |
2996 if (gui.ascii_glyphs != NULL) | |
2997 { | |
2998 pango_glyph_string_free(gui.ascii_glyphs); | |
2999 gui.ascii_glyphs = NULL; | |
3000 } | |
3001 if (gui.ascii_font != NULL) | |
3002 { | |
3003 g_object_unref(gui.ascii_font); | |
3004 gui.ascii_font = NULL; | |
3005 } | |
3006 g_object_unref(gui.text_context); | |
3007 gui.text_context = NULL; | |
3008 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3009 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3010 if (gui.surface != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3011 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3012 cairo_surface_destroy(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3013 gui.surface = NULL; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3014 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3015 #else |
7 | 3016 g_object_unref(gui.text_gc); |
3017 gui.text_gc = NULL; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3018 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3019 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3020 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3021 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
|
3022 #else |
7 | 3023 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
|
3024 #endif |
7 | 3025 gui.blank_pointer = NULL; |
3026 } | |
3027 | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3028 #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
|
3029 static void |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3030 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
|
3031 gpointer data UNUSED) |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3032 #else |
7 | 3033 static void |
1884 | 3034 drawarea_style_set_cb(GtkWidget *widget UNUSED, |
3035 GtkStyle *previous_style UNUSED, | |
3036 gpointer data UNUSED) | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3037 #endif |
7 | 3038 { |
3039 gui_mch_new_colors(); | |
3040 } | |
3041 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3042 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3043 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3044 drawarea_configure_event_cb(GtkWidget *widget, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3045 GdkEventConfigure *event, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3046 gpointer data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3047 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3048 static int cur_width = 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3049 static int cur_height = 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3050 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3051 g_return_val_if_fail(event |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3052 && 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
|
3053 |
10402
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
3054 # 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
|
3055 /* 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
|
3056 * 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
|
3057 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3058 * 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
|
3059 * 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
|
3060 * 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
|
3061 * "native" one from non-native one. |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3062 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3063 * 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
|
3064 * 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
|
3065 * 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
|
3066 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3067 * 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
|
3068 * 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
|
3069 * configure_native_child(). |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3070 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3071 * 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
|
3072 * 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
|
3073 * 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
|
3074 */ |
10402
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
3075 /* Follow-up |
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
3076 * 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
|
3077 * 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
|
3078 * 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
|
3079 if (event->send_event == FALSE) |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3080 return TRUE; |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3081 # endif |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3082 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3083 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
|
3084 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3085 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3086 cur_width = event->width; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3087 cur_height = event->height; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3088 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3089 if (gui.surface != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3090 cairo_surface_destroy(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3091 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3092 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
|
3093 gtk_widget_get_window(widget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3094 CAIRO_CONTENT_COLOR_ALPHA, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3095 event->width, event->height); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3096 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3097 gtk_widget_queue_draw(widget); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3098 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3099 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3100 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3101 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3102 |
7 | 3103 /* |
3104 * Callback routine for the "delete_event" signal on the toplevel window. | |
3105 * Tries to vim gracefully, or refuses to exit with changed buffers. | |
3106 */ | |
3107 static gint | |
1884 | 3108 delete_event_cb(GtkWidget *widget UNUSED, |
3109 GdkEventAny *event UNUSED, | |
3110 gpointer data UNUSED) | |
7 | 3111 { |
3112 gui_shell_closed(); | |
3113 return TRUE; | |
3114 } | |
3115 | |
685 | 3116 #if defined(FEAT_MENU) || defined(FEAT_TOOLBAR) || defined(FEAT_GUI_TABLINE) |
3117 static int | |
3118 get_item_dimensions(GtkWidget *widget, GtkOrientation orientation) | |
3119 { | |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3120 # ifdef FEAT_GUI_GNOME |
685 | 3121 GtkOrientation item_orientation = GTK_ORIENTATION_HORIZONTAL; |
3122 | |
3123 if (using_gnome && widget != NULL) | |
3124 { | |
856 | 3125 GtkWidget *parent; |
685 | 3126 BonoboDockItem *dockitem; |
3127 | |
791 | 3128 parent = gtk_widget_get_parent(widget); |
856 | 3129 if (G_TYPE_FROM_INSTANCE(parent) == BONOBO_TYPE_DOCK_ITEM) |
3130 { | |
3131 /* Only menu & toolbar are dock items. Could tabline be? | |
3132 * Seem to be only the 2 defined in GNOME */ | |
3133 widget = parent; | |
3134 dockitem = BONOBO_DOCK_ITEM(widget); | |
3135 | |
3136 if (dockitem == NULL || dockitem->is_floating) | |
3137 return 0; | |
3138 item_orientation = bonobo_dock_item_get_orientation(dockitem); | |
3139 } | |
685 | 3140 } |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3141 # else |
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3142 # 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
|
3143 # endif |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3144 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3145 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3146 if (widget != NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3147 && item_orientation == orientation |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3148 && gtk_widget_get_realized(widget) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3149 && gtk_widget_get_visible(widget)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3150 # else |
685 | 3151 if (widget != NULL |
3152 && item_orientation == orientation | |
3153 && GTK_WIDGET_REALIZED(widget) | |
3154 && GTK_WIDGET_VISIBLE(widget)) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3155 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3156 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3157 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3158 GtkAllocation allocation; |
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_get_allocation(widget, &allocation); |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3161 return allocation.height; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3162 # else |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3163 # ifdef FEAT_GUI_GNOME |
685 | 3164 if (orientation == GTK_ORIENTATION_HORIZONTAL) |
3165 return widget->allocation.height; | |
3166 else | |
3167 return widget->allocation.width; | |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3168 # else |
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3169 return widget->allocation.height; |
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3170 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3171 # endif |
685 | 3172 } |
3173 return 0; | |
3174 } | |
3175 #endif | |
3176 | |
3177 static int | |
3178 get_menu_tool_width(void) | |
3179 { | |
3180 int width = 0; | |
3181 | |
3182 #ifdef FEAT_GUI_GNOME /* these are never vertical without GNOME */ | |
3183 # ifdef FEAT_MENU | |
3184 width += get_item_dimensions(gui.menubar, GTK_ORIENTATION_VERTICAL); | |
3185 # endif | |
3186 # ifdef FEAT_TOOLBAR | |
3187 width += get_item_dimensions(gui.toolbar, GTK_ORIENTATION_VERTICAL); | |
3188 # endif | |
3189 # ifdef FEAT_GUI_TABLINE | |
782 | 3190 if (gui.tabline != NULL) |
3191 width += get_item_dimensions(gui.tabline, GTK_ORIENTATION_VERTICAL); | |
685 | 3192 # endif |
3193 #endif | |
3194 | |
3195 return width; | |
3196 } | |
3197 | |
3198 static int | |
3199 get_menu_tool_height(void) | |
3200 { | |
3201 int height = 0; | |
3202 | |
3203 #ifdef FEAT_MENU | |
3204 height += get_item_dimensions(gui.menubar, GTK_ORIENTATION_HORIZONTAL); | |
3205 #endif | |
3206 #ifdef FEAT_TOOLBAR | |
3207 height += get_item_dimensions(gui.toolbar, GTK_ORIENTATION_HORIZONTAL); | |
3208 #endif | |
3209 #ifdef FEAT_GUI_TABLINE | |
782 | 3210 if (gui.tabline != NULL) |
3211 height += get_item_dimensions(gui.tabline, GTK_ORIENTATION_HORIZONTAL); | |
685 | 3212 #endif |
3213 | |
3214 return height; | |
3215 } | |
3216 | |
791 | 3217 /* This controls whether we can set the real window hints at |
3218 * start-up when in a GtkPlug. | |
3219 * 0 = normal processing (default) | |
3220 * 1 = init. hints set, no-one's tried to reset since last check | |
3221 * 2 = init. hints set, attempt made to change hints | |
3222 */ | |
3223 static int init_window_hints_state = 0; | |
3224 | |
685 | 3225 static void |
791 | 3226 update_window_manager_hints(int force_width, int force_height) |
685 | 3227 { |
3228 static int old_width = 0; | |
3229 static int old_height = 0; | |
791 | 3230 static int old_min_width = 0; |
3231 static int old_min_height = 0; | |
685 | 3232 static int old_char_width = 0; |
3233 static int old_char_height = 0; | |
3234 | |
3235 int width; | |
3236 int height; | |
791 | 3237 int min_width; |
3238 int min_height; | |
3239 | |
3240 /* At start-up, don't try to set the hints until the initial | |
3241 * values have been used (those that dictate our initial size) | |
1884 | 3242 * Let forced (i.e., correct) values through always. |
791 | 3243 */ |
3244 if (!(force_width && force_height) && init_window_hints_state > 0) | |
3245 { | |
856 | 3246 /* Don't do it! */ |
3247 init_window_hints_state = 2; | |
3248 return; | |
791 | 3249 } |
685 | 3250 |
3251 /* This also needs to be done when the main window isn't there yet, | |
3252 * otherwise the hints don't work. */ | |
3253 width = gui_get_base_width(); | |
3254 height = gui_get_base_height(); | |
3255 # ifdef FEAT_MENU | |
3256 height += tabline_height() * gui.char_height; | |
3257 # endif | |
3258 width += get_menu_tool_width(); | |
3259 height += get_menu_tool_height(); | |
3260 | |
791 | 3261 /* GtkSockets use GtkPlug's [gui,mainwin] min-size hints to determine |
1226 | 3262 * their actual widget size. When we set our size ourselves (e.g., |
791 | 3263 * 'set columns=' or init. -geom) we briefly set the min. to the size |
3264 * we wish to be instead of the legitimate minimum so that we actually | |
3265 * resize correctly. | |
3266 */ | |
3267 if (force_width && force_height) | |
3268 { | |
856 | 3269 min_width = force_width; |
3270 min_height = force_height; | |
791 | 3271 } |
3272 else | |
3273 { | |
856 | 3274 min_width = width + MIN_COLUMNS * gui.char_width; |
3275 min_height = height + MIN_LINES * gui.char_height; | |
791 | 3276 } |
3277 | |
685 | 3278 /* Avoid an expose event when the size didn't change. */ |
3279 if (width != old_width | |
3280 || height != old_height | |
856 | 3281 || min_width != old_min_width |
791 | 3282 || min_height != old_min_height |
685 | 3283 || gui.char_width != old_char_width |
3284 || gui.char_height != old_char_height) | |
3285 { | |
3286 GdkGeometry geometry; | |
3287 GdkWindowHints geometry_mask; | |
3288 | |
3289 geometry.width_inc = gui.char_width; | |
3290 geometry.height_inc = gui.char_height; | |
3291 geometry.base_width = width; | |
3292 geometry.base_height = height; | |
856 | 3293 geometry.min_width = min_width; |
3294 geometry.min_height = min_height; | |
685 | 3295 geometry_mask = GDK_HINT_BASE_SIZE|GDK_HINT_RESIZE_INC |
3296 |GDK_HINT_MIN_SIZE; | |
3297 /* Using gui.formwin as geometry widget doesn't work as expected | |
3298 * with GTK+ 2 -- dunno why. Presumably all the resizing hacks | |
3299 * in Vim confuse GTK+. */ | |
3300 gtk_window_set_geometry_hints(GTK_WINDOW(gui.mainwin), gui.mainwin, | |
3301 &geometry, geometry_mask); | |
856 | 3302 old_width = width; |
3303 old_height = height; | |
3304 old_min_width = min_width; | |
3305 old_min_height = min_height; | |
3306 old_char_width = gui.char_width; | |
3307 old_char_height = gui.char_height; | |
685 | 3308 } |
3309 } | |
3310 | |
7 | 3311 #ifdef FEAT_TOOLBAR |
3312 | |
3313 /* | |
3314 * This extra effort wouldn't be necessary if we only used stock icons in the | |
3315 * toolbar, as we do for all builtin icons. But user-defined toolbar icons | |
3316 * shouldn't be treated differently, thus we do need this. | |
3317 */ | |
3318 static void | |
3319 icon_size_changed_foreach(GtkWidget *widget, gpointer user_data) | |
3320 { | |
3321 if (GTK_IS_IMAGE(widget)) | |
3322 { | |
3323 GtkImage *image = (GtkImage *)widget; | |
3324 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3325 # 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
|
3326 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
|
3327 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3328 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
|
3329 const gchar *icon_name; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3330 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3331 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
|
3332 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3333 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
|
3334 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3335 # else |
7 | 3336 /* User-defined icons are stored in a GtkIconSet */ |
3337 if (gtk_image_get_storage_type(image) == GTK_IMAGE_ICON_SET) | |
3338 { | |
3339 GtkIconSet *icon_set; | |
3340 GtkIconSize icon_size; | |
3341 | |
3342 gtk_image_get_icon_set(image, &icon_set, &icon_size); | |
3343 icon_size = (GtkIconSize)(long)user_data; | |
3344 | |
3345 gtk_icon_set_ref(icon_set); | |
3346 gtk_image_set_from_icon_set(image, icon_set, icon_size); | |
3347 gtk_icon_set_unref(icon_set); | |
3348 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3349 # endif |
7 | 3350 } |
3351 else if (GTK_IS_CONTAINER(widget)) | |
3352 { | |
3353 gtk_container_foreach((GtkContainer *)widget, | |
3354 &icon_size_changed_foreach, | |
3355 user_data); | |
3356 } | |
3357 } | |
3358 | |
3359 static void | |
3360 set_toolbar_style(GtkToolbar *toolbar) | |
3361 { | |
3362 GtkToolbarStyle style; | |
3363 GtkIconSize size; | |
3364 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
|
3365 |
7 | 3366 if ((toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS | TOOLBAR_HORIZ)) |
3367 == (TOOLBAR_TEXT | TOOLBAR_ICONS | TOOLBAR_HORIZ)) | |
3368 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
|
3369 else if ((toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS)) |
7 | 3370 == (TOOLBAR_TEXT | TOOLBAR_ICONS)) |
3371 style = GTK_TOOLBAR_BOTH; | |
3372 else if (toolbar_flags & TOOLBAR_TEXT) | |
3373 style = GTK_TOOLBAR_TEXT; | |
3374 else | |
3375 style = GTK_TOOLBAR_ICONS; | |
3376 | |
3377 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
|
3378 # if !GTK_CHECK_VERSION(3,0,0) |
7 | 3379 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
|
3380 # endif |
7 | 3381 |
3382 switch (tbis_flags) | |
3383 { | |
3384 case TBIS_TINY: size = GTK_ICON_SIZE_MENU; break; | |
3385 case TBIS_SMALL: size = GTK_ICON_SIZE_SMALL_TOOLBAR; break; | |
3386 case TBIS_MEDIUM: size = GTK_ICON_SIZE_BUTTON; break; | |
3387 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
|
3388 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
|
3389 case TBIS_GIANT: size = GTK_ICON_SIZE_DIALOG; break; |
7 | 3390 default: size = GTK_ICON_SIZE_INVALID; break; |
3391 } | |
3392 oldsize = gtk_toolbar_get_icon_size(toolbar); | |
3393 | |
3394 if (size == GTK_ICON_SIZE_INVALID) | |
3395 { | |
3396 /* Let global user preferences decide the icon size. */ | |
3397 gtk_toolbar_unset_icon_size(toolbar); | |
3398 size = gtk_toolbar_get_icon_size(toolbar); | |
3399 } | |
3400 if (size != oldsize) | |
3401 { | |
3402 gtk_container_foreach(GTK_CONTAINER(toolbar), | |
3403 &icon_size_changed_foreach, | |
3404 GINT_TO_POINTER((int)size)); | |
3405 } | |
3406 gtk_toolbar_set_icon_size(toolbar, size); | |
3407 } | |
3408 | |
3409 #endif /* FEAT_TOOLBAR */ | |
3410 | |
685 | 3411 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
3412 static int ignore_tabline_evt = FALSE; | |
689 | 3413 static GtkWidget *tabline_menu; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3414 # if !GTK_CHECK_VERSION(3,0,0) |
846 | 3415 static GtkTooltips *tabline_tooltip; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3416 # endif |
689 | 3417 static int clicked_page; /* page clicked in tab line */ |
3418 | |
3419 /* | |
3420 * Handle selecting an item in the tab line popup menu. | |
3421 */ | |
3422 static void | |
1884 | 3423 tabline_menu_handler(GtkMenuItem *item UNUSED, gpointer user_data) |
689 | 3424 { |
3425 /* Add the string cmd into input buffer */ | |
824 | 3426 send_tabline_menu_event(clicked_page, (int)(long)user_data); |
689 | 3427 } |
3428 | |
851 | 3429 static void |
3430 add_tabline_menu_item(GtkWidget *menu, char_u *text, int resp) | |
3431 { | |
3432 GtkWidget *item; | |
3433 char_u *utf_text; | |
3434 | |
3435 utf_text = CONVERT_TO_UTF8(text); | |
3436 item = gtk_menu_item_new_with_label((const char *)utf_text); | |
3437 gtk_widget_show(item); | |
3438 CONVERT_TO_UTF8_FREE(utf_text); | |
3439 | |
3440 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
|
3441 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3442 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
|
3443 G_CALLBACK(tabline_menu_handler), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3444 GINT_TO_POINTER(resp)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3445 # else |
851 | 3446 gtk_signal_connect(GTK_OBJECT(item), "activate", |
3447 GTK_SIGNAL_FUNC(tabline_menu_handler), | |
1660 | 3448 (gpointer)(long)resp); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3449 # endif |
851 | 3450 } |
3451 | |
689 | 3452 /* |
3453 * Create a menu for the tab line. | |
3454 */ | |
3455 static GtkWidget * | |
3456 create_tabline_menu(void) | |
3457 { | |
851 | 3458 GtkWidget *menu; |
689 | 3459 |
3460 menu = gtk_menu_new(); | |
6819 | 3461 if (first_tabpage->tp_next != NULL) |
3462 add_tabline_menu_item(menu, (char_u *)_("Close tab"), | |
3463 TABLINE_MENU_CLOSE); | |
851 | 3464 add_tabline_menu_item(menu, (char_u *)_("New tab"), TABLINE_MENU_NEW); |
3465 add_tabline_menu_item(menu, (char_u *)_("Open Tab..."), TABLINE_MENU_OPEN); | |
689 | 3466 |
3467 return menu; | |
3468 } | |
3469 | |
3470 static gboolean | |
3471 on_tabline_menu(GtkWidget *widget, GdkEvent *event) | |
3472 { | |
3473 /* Was this button press event ? */ | |
3474 if (event->type == GDK_BUTTON_PRESS) | |
3475 { | |
3476 GdkEventButton *bevent = (GdkEventButton *)event; | |
3477 int x = bevent->x; | |
851 | 3478 int y = bevent->y; |
3479 GtkWidget *tabwidget; | |
3480 GdkWindow *tabwin; | |
689 | 3481 |
844 | 3482 /* When ignoring events return TRUE so that the selected page doesn't |
3483 * change. */ | |
3484 if (hold_gui_events | |
3485 # ifdef FEAT_CMDWIN | |
3486 || cmdwin_type != 0 | |
3487 # endif | |
3488 ) | |
3489 return TRUE; | |
3490 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3491 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3492 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
|
3493 # else |
851 | 3494 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
|
3495 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3496 |
851 | 3497 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
|
3498 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3499 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
|
3500 "tab_num")); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3501 # else |
851 | 3502 clicked_page = (int)(long)gtk_object_get_user_data( |
3503 GTK_OBJECT(tabwidget)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3504 # endif |
689 | 3505 |
3506 /* If the event was generated for 3rd button popup the menu. */ | |
3507 if (bevent->button == 3) | |
3508 { | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3509 # 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
|
3510 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
|
3511 # else |
689 | 3512 gtk_menu_popup(GTK_MENU(widget), NULL, NULL, NULL, NULL, |
3513 bevent->button, bevent->time); | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3514 # endif |
689 | 3515 /* We handled the event. */ |
3516 return TRUE; | |
3517 } | |
868 | 3518 else if (bevent->button == 1) |
693 | 3519 { |
868 | 3520 if (clicked_page == 0) |
3521 { | |
1394 | 3522 /* Click after all tabs moves to next tab page. When "x" is |
3523 * 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
|
3524 send_tabline_event(x < 50 ? -1 : 0); |
868 | 3525 } |
693 | 3526 } |
689 | 3527 } |
844 | 3528 |
689 | 3529 /* We didn't handle the event. */ |
3530 return FALSE; | |
3531 } | |
685 | 3532 |
3533 /* | |
3534 * Handle selecting one of the tabs. | |
3535 */ | |
3536 static void | |
3537 on_select_tab( | |
1884 | 3538 GtkNotebook *notebook UNUSED, |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3539 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3540 gpointer *page UNUSED, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3541 # else |
1884 | 3542 GtkNotebookPage *page UNUSED, |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3543 # endif |
944 | 3544 gint idx, |
1884 | 3545 gpointer data UNUSED) |
685 | 3546 { |
3547 if (!ignore_tabline_evt) | |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
3548 send_tabline_event(idx + 1); |
12666
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3549 } |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3550 |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3551 /* |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3552 * Handle reordering the tabs (using D&D). |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3553 */ |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3554 static void |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3555 on_tab_reordered( |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3556 GtkNotebook *notebook UNUSED, |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3557 # if GTK_CHECK_VERSION(3,0,0) |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3558 gpointer *page UNUSED, |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3559 # else |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3560 GtkNotebookPage *page UNUSED, |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3561 # endif |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3562 gint idx, |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3563 gpointer data UNUSED) |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3564 { |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3565 if (!ignore_tabline_evt) |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3566 { |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3567 if ((tabpage_index(curtab) - 1) < idx) |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3568 tabpage_move(idx + 1); |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3569 else |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3570 tabpage_move(idx); |
693 | 3571 } |
685 | 3572 } |
3573 | |
3574 /* | |
3575 * Show or hide the tabline. | |
3576 */ | |
3577 void | |
3578 gui_mch_show_tabline(int showit) | |
3579 { | |
3580 if (gui.tabline == NULL) | |
3581 return; | |
3582 | |
3583 if (!showit != !gtk_notebook_get_show_tabs(GTK_NOTEBOOK(gui.tabline))) | |
3584 { | |
708 | 3585 /* Note: this may cause a resize event */ |
685 | 3586 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gui.tabline), showit); |
791 | 3587 update_window_manager_hints(0, 0); |
868 | 3588 if (showit) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3589 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3590 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
|
3591 # else |
868 | 3592 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
|
3593 # endif |
868 | 3594 } |
3595 | |
3596 gui_mch_update(); | |
685 | 3597 } |
3598 | |
3599 /* | |
708 | 3600 * Return TRUE when tabline is displayed. |
3601 */ | |
3602 int | |
3603 gui_mch_showing_tabline(void) | |
3604 { | |
3605 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
|
3606 && gtk_notebook_get_show_tabs(GTK_NOTEBOOK(gui.tabline)); |
708 | 3607 } |
3608 | |
3609 /* | |
685 | 3610 * Update the labels of the tabline. |
3611 */ | |
3612 void | |
3613 gui_mch_update_tabline(void) | |
3614 { | |
3615 GtkWidget *page; | |
846 | 3616 GtkWidget *event_box; |
685 | 3617 GtkWidget *label; |
3618 tabpage_T *tp; | |
3619 int nr = 0; | |
851 | 3620 int tab_num; |
685 | 3621 int curtabidx = 0; |
836 | 3622 char_u *labeltext; |
685 | 3623 |
3624 if (gui.tabline == NULL) | |
3625 return; | |
3626 | |
3627 ignore_tabline_evt = TRUE; | |
3628 | |
3629 /* Add a label for each tab page. They all contain the same text area. */ | |
3630 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr) | |
3631 { | |
3632 if (tp == curtab) | |
3633 curtabidx = nr; | |
3634 | |
851 | 3635 tab_num = nr + 1; |
3636 | |
685 | 3637 page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr); |
3638 if (page == NULL) | |
3639 { | |
3640 /* Add notebook page */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3641 # 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
|
3642 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
|
3643 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
|
3644 # else |
685 | 3645 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
|
3646 # endif |
685 | 3647 gtk_widget_show(page); |
846 | 3648 event_box = gtk_event_box_new(); |
3649 gtk_widget_show(event_box); | |
685 | 3650 label = gtk_label_new("-Empty-"); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3651 # if !GTK_CHECK_VERSION(3,14,0) |
851 | 3652 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
|
3653 # endif |
846 | 3654 gtk_container_add(GTK_CONTAINER(event_box), label); |
685 | 3655 gtk_widget_show(label); |
3656 gtk_notebook_insert_page(GTK_NOTEBOOK(gui.tabline), | |
3657 page, | |
846 | 3658 event_box, |
685 | 3659 nr++); |
12666
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3660 gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(gui.tabline), |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3661 page, |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3662 TRUE); |
685 | 3663 } |
3664 | |
846 | 3665 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
|
3666 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3667 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
|
3668 GINT_TO_POINTER(tab_num)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3669 # else |
1660 | 3670 gtk_object_set_user_data(GTK_OBJECT(event_box), |
3671 (gpointer)(long)tab_num); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3672 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3673 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3674 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
|
3675 # else |
846 | 3676 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
|
3677 # endif |
839 | 3678 get_tabline_label(tp, FALSE); |
836 | 3679 labeltext = CONVERT_TO_UTF8(NameBuff); |
846 | 3680 gtk_label_set_text(GTK_LABEL(label), (const char *)labeltext); |
836 | 3681 CONVERT_TO_UTF8_FREE(labeltext); |
846 | 3682 |
3683 get_tabline_label(tp, TRUE); | |
3684 labeltext = CONVERT_TO_UTF8(NameBuff); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3685 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3686 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
|
3687 # else |
846 | 3688 gtk_tooltips_set_tip(GTK_TOOLTIPS(tabline_tooltip), event_box, |
3689 (const char *)labeltext, NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3690 # endif |
846 | 3691 CONVERT_TO_UTF8_FREE(labeltext); |
685 | 3692 } |
3693 | |
3694 /* Remove any old labels. */ | |
3695 while (gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr) != NULL) | |
3696 gtk_notebook_remove_page(GTK_NOTEBOOK(gui.tabline), nr); | |
3697 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3698 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3699 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
|
3700 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
|
3701 # else |
685 | 3702 if (gtk_notebook_current_page(GTK_NOTEBOOK(gui.tabline)) != curtabidx) |
856 | 3703 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
|
3704 # endif |
685 | 3705 |
851 | 3706 /* Make sure everything is in place before drawing text. */ |
3707 gui_mch_update(); | |
3708 | |
685 | 3709 ignore_tabline_evt = FALSE; |
3710 } | |
3711 | |
3712 /* | |
3713 * Set the current tab to "nr". First tab is 1. | |
3714 */ | |
3715 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
3716 gui_mch_set_curtab(int nr) |
685 | 3717 { |
3718 if (gui.tabline == NULL) | |
3719 return; | |
3720 | |
3721 ignore_tabline_evt = TRUE; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3722 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3723 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
|
3724 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
|
3725 # else |
685 | 3726 if (gtk_notebook_current_page(GTK_NOTEBOOK(gui.tabline)) != nr - 1) |
856 | 3727 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
|
3728 # endif |
685 | 3729 ignore_tabline_evt = FALSE; |
3730 } | |
3731 | |
3732 #endif /* FEAT_GUI_TABLINE */ | |
3733 | |
7 | 3734 /* |
2183 | 3735 * Add selection targets for PRIMARY and CLIPBOARD selections. |
3736 */ | |
3737 void | |
3738 gui_gtk_set_selection_targets(void) | |
3739 { | |
3740 int i, j = 0; | |
3741 int n_targets = N_SELECTION_TARGETS; | |
3742 GtkTargetEntry targets[N_SELECTION_TARGETS]; | |
3743 | |
3744 for (i = 0; i < (int)N_SELECTION_TARGETS; ++i) | |
3745 { | |
3518 | 3746 /* OpenOffice tries to use TARGET_HTML and fails when we don't |
2183 | 3747 * return something, instead of trying another target. Therefore only |
3748 * offer TARGET_HTML when it works. */ | |
3749 if (!clip_html && selection_targets[i].info == TARGET_HTML) | |
3750 n_targets--; | |
3751 else | |
3752 targets[j++] = selection_targets[i]; | |
3753 } | |
3754 | |
3755 gtk_selection_clear_targets(gui.drawarea, (GdkAtom)GDK_SELECTION_PRIMARY); | |
3756 gtk_selection_clear_targets(gui.drawarea, (GdkAtom)clip_plus.gtk_sel_atom); | |
3757 gtk_selection_add_targets(gui.drawarea, | |
3758 (GdkAtom)GDK_SELECTION_PRIMARY, | |
3759 targets, n_targets); | |
3760 gtk_selection_add_targets(gui.drawarea, | |
3761 (GdkAtom)clip_plus.gtk_sel_atom, | |
3762 targets, n_targets); | |
3763 } | |
3764 | |
3765 /* | |
3766 * Set up for receiving DND items. | |
3767 */ | |
3768 void | |
3769 gui_gtk_set_dnd_targets(void) | |
3770 { | |
3771 int i, j = 0; | |
3772 int n_targets = N_DND_TARGETS; | |
3773 GtkTargetEntry targets[N_DND_TARGETS]; | |
3774 | |
3775 for (i = 0; i < (int)N_DND_TARGETS; ++i) | |
3776 { | |
3154 | 3777 if (!clip_html && dnd_targets[i].info == TARGET_HTML) |
2183 | 3778 n_targets--; |
3779 else | |
3780 targets[j++] = dnd_targets[i]; | |
3781 } | |
3782 | |
3783 gtk_drag_dest_unset(gui.drawarea); | |
3784 gtk_drag_dest_set(gui.drawarea, | |
3785 GTK_DEST_DEFAULT_ALL, | |
3786 targets, n_targets, | |
2718 | 3787 GDK_ACTION_COPY | GDK_ACTION_MOVE); |
2183 | 3788 } |
3789 | |
3790 /* | |
7 | 3791 * Initialize the GUI. Create all the windows, set up all the callbacks etc. |
3792 * Returns OK for success, FAIL when the GUI can't be started. | |
3793 */ | |
3794 int | |
3795 gui_mch_init(void) | |
3796 { | |
3797 GtkWidget *vbox; | |
3798 | |
3799 #ifdef FEAT_GUI_GNOME | |
3800 /* Initialize the GNOME libraries. gnome_program_init()/gnome_init() | |
3801 * exits on failure, but that's a non-issue because we already called | |
3802 * gtk_init_check() in gui_mch_init_check(). */ | |
3803 if (using_gnome) | |
4045 | 3804 { |
7 | 3805 gnome_program_init(VIMPACKAGE, VIM_VERSION_SHORT, |
3806 LIBGNOMEUI_MODULE, gui_argc, gui_argv, NULL); | |
4045 | 3807 # if defined(FEAT_FLOAT) && defined(LC_NUMERIC) |
5854 | 3808 { |
3809 char *p = setlocale(LC_NUMERIC, NULL); | |
3810 | |
3811 /* Make sure strtod() uses a decimal point, not a comma. Gnome | |
3812 * init may change it. */ | |
3813 if (p == NULL || strcmp(p, "C") != 0) | |
3814 setlocale(LC_NUMERIC, "C"); | |
3815 } | |
4045 | 3816 # endif |
3817 } | |
7 | 3818 #endif |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13152
diff
changeset
|
3819 VIM_CLEAR(gui_argv); |
7 | 3820 |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3821 #if GLIB_CHECK_VERSION(2,1,3) |
7 | 3822 /* Set the human-readable application name */ |
3823 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
|
3824 #endif |
7 | 3825 /* |
3826 * Force UTF-8 output no matter what the value of 'encoding' is. | |
3827 * did_set_string_option() in option.c prohibits changing 'termencoding' | |
3828 * to something else than UTF-8 if the GUI is in use. | |
3829 */ | |
3830 set_option_value((char_u *)"termencoding", 0L, (char_u *)"utf-8", 0); | |
3831 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3832 #ifdef FEAT_TOOLBAR |
7 | 3833 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
|
3834 #endif |
7 | 3835 /* FIXME: Need to install the classic icons and a gtkrc.classic file. |
3836 * 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
|
3837 #if !GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3838 # if 0 |
7 | 3839 gtk_rc_parse("gtkrc"); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3840 # endif |
7 | 3841 #endif |
3842 | |
3843 /* Initialize values */ | |
3844 gui.border_width = 2; | |
3845 gui.scrollbar_width = SB_DEFAULT_WIDTH; | |
3846 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
|
3847 #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
|
3848 gui.fgcolor = g_new(GdkRGBA, 1); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
3849 gui.bgcolor = g_new(GdkRGBA, 1); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
3850 gui.spcolor = g_new(GdkRGBA, 1); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
3851 #else |
136 | 3852 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
7 | 3853 gui.fgcolor = g_new0(GdkColor, 1); |
136 | 3854 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
7 | 3855 gui.bgcolor = g_new0(GdkColor, 1); |
207 | 3856 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
3857 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
|
3858 #endif |
7 | 3859 |
3860 /* Initialise atoms */ | |
1904 | 3861 html_atom = gdk_atom_intern("text/html", FALSE); |
7 | 3862 utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE); |
3863 | |
3864 /* Set default foreground and background colors. */ | |
3865 gui.norm_pixel = gui.def_norm_pixel; | |
3866 gui.back_pixel = gui.def_back_pixel; | |
3867 | |
3868 if (gtk_socket_id != 0) | |
3869 { | |
3870 GtkWidget *plug; | |
3871 | |
3872 /* Use GtkSocket from another app. */ | |
3873 plug = gtk_plug_new_for_display(gdk_display_get_default(), | |
3874 gtk_socket_id); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3875 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3876 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
|
3877 #else |
7 | 3878 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
|
3879 #endif |
7 | 3880 { |
3881 gui.mainwin = plug; | |
3882 } | |
3883 else | |
3884 { | |
3885 g_warning("Connection to GTK+ socket (ID %u) failed", | |
3886 (unsigned int)gtk_socket_id); | |
3887 /* Pretend we never wanted it if it failed (get own window) */ | |
3888 gtk_socket_id = 0; | |
3889 } | |
3890 } | |
3891 | |
3892 if (gtk_socket_id == 0) | |
3893 { | |
3894 #ifdef FEAT_GUI_GNOME | |
3895 if (using_gnome) | |
3896 { | |
3897 gui.mainwin = gnome_app_new("Vim", NULL); | |
3898 # ifdef USE_XSMP | |
3899 /* Use the GNOME save-yourself functionality now. */ | |
3900 xsmp_close(); | |
3901 # endif | |
3902 } | |
3903 else | |
3904 #endif | |
3905 gui.mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
3906 } | |
3907 | |
3908 gtk_widget_set_name(gui.mainwin, "vim-main-window"); | |
3909 | |
3910 /* Create the PangoContext used for drawing all text. */ | |
3911 gui.text_context = gtk_widget_create_pango_context(gui.mainwin); | |
3912 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
|
3913 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3914 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3915 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
|
3916 #else |
7 | 3917 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
|
3918 #endif |
7 | 3919 gtk_widget_add_events(gui.mainwin, GDK_VISIBILITY_NOTIFY_MASK); |
3920 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3921 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3922 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
|
3923 G_CALLBACK(&delete_event_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3924 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3925 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
|
3926 G_CALLBACK(&mainwin_realize), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3927 #else |
7 | 3928 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "delete_event", |
3929 GTK_SIGNAL_FUNC(&delete_event_cb), NULL); | |
3930 | |
3931 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "realize", | |
3932 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
|
3933 #endif |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3934 |
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3935 g_signal_connect(G_OBJECT(gui.mainwin), "screen-changed", |
7 | 3936 G_CALLBACK(&mainwin_screen_changed_cb), NULL); |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3937 |
7 | 3938 gui.accel_group = gtk_accel_group_new(); |
3939 gtk_window_add_accel_group(GTK_WINDOW(gui.mainwin), gui.accel_group); | |
3940 | |
685 | 3941 /* 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
|
3942 #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
|
3943 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
|
3944 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
|
3945 #else |
7 | 3946 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
|
3947 #endif |
7 | 3948 |
3949 #ifdef FEAT_GUI_GNOME | |
3950 if (using_gnome) | |
3951 { | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3952 # if defined(FEAT_MENU) |
7 | 3953 /* automagically restore menubar/toolbar placement */ |
3954 gnome_app_enable_layout_config(GNOME_APP(gui.mainwin), TRUE); | |
3955 # endif | |
3956 gnome_app_set_contents(GNOME_APP(gui.mainwin), vbox); | |
3957 } | |
3958 else | |
3959 #endif | |
3960 { | |
3961 gtk_container_add(GTK_CONTAINER(gui.mainwin), vbox); | |
3962 gtk_widget_show(vbox); | |
3963 } | |
3964 | |
3965 #ifdef FEAT_MENU | |
3966 /* | |
3967 * Create the menubar and handle | |
3968 */ | |
3969 gui.menubar = gtk_menu_bar_new(); | |
3970 gtk_widget_set_name(gui.menubar, "vim-menubar"); | |
3971 | |
36 | 3972 /* Avoid that GTK takes <F10> away from us. */ |
3973 { | |
3974 GtkSettings *gtk_settings; | |
3975 | |
3976 gtk_settings = gtk_settings_get_for_screen(gdk_screen_get_default()); | |
3977 g_object_set(gtk_settings, "gtk-menu-bar-accel", NULL, NULL); | |
3978 } | |
3979 | |
3980 | |
7 | 3981 # ifdef FEAT_GUI_GNOME |
3982 if (using_gnome) | |
3983 { | |
3984 BonoboDockItem *dockitem; | |
3985 | |
3986 gnome_app_set_menus(GNOME_APP(gui.mainwin), GTK_MENU_BAR(gui.menubar)); | |
3987 dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), | |
3988 GNOME_APP_MENUBAR_NAME); | |
798 | 3989 /* We don't want the menu to float. */ |
3990 bonobo_dock_item_set_behavior(dockitem, | |
3991 bonobo_dock_item_get_behavior(dockitem) | |
3992 | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); | |
7 | 3993 gui.menubar_h = GTK_WIDGET(dockitem); |
3994 } | |
3995 else | |
3996 # endif /* FEAT_GUI_GNOME */ | |
3997 { | |
827 | 3998 /* Always show the menubar, otherwise <F10> doesn't work. It may be |
3999 * disabled in gui_init() later. */ | |
4000 gtk_widget_show(gui.menubar); | |
7 | 4001 gtk_box_pack_start(GTK_BOX(vbox), gui.menubar, FALSE, FALSE, 0); |
4002 } | |
4003 #endif /* FEAT_MENU */ | |
4004 | |
4005 #ifdef FEAT_TOOLBAR | |
4006 /* | |
4007 * Create the toolbar and handle | |
4008 */ | |
4009 /* some aesthetics on the toolbar */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4010 # ifdef USE_GTK3 |
8301
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4011 /* 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
|
4012 /* 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
|
4013 * 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
|
4014 # else |
7 | 4015 gtk_rc_parse_string( |
4016 "style \"vim-toolbar-style\" {\n" | |
4017 " GtkToolbar::button_relief = GTK_RELIEF_NONE\n" | |
4018 "}\n" | |
4019 "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
|
4020 # endif |
7 | 4021 gui.toolbar = gtk_toolbar_new(); |
4022 gtk_widget_set_name(gui.toolbar, "vim-toolbar"); | |
4023 set_toolbar_style(GTK_TOOLBAR(gui.toolbar)); | |
4024 | |
4025 # ifdef FEAT_GUI_GNOME | |
4026 if (using_gnome) | |
4027 { | |
4028 BonoboDockItem *dockitem; | |
4029 | |
4030 gnome_app_set_toolbar(GNOME_APP(gui.mainwin), GTK_TOOLBAR(gui.toolbar)); | |
4031 dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), | |
4032 GNOME_APP_TOOLBAR_NAME); | |
4033 gui.toolbar_h = GTK_WIDGET(dockitem); | |
795 | 4034 /* When the toolbar is floating it gets stuck. So long as that isn't |
798 | 4035 * fixed let's disallow floating. */ |
795 | 4036 bonobo_dock_item_set_behavior(dockitem, |
798 | 4037 bonobo_dock_item_get_behavior(dockitem) |
4038 | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); | |
7 | 4039 gtk_container_set_border_width(GTK_CONTAINER(gui.toolbar), 0); |
4040 } | |
4041 else | |
4042 # endif /* FEAT_GUI_GNOME */ | |
4043 { | |
4044 if (vim_strchr(p_go, GO_TOOLBAR) != NULL | |
4045 && (toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS))) | |
4046 gtk_widget_show(gui.toolbar); | |
4047 gtk_box_pack_start(GTK_BOX(vbox), gui.toolbar, FALSE, FALSE, 0); | |
4048 } | |
4049 #endif /* FEAT_TOOLBAR */ | |
4050 | |
685 | 4051 #ifdef FEAT_GUI_TABLINE |
782 | 4052 /* |
4053 * Use a Notebook for the tab pages labels. The labels are hidden by | |
4054 * default. | |
4055 */ | |
791 | 4056 gui.tabline = gtk_notebook_new(); |
4057 gtk_widget_show(gui.tabline); | |
4058 gtk_box_pack_start(GTK_BOX(vbox), gui.tabline, FALSE, FALSE, 0); | |
4059 gtk_notebook_set_show_border(GTK_NOTEBOOK(gui.tabline), FALSE); | |
4060 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gui.tabline), FALSE); | |
841 | 4061 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
|
4062 # if !GTK_CHECK_VERSION(3,0,0) |
868 | 4063 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
|
4064 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4065 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4066 # if !GTK_CHECK_VERSION(3,0,0) |
846 | 4067 tabline_tooltip = gtk_tooltips_new(); |
4068 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
|
4069 # endif |
846 | 4070 |
4071 { | |
4072 GtkWidget *page, *label, *event_box; | |
791 | 4073 |
856 | 4074 /* Add the first tab. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4075 # 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
|
4076 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
|
4077 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
|
4078 # else |
846 | 4079 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
|
4080 # endif |
846 | 4081 gtk_widget_show(page); |
4082 gtk_container_add(GTK_CONTAINER(gui.tabline), page); | |
4083 label = gtk_label_new("-Empty-"); | |
4084 gtk_widget_show(label); | |
4085 event_box = gtk_event_box_new(); | |
4086 gtk_widget_show(event_box); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4087 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4088 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
|
4089 # else |
1660 | 4090 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
|
4091 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4092 # if !GTK_CHECK_VERSION(3,14,0) |
851 | 4093 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
|
4094 # endif |
846 | 4095 gtk_container_add(GTK_CONTAINER(event_box), label); |
4096 gtk_notebook_set_tab_label(GTK_NOTEBOOK(gui.tabline), page, event_box); | |
12666
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
4097 gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(gui.tabline), page, TRUE); |
791 | 4098 } |
865 | 4099 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4100 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4101 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
|
4102 G_CALLBACK(on_select_tab), NULL); |
12666
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
4103 g_signal_connect(G_OBJECT(gui.tabline), "page-reordered", |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
4104 G_CALLBACK(on_tab_reordered), NULL); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4105 # else |
791 | 4106 gtk_signal_connect(GTK_OBJECT(gui.tabline), "switch_page", |
856 | 4107 GTK_SIGNAL_FUNC(on_select_tab), NULL); |
12666
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
4108 gtk_signal_connect(GTK_OBJECT(gui.tabline), "page-reordered", |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
4109 GTK_SIGNAL_FUNC(on_tab_reordered), NULL); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4110 # endif |
791 | 4111 |
4112 /* Create a popup menu for the tab line and connect it. */ | |
4113 tabline_menu = create_tabline_menu(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4114 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4115 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
|
4116 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
|
4117 # else |
791 | 4118 gtk_signal_connect_object(GTK_OBJECT(gui.tabline), "button_press_event", |
856 | 4119 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
|
4120 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4121 #endif /* FEAT_GUI_TABLINE */ |
685 | 4122 |
7 | 4123 gui.formwin = gtk_form_new(); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4124 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4125 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
|
4126 #else |
7 | 4127 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
|
4128 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4129 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 4130 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
|
4131 #endif |
7 | 4132 |
4133 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
|
4134 #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
|
4135 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
|
4136 #endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4137 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4138 gui.surface = NULL; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4139 gui.by_signal = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4140 #endif |
7 | 4141 |
4142 /* Determine which events we will filter. */ | |
4143 gtk_widget_set_events(gui.drawarea, | |
4144 GDK_EXPOSURE_MASK | | |
4145 GDK_ENTER_NOTIFY_MASK | | |
4146 GDK_LEAVE_NOTIFY_MASK | | |
4147 GDK_BUTTON_PRESS_MASK | | |
4148 GDK_BUTTON_RELEASE_MASK | | |
4149 GDK_SCROLL_MASK | | |
4150 GDK_KEY_PRESS_MASK | | |
4151 GDK_KEY_RELEASE_MASK | | |
4152 GDK_POINTER_MOTION_MASK | | |
4153 GDK_POINTER_MOTION_HINT_MASK); | |
4154 | |
4155 gtk_widget_show(gui.drawarea); | |
4156 gtk_form_put(GTK_FORM(gui.formwin), gui.drawarea, 0, 0); | |
4157 gtk_widget_show(gui.formwin); | |
4158 gtk_box_pack_start(GTK_BOX(vbox), gui.formwin, TRUE, TRUE, 0); | |
4159 | |
4160 /* For GtkSockets, key-presses must go to the focus widget (drawarea) | |
4161 * and not the window. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4162 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4163 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
|
4164 : G_OBJECT(gui.drawarea), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4165 "key-press-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4166 G_CALLBACK(key_press_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4167 #else |
7 | 4168 gtk_signal_connect((gtk_socket_id == 0) ? GTK_OBJECT(gui.mainwin) |
4169 : GTK_OBJECT(gui.drawarea), | |
4170 "key_press_event", | |
4171 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
|
4172 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4173 #if defined(FEAT_XIM) || GTK_CHECK_VERSION(3,0,0) |
7 | 4174 /* Also forward key release events for the benefit of GTK+ 2 input |
4175 * modules. Try CTRL-SHIFT-xdigits to enter a Unicode code point. */ | |
4176 g_signal_connect((gtk_socket_id == 0) ? G_OBJECT(gui.mainwin) | |
4177 : G_OBJECT(gui.drawarea), | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4178 "key-release-event", |
7 | 4179 G_CALLBACK(&key_release_event), NULL); |
4180 #endif | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4181 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4182 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
|
4183 G_CALLBACK(drawarea_realize_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4184 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
|
4185 G_CALLBACK(drawarea_unrealize_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4186 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
|
4187 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
|
4188 # 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
|
4189 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
|
4190 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
|
4191 # else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4192 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
|
4193 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
|
4194 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4195 #else |
7 | 4196 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "realize", |
4197 GTK_SIGNAL_FUNC(drawarea_realize_cb), NULL); | |
4198 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "unrealize", | |
4199 GTK_SIGNAL_FUNC(drawarea_unrealize_cb), NULL); | |
4200 | |
4201 gtk_signal_connect_after(GTK_OBJECT(gui.drawarea), "style_set", | |
4202 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
|
4203 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4204 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4205 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 4206 gui.visibility = GDK_VISIBILITY_UNOBSCURED; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4207 #endif |
7 | 4208 |
4209 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
4210 wm_protocols_atom = gdk_atom_intern("WM_PROTOCOLS", FALSE); | |
4211 save_yourself_atom = gdk_atom_intern("WM_SAVE_YOURSELF", FALSE); | |
4212 #endif | |
4213 | |
4214 if (gtk_socket_id != 0) | |
1884 | 4215 /* 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
|
4216 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4217 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
|
4218 #else |
7 | 4219 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
|
4220 #endif |
7 | 4221 |
4222 /* | |
4223 * Set clipboard specific atoms | |
4224 */ | |
4225 vim_atom = gdk_atom_intern(VIM_ATOM_NAME, FALSE); | |
4226 vimenc_atom = gdk_atom_intern(VIMENC_ATOM_NAME, FALSE); | |
4227 clip_star.gtk_sel_atom = GDK_SELECTION_PRIMARY; | |
4228 clip_plus.gtk_sel_atom = gdk_atom_intern("CLIPBOARD", FALSE); | |
4229 | |
4230 /* | |
4231 * Start out by adding the configured border width into the border offset. | |
4232 */ | |
4233 gui.border_offset = gui.border_width; | |
4234 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4235 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4236 g_signal_connect(G_OBJECT(gui.drawarea), "draw", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4237 G_CALLBACK(draw_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4238 #else |
7 | 4239 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "visibility_notify_event", |
4240 GTK_SIGNAL_FUNC(visibility_event), NULL); | |
4241 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "expose_event", | |
4242 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
|
4243 #endif |
7 | 4244 |
4245 /* | |
4246 * Only install these enter/leave callbacks when 'p' in 'guioptions'. | |
4247 * Only needed for some window managers. | |
4248 */ | |
4249 if (vim_strchr(p_go, GO_POINTER) != NULL) | |
4250 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4251 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4252 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
|
4253 G_CALLBACK(leave_notify_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4254 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
|
4255 G_CALLBACK(enter_notify_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4256 #else |
7 | 4257 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "leave_notify_event", |
4258 GTK_SIGNAL_FUNC(leave_notify_event), NULL); | |
4259 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "enter_notify_event", | |
4260 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
|
4261 #endif |
7 | 4262 } |
4263 | |
791 | 4264 /* Real windows can get focus ... GtkPlug, being a mere container can't, |
4265 * only its widgets. Arguably, this could be common code and we not use | |
4266 * the window focus at all, but let's be safe. | |
4267 */ | |
4268 if (gtk_socket_id == 0) | |
4269 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4270 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4271 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
|
4272 G_CALLBACK(focus_out_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4273 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
|
4274 G_CALLBACK(focus_in_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4275 #else |
856 | 4276 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "focus_out_event", |
4277 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
4278 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "focus_in_event", | |
4279 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
|
4280 #endif |
791 | 4281 } |
4282 else | |
4283 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4284 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4285 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
|
4286 G_CALLBACK(focus_out_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4287 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
|
4288 G_CALLBACK(focus_in_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4289 #else |
856 | 4290 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "focus_out_event", |
4291 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
4292 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "focus_in_event", | |
4293 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
|
4294 #endif |
791 | 4295 #ifdef FEAT_GUI_TABLINE |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4296 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4297 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
|
4298 G_CALLBACK(focus_out_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4299 g_signal_connect(G_OBJECT(gui.tabline), "focus-in-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4300 G_CALLBACK(focus_in_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4301 # else |
856 | 4302 gtk_signal_connect(GTK_OBJECT(gui.tabline), "focus_out_event", |
4303 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
4304 gtk_signal_connect(GTK_OBJECT(gui.tabline), "focus_in_event", | |
4305 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
|
4306 # endif |
791 | 4307 #endif /* FEAT_GUI_TABLINE */ |
4308 } | |
7 | 4309 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4310 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4311 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
|
4312 G_CALLBACK(motion_notify_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4313 g_signal_connect(G_OBJECT(gui.drawarea), "button-press-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4314 G_CALLBACK(button_press_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4315 g_signal_connect(G_OBJECT(gui.drawarea), "button-release-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4316 G_CALLBACK(button_release_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4317 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
|
4318 G_CALLBACK(&scroll_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4319 #else |
7 | 4320 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "motion_notify_event", |
4321 GTK_SIGNAL_FUNC(motion_notify_event), NULL); | |
4322 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "button_press_event", | |
4323 GTK_SIGNAL_FUNC(button_press_event), NULL); | |
4324 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "button_release_event", | |
4325 GTK_SIGNAL_FUNC(button_release_event), NULL); | |
4326 g_signal_connect(G_OBJECT(gui.drawarea), "scroll_event", | |
4327 G_CALLBACK(&scroll_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4328 #endif |
7 | 4329 |
4330 /* | |
4331 * Add selection handler functions. | |
4332 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4333 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4334 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
|
4335 G_CALLBACK(selection_clear_event), NULL); |
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.drawarea), "selection-received", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4337 G_CALLBACK(selection_received_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4338 #else |
7 | 4339 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_clear_event", |
4340 GTK_SIGNAL_FUNC(selection_clear_event), NULL); | |
4341 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_received", | |
4342 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
|
4343 #endif |
7 | 4344 |
2183 | 4345 gui_gtk_set_selection_targets(); |
7 | 4346 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4347 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4348 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
|
4349 G_CALLBACK(selection_get_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4350 #else |
7 | 4351 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_get", |
4352 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
|
4353 #endif |
7 | 4354 |
4355 /* Pretend we don't have input focus, we will get an event if we do. */ | |
4356 gui.in_focus = FALSE; | |
4357 | |
14471
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
4358 // Handle changes to the "Xft/DPI" setting. |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
4359 { |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
4360 GtkSettings *gtk_settings = |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
4361 gtk_settings_get_for_screen(gdk_screen_get_default()); |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
4362 |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
4363 g_signal_connect(gtk_settings, "notify::gtk-xft-dpi", |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
4364 G_CALLBACK(gtk_settings_xft_dpi_changed_cb), NULL); |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
4365 } |
2f6f886d9a87
patch 8.1.0249: GTK: when screen DPI changes Vim does not handle it
Christian Brabandt <cb@256bit.org>
parents:
13674
diff
changeset
|
4366 |
7 | 4367 return OK; |
4368 } | |
4369 | |
4370 #if (defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) || defined(PROTO) | |
4371 /* | |
4372 * This is called from gui_start() after a fork() has been done. | |
4373 * We have to tell the session manager our new PID. | |
4374 */ | |
4375 void | |
4376 gui_mch_forked(void) | |
4377 { | |
4378 if (using_gnome) | |
4379 { | |
4380 GnomeClient *client; | |
4381 | |
4382 client = gnome_master_client(); | |
4383 | |
4384 if (client != NULL) | |
4385 gnome_client_set_process_id(client, getpid()); | |
4386 } | |
4387 } | |
4388 #endif /* FEAT_GUI_GNOME && FEAT_SESSION */ | |
4389 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4390 #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
|
4391 static GdkRGBA |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4392 color_to_rgba(guicolor_T color) |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4393 { |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4394 GdkRGBA rgba; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4395 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
|
4396 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
|
4397 rgba.blue = ((color & 0xff)) / 255.0; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4398 rgba.alpha = 1.0; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4399 return rgba; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4400 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4401 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4402 static void |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4403 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
|
4404 { |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4405 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
|
4406 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
|
4407 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4408 #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
|
4409 |
7 | 4410 /* |
4411 * Called when the foreground or background color has been changed. | |
4412 * This used to change the graphics contexts directly but we are | |
4413 * currently manipulating them where desired. | |
4414 */ | |
4415 void | |
4416 gui_mch_new_colors(void) | |
4417 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4418 #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
|
4419 # 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
|
4420 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
|
4421 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4422 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4423 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
|
4424 #else |
7 | 4425 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
|
4426 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4427 { |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4428 #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
|
4429 GtkStyleContext * const context |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4430 = 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
|
4431 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
|
4432 gchar * const css = g_strdup_printf( |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4433 "widget#vim-gui-drawarea {\n" |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4434 " background-color: #%.2lx%.2lx%.2lx;\n" |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4435 "}\n", |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4436 (gui.back_pixel >> 16) & 0xff, |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4437 (gui.back_pixel >> 8) & 0xff, |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4438 gui.back_pixel & 0xff); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4439 |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4440 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
|
4441 gtk_style_context_add_provider(context, |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4442 GTK_STYLE_PROVIDER(provider), G_MAXUINT); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4443 |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4444 g_free(css); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4445 g_object_unref(provider); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4446 #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
|
4447 GdkRGBA rgba; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4448 |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4449 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
|
4450 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4451 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
|
4452 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
|
4453 if (pat != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4454 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4455 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
|
4456 cairo_pattern_destroy(pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4457 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4458 else |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4459 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
|
4460 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4461 #else /* !GTK_CHECK_VERSION(3,4,0) */ |
7 | 4462 GdkColor color = { 0, 0, 0, 0 }; |
4463 | |
4464 color.pixel = gui.back_pixel; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4465 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4466 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
|
4467 # else |
7 | 4468 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
|
4469 # endif |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4470 #endif /* !GTK_CHECK_VERSION(3,22,2) */ |
7 | 4471 } |
4472 } | |
4473 | |
4474 /* | |
4475 * This signal informs us about the need to rearrange our sub-widgets. | |
4476 */ | |
4477 static gint | |
1884 | 4478 form_configure_event(GtkWidget *widget UNUSED, |
4479 GdkEventConfigure *event, | |
4480 gpointer data UNUSED) | |
7 | 4481 { |
791 | 4482 int usable_height = event->height; |
4483 | |
10402
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
4484 #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
|
4485 /* 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
|
4486 * 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
|
4487 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4488 * 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
|
4489 * 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
|
4490 * 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
|
4491 * "native" one from non-native one. |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4492 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4493 * 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
|
4494 * 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
|
4495 * gui.formwin. |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4496 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4497 * 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
|
4498 * 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
|
4499 */ |
10402
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
4500 /* Follow-up |
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
4501 * 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
|
4502 * 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
|
4503 * 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
|
4504 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
|
4505 return TRUE; |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4506 #endif |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4507 |
791 | 4508 /* When in a GtkPlug, we can't guarantee valid heights (as a round |
4509 * no. of char-heights), so we have to manually sanitise them. | |
4510 * Widths seem to sort themselves out, don't ask me why. | |
4511 */ | |
4512 if (gtk_socket_id != 0) | |
856 | 4513 usable_height -= (gui.char_height - (gui.char_height/2)); /* sic. */ |
791 | 4514 |
7 | 4515 gtk_form_freeze(GTK_FORM(gui.formwin)); |
791 | 4516 gui_resize_shell(event->width, usable_height); |
7 | 4517 gtk_form_thaw(GTK_FORM(gui.formwin)); |
4518 | |
4519 return TRUE; | |
4520 } | |
4521 | |
4522 /* | |
4523 * Function called when window already closed. | |
4524 * We can't do much more here than to trying to preserve what had been done, | |
4525 * since the window is already inevitably going away. | |
4526 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4527 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4528 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4529 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
|
4530 #else |
7 | 4531 static void |
1884 | 4532 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
|
4533 #endif |
7 | 4534 { |
4535 /* Don't write messages to the GUI anymore */ | |
4536 full_screen = FALSE; | |
4537 | |
4538 gui.mainwin = NULL; | |
4539 gui.drawarea = NULL; | |
4540 | |
4541 if (!exiting) /* only do anything if the destroy was unexpected */ | |
4542 { | |
419 | 4543 vim_strncpy(IObuff, |
4544 (char_u *)_("Vim: Main window unexpectedly destroyed\n"), | |
4545 IOSIZE - 1); | |
7 | 4546 preserve_exit(); |
4547 } | |
7380
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
4548 #ifdef USE_GRESOURCE |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
4549 gui_gtk_unregister_resource(); |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
4550 #endif |
7 | 4551 } |
4552 | |
791 | 4553 |
4554 /* | |
4555 * Bit of a hack to ensure we start GtkPlug windows with the correct window | |
4556 * hints (and thus the required size from -geom), but that after that we | |
4557 * put the hints back to normal (the actual minimum size) so we may | |
4558 * subsequently be resized smaller. GtkSocket (the parent end) uses the | |
1226 | 4559 * plug's window 'min hints to set *it's* minimum size, but that's also the |
791 | 4560 * only way we have of making ourselves bigger (by set lines/columns). |
4561 * 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
|
4562 * 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
|
4563 * scrollbar init.), actually do the standard hints and stop the timer. |
791 | 4564 * We'll not let the default hints be set while this timer's active. |
4565 */ | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
4566 static timeout_cb_type |
1884 | 4567 check_startup_plug_hints(gpointer data UNUSED) |
791 | 4568 { |
4569 if (init_window_hints_state == 1) | |
4570 { | |
856 | 4571 /* Safe to use normal hints now */ |
4572 init_window_hints_state = 0; | |
4573 update_window_manager_hints(0, 0); | |
4574 return FALSE; /* stop timer */ | |
791 | 4575 } |
4576 | |
4577 /* Keep on trying */ | |
4578 init_window_hints_state = 1; | |
4579 return TRUE; | |
4580 } | |
4581 | |
7 | 4582 /* |
4583 * Open the GUI window which was created by a call to gui_mch_init(). | |
4584 */ | |
4585 int | |
4586 gui_mch_open(void) | |
4587 { | |
4588 guicolor_T fg_pixel = INVALCOLOR; | |
4589 guicolor_T bg_pixel = INVALCOLOR; | |
1966 | 4590 guint pixel_width; |
4591 guint pixel_height; | |
7 | 4592 |
4593 /* | |
4594 * Allow setting a window role on the command line, or invent one | |
4595 * if none was specified. This is mainly useful for GNOME session | |
4596 * support; allowing the WM to restore window placement. | |
4597 */ | |
4598 if (role_argument != NULL) | |
4599 { | |
4600 gtk_window_set_role(GTK_WINDOW(gui.mainwin), role_argument); | |
4601 } | |
4602 else | |
4603 { | |
4604 char *role; | |
4605 | |
4606 /* Invent a unique-enough ID string for the role */ | |
4607 role = g_strdup_printf("vim-%u-%u-%u", | |
4608 (unsigned)mch_get_pid(), | |
4609 (unsigned)g_random_int(), | |
4610 (unsigned)time(NULL)); | |
4611 | |
4612 gtk_window_set_role(GTK_WINDOW(gui.mainwin), role); | |
4613 g_free(role); | |
4614 } | |
4615 | |
4616 if (gui_win_x != -1 && gui_win_y != -1) | |
4617 gtk_window_move(GTK_WINDOW(gui.mainwin), gui_win_x, gui_win_y); | |
4618 | |
4619 /* Determine user specified geometry, if present. */ | |
4620 if (gui.geom != NULL) | |
4621 { | |
4622 int mask; | |
4623 unsigned int w, h; | |
4624 int x = 0; | |
4625 int y = 0; | |
4626 | |
4627 mask = XParseGeometry((char *)gui.geom, &x, &y, &w, &h); | |
4628 | |
4629 if (mask & WidthValue) | |
4630 Columns = w; | |
4631 if (mask & HeightValue) | |
857 | 4632 { |
1884 | 4633 if (p_window > (long)h - 1 || !option_was_set((char_u *)"window")) |
857 | 4634 p_window = h - 1; |
7 | 4635 Rows = h; |
857 | 4636 } |
5070
cf52d2a8c05c
updated for version 7.3.1278
Bram Moolenaar <bram@vim.org>
parents:
4474
diff
changeset
|
4637 limit_screen_size(); |
1426 | 4638 |
4639 pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width); | |
4640 pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height); | |
4641 | |
4642 pixel_width += get_menu_tool_width(); | |
4643 pixel_height += get_menu_tool_height(); | |
4644 | |
7 | 4645 if (mask & (XValue | YValue)) |
1426 | 4646 { |
1757 | 4647 int ww, hh; |
4648 gui_mch_get_screen_dimensions(&ww, &hh); | |
4649 hh += p_ghr + get_menu_tool_height(); | |
4650 ww += get_menu_tool_width(); | |
1426 | 4651 if (mask & XNegative) |
1757 | 4652 x += ww - pixel_width; |
1426 | 4653 if (mask & YNegative) |
1757 | 4654 y += hh - pixel_height; |
7 | 4655 gtk_window_move(GTK_WINDOW(gui.mainwin), x, y); |
1426 | 4656 } |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13152
diff
changeset
|
4657 VIM_CLEAR(gui.geom); |
791 | 4658 |
856 | 4659 /* From now until everyone's stopped trying to set the window hints |
4660 * to their correct minimum values, stop them being set as we need | |
4661 * them to remain at our required size for the parent GtkSocket to | |
4662 * give us the right initial size. | |
4663 */ | |
791 | 4664 if (gtk_socket_id != 0 && (mask & WidthValue || mask & HeightValue)) |
856 | 4665 { |
4666 update_window_manager_hints(pixel_width, pixel_height); | |
4667 init_window_hints_state = 1; | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
4668 timeout_add(1000, check_startup_plug_hints, NULL); |
856 | 4669 } |
7 | 4670 } |
4671 | |
1966 | 4672 pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width); |
4673 pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height); | |
4674 /* For GTK2 changing the size of the form widget doesn't cause window | |
4675 * resizing. */ | |
2254
4620acaf4814
One more fix for conceal patch.
Bram Moolenaar <bram@vim.org>
parents:
2248
diff
changeset
|
4676 if (gtk_socket_id == 0) |
1966 | 4677 gtk_window_resize(GTK_WINDOW(gui.mainwin), pixel_width, pixel_height); |
791 | 4678 update_window_manager_hints(0, 0); |
7 | 4679 |
4680 if (foreground_argument != NULL) | |
4681 fg_pixel = gui_get_color((char_u *)foreground_argument); | |
4682 if (fg_pixel == INVALCOLOR) | |
4683 fg_pixel = gui_get_color((char_u *)"Black"); | |
4684 | |
4685 if (background_argument != NULL) | |
4686 bg_pixel = gui_get_color((char_u *)background_argument); | |
4687 if (bg_pixel == INVALCOLOR) | |
4688 bg_pixel = gui_get_color((char_u *)"White"); | |
4689 | |
4690 if (found_reverse_arg) | |
4691 { | |
4692 gui.def_norm_pixel = bg_pixel; | |
4693 gui.def_back_pixel = fg_pixel; | |
4694 } | |
4695 else | |
4696 { | |
4697 gui.def_norm_pixel = fg_pixel; | |
4698 gui.def_back_pixel = bg_pixel; | |
4699 } | |
4700 | |
4701 /* Get the colors from the "Normal" and "Menu" group (set in syntax.c or | |
4702 * in a vimrc file) */ | |
4703 set_normal_colors(); | |
4704 | |
4705 /* Check that none of the colors are the same as the background color */ | |
4706 gui_check_colors(); | |
4707 | |
4708 /* Get the colors for the highlight groups (gui_check_colors() might have | |
4709 * changed them). */ | |
4710 highlight_gui_started(); /* re-init colors and fonts */ | |
4711 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4712 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4713 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
|
4714 G_CALLBACK(mainwin_destroy_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4715 #else |
7 | 4716 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "destroy", |
4717 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
|
4718 #endif |
7 | 4719 |
4720 #ifdef FEAT_HANGULIN | |
4721 hangul_keyboard_set(); | |
4722 #endif | |
4723 | |
4724 /* | |
4725 * Notify the fixed area about the need to resize the contents of the | |
4726 * gui.formwin, which we use for random positioning of the included | |
4727 * components. | |
4728 * | |
4729 * We connect this signal deferred finally after anything is in place, | |
4730 * since this is intended to handle resizements coming from the window | |
4731 * manager upon us and should not interfere with what VIM is requesting | |
4732 * upon startup. | |
4733 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4734 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4735 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
|
4736 G_CALLBACK(form_configure_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4737 #else |
7 | 4738 gtk_signal_connect(GTK_OBJECT(gui.formwin), "configure_event", |
4739 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
|
4740 #endif |
7 | 4741 |
4742 #ifdef FEAT_DND | |
2183 | 4743 /* Set up for receiving DND items. */ |
4744 gui_gtk_set_dnd_targets(); | |
7 | 4745 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4746 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4747 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
|
4748 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
|
4749 # else |
7 | 4750 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "drag_data_received", |
4751 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
|
4752 # endif |
7 | 4753 #endif |
4754 | |
4755 /* 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
|
4756 * to avoid mapping the window for a short time. */ |
7 | 4757 if (found_iconic_arg && gtk_socket_id == 0) |
4758 gui_mch_iconify(); | |
4759 | |
4760 { | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
4761 #if defined(FEAT_GUI_GNOME) && defined(FEAT_MENU) |
7 | 4762 unsigned long menu_handler = 0; |
4763 # ifdef FEAT_TOOLBAR | |
4764 unsigned long tool_handler = 0; | |
4765 # endif | |
4766 /* | |
4767 * Urgh hackish :/ For some reason BonoboDockLayout always forces a | |
4768 * show when restoring the saved layout configuration. We can't just | |
4769 * hide the widgets again after gtk_widget_show(gui.mainwin) since it's | |
4770 * a toplevel window and thus will be realized immediately. Instead, | |
4771 * connect signal handlers to hide the widgets just after they've been | |
4772 * marked visible, but before the main window is realized. | |
4773 */ | |
4774 if (using_gnome && vim_strchr(p_go, GO_MENUS) == NULL) | |
4775 menu_handler = g_signal_connect_after(gui.menubar_h, "show", | |
4776 G_CALLBACK(>k_widget_hide), | |
4777 NULL); | |
4778 # ifdef FEAT_TOOLBAR | |
4779 if (using_gnome && vim_strchr(p_go, GO_TOOLBAR) == NULL | |
4780 && (toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS))) | |
4781 tool_handler = g_signal_connect_after(gui.toolbar_h, "show", | |
4782 G_CALLBACK(>k_widget_hide), | |
4783 NULL); | |
4784 # endif | |
4785 #endif | |
4786 gtk_widget_show(gui.mainwin); | |
4787 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
4788 #if defined(FEAT_GUI_GNOME) && defined(FEAT_MENU) |
7 | 4789 if (menu_handler != 0) |
4790 g_signal_handler_disconnect(gui.menubar_h, menu_handler); | |
4791 # ifdef FEAT_TOOLBAR | |
4792 if (tool_handler != 0) | |
4793 g_signal_handler_disconnect(gui.toolbar_h, tool_handler); | |
4794 # endif | |
4795 #endif | |
4796 } | |
4797 | |
4798 return OK; | |
4799 } | |
4800 | |
4801 | |
4802 void | |
1884 | 4803 gui_mch_exit(int rc UNUSED) |
7 | 4804 { |
4805 if (gui.mainwin != NULL) | |
4806 gtk_widget_destroy(gui.mainwin); | |
4807 } | |
4808 | |
4809 /* | |
4810 * Get the position of the top left corner of the window. | |
4811 */ | |
4812 int | |
4813 gui_mch_get_winpos(int *x, int *y) | |
4814 { | |
4815 gtk_window_get_position(GTK_WINDOW(gui.mainwin), x, y); | |
4816 return OK; | |
4817 } | |
4818 | |
4819 /* | |
4820 * Set the position of the top left corner of the window to the given | |
4821 * coordinates. | |
4822 */ | |
4823 void | |
4824 gui_mch_set_winpos(int x, int y) | |
4825 { | |
4826 gtk_window_move(GTK_WINDOW(gui.mainwin), x, y); | |
4827 } | |
4828 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4829 #if !GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4830 # if 0 |
7 | 4831 static int resize_idle_installed = FALSE; |
4832 /* | |
4833 * Idle handler to force resize. Used by gui_mch_set_shellsize() to ensure | |
4834 * the shell size doesn't exceed the window size, i.e. if the window manager | |
4835 * ignored our size request. Usually this happens if the window is maximized. | |
4836 * | |
4837 * FIXME: It'd be nice if we could find a little more orthodox solution. | |
4838 * See also the remark below in gui_mch_set_shellsize(). | |
4839 * | |
4840 * DISABLED: When doing ":set lines+=1" this function would first invoke | |
4841 * gui_resize_shell() with the old size, then the normal callback would | |
4842 * report the new size through form_configure_event(). That caused the window | |
4843 * layout to be messed up. | |
4844 */ | |
4845 static gboolean | |
4846 force_shell_resize_idle(gpointer data) | |
4847 { | |
4848 if (gui.mainwin != NULL | |
4849 && GTK_WIDGET_REALIZED(gui.mainwin) | |
4850 && GTK_WIDGET_VISIBLE(gui.mainwin)) | |
4851 { | |
4852 int width; | |
4853 int height; | |
4854 | |
4855 gtk_window_get_size(GTK_WINDOW(gui.mainwin), &width, &height); | |
4856 | |
4857 width -= get_menu_tool_width(); | |
4858 height -= get_menu_tool_height(); | |
4859 | |
4860 gui_resize_shell(width, height); | |
4861 } | |
4862 | |
4863 resize_idle_installed = FALSE; | |
4864 return FALSE; /* don't call me again */ | |
4865 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4866 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4867 #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
|
4868 |
1967 | 4869 /* |
4870 * Return TRUE if the main window is maximized. | |
4871 */ | |
4872 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
4873 gui_mch_maximized(void) |
1967 | 4874 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4875 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
|
4876 && (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
|
4877 & GDK_WINDOW_STATE_MAXIMIZED)); |
1967 | 4878 } |
4879 | |
4880 /* | |
4881 * Unmaximize the main window | |
4882 */ | |
4883 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
4884 gui_mch_unmaximize(void) |
1967 | 4885 { |
4886 if (gui.mainwin != NULL) | |
4887 gtk_window_unmaximize(GTK_WINDOW(gui.mainwin)); | |
4888 } | |
4889 | |
7 | 4890 /* |
12802
29a728529f92
patch 8.0.1278: GUI window always resizes when adding scrollbar
Christian Brabandt <cb@256bit.org>
parents:
12666
diff
changeset
|
4891 * Called when the font changed while the window is maximized or GO_KEEPWINSIZE |
29a728529f92
patch 8.0.1278: GUI window always resizes when adding scrollbar
Christian Brabandt <cb@256bit.org>
parents:
12666
diff
changeset
|
4892 * is set. Compute the new Rows and Columns. This is like resizing the |
29a728529f92
patch 8.0.1278: GUI window always resizes when adding scrollbar
Christian Brabandt <cb@256bit.org>
parents:
12666
diff
changeset
|
4893 * window. |
3014 | 4894 */ |
4895 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
4896 gui_mch_newfont(void) |
3014 | 4897 { |
4898 int w, h; | |
4899 | |
4900 gtk_window_get_size(GTK_WINDOW(gui.mainwin), &w, &h); | |
4901 w -= get_menu_tool_width(); | |
4902 h -= get_menu_tool_height(); | |
4903 gui_resize_shell(w, h); | |
4904 } | |
4905 | |
4906 /* | |
7 | 4907 * Set the windows size. |
4908 */ | |
4909 void | |
4910 gui_mch_set_shellsize(int width, int height, | |
1884 | 4911 int min_width UNUSED, int min_height UNUSED, |
4912 int base_width UNUSED, int base_height UNUSED, | |
4913 int direction UNUSED) | |
7 | 4914 { |
4915 /* give GTK+ a chance to put all widget's into place */ | |
4916 gui_mch_update(); | |
4917 | |
791 | 4918 /* this will cause the proper resizement to happen too */ |
4919 if (gtk_socket_id == 0) | |
856 | 4920 update_window_manager_hints(0, 0); |
791 | 4921 |
7 | 4922 /* With GTK+ 2, changing the size of the form widget doesn't resize |
791 | 4923 * the window. So let's do it the other way around and resize the |
7 | 4924 * main window instead. */ |
4925 width += get_menu_tool_width(); | |
4926 height += get_menu_tool_height(); | |
4927 | |
791 | 4928 if (gtk_socket_id == 0) |
856 | 4929 gtk_window_resize(GTK_WINDOW(gui.mainwin), width, height); |
791 | 4930 else |
856 | 4931 update_window_manager_hints(width, height); |
7 | 4932 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4933 # if !GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4934 # if 0 |
7 | 4935 if (!resize_idle_installed) |
4936 { | |
4937 g_idle_add_full(GDK_PRIORITY_EVENTS + 10, | |
4938 &force_shell_resize_idle, NULL, NULL); | |
4939 resize_idle_installed = TRUE; | |
4940 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4941 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4942 # endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 4943 /* |
4944 * Wait until all events are processed to prevent a crash because the | |
4945 * real size of the drawing area doesn't reflect Vim's internal ideas. | |
4946 * | |
4947 * This is a bit of a hack, since Vim is a terminal application with a GUI | |
4948 * on top, while the GUI expects to be the boss. | |
4949 */ | |
4950 gui_mch_update(); | |
4951 } | |
4952 | |
12409
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4953 void |
14575
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4954 gui_gtk_get_screen_geom_of_win( |
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4955 GtkWidget *wid, |
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4956 int *screen_x, |
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4957 int *screen_y, |
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4958 int *width, |
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4959 int *height) |
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4960 { |
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4961 GdkRectangle geometry; |
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4962 GdkWindow *win = gtk_widget_get_window(wid); |
12409
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4963 #if GTK_CHECK_VERSION(3,22,0) |
12413
ca7f2685e339
patch 8.0.1086: can't build with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
12409
diff
changeset
|
4964 GdkDisplay *dpy = gtk_widget_get_display(wid); |
12409
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4965 GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win); |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4966 |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4967 gdk_monitor_get_geometry(monitor, &geometry); |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4968 #else |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4969 GdkScreen* screen; |
14575
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4970 int monitor; |
12409
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4971 |
12413
ca7f2685e339
patch 8.0.1086: can't build with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
12409
diff
changeset
|
4972 if (wid != NULL && gtk_widget_has_screen(wid)) |
ca7f2685e339
patch 8.0.1086: can't build with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
12409
diff
changeset
|
4973 screen = gtk_widget_get_screen(wid); |
12409
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4974 else |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4975 screen = gdk_screen_get_default(); |
14575
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4976 monitor = gdk_screen_get_monitor_at_window(screen, win); |
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4977 gdk_screen_get_monitor_geometry(screen, monitor, &geometry); |
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4978 #endif |
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4979 *screen_x = geometry.x; |
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4980 *screen_y = geometry.y; |
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4981 *width = geometry.width; |
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4982 *height = geometry.height; |
12409
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4983 } |
7 | 4984 |
4985 /* | |
4986 * The screen size is used to make sure the initial window doesn't get bigger | |
4987 * than the screen. This subtracts some room for menubar, toolbar and window | |
4988 * decorations. | |
4989 */ | |
4990 void | |
4991 gui_mch_get_screen_dimensions(int *screen_w, int *screen_h) | |
4992 { | |
14575
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4993 int x, y; |
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4994 |
f8cd07a1cbb5
patch 8.1.0301: GTK: input method popup displayed on wrong screen.
Christian Brabandt <cb@256bit.org>
parents:
14471
diff
changeset
|
4995 gui_gtk_get_screen_geom_of_win(gui.mainwin, &x, &y, screen_w, screen_h); |
12409
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4996 |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4997 /* Subtract 'guiheadroom' from the height to allow some room for the |
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4998 * window manager (task list and window title bar). */ |
12409
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4999 *screen_h -= p_ghr; |
7 | 5000 |
5001 /* | |
5002 * FIXME: dirty trick: Because the gui_get_base_height() doesn't include | |
5003 * 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
|
5004 * height, so that the window size can be made to fit on the screen. |
7 | 5005 * This should be completely changed later. |
5006 */ | |
5007 *screen_w -= get_menu_tool_width(); | |
5008 *screen_h -= get_menu_tool_height(); | |
5009 } | |
5010 | |
5011 #if defined(FEAT_TITLE) || defined(PROTO) | |
5012 void | |
1884 | 5013 gui_mch_settitle(char_u *title, char_u *icon UNUSED) |
7 | 5014 { |
5015 if (title != NULL && output_conv.vc_type != CONV_NONE) | |
5016 title = string_convert(&output_conv, title, NULL); | |
5017 | |
5018 gtk_window_set_title(GTK_WINDOW(gui.mainwin), (const char *)title); | |
5019 | |
5020 if (output_conv.vc_type != CONV_NONE) | |
5021 vim_free(title); | |
5022 } | |
5023 #endif /* FEAT_TITLE */ | |
5024 | |
5025 #if defined(FEAT_MENU) || defined(PROTO) | |
5026 void | |
5027 gui_mch_enable_menu(int showit) | |
5028 { | |
5029 GtkWidget *widget; | |
5030 | |
5031 # ifdef FEAT_GUI_GNOME | |
5032 if (using_gnome) | |
5033 widget = gui.menubar_h; | |
5034 else | |
5035 # endif | |
5036 widget = gui.menubar; | |
5037 | |
827 | 5038 /* 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
|
5039 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5040 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
|
5041 # else |
827 | 5042 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
|
5043 # endif |
7 | 5044 { |
5045 if (showit) | |
5046 gtk_widget_show(widget); | |
5047 else | |
5048 gtk_widget_hide(widget); | |
5049 | |
791 | 5050 update_window_manager_hints(0, 0); |
7 | 5051 } |
5052 } | |
5053 #endif /* FEAT_MENU */ | |
5054 | |
5055 #if defined(FEAT_TOOLBAR) || defined(PROTO) | |
5056 void | |
5057 gui_mch_show_toolbar(int showit) | |
5058 { | |
5059 GtkWidget *widget; | |
5060 | |
5061 if (gui.toolbar == NULL) | |
5062 return; | |
5063 | |
5064 # ifdef FEAT_GUI_GNOME | |
5065 if (using_gnome) | |
5066 widget = gui.toolbar_h; | |
5067 else | |
5068 # endif | |
5069 widget = gui.toolbar; | |
5070 | |
5071 if (showit) | |
5072 set_toolbar_style(GTK_TOOLBAR(gui.toolbar)); | |
5073 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5074 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5075 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
|
5076 # else |
7 | 5077 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
|
5078 # endif |
7 | 5079 { |
5080 if (showit) | |
5081 gtk_widget_show(widget); | |
5082 else | |
5083 gtk_widget_hide(widget); | |
5084 | |
791 | 5085 update_window_manager_hints(0, 0); |
7 | 5086 } |
5087 } | |
5088 #endif /* FEAT_TOOLBAR */ | |
5089 | |
5090 /* | |
5091 * Check if a given font is a CJK font. This is done in a very crude manner. It | |
5092 * just see if U+04E00 for zh and ja and U+AC00 for ko are covered in a given | |
5093 * font. Consequently, this function cannot be used as a general purpose check | |
5094 * for CJK-ness for which fontconfig APIs should be used. This is only used by | |
5095 * gui_mch_init_font() to deal with 'CJK fixed width fonts'. | |
5096 */ | |
5097 static int | |
5098 is_cjk_font(PangoFontDescription *font_desc) | |
5099 { | |
5100 static const char * const cjk_langs[] = | |
5101 {"zh_CN", "zh_TW", "zh_HK", "ja", "ko"}; | |
5102 | |
5103 PangoFont *font; | |
5104 unsigned i; | |
5105 int is_cjk = FALSE; | |
5106 | |
5107 font = pango_context_load_font(gui.text_context, font_desc); | |
5108 | |
5109 if (font == NULL) | |
5110 return FALSE; | |
5111 | |
5112 for (i = 0; !is_cjk && i < G_N_ELEMENTS(cjk_langs); ++i) | |
5113 { | |
5114 PangoCoverage *coverage; | |
5115 gunichar uc; | |
5116 | |
5117 coverage = pango_font_get_coverage( | |
5118 font, pango_language_from_string(cjk_langs[i])); | |
5119 | |
5120 if (coverage != NULL) | |
5121 { | |
5122 uc = (cjk_langs[i][0] == 'k') ? 0xAC00 : 0x4E00; | |
5123 is_cjk = (pango_coverage_get(coverage, uc) == PANGO_COVERAGE_EXACT); | |
5124 pango_coverage_unref(coverage); | |
5125 } | |
5126 } | |
5127 | |
5128 g_object_unref(font); | |
5129 | |
5130 return is_cjk; | |
5131 } | |
5132 | |
445 | 5133 /* |
5134 * Adjust gui.char_height (after 'linespace' was changed). | |
5135 */ | |
7 | 5136 int |
445 | 5137 gui_mch_adjust_charheight(void) |
7 | 5138 { |
5139 PangoFontMetrics *metrics; | |
5140 int ascent; | |
5141 int descent; | |
5142 | |
5143 metrics = pango_context_get_metrics(gui.text_context, gui.norm_font, | |
5144 pango_context_get_language(gui.text_context)); | |
5145 ascent = pango_font_metrics_get_ascent(metrics); | |
5146 descent = pango_font_metrics_get_descent(metrics); | |
5147 | |
5148 pango_font_metrics_unref(metrics); | |
5149 | |
5150 gui.char_height = (ascent + descent + PANGO_SCALE - 1) / PANGO_SCALE | |
445 | 5151 + p_linespace; |
136 | 5152 /* LINTED: avoid warning: bitwise operation on signed value */ |
7 | 5153 gui.char_ascent = PANGO_PIXELS(ascent + p_linespace * PANGO_SCALE / 2); |
5154 | |
5155 /* A not-positive value of char_height may crash Vim. Only happens | |
5156 * if 'linespace' is negative (which does make sense sometimes). */ | |
5157 gui.char_ascent = MAX(gui.char_ascent, 0); | |
5158 gui.char_height = MAX(gui.char_height, gui.char_ascent + 1); | |
5159 | |
5160 return OK; | |
5161 } | |
5162 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5163 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5164 /* 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
|
5165 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5166 font_filter(const PangoFontFamily *family, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5167 const PangoFontFace *face UNUSED, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5168 gpointer data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5169 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5170 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
|
5171 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5172 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5173 |
7 | 5174 /* |
5175 * Put up a font dialog and return the selected font name in allocated memory. | |
5176 * "oldval" is the previous value. Return NULL when cancelled. | |
5177 * This should probably go into gui_gtk.c. Hmm. | |
5178 * FIXME: | |
5179 * The GTK2 font selection dialog has no filtering API. So we could either | |
5180 * a) implement our own (possibly copying the code from somewhere else) or | |
5181 * b) just live with it. | |
5182 */ | |
5183 char_u * | |
5184 gui_mch_font_dialog(char_u *oldval) | |
5185 { | |
5186 GtkWidget *dialog; | |
5187 int response; | |
5188 char_u *fontname = NULL; | |
5189 char_u *oldname; | |
5190 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5191 #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
|
5192 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
|
5193 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
|
5194 NULL, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5195 #else |
7 | 5196 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
|
5197 #endif |
7 | 5198 |
5199 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gui.mainwin)); | |
5200 gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); | |
5201 | |
5202 if (oldval != NULL && oldval[0] != NUL) | |
5203 { | |
5204 if (output_conv.vc_type != CONV_NONE) | |
5205 oldname = string_convert(&output_conv, oldval, NULL); | |
5206 else | |
5207 oldname = oldval; | |
5208 | |
5209 /* Annoying bug in GTK (or Pango): if the font name does not include a | |
5210 * size, zero is used. Use default point size ten. */ | |
5211 if (!vim_isdigit(oldname[STRLEN(oldname) - 1])) | |
5212 { | |
5213 char_u *p = vim_strnsave(oldname, STRLEN(oldname) + 3); | |
5214 | |
5215 if (p != NULL) | |
5216 { | |
5217 STRCPY(p + STRLEN(p), " 10"); | |
5218 if (oldname != oldval) | |
5219 vim_free(oldname); | |
5220 oldname = p; | |
5221 } | |
5222 } | |
5223 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5224 #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
|
5225 gtk_font_chooser_set_font( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5226 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
|
5227 #else |
7 | 5228 gtk_font_selection_dialog_set_font_name( |
5229 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
|
5230 #endif |
7 | 5231 |
5232 if (oldname != oldval) | |
100 | 5233 vim_free(oldname); |
7 | 5234 } |
1959 | 5235 else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5236 #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
|
5237 gtk_font_chooser_set_font( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5238 GTK_FONT_CHOOSER(dialog), DEFAULT_FONT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5239 #else |
1959 | 5240 gtk_font_selection_dialog_set_font_name( |
5241 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
|
5242 #endif |
7 | 5243 |
5244 response = gtk_dialog_run(GTK_DIALOG(dialog)); | |
5245 | |
5246 if (response == GTK_RESPONSE_OK) | |
5247 { | |
5248 char *name; | |
5249 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5250 #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
|
5251 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
|
5252 #else |
7 | 5253 name = gtk_font_selection_dialog_get_font_name( |
5254 GTK_FONT_SELECTION_DIALOG(dialog)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5255 #endif |
7 | 5256 if (name != NULL) |
5257 { | |
714 | 5258 char_u *p; |
5259 | |
5260 /* Apparently some font names include a comma, need to escape | |
5261 * that, because in 'guifont' it separates names. */ | |
5262 p = vim_strsave_escaped((char_u *)name, (char_u *)","); | |
5263 g_free(name); | |
840 | 5264 if (p != NULL && input_conv.vc_type != CONV_NONE) |
714 | 5265 { |
5266 fontname = string_convert(&input_conv, p, NULL); | |
5267 vim_free(p); | |
5268 } | |
7 | 5269 else |
714 | 5270 fontname = p; |
7 | 5271 } |
5272 } | |
5273 | |
5274 if (response != GTK_RESPONSE_NONE) | |
5275 gtk_widget_destroy(dialog); | |
5276 | |
5277 return fontname; | |
5278 } | |
5279 | |
5280 /* | |
5281 * Some monospace fonts don't support a bold weight, and fall back | |
5282 * silently to the regular weight. But this is no good since our text | |
5283 * drawing function can emulate bold by overstriking. So let's try | |
5284 * to detect whether bold weight is actually available and emulate it | |
5285 * otherwise. | |
5286 * | |
5287 * Note that we don't need to check for italic style since Xft can | |
5288 * emulate italic on its own, provided you have a proper fontconfig | |
5289 * setup. We wouldn't be able to emulate it in Vim anyway. | |
5290 */ | |
5291 static void | |
5292 get_styled_font_variants(void) | |
5293 { | |
5294 PangoFontDescription *bold_font_desc; | |
5295 PangoFont *plain_font; | |
5296 PangoFont *bold_font; | |
5297 | |
5298 gui.font_can_bold = FALSE; | |
5299 | |
5300 plain_font = pango_context_load_font(gui.text_context, gui.norm_font); | |
5301 | |
5302 if (plain_font == NULL) | |
5303 return; | |
5304 | |
5305 bold_font_desc = pango_font_description_copy_static(gui.norm_font); | |
5306 pango_font_description_set_weight(bold_font_desc, PANGO_WEIGHT_BOLD); | |
5307 | |
5308 bold_font = pango_context_load_font(gui.text_context, bold_font_desc); | |
5309 /* | |
5310 * The comparison relies on the unique handle nature of a PangoFont*, | |
5311 * i.e. it's assumed that a different PangoFont* won't refer to the | |
5312 * same font. Seems to work, and failing here isn't critical anyway. | |
5313 */ | |
5314 if (bold_font != NULL) | |
5315 { | |
5316 gui.font_can_bold = (bold_font != plain_font); | |
5317 g_object_unref(bold_font); | |
5318 } | |
5319 | |
5320 pango_font_description_free(bold_font_desc); | |
5321 g_object_unref(plain_font); | |
5322 } | |
5323 | |
5324 static PangoEngineShape *default_shape_engine = NULL; | |
5325 | |
5326 /* | |
5327 * Create a map from ASCII characters in the range [32,126] to glyphs | |
5328 * of the current font. This is used by gui_gtk2_draw_string() to skip | |
5329 * the itemize and shaping process for the most common case. | |
5330 */ | |
5331 static void | |
5332 ascii_glyph_table_init(void) | |
5333 { | |
9879
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5334 char_u ascii_chars[2 * 128]; |
7 | 5335 PangoAttrList *attr_list; |
5336 GList *item_list; | |
5337 int i; | |
5338 | |
5339 if (gui.ascii_glyphs != NULL) | |
5340 pango_glyph_string_free(gui.ascii_glyphs); | |
5341 if (gui.ascii_font != NULL) | |
5342 g_object_unref(gui.ascii_font); | |
5343 | |
5344 gui.ascii_glyphs = NULL; | |
5345 gui.ascii_font = NULL; | |
5346 | |
9879
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5347 /* 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
|
5348 * 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
|
5349 for (i = 0; i < 128; ++i) |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5350 { |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5351 if (i >= 32 && i < 127) |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5352 ascii_chars[2 * i] = i; |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5353 else |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5354 ascii_chars[2 * i] = '?'; |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5355 ascii_chars[2 * i + 1] = ' '; |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5356 } |
7 | 5357 |
5358 attr_list = pango_attr_list_new(); | |
5359 item_list = pango_itemize(gui.text_context, (const char *)ascii_chars, | |
5360 0, sizeof(ascii_chars), attr_list, NULL); | |
5361 | |
5362 if (item_list != NULL && item_list->next == NULL) /* play safe */ | |
5363 { | |
5364 PangoItem *item; | |
5365 int width; | |
5366 | |
5367 item = (PangoItem *)item_list->data; | |
5368 width = gui.char_width * PANGO_SCALE; | |
5369 | |
5370 /* Remember the shape engine used for ASCII. */ | |
5371 default_shape_engine = item->analysis.shape_engine; | |
5372 | |
5373 gui.ascii_font = item->analysis.font; | |
5374 g_object_ref(gui.ascii_font); | |
5375 | |
5376 gui.ascii_glyphs = pango_glyph_string_new(); | |
5377 | |
5378 pango_shape((const char *)ascii_chars, sizeof(ascii_chars), | |
5379 &item->analysis, gui.ascii_glyphs); | |
5380 | |
5381 g_return_if_fail(gui.ascii_glyphs->num_glyphs == sizeof(ascii_chars)); | |
5382 | |
5383 for (i = 0; i < gui.ascii_glyphs->num_glyphs; ++i) | |
5384 { | |
5385 PangoGlyphGeometry *geom; | |
5386 | |
5387 geom = &gui.ascii_glyphs->glyphs[i].geometry; | |
5388 geom->x_offset += MAX(0, width - geom->width) / 2; | |
5389 geom->width = width; | |
5390 } | |
5391 } | |
5392 | |
5393 g_list_foreach(item_list, (GFunc)&pango_item_free, NULL); | |
5394 g_list_free(item_list); | |
5395 pango_attr_list_unref(attr_list); | |
5396 } | |
5397 | |
5398 /* | |
5399 * Initialize Vim to use the font or fontset with the given name. | |
5400 * Return FAIL if the font could not be loaded, OK otherwise. | |
5401 */ | |
5402 int | |
1884 | 5403 gui_mch_init_font(char_u *font_name, int fontset UNUSED) |
7 | 5404 { |
5405 PangoFontDescription *font_desc; | |
5406 PangoLayout *layout; | |
5407 int width; | |
5408 | |
5409 /* If font_name is NULL, this means to use the default, which should | |
5410 * be present on all proper Pango/fontconfig installations. */ | |
5411 if (font_name == NULL) | |
5412 font_name = (char_u *)DEFAULT_FONT; | |
5413 | |
5414 font_desc = gui_mch_get_font(font_name, FALSE); | |
5415 | |
5416 if (font_desc == NULL) | |
5417 return FAIL; | |
5418 | |
5419 gui_mch_free_font(gui.norm_font); | |
5420 gui.norm_font = font_desc; | |
5421 | |
5422 pango_context_set_font_description(gui.text_context, font_desc); | |
5423 | |
5424 layout = pango_layout_new(gui.text_context); | |
5425 pango_layout_set_text(layout, "MW", 2); | |
5426 pango_layout_get_size(layout, &width, NULL); | |
5427 /* | |
5428 * Set char_width to half the width obtained from pango_layout_get_size() | |
5429 * for CJK fixed_width/bi-width fonts. An unpatched version of Xft leads | |
5430 * Pango to use the same width for both non-CJK characters (e.g. Latin | |
5431 * letters and numbers) and CJK characters. This results in 's p a c e d | |
5432 * o u t' rendering when a CJK 'fixed width' font is used. To work around | |
5433 * that, divide the width returned by Pango by 2 if cjk_width is equal to | |
5434 * width for CJK fonts. | |
5435 * | |
5436 * For related bugs, see: | |
5437 * http://bugzilla.gnome.org/show_bug.cgi?id=106618 | |
5438 * http://bugzilla.gnome.org/show_bug.cgi?id=106624 | |
5439 * | |
5440 * With this, for all four of the following cases, Vim works fine: | |
5441 * guifont=CJK_fixed_width_font | |
5442 * guifont=Non_CJK_fixed_font | |
5443 * guifont=Non_CJK_fixed_font,CJK_Fixed_font | |
5444 * guifont=Non_CJK_fixed_font guifontwide=CJK_fixed_font | |
5445 */ | |
5446 if (is_cjk_font(gui.norm_font)) | |
5447 { | |
5448 int cjk_width; | |
5449 | |
5450 /* Measure the text extent of U+4E00 and U+4E8C */ | |
5451 pango_layout_set_text(layout, "\344\270\200\344\272\214", -1); | |
5452 pango_layout_get_size(layout, &cjk_width, NULL); | |
5453 | |
5454 if (width == cjk_width) /* Xft not patched */ | |
5455 width /= 2; | |
5456 } | |
5457 g_object_unref(layout); | |
5458 | |
5459 gui.char_width = (width / 2 + PANGO_SCALE - 1) / PANGO_SCALE; | |
5460 | |
5461 /* A zero width may cause a crash. Happens for semi-invalid fontsets. */ | |
5462 if (gui.char_width <= 0) | |
5463 gui.char_width = 8; | |
5464 | |
445 | 5465 gui_mch_adjust_charheight(); |
7 | 5466 |
5467 /* Set the fontname, which will be used for information purposes */ | |
5468 hl_set_font_name(font_name); | |
5469 | |
5470 get_styled_font_variants(); | |
5471 ascii_glyph_table_init(); | |
5472 | |
5473 /* Avoid unnecessary overhead if 'guifontwide' is equal to 'guifont'. */ | |
5474 if (gui.wide_font != NULL | |
5475 && pango_font_description_equal(gui.norm_font, gui.wide_font)) | |
5476 { | |
5477 pango_font_description_free(gui.wide_font); | |
5478 gui.wide_font = NULL; | |
5479 } | |
5480 | |
1986 | 5481 if (gui_mch_maximized()) |
5482 { | |
5483 /* Update lines and columns in accordance with the new font, keep the | |
5484 * window maximized. */ | |
3014 | 5485 gui_mch_newfont(); |
1986 | 5486 } |
5487 else | |
5488 { | |
5489 /* Preserve the logical dimensions of the screen. */ | |
5490 update_window_manager_hints(0, 0); | |
5491 } | |
7 | 5492 |
5493 return OK; | |
5494 } | |
5495 | |
5496 /* | |
5497 * Get a reference to the font "name". | |
5498 * Return zero for failure. | |
5499 */ | |
5500 GuiFont | |
5501 gui_mch_get_font(char_u *name, int report_error) | |
5502 { | |
5503 PangoFontDescription *font; | |
5504 | |
5505 /* can't do this when GUI is not running */ | |
5506 if (!gui.in_use || name == NULL) | |
5507 return NULL; | |
5508 | |
5509 if (output_conv.vc_type != CONV_NONE) | |
5510 { | |
5511 char_u *buf; | |
5512 | |
5513 buf = string_convert(&output_conv, name, NULL); | |
5514 if (buf != NULL) | |
5515 { | |
5516 font = pango_font_description_from_string((const char *)buf); | |
5517 vim_free(buf); | |
5518 } | |
5519 else | |
5520 font = NULL; | |
5521 } | |
5522 else | |
5523 font = pango_font_description_from_string((const char *)name); | |
5524 | |
5525 if (font != NULL) | |
5526 { | |
5527 PangoFont *real_font; | |
5528 | |
5529 /* pango_context_load_font() bails out if no font size is set */ | |
5530 if (pango_font_description_get_size(font) <= 0) | |
5531 pango_font_description_set_size(font, 10 * PANGO_SCALE); | |
5532 | |
5533 real_font = pango_context_load_font(gui.text_context, font); | |
5534 | |
5535 if (real_font == NULL) | |
5536 { | |
5537 pango_font_description_free(font); | |
5538 font = NULL; | |
5539 } | |
5540 else | |
5541 g_object_unref(real_font); | |
5542 } | |
5543 | |
5544 if (font == NULL) | |
5545 { | |
5546 if (report_error) | |
1666 | 5547 EMSG2(_((char *)e_font), name); |
7 | 5548 return NULL; |
5549 } | |
5550 | |
5551 return font; | |
5552 } | |
5553 | |
39 | 5554 #if defined(FEAT_EVAL) || defined(PROTO) |
38 | 5555 /* |
5556 * Return the name of font "font" in allocated memory. | |
5557 */ | |
5558 char_u * | |
1884 | 5559 gui_mch_get_fontname(GuiFont font, char_u *name UNUSED) |
38 | 5560 { |
5561 if (font != NOFONT) | |
5562 { | |
944 | 5563 char *pangoname = pango_font_description_to_string(font); |
5564 | |
5565 if (pangoname != NULL) | |
38 | 5566 { |
944 | 5567 char_u *s = vim_strsave((char_u *)pangoname); |
5568 | |
5569 g_free(pangoname); | |
38 | 5570 return s; |
5571 } | |
5572 } | |
5573 return NULL; | |
5574 } | |
39 | 5575 #endif |
38 | 5576 |
7 | 5577 /* |
5578 * If a font is not going to be used, free its structure. | |
5579 */ | |
5580 void | |
5581 gui_mch_free_font(GuiFont font) | |
5582 { | |
5583 if (font != NOFONT) | |
5584 pango_font_description_free(font); | |
5585 } | |
5586 | |
5587 /* | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5588 * 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
|
5589 * |
7 | 5590 * Return INVALCOLOR for error. |
5591 */ | |
5592 guicolor_T | |
5593 gui_mch_get_color(char_u *name) | |
5594 { | |
13674
1feeefd8cddb
patch 8.0.1709: some non-C89 code may slip through
Christian Brabandt <cb@256bit.org>
parents:
13503
diff
changeset
|
5595 guicolor_T color = INVALCOLOR; |
1feeefd8cddb
patch 8.0.1709: some non-C89 code may slip through
Christian Brabandt <cb@256bit.org>
parents:
13503
diff
changeset
|
5596 |
7 | 5597 if (!gui.in_use) /* can't do this when GUI not running */ |
13674
1feeefd8cddb
patch 8.0.1709: some non-C89 code may slip through
Christian Brabandt <cb@256bit.org>
parents:
13503
diff
changeset
|
5598 return color; |
1feeefd8cddb
patch 8.0.1709: some non-C89 code may slip through
Christian Brabandt <cb@256bit.org>
parents:
13503
diff
changeset
|
5599 |
1feeefd8cddb
patch 8.0.1709: some non-C89 code may slip through
Christian Brabandt <cb@256bit.org>
parents:
13503
diff
changeset
|
5600 if (name != NULL) |
1feeefd8cddb
patch 8.0.1709: some non-C89 code may slip through
Christian Brabandt <cb@256bit.org>
parents:
13503
diff
changeset
|
5601 color = gui_get_color_cmn(name); |
7 | 5602 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5603 #if GTK_CHECK_VERSION(3,0,0) |
13674
1feeefd8cddb
patch 8.0.1709: some non-C89 code may slip through
Christian Brabandt <cb@256bit.org>
parents:
13503
diff
changeset
|
5604 return color; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5605 #else |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5606 if (color == INVALCOLOR) |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5607 return INVALCOLOR; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5608 |
11745
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5609 return gui_mch_get_rgb_color( |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5610 (color & 0xff0000) >> 16, |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5611 (color & 0xff00) >> 8, |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5612 color & 0xff); |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5613 #endif |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5614 } |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5615 |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5616 /* |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5617 * Return the Pixel value (color) for the given RGB values. |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5618 * Return INVALCOLOR for error. |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5619 */ |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5620 guicolor_T |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5621 gui_mch_get_rgb_color(int r, int g, int b) |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5622 { |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5623 #if GTK_CHECK_VERSION(3,0,0) |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5624 return gui_get_rgb_color_cmn(r, g, b); |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5625 #else |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5626 GdkColor gcolor; |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5627 int ret; |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5628 |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5629 gcolor.red = (guint16)(r / 255.0 * 65535 + 0.5); |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5630 gcolor.green = (guint16)(g / 255.0 * 65535 + 0.5); |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5631 gcolor.blue = (guint16)(b / 255.0 * 65535 + 0.5); |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5632 |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5633 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
|
5634 &gcolor, FALSE, TRUE); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5635 |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5636 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
|
5637 #endif |
7 | 5638 } |
5639 | |
5640 /* | |
5641 * Set the current text foreground color. | |
5642 */ | |
5643 void | |
5644 gui_mch_set_fg_color(guicolor_T color) | |
5645 { | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5646 #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
|
5647 *gui.fgcolor = color_to_rgba(color); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5648 #else |
7 | 5649 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
|
5650 #endif |
7 | 5651 } |
5652 | |
5653 /* | |
5654 * Set the current text background color. | |
5655 */ | |
5656 void | |
5657 gui_mch_set_bg_color(guicolor_T color) | |
5658 { | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5659 #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
|
5660 *gui.bgcolor = color_to_rgba(color); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5661 #else |
7 | 5662 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
|
5663 #endif |
7 | 5664 } |
5665 | |
207 | 5666 /* |
5667 * Set the current text special color. | |
5668 */ | |
5669 void | |
5670 gui_mch_set_sp_color(guicolor_T color) | |
5671 { | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5672 #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
|
5673 *gui.spcolor = color_to_rgba(color); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5674 #else |
207 | 5675 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
|
5676 #endif |
207 | 5677 } |
5678 | |
7 | 5679 /* |
5680 * Function-like convenience macro for the sake of efficiency. | |
5681 */ | |
5682 #define INSERT_PANGO_ATTR(Attribute, AttrList, Start, End) \ | |
5683 G_STMT_START{ \ | |
5684 PangoAttribute *tmp_attr_; \ | |
5685 tmp_attr_ = (Attribute); \ | |
5686 tmp_attr_->start_index = (Start); \ | |
5687 tmp_attr_->end_index = (End); \ | |
5688 pango_attr_list_insert((AttrList), tmp_attr_); \ | |
5689 }G_STMT_END | |
5690 | |
5691 static void | |
5692 apply_wide_font_attr(char_u *s, int len, PangoAttrList *attr_list) | |
5693 { | |
5694 char_u *start = NULL; | |
5695 char_u *p; | |
5696 int uc; | |
5697 | |
5698 for (p = s; p < s + len; p += utf_byte2len(*p)) | |
5699 { | |
5700 uc = utf_ptr2char(p); | |
5701 | |
5702 if (start == NULL) | |
5703 { | |
5704 if (uc >= 0x80 && utf_char2cells(uc) == 2) | |
5705 start = p; | |
5706 } | |
5707 else if (uc < 0x80 /* optimization shortcut */ | |
5708 || (utf_char2cells(uc) != 2 && !utf_iscomposing(uc))) | |
5709 { | |
5710 INSERT_PANGO_ATTR(pango_attr_font_desc_new(gui.wide_font), | |
5711 attr_list, start - s, p - s); | |
5712 start = NULL; | |
5713 } | |
5714 } | |
5715 | |
5716 if (start != NULL) | |
5717 INSERT_PANGO_ATTR(pango_attr_font_desc_new(gui.wide_font), | |
5718 attr_list, start - s, len); | |
5719 } | |
5720 | |
5721 static int | |
5722 count_cluster_cells(char_u *s, PangoItem *item, | |
5723 PangoGlyphString* glyphs, int i, | |
5724 int *cluster_width, | |
5725 int *last_glyph_rbearing) | |
5726 { | |
5727 char_u *p; | |
5728 int next; /* glyph start index of next cluster */ | |
5729 int start, end; /* string segment of current cluster */ | |
5730 int width; /* real cluster width in Pango units */ | |
5731 int uc; | |
5732 int cellcount = 0; | |
5733 | |
5734 width = glyphs->glyphs[i].geometry.width; | |
5735 | |
5736 for (next = i + 1; next < glyphs->num_glyphs; ++next) | |
5737 { | |
5738 if (glyphs->glyphs[next].attr.is_cluster_start) | |
5739 break; | |
5740 else if (glyphs->glyphs[next].geometry.width > width) | |
5741 width = glyphs->glyphs[next].geometry.width; | |
5742 } | |
5743 | |
5744 start = item->offset + glyphs->log_clusters[i]; | |
5745 end = item->offset + ((next < glyphs->num_glyphs) ? | |
5746 glyphs->log_clusters[next] : item->length); | |
5747 | |
5748 for (p = s + start; p < s + end; p += utf_byte2len(*p)) | |
5749 { | |
5750 uc = utf_ptr2char(p); | |
5751 if (uc < 0x80) | |
5752 ++cellcount; | |
5753 else if (!utf_iscomposing(uc)) | |
5754 cellcount += utf_char2cells(uc); | |
5755 } | |
5756 | |
5757 if (last_glyph_rbearing != NULL | |
5758 && cellcount > 0 && next == glyphs->num_glyphs) | |
5759 { | |
5760 PangoRectangle ink_rect; | |
5761 /* | |
5762 * If a certain combining mark had to be taken from a non-monospace | |
5763 * font, we have to compensate manually by adapting x_offset according | |
5764 * to the ink extents of the previous glyph. | |
5765 */ | |
5766 pango_font_get_glyph_extents(item->analysis.font, | |
5767 glyphs->glyphs[i].glyph, | |
5768 &ink_rect, NULL); | |
5769 | |
5770 if (PANGO_RBEARING(ink_rect) > 0) | |
5771 *last_glyph_rbearing = PANGO_RBEARING(ink_rect); | |
5772 } | |
5773 | |
5774 if (cellcount > 0) | |
5775 *cluster_width = width; | |
5776 | |
5777 return cellcount; | |
5778 } | |
5779 | |
5780 /* | |
5781 * If there are only combining characters in the cluster, we cannot just | |
5782 * change the width of the previous glyph since there is none. Therefore | |
5783 * some guesswork is needed. | |
5784 * | |
5785 * If ink_rect.x is negative Pango apparently has taken care of the composing | |
5786 * by itself. Actually setting x_offset = 0 should be sufficient then, but due | |
5787 * 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
|
5788 * x_offset to avoid ugliness. |
7 | 5789 * |
5790 * If ink_rect.x is not negative, force overstriking by pointing x_offset to | |
5791 * the position of the previous glyph. Apparently this happens only with old | |
5792 * X fonts which don't provide the special combining information needed by | |
5793 * Pango. | |
5794 */ | |
5795 static void | |
5796 setup_zero_width_cluster(PangoItem *item, PangoGlyphInfo *glyph, | |
5797 int last_cellcount, int last_cluster_width, | |
5798 int last_glyph_rbearing) | |
5799 { | |
5800 PangoRectangle ink_rect; | |
5801 PangoRectangle logical_rect; | |
5802 int width; | |
5803 | |
5804 width = last_cellcount * gui.char_width * PANGO_SCALE; | |
5805 glyph->geometry.x_offset = -width + MAX(0, width - last_cluster_width) / 2; | |
5806 glyph->geometry.width = 0; | |
5807 | |
5808 pango_font_get_glyph_extents(item->analysis.font, | |
5809 glyph->glyph, | |
5810 &ink_rect, &logical_rect); | |
5811 if (ink_rect.x < 0) | |
5812 { | |
5813 glyph->geometry.x_offset += last_glyph_rbearing; | |
5814 glyph->geometry.y_offset = logical_rect.height | |
5815 - (gui.char_height - p_linespace) * PANGO_SCALE; | |
5816 } | |
2507
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
5817 else |
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
5818 /* 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
|
5819 * 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
|
5820 glyph->geometry.x_offset = -width + MAX(0, width - ink_rect.width) / 2; |
7 | 5821 } |
5822 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5823 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5824 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5825 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
|
5826 PangoFont *font, PangoGlyphString *glyphs, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5827 cairo_t *cr) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5828 #else |
7 | 5829 static void |
5830 draw_glyph_string(int row, int col, int num_cells, int flags, | |
5831 PangoFont *font, PangoGlyphString *glyphs) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5832 #endif |
7 | 5833 { |
5834 if (!(flags & DRAW_TRANSP)) | |
5835 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5836 #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
|
5837 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5838 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
|
5839 gui.bgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5840 cairo_rectangle(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5841 FILL_X(col), FILL_Y(row), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5842 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
|
5843 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5844 #else |
7 | 5845 gdk_gc_set_foreground(gui.text_gc, gui.bgcolor); |
5846 | |
5847 gdk_draw_rectangle(gui.drawarea->window, | |
5848 gui.text_gc, | |
5849 TRUE, | |
5850 FILL_X(col), | |
5851 FILL_Y(row), | |
5852 num_cells * gui.char_width, | |
5853 gui.char_height); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5854 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5855 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5856 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5857 #if GTK_CHECK_VERSION(3,0,0) |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5858 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5859 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
|
5860 gui.fgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5861 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
|
5862 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
|
5863 #else |
7 | 5864 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
5865 | |
5866 gdk_draw_glyphs(gui.drawarea->window, | |
5867 gui.text_gc, | |
5868 font, | |
5869 TEXT_X(col), | |
5870 TEXT_Y(row), | |
5871 glyphs); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5872 #endif |
7 | 5873 |
5874 /* redraw the contents with an offset of 1 to emulate bold */ | |
5875 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
|
5876 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5877 { |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5878 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5879 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
|
5880 gui.fgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5881 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
|
5882 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
|
5883 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5884 #else |
7 | 5885 gdk_draw_glyphs(gui.drawarea->window, |
5886 gui.text_gc, | |
5887 font, | |
5888 TEXT_X(col) + 1, | |
5889 TEXT_Y(row), | |
5890 glyphs); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5891 #endif |
7 | 5892 } |
5893 | |
207 | 5894 /* |
5895 * Draw underline and undercurl at the bottom of the character cell. | |
5896 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5897 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5898 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5899 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
|
5900 #else |
207 | 5901 static void |
5902 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
|
5903 #endif |
207 | 5904 { |
5905 int i; | |
5906 int offset; | |
1884 | 5907 static const int val[8] = {1, 0, 0, 0, 1, 2, 2, 2 }; |
207 | 5908 int y = FILL_Y(row + 1) - 1; |
5909 | |
5910 /* Undercurl: draw curl at the bottom of the character cell. */ | |
5911 if (flags & DRAW_UNDERC) | |
5912 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5913 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5914 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
|
5915 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
|
5916 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5917 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
|
5918 gui.spcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5919 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
|
5920 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5921 offset = val[i % 8]; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5922 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
|
5923 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5924 cairo_stroke(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5925 #else |
207 | 5926 gdk_gc_set_foreground(gui.text_gc, gui.spcolor); |
5927 for (i = FILL_X(col); i < FILL_X(col + cells); ++i) | |
5928 { | |
5929 offset = val[i % 8]; | |
5930 gdk_draw_point(gui.drawarea->window, gui.text_gc, i, y - offset); | |
5931 } | |
5932 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
|
5933 #endif |
207 | 5934 } |
5935 | |
12317
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5936 /* Draw a strikethrough line */ |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5937 if (flags & DRAW_STRIKE) |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5938 { |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5939 #if GTK_CHECK_VERSION(3,0,0) |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5940 cairo_set_line_width(cr, 1.0); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5941 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5942 cairo_set_source_rgba(cr, |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5943 gui.spcolor->red, gui.spcolor->green, gui.spcolor->blue, |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5944 gui.spcolor->alpha); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5945 cairo_move_to(cr, FILL_X(col), y + 1 - gui.char_height/2 + 0.5); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5946 cairo_line_to(cr, FILL_X(col + cells), y + 1 - gui.char_height/2 + 0.5); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5947 cairo_stroke(cr); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5948 #else |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5949 gdk_gc_set_foreground(gui.text_gc, gui.spcolor); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5950 gdk_draw_line(gui.drawarea->window, gui.text_gc, |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5951 FILL_X(col), y + 1 - gui.char_height/2, |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5952 FILL_X(col + cells), y + 1 - gui.char_height/2); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5953 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5954 #endif |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5955 } |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5956 |
207 | 5957 /* Underline: draw a line at the bottom of the character cell. */ |
5958 if (flags & DRAW_UNDERL) | |
5959 { | |
5960 /* When p_linespace is 0, overwrite the bottom row of pixels. | |
5961 * Otherwise put the line just below the character. */ | |
5962 if (p_linespace > 1) | |
5963 y -= p_linespace - 1; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5964 #if GTK_CHECK_VERSION(3,0,0) |
12317
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5965 cairo_set_line_width(cr, 1.0); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5966 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5967 cairo_set_source_rgba(cr, |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5968 gui.fgcolor->red, gui.fgcolor->green, gui.fgcolor->blue, |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5969 gui.fgcolor->alpha); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5970 cairo_move_to(cr, FILL_X(col), y + 0.5); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5971 cairo_line_to(cr, FILL_X(col + cells), y + 0.5); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5972 cairo_stroke(cr); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5973 #else |
207 | 5974 gdk_draw_line(gui.drawarea->window, gui.text_gc, |
5975 FILL_X(col), y, | |
5976 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
|
5977 #endif |
207 | 5978 } |
5979 } | |
5980 | |
7 | 5981 int |
5982 gui_gtk2_draw_string(int row, int col, char_u *s, int len, int flags) | |
5983 { | |
5984 GdkRectangle area; /* area for clip mask */ | |
5985 PangoGlyphString *glyphs; /* glyphs of current item */ | |
5986 int column_offset = 0; /* column offset in cells */ | |
5987 int i; | |
5988 char_u *conv_buf = NULL; /* result of UTF-8 conversion */ | |
5989 char_u *new_conv_buf; | |
5990 int convlen; | |
5991 char_u *sp, *bp; | |
5992 int plen; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5993 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5994 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5995 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5996 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5997 if (gui.text_context == NULL || gtk_widget_get_window(gui.drawarea) == NULL) |
7 | 5998 return len; |
5999 | |
6000 if (output_conv.vc_type != CONV_NONE) | |
6001 { | |
6002 /* | |
6003 * Convert characters from 'encoding' to 'termencoding', which is set | |
6004 * to UTF-8 by gui_mch_init(). did_set_string_option() in option.c | |
6005 * prohibits changing this to something else than UTF-8 if the GUI is | |
6006 * in use. | |
6007 */ | |
6008 convlen = len; | |
6009 conv_buf = string_convert(&output_conv, s, &convlen); | |
6010 g_return_val_if_fail(conv_buf != NULL, len); | |
6011 | |
6012 /* Correct for differences in char width: some chars are | |
6013 * double-wide in 'encoding' but single-wide in utf-8. Add a space to | |
6014 * compensate for that. */ | |
6015 for (sp = s, bp = conv_buf; sp < s + len && bp < conv_buf + convlen; ) | |
6016 { | |
474 | 6017 plen = utf_ptr2len(bp); |
7 | 6018 if ((*mb_ptr2cells)(sp) == 2 && utf_ptr2cells(bp) == 1) |
6019 { | |
6020 new_conv_buf = alloc(convlen + 2); | |
6021 if (new_conv_buf == NULL) | |
6022 return len; | |
6023 plen += bp - conv_buf; | |
6024 mch_memmove(new_conv_buf, conv_buf, plen); | |
6025 new_conv_buf[plen] = ' '; | |
6026 mch_memmove(new_conv_buf + plen + 1, conv_buf + plen, | |
6027 convlen - plen + 1); | |
6028 vim_free(conv_buf); | |
6029 conv_buf = new_conv_buf; | |
6030 ++convlen; | |
6031 bp = conv_buf + plen; | |
6032 plen = 1; | |
6033 } | |
474 | 6034 sp += (*mb_ptr2len)(sp); |
7 | 6035 bp += plen; |
6036 } | |
6037 s = conv_buf; | |
6038 len = convlen; | |
6039 } | |
6040 | |
6041 /* | |
6042 * Restrict all drawing to the current screen line in order to prevent | |
6043 * fuzzy font lookups from messing up the screen. | |
6044 */ | |
6045 area.x = gui.border_offset; | |
6046 area.y = FILL_Y(row); | |
6047 area.width = gui.num_cols * gui.char_width; | |
6048 area.height = gui.char_height; | |
6049 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6050 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6051 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6052 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
|
6053 cairo_clip(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6054 #else |
7 | 6055 gdk_gc_set_clip_origin(gui.text_gc, 0, 0); |
6056 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
|
6057 #endif |
7 | 6058 |
6059 glyphs = pango_glyph_string_new(); | |
6060 | |
6061 /* | |
6062 * Optimization hack: If possible, skip the itemize and shaping process | |
6063 * for pure ASCII strings. This optimization is particularly effective | |
6064 * because Vim draws space characters to clear parts of the screen. | |
6065 */ | |
6066 if (!(flags & DRAW_ITALIC) | |
6067 && !((flags & DRAW_BOLD) && gui.font_can_bold) | |
6068 && gui.ascii_glyphs != NULL) | |
6069 { | |
6070 char_u *p; | |
6071 | |
6072 for (p = s; p < s + len; ++p) | |
6073 if (*p & 0x80) | |
6074 goto not_ascii; | |
6075 | |
6076 pango_glyph_string_set_size(glyphs, len); | |
6077 | |
6078 for (i = 0; i < len; ++i) | |
6079 { | |
9879
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
6080 glyphs->glyphs[i] = gui.ascii_glyphs->glyphs[2 * s[i]]; |
7 | 6081 glyphs->log_clusters[i] = i; |
6082 } | |
6083 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6084 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6085 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
|
6086 #else |
7 | 6087 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
|
6088 #endif |
7 | 6089 |
6090 column_offset = len; | |
6091 } | |
6092 else | |
6093 not_ascii: | |
6094 { | |
6095 PangoAttrList *attr_list; | |
6096 GList *item_list; | |
6097 int cluster_width; | |
6098 int last_glyph_rbearing; | |
6099 int cells = 0; /* cells occupied by current cluster */ | |
6100 | |
26 | 6101 /* Safety check: pango crashes when invoked with invalid utf-8 |
6102 * characters. */ | |
6103 if (!utf_valid_string(s, s + len)) | |
6104 { | |
6105 column_offset = len; | |
6106 goto skipitall; | |
6107 } | |
6108 | |
7 | 6109 /* original width of the current cluster */ |
6110 cluster_width = PANGO_SCALE * gui.char_width; | |
6111 | |
6112 /* right bearing of the last non-composing glyph */ | |
6113 last_glyph_rbearing = PANGO_SCALE * gui.char_width; | |
6114 | |
6115 attr_list = pango_attr_list_new(); | |
6116 | |
6117 /* If 'guifontwide' is set then use that for double-width characters. | |
6118 * Otherwise just go with 'guifont' and let Pango do its thing. */ | |
6119 if (gui.wide_font != NULL) | |
6120 apply_wide_font_attr(s, len, attr_list); | |
6121 | |
6122 if ((flags & DRAW_BOLD) && gui.font_can_bold) | |
6123 INSERT_PANGO_ATTR(pango_attr_weight_new(PANGO_WEIGHT_BOLD), | |
6124 attr_list, 0, len); | |
6125 if (flags & DRAW_ITALIC) | |
6126 INSERT_PANGO_ATTR(pango_attr_style_new(PANGO_STYLE_ITALIC), | |
6127 attr_list, 0, len); | |
6128 /* | |
6129 * Break the text into segments with consistent directional level | |
6130 * and shaping engine. Pure Latin text needs only a single segment, | |
6131 * so there's no need to worry about the loop's efficiency. Better | |
6132 * try to optimize elsewhere, e.g. reducing exposes and stuff :) | |
6133 */ | |
6134 item_list = pango_itemize(gui.text_context, | |
6135 (const char *)s, 0, len, attr_list, NULL); | |
6136 | |
6137 while (item_list != NULL) | |
6138 { | |
6139 PangoItem *item; | |
6140 int item_cells = 0; /* item length in cells */ | |
6141 | |
6142 item = (PangoItem *)item_list->data; | |
6143 item_list = g_list_delete_link(item_list, item_list); | |
6144 /* | |
6145 * Increment the bidirectional embedding level by 1 if it is not | |
6146 * even. An odd number means the output will be RTL, but we don't | |
6147 * want that since Vim handles right-to-left text on its own. It | |
6148 * would probably be sufficient to just set level = 0, but you can | |
6149 * never know :) | |
6150 * | |
6151 * Unfortunately we can't take advantage of Pango's ability to | |
6152 * render both LTR and RTL at the same time. In order to support | |
6153 * that, Vim's main screen engine would have to make use of Pango | |
6154 * functionality. | |
6155 */ | |
6156 item->analysis.level = (item->analysis.level + 1) & (~1U); | |
6157 | |
6158 /* HACK: Overrule the shape engine, we don't want shaping to be | |
6159 * done, because drawing the cursor would change the display. */ | |
6160 item->analysis.shape_engine = default_shape_engine; | |
6161 | |
7098
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6162 #ifdef HAVE_PANGO_SHAPE_FULL |
7086
3825da022231
commit https://github.com/vim/vim/commit/7e2ec008f5c5152205d0b8a7d88177b374225d8d
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
6163 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
|
6164 (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
|
6165 #else |
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6166 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
|
6167 &item->analysis, glyphs); |
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6168 #endif |
7 | 6169 /* |
6170 * Fixed-width hack: iterate over the array and assign a fixed | |
6171 * width to each glyph, thus overriding the choice made by the | |
6172 * shaping engine. We use utf_char2cells() to determine the | |
6173 * number of cells needed. | |
6174 * | |
6175 * Also perform all kind of dark magic to get composing | |
6176 * characters right (and pretty too of course). | |
6177 */ | |
6178 for (i = 0; i < glyphs->num_glyphs; ++i) | |
6179 { | |
6180 PangoGlyphInfo *glyph; | |
6181 | |
6182 glyph = &glyphs->glyphs[i]; | |
6183 | |
6184 if (glyph->attr.is_cluster_start) | |
6185 { | |
6186 int cellcount; | |
6187 | |
6188 cellcount = count_cluster_cells( | |
6189 s, item, glyphs, i, &cluster_width, | |
6190 (item_list != NULL) ? &last_glyph_rbearing : NULL); | |
6191 | |
6192 if (cellcount > 0) | |
6193 { | |
6194 int width; | |
6195 | |
6196 width = cellcount * gui.char_width * PANGO_SCALE; | |
6197 glyph->geometry.x_offset += | |
6198 MAX(0, width - cluster_width) / 2; | |
6199 glyph->geometry.width = width; | |
6200 } | |
6201 else | |
6202 { | |
6203 /* If there are only combining characters in the | |
6204 * cluster, we cannot just change the width of the | |
6205 * previous glyph since there is none. Therefore | |
6206 * some guesswork is needed. */ | |
6207 setup_zero_width_cluster(item, glyph, cells, | |
6208 cluster_width, | |
6209 last_glyph_rbearing); | |
6210 } | |
6211 | |
6212 item_cells += cellcount; | |
6213 cells = cellcount; | |
6214 } | |
6215 else if (i > 0) | |
6216 { | |
6217 int width; | |
6218 | |
6219 /* 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
|
6220 * characters the canonical way. |
2517
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6221 * 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
|
6222 * 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
|
6223 * and set the previous width to zero. |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6224 * 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
|
6225 * 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
|
6226 * 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
|
6227 * 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
|
6228 * 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
|
6229 if (glyph->geometry.x_offset >= 0) |
2517
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6230 { |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6231 glyphs->glyphs[i].geometry.width = |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6232 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
|
6233 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
|
6234 } |
7 | 6235 width = cells * gui.char_width * PANGO_SCALE; |
6236 glyph->geometry.x_offset += | |
6237 MAX(0, width - cluster_width) / 2; | |
6238 } | |
6239 else /* i == 0 "cannot happen" */ | |
6240 { | |
6241 glyph->geometry.width = 0; | |
6242 } | |
6243 } | |
6244 | |
6245 /*** Aaaaand action! ***/ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6246 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6247 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
|
6248 flags, item->analysis.font, glyphs, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6249 cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6250 #else |
7 | 6251 draw_glyph_string(row, col + column_offset, item_cells, |
6252 flags, item->analysis.font, glyphs); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6253 #endif |
7 | 6254 |
6255 pango_item_free(item); | |
6256 | |
6257 column_offset += item_cells; | |
6258 } | |
6259 | |
6260 pango_attr_list_unref(attr_list); | |
6261 } | |
6262 | |
26 | 6263 skipitall: |
207 | 6264 /* Draw underline and undercurl. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6265 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6266 draw_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
|
6267 #else |
207 | 6268 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
|
6269 #endif |
7 | 6270 |
6271 pango_glyph_string_free(glyphs); | |
6272 vim_free(conv_buf); | |
6273 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6274 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6275 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6276 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6277 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
|
6278 &area, FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6279 #else |
7 | 6280 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
|
6281 #endif |
7 | 6282 |
6283 return column_offset; | |
6284 } | |
6285 | |
6286 /* | |
6287 * Return OK if the key with the termcap name "name" is supported. | |
6288 */ | |
6289 int | |
6290 gui_mch_haskey(char_u *name) | |
6291 { | |
6292 int i; | |
6293 | |
6294 for (i = 0; special_keys[i].key_sym != 0; i++) | |
6295 if (name[0] == special_keys[i].code0 | |
6296 && name[1] == special_keys[i].code1) | |
6297 return OK; | |
6298 return FAIL; | |
6299 } | |
6300 | |
4133 | 6301 #if defined(FEAT_TITLE) || defined(FEAT_EVAL) || defined(PROTO) |
7 | 6302 /* |
6303 * Return the text window-id and display. Only required for X-based GUI's | |
6304 */ | |
6305 int | |
6306 gui_get_x11_windis(Window *win, Display **dis) | |
6307 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6308 if (gui.mainwin != NULL && gtk_widget_get_window(gui.mainwin) != NULL) |
14712
82e7ce311065
patch 8.1.0368: GTK code has too many #ifdefs and GTK 2.10 building fails
Christian Brabandt <cb@256bit.org>
parents:
14575
diff
changeset
|
6309 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6310 *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
|
6311 *win = GDK_WINDOW_XID(gtk_widget_get_window(gui.mainwin)); |
7 | 6312 return OK; |
6313 } | |
6314 | |
6315 *dis = NULL; | |
6316 *win = 0; | |
6317 return FAIL; | |
6318 } | |
6319 #endif | |
6320 | |
6321 #if defined(FEAT_CLIENTSERVER) \ | |
6322 || (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO) | |
6323 | |
6324 Display * | |
6325 gui_mch_get_display(void) | |
6326 { | |
8218
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)); |
7 | 6329 else |
6330 return NULL; | |
6331 } | |
6332 #endif | |
6333 | |
6334 void | |
6335 gui_mch_beep(void) | |
6336 { | |
6337 GdkDisplay *display; | |
6338 | |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6339 #if GTK_CHECK_VERSION(3,0,0) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6340 if (gui.mainwin != NULL && gtk_widget_get_realized(gui.mainwin)) |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6341 #else |
7 | 6342 if (gui.mainwin != NULL && GTK_WIDGET_REALIZED(gui.mainwin)) |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6343 #endif |
7 | 6344 display = gtk_widget_get_display(gui.mainwin); |
6345 else | |
6346 display = gdk_display_get_default(); | |
6347 | |
6348 if (display != NULL) | |
6349 gdk_display_beep(display); | |
6350 } | |
6351 | |
6352 void | |
6353 gui_mch_flash(int msec) | |
6354 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6355 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6356 /* TODO Replace GdkGC with Cairo */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6357 (void)msec; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6358 #else |
7 | 6359 GdkGCValues values; |
6360 GdkGC *invert_gc; | |
6361 | |
6362 if (gui.drawarea->window == NULL) | |
6363 return; | |
6364 | |
6365 values.foreground.pixel = gui.norm_pixel ^ gui.back_pixel; | |
6366 values.background.pixel = gui.norm_pixel ^ gui.back_pixel; | |
6367 values.function = GDK_XOR; | |
6368 invert_gc = gdk_gc_new_with_values(gui.drawarea->window, | |
6369 &values, | |
6370 GDK_GC_FOREGROUND | | |
6371 GDK_GC_BACKGROUND | | |
6372 GDK_GC_FUNCTION); | |
6373 gdk_gc_set_exposures(invert_gc, | |
6374 gui.visibility != GDK_VISIBILITY_UNOBSCURED); | |
6375 /* | |
6376 * Do a visual beep by changing back and forth in some undetermined way, | |
6377 * the foreground and background colors. This is due to the fact that | |
6378 * there can't be really any prediction about the effects of XOR on | |
6379 * arbitrary X11 servers. However this seems to be enough for what we | |
6380 * intend it to do. | |
6381 */ | |
6382 gdk_draw_rectangle(gui.drawarea->window, invert_gc, | |
6383 TRUE, | |
6384 0, 0, | |
6385 FILL_X((int)Columns) + gui.border_offset, | |
6386 FILL_Y((int)Rows) + gui.border_offset); | |
6387 | |
6388 gui_mch_flush(); | |
6389 ui_delay((long)msec, TRUE); /* wait so many msec */ | |
6390 | |
6391 gdk_draw_rectangle(gui.drawarea->window, invert_gc, | |
6392 TRUE, | |
6393 0, 0, | |
6394 FILL_X((int)Columns) + gui.border_offset, | |
6395 FILL_Y((int)Rows) + gui.border_offset); | |
6396 | |
6397 gdk_gc_destroy(invert_gc); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6398 #endif |
7 | 6399 } |
6400 | |
6401 /* | |
6402 * Invert a rectangle from row r, column c, for nr rows and nc columns. | |
6403 */ | |
6404 void | |
6405 gui_mch_invert_rectangle(int r, int c, int nr, int nc) | |
6406 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6407 #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
|
6408 const GdkRectangle rect = { |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6409 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
|
6410 }; |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6411 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
|
6412 |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6413 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
|
6414 # 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
|
6415 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
|
6416 # else |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6417 /* 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
|
6418 # endif |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6419 gdk_cairo_rectangle(cr, &rect); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6420 cairo_fill(cr); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6421 |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6422 cairo_destroy(cr); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6423 |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6424 if (!gui.by_signal) |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6425 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
|
6426 rect.width, rect.height); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6427 #else |
7 | 6428 GdkGCValues values; |
6429 GdkGC *invert_gc; | |
6430 | |
6431 if (gui.drawarea->window == NULL) | |
6432 return; | |
6433 | |
944 | 6434 values.foreground.pixel = gui.norm_pixel ^ gui.back_pixel; |
6435 values.background.pixel = gui.norm_pixel ^ gui.back_pixel; | |
7 | 6436 values.function = GDK_XOR; |
6437 invert_gc = gdk_gc_new_with_values(gui.drawarea->window, | |
6438 &values, | |
6439 GDK_GC_FOREGROUND | | |
6440 GDK_GC_BACKGROUND | | |
6441 GDK_GC_FUNCTION); | |
944 | 6442 gdk_gc_set_exposures(invert_gc, gui.visibility != |
6443 GDK_VISIBILITY_UNOBSCURED); | |
7 | 6444 gdk_draw_rectangle(gui.drawarea->window, invert_gc, |
6445 TRUE, | |
6446 FILL_X(c), FILL_Y(r), | |
6447 (nc) * gui.char_width, (nr) * gui.char_height); | |
6448 gdk_gc_destroy(invert_gc); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6449 #endif |
7 | 6450 } |
6451 | |
6452 /* | |
6453 * Iconify the GUI window. | |
6454 */ | |
6455 void | |
6456 gui_mch_iconify(void) | |
6457 { | |
6458 gtk_window_iconify(GTK_WINDOW(gui.mainwin)); | |
6459 } | |
6460 | |
6461 #if defined(FEAT_EVAL) || defined(PROTO) | |
6462 /* | |
6463 * Bring the Vim window to the foreground. | |
6464 */ | |
6465 void | |
6466 gui_mch_set_foreground(void) | |
6467 { | |
6468 gtk_window_present(GTK_WINDOW(gui.mainwin)); | |
6469 } | |
6470 #endif | |
6471 | |
6472 /* | |
6473 * Draw a cursor without focus. | |
6474 */ | |
6475 void | |
6476 gui_mch_draw_hollow_cursor(guicolor_T color) | |
6477 { | |
6478 int i = 1; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6479 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6480 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6481 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6482 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6483 if (gtk_widget_get_window(gui.drawarea) == NULL) |
7 | 6484 return; |
6485 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6486 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6487 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6488 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6489 |
7 | 6490 gui_mch_set_fg_color(color); |
6491 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6492 #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
|
6493 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6494 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
|
6495 gui.fgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6496 #else |
7 | 6497 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
|
6498 #endif |
7 | 6499 if (mb_lefthalve(gui.row, gui.col)) |
6500 i = 2; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6501 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6502 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
|
6503 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
|
6504 cairo_rectangle(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6505 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
|
6506 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
|
6507 cairo_stroke(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6508 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6509 #else |
7 | 6510 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, |
6511 FALSE, | |
6512 FILL_X(gui.col), FILL_Y(gui.row), | |
6513 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
|
6514 #endif |
7 | 6515 } |
6516 | |
6517 /* | |
6518 * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using | |
6519 * color "color". | |
6520 */ | |
6521 void | |
6522 gui_mch_draw_part_cursor(int w, int h, guicolor_T color) | |
6523 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6524 if (gtk_widget_get_window(gui.drawarea) == NULL) |
7 | 6525 return; |
6526 | |
6527 gui_mch_set_fg_color(color); | |
6528 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6529 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6530 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6531 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6532 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6533 cr = cairo_create(gui.surface); |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6534 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6535 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
|
6536 gui.fgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6537 cairo_rectangle(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6538 # ifdef FEAT_RIGHTLEFT |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6539 /* 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
|
6540 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
|
6541 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6542 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
|
6543 w, h); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6544 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6545 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6546 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6547 #else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6548 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
6549 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, | |
6550 TRUE, | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6551 # ifdef FEAT_RIGHTLEFT |
7 | 6552 /* vertical line should be on the right of current point */ |
6553 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
|
6554 # endif |
7 | 6555 FILL_X(gui.col), |
6556 FILL_Y(gui.row) + gui.char_height - h, | |
6557 w, h); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6558 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6559 } |
6560 | |
6561 | |
6562 /* | |
6563 * Catch up with any queued X11 events. This may put keyboard input into the | |
6564 * input buffer, call resize call-backs, trigger timers etc. If there is | |
6565 * nothing in the X11 event queue (& no timers pending), then we return | |
6566 * immediately. | |
6567 */ | |
6568 void | |
6569 gui_mch_update(void) | |
6570 { | |
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
|
6571 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
|
6572 g_main_context_iteration(NULL, TRUE); |
7 | 6573 } |
6574 | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6575 static timeout_cb_type |
7 | 6576 input_timer_cb(gpointer data) |
6577 { | |
6578 int *timed_out = (int *) data; | |
6579 | |
1226 | 6580 /* Just inform the caller about the occurrence of it */ |
7 | 6581 *timed_out = TRUE; |
6582 | |
6583 return FALSE; /* don't happen again */ | |
6584 } | |
6585 | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6586 #ifdef FEAT_JOB_CHANNEL |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6587 static timeout_cb_type |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6588 channel_poll_cb(gpointer data UNUSED) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6589 { |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6590 /* Using an event handler for a channel that may be disconnected does |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6591 * not work, it hangs. Instead poll for messages. */ |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6592 channel_handle_events(TRUE); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6593 parse_queued_messages(); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6594 |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6595 return TRUE; /* repeat */ |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6596 } |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6597 #endif |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6598 |
7 | 6599 /* |
6600 * GUI input routine called by gui_wait_for_chars(). Waits for a character | |
6601 * from the keyboard. | |
6602 * wtime == -1 Wait forever. | |
6603 * wtime == 0 This should never happen. | |
6604 * wtime > 0 Wait wtime milliseconds for a character. | |
6605 * Returns OK if a character was found to be available within the given time, | |
6606 * or FAIL otherwise. | |
6607 */ | |
6608 int | |
6609 gui_mch_wait_for_chars(long wtime) | |
6610 { | |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6611 int focus; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6612 guint timer; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6613 static int timed_out; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6614 int retval = FAIL; |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6615 #ifdef FEAT_JOB_CHANNEL |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6616 guint channel_timer = 0; |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6617 #endif |
7 | 6618 |
6619 timed_out = FALSE; | |
6620 | |
6621 /* this timeout makes sure that we will return if no characters arrived in | |
6622 * time */ | |
6623 if (wtime > 0) | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6624 timer = timeout_add(wtime, input_timer_cb, &timed_out); |
7 | 6625 else |
6626 timer = 0; | |
6627 | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6628 #ifdef FEAT_JOB_CHANNEL |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6629 /* If there is a channel with the keep_open flag we need to poll for input |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6630 * on them. */ |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6631 if (channel_any_keep_open()) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6632 channel_timer = timeout_add(20, channel_poll_cb, NULL); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6633 #endif |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6634 |
7 | 6635 focus = gui.in_focus; |
6636 | |
6637 do | |
6638 { | |
6639 /* Stop or start blinking when focus changes */ | |
6640 if (gui.in_focus != focus) | |
6641 { | |
6642 if (gui.in_focus) | |
6643 gui_mch_start_blink(); | |
6644 else | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
6645 gui_mch_stop_blink(TRUE); |
7 | 6646 focus = gui.in_focus; |
6647 } | |
6648 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
6649 #ifdef MESSAGE_QUEUE |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6650 # ifdef FEAT_TIMERS |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6651 did_add_timer = FALSE; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6652 # endif |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
6653 parse_queued_messages(); |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6654 # ifdef FEAT_TIMERS |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6655 if (did_add_timer) |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6656 /* Need to recompute the waiting time. */ |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6657 goto theend; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6658 # endif |
1624 | 6659 #endif |
6660 | |
7 | 6661 /* |
6662 * Loop in GTK+ processing until a timeout or input occurs. | |
22 | 6663 * Skip this if input is available anyway (can happen in rare |
6664 * situations, sort of race condition). | |
7 | 6665 */ |
22 | 6666 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
|
6667 g_main_context_iteration(NULL, TRUE); |
7 | 6668 |
6669 /* Got char, return immediately */ | |
6670 if (input_available()) | |
6671 { | |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6672 retval = OK; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6673 goto theend; |
7 | 6674 } |
6675 } while (wtime < 0 || !timed_out); | |
6676 | |
6677 /* | |
6678 * Flush all eventually pending (drawing) events. | |
6679 */ | |
6680 gui_mch_update(); | |
6681 | |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6682 theend: |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6683 if (timer != 0 && !timed_out) |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6684 timeout_remove(timer); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6685 #ifdef FEAT_JOB_CHANNEL |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6686 if (channel_timer != 0) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6687 timeout_remove(channel_timer); |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6688 #endif |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6689 |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6690 return retval; |
7 | 6691 } |
6692 | |
6693 | |
6694 /**************************************************************************** | |
6695 * Output drawing routines. | |
6696 ****************************************************************************/ | |
6697 | |
6698 | |
6699 /* Flush any output to the screen */ | |
6700 void | |
6701 gui_mch_flush(void) | |
6702 { | |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6703 #if GTK_CHECK_VERSION(3,0,0) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6704 if (gui.mainwin != NULL && gtk_widget_get_realized(gui.mainwin)) |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6705 #else |
7 | 6706 if (gui.mainwin != NULL && GTK_WIDGET_REALIZED(gui.mainwin)) |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6707 #endif |
9523
9d1abad90d6c
commit https://github.com/vim/vim/commit/fdadad994a6e8f6cc8b11519082e23200b96d0ba
Christian Brabandt <cb@256bit.org>
parents:
9489
diff
changeset
|
6708 gdk_display_flush(gtk_widget_get_display(gui.mainwin)); |
7 | 6709 } |
6710 | |
6711 /* | |
6712 * Clear a rectangular region of the screen from text pos (row1, col1) to | |
6713 * (row2, col2) inclusive. | |
6714 */ | |
6715 void | |
10920
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6716 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
|
6717 { |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6718 |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6719 int col1 = check_col(col1arg); |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6720 int col2 = check_col(col2arg); |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6721 int row1 = check_row(row1arg); |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6722 int row2 = check_row(row2arg); |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6723 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6724 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6725 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
|
6726 return; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6727 #else |
7 | 6728 GdkColor color; |
6729 | |
6730 if (gui.drawarea->window == NULL) | |
6731 return; | |
6732 | |
6733 color.pixel = gui.back_pixel; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6734 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6735 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6736 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6737 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6738 /* 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
|
6739 * bold glyph may sit there. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6740 const GdkRectangle rect = { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6741 FILL_X(col1), FILL_Y(row1), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6742 (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
|
6743 (row2 - row1 + 1) * gui.char_height |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6744 }; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6745 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
|
6746 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
|
6747 # 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
|
6748 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
|
6749 # else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6750 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
|
6751 if (pat != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6752 cairo_set_source(cr, pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6753 else |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6754 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
|
6755 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6756 gdk_cairo_rectangle(cr, &rect); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6757 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6758 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6759 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6760 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6761 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
|
6762 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6763 #else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6764 gdk_gc_set_foreground(gui.text_gc, &color); |
6765 | |
6766 /* Clear one extra pixel at the far right, for when bold characters have | |
6767 * spilled over to the window border. */ | |
6768 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, TRUE, | |
6769 FILL_X(col1), FILL_Y(row1), | |
6770 (col2 - col1 + 1) * gui.char_width | |
6771 + (col2 == Columns - 1), | |
6772 (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
|
6773 #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
|
6774 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6775 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6776 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6777 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6778 gui_gtk_window_clear(GdkWindow *win) |
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 const GdkRectangle rect = { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6781 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
|
6782 }; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6783 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
|
6784 # 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
|
6785 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
|
6786 # else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6787 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
|
6788 if (pat != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6789 cairo_set_source(cr, pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6790 else |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6791 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
|
6792 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6793 gdk_cairo_rectangle(cr, &rect); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6794 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6795 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6796 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6797 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6798 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
|
6799 } |
14712
82e7ce311065
patch 8.1.0368: GTK code has too many #ifdefs and GTK 2.10 building fails
Christian Brabandt <cb@256bit.org>
parents:
14575
diff
changeset
|
6800 #else |
82e7ce311065
patch 8.1.0368: GTK code has too many #ifdefs and GTK 2.10 building fails
Christian Brabandt <cb@256bit.org>
parents:
14575
diff
changeset
|
6801 # define gui_gtk_window_clear(win) gdk_window_clear(win) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6802 #endif |
7 | 6803 |
6804 void | |
6805 gui_mch_clear_all(void) | |
6806 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6807 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
|
6808 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
|
6809 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6810 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6811 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 6812 /* |
6813 * Redraw any text revealed by scrolling up/down. | |
6814 */ | |
6815 static void | |
6816 check_copy_area(void) | |
6817 { | |
6818 GdkEvent *event; | |
6819 int expose_count; | |
6820 | |
6821 if (gui.visibility != GDK_VISIBILITY_PARTIAL) | |
6822 return; | |
6823 | |
6824 /* Avoid redrawing the cursor while scrolling or it'll end up where | |
6825 * we don't want it to be. I'm not sure if it's correct to call | |
6826 * gui_dont_update_cursor() at this point but it works as a quick | |
6827 * fix for now. */ | |
9848
664276833670
commit https://github.com/vim/vim/commit/107abd2ca53c31fd3bb40d77ff296e98eaae2975
Christian Brabandt <cb@256bit.org>
parents:
9836
diff
changeset
|
6828 gui_dont_update_cursor(TRUE); |
7 | 6829 |
6830 do | |
6831 { | |
6832 /* Wait to check whether the scroll worked or not. */ | |
6833 event = gdk_event_get_graphics_expose(gui.drawarea->window); | |
6834 | |
6835 if (event == NULL) | |
6836 break; /* received NoExpose event */ | |
6837 | |
6838 gui_redraw(event->expose.area.x, event->expose.area.y, | |
6839 event->expose.area.width, event->expose.area.height); | |
6840 | |
6841 expose_count = event->expose.count; | |
6842 gdk_event_free(event); | |
6843 } | |
6844 while (expose_count > 0); /* more events follow */ | |
6845 | |
6846 gui_can_update_cursor(); | |
6847 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6848 #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
|
6849 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6850 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6851 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6852 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
|
6853 int src_x, int src_y, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6854 int width, int height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6855 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6856 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
|
6857 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6858 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
|
6859 cairo_clip(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6860 cairo_push_group(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6861 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
|
6862 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6863 cairo_pop_group_to_source(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6864 cairo_paint(cr); |
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_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6867 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6868 #endif |
7 | 6869 |
6870 /* | |
6871 * Delete the given number of lines from the given row, scrolling up any | |
6872 * text further down within the scroll region. | |
6873 */ | |
6874 void | |
6875 gui_mch_delete_lines(int row, int num_lines) | |
6876 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6877 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6878 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
|
6879 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
|
6880 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
|
6881 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6882 gui_gtk_surface_copy_rect( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6883 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
|
6884 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
|
6885 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
|
6886 gui_clear_block( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6887 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
|
6888 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
|
6889 gui_gtk3_redraw( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6890 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
|
6891 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
|
6892 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6893 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
|
6894 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
|
6895 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
|
6896 #else |
7 | 6897 if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) |
6898 return; /* Can't see the window */ | |
6899 | |
6900 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
6901 gdk_gc_set_background(gui.text_gc, gui.bgcolor); | |
6902 | |
6903 /* copy one extra pixel, for when bold has spilled over */ | |
6904 gdk_window_copy_area(gui.drawarea->window, gui.text_gc, | |
6905 FILL_X(gui.scroll_region_left), FILL_Y(row), | |
6906 gui.drawarea->window, | |
6907 FILL_X(gui.scroll_region_left), | |
6908 FILL_Y(row + num_lines), | |
6909 gui.char_width * (gui.scroll_region_right | |
6910 - gui.scroll_region_left + 1) + 1, | |
6911 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1)); | |
6912 | |
6913 gui_clear_block(gui.scroll_region_bot - num_lines + 1, | |
6914 gui.scroll_region_left, | |
6915 gui.scroll_region_bot, gui.scroll_region_right); | |
6916 check_copy_area(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6917 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6918 } |
6919 | |
6920 /* | |
6921 * Insert the given number of lines before the given row, scrolling down any | |
6922 * following text within the scroll region. | |
6923 */ | |
6924 void | |
6925 gui_mch_insert_lines(int row, int num_lines) | |
6926 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6927 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6928 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
|
6929 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
|
6930 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
|
6931 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6932 gui_gtk_surface_copy_rect( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6933 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
|
6934 FILL_X(gui.scroll_region_left), FILL_Y(row), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6935 gui.char_width * ncols + 1, gui.char_height * src_nrows); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6936 gui_mch_clear_block( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6937 row, gui.scroll_region_left, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6938 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
|
6939 gui_gtk3_redraw( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6940 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
|
6941 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
|
6942 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6943 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
|
6944 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
|
6945 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
|
6946 #else |
7 | 6947 if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) |
6948 return; /* Can't see the window */ | |
6949 | |
6950 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
6951 gdk_gc_set_background(gui.text_gc, gui.bgcolor); | |
6952 | |
6953 /* copy one extra pixel, for when bold has spilled over */ | |
6954 gdk_window_copy_area(gui.drawarea->window, gui.text_gc, | |
6955 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), | |
6956 gui.drawarea->window, | |
6957 FILL_X(gui.scroll_region_left), FILL_Y(row), | |
6958 gui.char_width * (gui.scroll_region_right | |
6959 - gui.scroll_region_left + 1) + 1, | |
6960 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1)); | |
6961 | |
6962 gui_clear_block(row, gui.scroll_region_left, | |
6963 row + num_lines - 1, gui.scroll_region_right); | |
6964 check_copy_area(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6965 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6966 } |
6967 | |
6968 /* | |
6969 * X Selection stuff, for cutting and pasting text to other windows. | |
6970 */ | |
6971 void | |
6972 clip_mch_request_selection(VimClipboard *cbd) | |
6973 { | |
6974 GdkAtom target; | |
6975 unsigned i; | |
1494 | 6976 time_t start; |
7 | 6977 |
6978 for (i = 0; i < N_SELECTION_TARGETS; ++i) | |
6979 { | |
1904 | 6980 if (!clip_html && selection_targets[i].info == TARGET_HTML) |
6981 continue; | |
7 | 6982 received_selection = RS_NONE; |
6983 target = gdk_atom_intern(selection_targets[i].target, FALSE); | |
6984 | |
6985 gtk_selection_convert(gui.drawarea, | |
6986 cbd->gtk_sel_atom, target, | |
6987 (guint32)GDK_CURRENT_TIME); | |
6988 | |
1494 | 6989 /* Hack: Wait up to three seconds for the selection. A hang was |
6990 * noticed here when using the netrw plugin combined with ":gui" | |
6991 * during the FocusGained event. */ | |
6992 start = time(NULL); | |
6993 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
|
6994 g_main_context_iteration(NULL, TRUE); /* wait for selection_received_cb */ |
7 | 6995 |
6996 if (received_selection != RS_FAIL) | |
6997 return; | |
6998 } | |
6999 | |
7000 /* 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
|
7001 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
|
7002 cbd); |
7 | 7003 } |
7004 | |
7005 /* | |
7006 * Disown the selection. | |
7007 */ | |
7008 void | |
1884 | 7009 clip_mch_lose_selection(VimClipboard *cbd UNUSED) |
7 | 7010 { |
13503
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7011 if (!in_selection_clear_event) |
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7012 { |
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7013 gtk_selection_owner_set(NULL, cbd->gtk_sel_atom, gui.event_time); |
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7014 gui_mch_update(); |
5d345460c984
patch 8.0.1625: test_quotestar is flaky when run in GTK GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7015 } |
7 | 7016 } |
7017 | |
7018 /* | |
7019 * Own the selection and return OK if it worked. | |
7020 */ | |
7021 int | |
7022 clip_mch_own_selection(VimClipboard *cbd) | |
7023 { | |
7024 int success; | |
7025 | |
7026 success = gtk_selection_owner_set(gui.drawarea, cbd->gtk_sel_atom, | |
2923 | 7027 gui.event_time); |
7 | 7028 gui_mch_update(); |
7029 return (success) ? OK : FAIL; | |
7030 } | |
7031 | |
7032 /* | |
7033 * Send the current selection to the clipboard. Do nothing for X because we | |
7034 * will fill in the selection only when requested by another app. | |
7035 */ | |
7036 void | |
1884 | 7037 clip_mch_set_selection(VimClipboard *cbd UNUSED) |
7 | 7038 { |
7039 } | |
7040 | |
4209 | 7041 int |
7042 clip_gtk_owner_exists(VimClipboard *cbd) | |
7043 { | |
7044 return gdk_selection_owner_get(cbd->gtk_sel_atom) != NULL; | |
7045 } | |
7046 | |
7 | 7047 |
7048 #if defined(FEAT_MENU) || defined(PROTO) | |
7049 /* | |
7050 * Make a menu item appear either active or not active (grey or not grey). | |
7051 */ | |
7052 void | |
7053 gui_mch_menu_grey(vimmenu_T *menu, int grey) | |
7054 { | |
7055 if (menu->id == NULL) | |
7056 return; | |
7057 | |
7058 if (menu_is_separator(menu->name)) | |
7059 grey = TRUE; | |
7060 | |
7061 gui_mch_menu_hidden(menu, FALSE); | |
7062 /* 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
|
7063 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7064 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
|
7065 # else |
7 | 7066 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
|
7067 # endif |
7 | 7068 { |
7069 gtk_widget_set_sensitive(menu->id, !grey); | |
7070 gui_mch_update(); | |
7071 } | |
7072 } | |
7073 | |
7074 /* | |
7075 * Make menu item hidden or not hidden. | |
7076 */ | |
7077 void | |
7078 gui_mch_menu_hidden(vimmenu_T *menu, int hidden) | |
7079 { | |
7080 if (menu->id == 0) | |
7081 return; | |
7082 | |
7083 if (hidden) | |
7084 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7085 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7086 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
|
7087 # else |
7 | 7088 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
|
7089 # endif |
7 | 7090 { |
7091 gtk_widget_hide(menu->id); | |
7092 gui_mch_update(); | |
7093 } | |
7094 } | |
7095 else | |
7096 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7097 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7098 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
|
7099 # else |
7 | 7100 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
|
7101 # endif |
7 | 7102 { |
7103 gtk_widget_show(menu->id); | |
7104 gui_mch_update(); | |
7105 } | |
7106 } | |
7107 } | |
7108 | |
7109 /* | |
7110 * This is called after setting all the menus to grey/hidden or not. | |
7111 */ | |
7112 void | |
7113 gui_mch_draw_menubar(void) | |
7114 { | |
7115 /* just make sure that the visual changes get effect immediately */ | |
7116 gui_mch_update(); | |
7117 } | |
7118 #endif /* FEAT_MENU */ | |
7119 | |
7120 /* | |
7121 * Scrollbar stuff. | |
7122 */ | |
7123 void | |
7124 gui_mch_enable_scrollbar(scrollbar_T *sb, int flag) | |
7125 { | |
7126 if (sb->id == NULL) | |
7127 return; | |
7128 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7129 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7130 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
|
7131 #else |
7 | 7132 if (flag) |
7133 gtk_widget_show(sb->id); | |
7134 else | |
7135 gtk_widget_hide(sb->id); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7136 #endif |
7 | 7137 |
791 | 7138 update_window_manager_hints(0, 0); |
7 | 7139 } |
7140 | |
7141 | |
7142 /* | |
7143 * Return the RGB value of a pixel as long. | |
7144 */ | |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9879
diff
changeset
|
7145 guicolor_T |
7 | 7146 gui_mch_get_rgb(guicolor_T pixel) |
7147 { | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7148 #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
|
7149 return (long_u)pixel; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7150 #else |
7 | 7151 GdkColor color; |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7152 |
7 | 7153 gdk_colormap_query_color(gtk_widget_get_colormap(gui.drawarea), |
7154 (unsigned long)pixel, &color); | |
7155 | |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9879
diff
changeset
|
7156 return (guicolor_T)( |
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9879
diff
changeset
|
7157 (((unsigned)color.red & 0xff00) << 8) |
7 | 7158 | ((unsigned)color.green & 0xff00) |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9879
diff
changeset
|
7159 | (((unsigned)color.blue & 0xff00) >> 8)); |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7160 #endif |
7 | 7161 } |
7162 | |
7163 /* | |
88 | 7164 * Get current mouse coordinates in text window. |
7 | 7165 */ |
88 | 7166 void |
7167 gui_mch_getmouse(int *x, int *y) | |
7 | 7168 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7169 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7170 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
|
7171 #else |
88 | 7172 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
|
7173 #endif |
7 | 7174 } |
7175 | |
7176 void | |
7177 gui_mch_setmouse(int x, int y) | |
7178 { | |
7179 /* Sorry for the Xlib call, but we can't avoid it, since there is no | |
7180 * internal GDK mechanism present to accomplish this. (and for good | |
7181 * reason...) */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7182 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
|
7183 (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
|
7184 0, 0, 0U, 0U, x, y); |
7 | 7185 } |
7186 | |
7187 | |
7188 #ifdef FEAT_MOUSESHAPE | |
7189 /* The last set mouse pointer shape is remembered, to be used when it goes | |
7190 * from hidden to not hidden. */ | |
7191 static int last_shape = 0; | |
7192 #endif | |
7193 | |
7194 /* | |
7195 * Use the blank mouse pointer or not. | |
7196 * | |
7197 * hide: TRUE = use blank ptr, FALSE = use parent ptr | |
7198 */ | |
7199 void | |
7200 gui_mch_mousehide(int hide) | |
7201 { | |
7202 if (gui.pointer_hidden != hide) | |
7203 { | |
7204 gui.pointer_hidden = hide; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7205 if (gtk_widget_get_window(gui.drawarea) && gui.blank_pointer != NULL) |
7 | 7206 { |
7207 if (hide) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7208 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
|
7209 gui.blank_pointer); |
7 | 7210 else |
7211 #ifdef FEAT_MOUSESHAPE | |
7212 mch_set_mouse_shape(last_shape); | |
14712
82e7ce311065
patch 8.1.0368: GTK code has too many #ifdefs and GTK 2.10 building fails
Christian Brabandt <cb@256bit.org>
parents:
14575
diff
changeset
|
7213 #else |
8301
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7214 gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), NULL); |
7 | 7215 #endif |
7216 } | |
7217 } | |
7218 } | |
7219 | |
7220 #if defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7221 | |
7222 /* Table for shape IDs. Keep in sync with the mshape_names[] table in | |
7223 * misc2.c! */ | |
7224 static const int mshape_ids[] = | |
7225 { | |
7226 GDK_LEFT_PTR, /* arrow */ | |
7227 GDK_CURSOR_IS_PIXMAP, /* blank */ | |
7228 GDK_XTERM, /* beam */ | |
7229 GDK_SB_V_DOUBLE_ARROW, /* updown */ | |
7230 GDK_SIZING, /* udsizing */ | |
7231 GDK_SB_H_DOUBLE_ARROW, /* leftright */ | |
7232 GDK_SIZING, /* lrsizing */ | |
7233 GDK_WATCH, /* busy */ | |
7234 GDK_X_CURSOR, /* no */ | |
7235 GDK_CROSSHAIR, /* crosshair */ | |
7236 GDK_HAND1, /* hand1 */ | |
7237 GDK_HAND2, /* hand2 */ | |
7238 GDK_PENCIL, /* pencil */ | |
7239 GDK_QUESTION_ARROW, /* question */ | |
7240 GDK_RIGHT_PTR, /* right-arrow */ | |
7241 GDK_CENTER_PTR, /* up-arrow */ | |
7242 GDK_LEFT_PTR /* last one */ | |
7243 }; | |
7244 | |
7245 void | |
7246 mch_set_mouse_shape(int shape) | |
7247 { | |
7248 int id; | |
7249 GdkCursor *c; | |
7250 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7251 if (gtk_widget_get_window(gui.drawarea) == NULL) |
7 | 7252 return; |
7253 | |
7254 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
|
7255 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
|
7256 gui.blank_pointer); |
7 | 7257 else |
7258 { | |
7259 if (shape >= MSHAPE_NUMBERED) | |
7260 { | |
7261 id = shape - MSHAPE_NUMBERED; | |
7262 if (id >= GDK_LAST_CURSOR) | |
7263 id = GDK_LEFT_PTR; | |
7264 else | |
7265 id &= ~1; /* they are always even (why?) */ | |
7266 } | |
1884 | 7267 else if (shape < (int)(sizeof(mshape_ids) / sizeof(int))) |
7 | 7268 id = mshape_ids[shape]; |
842 | 7269 else |
7270 return; | |
7 | 7271 c = gdk_cursor_new_for_display( |
136 | 7272 gtk_widget_get_display(gui.drawarea), (GdkCursorType)id); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7273 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
|
7274 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7275 g_object_unref(G_OBJECT(c)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7276 # else |
7 | 7277 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
|
7278 # endif |
7 | 7279 } |
7280 if (shape != MSHAPE_HIDE) | |
7281 last_shape = shape; | |
7282 } | |
7283 #endif /* FEAT_MOUSESHAPE */ | |
7284 | |
7285 | |
7286 #if defined(FEAT_SIGN_ICONS) || defined(PROTO) | |
7287 /* | |
7288 * Signs are currently always 2 chars wide. With GTK+ 2, the image will be | |
7289 * scaled down if the current font is not big enough, or scaled up if the image | |
7290 * size is less than 3/4 of the maximum sign size. With GTK+ 1, the pixmap | |
7291 * will be cut off if the current font is not big enough, or centered if it's | |
7292 * too small. | |
7293 */ | |
7294 # define SIGN_WIDTH (2 * gui.char_width) | |
7295 # define SIGN_HEIGHT (gui.char_height) | |
7296 # define SIGN_ASPECT ((double)SIGN_HEIGHT / (double)SIGN_WIDTH) | |
7297 | |
7298 void | |
7299 gui_mch_drawsign(int row, int col, int typenr) | |
7300 { | |
7301 GdkPixbuf *sign; | |
7302 | |
7303 sign = (GdkPixbuf *)sign_get_image(typenr); | |
7304 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7305 if (sign != NULL && gui.drawarea != NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7306 && gtk_widget_get_window(gui.drawarea) != NULL) |
7 | 7307 { |
7308 int width; | |
7309 int height; | |
7310 int xoffset; | |
7311 int yoffset; | |
7312 int need_scale; | |
7313 | |
7314 width = gdk_pixbuf_get_width(sign); | |
7315 height = gdk_pixbuf_get_height(sign); | |
7316 /* | |
7317 * Decide whether we need to scale. Allow one pixel of border | |
7318 * width to be cut off, in order to avoid excessive scaling for | |
7319 * tiny differences in font size. | |
5983 | 7320 * Do scale to fit the height to avoid gaps because of linespacing. |
7 | 7321 */ |
7322 need_scale = (width > SIGN_WIDTH + 2 | |
5983 | 7323 || height != SIGN_HEIGHT |
7 | 7324 || (width < 3 * SIGN_WIDTH / 4 |
7325 && height < 3 * SIGN_HEIGHT / 4)); | |
7326 if (need_scale) | |
7327 { | |
5983 | 7328 double aspect; |
7329 int w = width; | |
7330 int h = height; | |
7 | 7331 |
7332 /* Keep the original aspect ratio */ | |
7333 aspect = (double)height / (double)width; | |
7334 width = (double)SIGN_WIDTH * SIGN_ASPECT / aspect; | |
7335 width = MIN(width, SIGN_WIDTH); | |
5983 | 7336 if (((double)(MAX(height, SIGN_HEIGHT)) / |
7337 (double)(MIN(height, SIGN_HEIGHT))) < 1.15) | |
7338 { | |
7339 /* Change the aspect ratio by at most 15% to fill the | |
7340 * available space completly. */ | |
7341 height = (double)SIGN_HEIGHT * SIGN_ASPECT / aspect; | |
7342 height = MIN(height, SIGN_HEIGHT); | |
7343 } | |
7344 else | |
7345 height = (double)width * aspect; | |
7346 | |
7347 if (w == width && h == height) | |
7348 { | |
7349 /* no change in dimensions; don't decrease reference counter | |
7350 * (below) */ | |
7351 need_scale = FALSE; | |
7352 } | |
7353 else | |
7354 { | |
7355 /* This doesn't seem to be worth caching, and doing so would | |
7356 * complicate the code quite a bit. */ | |
7357 sign = gdk_pixbuf_scale_simple(sign, width, height, | |
7358 GDK_INTERP_BILINEAR); | |
7359 if (sign == NULL) | |
7360 return; /* out of memory */ | |
7361 } | |
7 | 7362 } |
7363 | |
7364 /* The origin is the upper-left corner of the pixmap. Therefore | |
7365 * these offset may become negative if the pixmap is smaller than | |
7366 * the 2x1 cells reserved for the sign icon. */ | |
7367 xoffset = (width - SIGN_WIDTH) / 2; | |
7368 yoffset = (height - SIGN_HEIGHT) / 2; | |
7369 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7370 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7371 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7372 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7373 cairo_surface_t *bg_surf; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7374 cairo_t *bg_cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7375 cairo_surface_t *sign_surf; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7376 cairo_t *sign_cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7377 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7378 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7379 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7380 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
|
7381 cairo_surface_get_content(gui.surface), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7382 SIGN_WIDTH, SIGN_HEIGHT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7383 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
|
7384 cairo_set_source_rgba(bg_cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7385 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
|
7386 gui.bgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7387 cairo_paint(bg_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7388 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7389 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
|
7390 cairo_surface_get_content(gui.surface), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7391 SIGN_WIDTH, SIGN_HEIGHT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7392 sign_cr = cairo_create(sign_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7393 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
|
7394 cairo_paint(sign_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7395 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7396 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
|
7397 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
|
7398 cairo_paint(sign_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7399 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7400 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
|
7401 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7402 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7403 cairo_destroy(sign_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7404 cairo_surface_destroy(sign_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7405 cairo_destroy(bg_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7406 cairo_surface_destroy(bg_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7407 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7408 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7409 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7410 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
|
7411 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
|
7412 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7413 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7414 # else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 7415 gdk_gc_set_foreground(gui.text_gc, gui.bgcolor); |
7416 | |
7417 gdk_draw_rectangle(gui.drawarea->window, | |
7418 gui.text_gc, | |
7419 TRUE, | |
7420 FILL_X(col), | |
7421 FILL_Y(row), | |
7422 SIGN_WIDTH, | |
7423 SIGN_HEIGHT); | |
7424 | |
7425 gdk_pixbuf_render_to_drawable_alpha(sign, | |
7426 gui.drawarea->window, | |
7427 MAX(0, xoffset), | |
7428 MAX(0, yoffset), | |
7429 FILL_X(col) - MIN(0, xoffset), | |
7430 FILL_Y(row) - MIN(0, yoffset), | |
7431 MIN(width, SIGN_WIDTH), | |
7432 MIN(height, SIGN_HEIGHT), | |
7433 GDK_PIXBUF_ALPHA_BILEVEL, | |
7434 127, | |
7435 GDK_RGB_DITHER_NORMAL, | |
7436 0, 0); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7437 # endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 7438 if (need_scale) |
7439 g_object_unref(sign); | |
7440 } | |
7441 } | |
7442 | |
7443 void * | |
7444 gui_mch_register_sign(char_u *signfile) | |
7445 { | |
7446 if (signfile[0] != NUL && signfile[0] != '-' && gui.in_use) | |
7447 { | |
7448 GdkPixbuf *sign; | |
7449 GError *error = NULL; | |
7450 char_u *message; | |
7451 | |
7452 sign = gdk_pixbuf_new_from_file((const char *)signfile, &error); | |
7453 | |
7454 if (error == NULL) | |
7455 return sign; | |
7456 | |
7457 message = (char_u *)error->message; | |
7458 | |
7459 if (message != NULL && input_conv.vc_type != CONV_NONE) | |
7460 message = string_convert(&input_conv, message, NULL); | |
7461 | |
7462 if (message != NULL) | |
7463 { | |
7464 /* The error message is already translated and will be more | |
7465 * descriptive than anything we could possibly do ourselves. */ | |
7466 EMSG2("E255: %s", message); | |
7467 | |
7468 if (input_conv.vc_type != CONV_NONE) | |
7469 vim_free(message); | |
7470 } | |
7471 g_error_free(error); | |
7472 } | |
7473 | |
7474 return NULL; | |
7475 } | |
7476 | |
7477 void | |
7478 gui_mch_destroy_sign(void *sign) | |
7479 { | |
7480 if (sign != NULL) | |
7481 g_object_unref(sign); | |
7482 } | |
7483 | |
7484 #endif /* FEAT_SIGN_ICONS */ |