Mercurial > vim
annotate src/gui_gtk_x11.c @ 13298:a88c5e12b860 v8.0.1523
patch 8.0.1523: cannot write and read terminal screendumps
commit https://github.com/vim/vim/commit/d96ff165113ce5fe62107add590997660e3d4802
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Feb 18 22:13:29 2018 +0100
patch 8.0.1523: cannot write and read terminal screendumps
Problem: Cannot write and read terminal screendumps.
Solution: Add term_dumpwrite(), term_dumpread() and term_dumpdiff().
Also add assert_equalfile().
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 18 Feb 2018 22:15:06 +0100 |
parents | ac42c4b11dbc |
children | 5d345460c984 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9939
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * Porting to GTK+ was done by: | |
12 * | |
70 | 13 * (C) 1998,1999,2000 by Marcin Dalecki <martin@dalecki.de> |
7 | 14 * |
15 * With GREAT support and continuous encouragements by Andy Kahn and of | |
16 * course Bram Moolenaar! | |
17 * | |
18 * Support for GTK+ 2 was added by: | |
19 * | |
20 * (C) 2002,2003 Jason Hildebrand <jason@peaceworks.ca> | |
21 * Daniel Elstner <daniel.elstner@gmx.net> | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
22 * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
23 * Support for GTK+ 3 was added by: |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
24 * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
25 * 2016 Kazunobu Kuriyama <kazunobu.kuriyama@gmail.com> |
7 | 26 */ |
27 | |
28 #include "vim.h" | |
7380
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
29 #ifdef USE_GRESOURCE |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
30 #include "auto/gui_gtk_gresources.h" |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
31 #endif |
1666 | 32 |
7 | 33 #ifdef FEAT_GUI_GNOME |
34 /* Gnome redefines _() and N_(). Grrr... */ | |
35 # ifdef _ | |
36 # undef _ | |
37 # endif | |
38 # ifdef N_ | |
39 # undef N_ | |
40 # endif | |
41 # ifdef textdomain | |
42 # undef textdomain | |
43 # endif | |
44 # ifdef bindtextdomain | |
45 # undef bindtextdomain | |
46 # endif | |
1286 | 47 # ifdef bind_textdomain_codeset |
48 # undef bind_textdomain_codeset | |
1226 | 49 # endif |
7 | 50 # if defined(FEAT_GETTEXT) && !defined(ENABLE_NLS) |
51 # define ENABLE_NLS /* so the texts in the dialog boxes are translated */ | |
52 # endif | |
53 # include <gnome.h> | |
54 # include "version.h" | |
798 | 55 /* missing prototype in bonobo-dock-item.h */ |
56 extern void bonobo_dock_item_set_behavior(BonoboDockItem *dock_item, BonoboDockItemBehavior beh); | |
7 | 57 #endif |
58 | |
59 #if !defined(FEAT_GUI_GTK) && defined(PROTO) | |
60 /* When generating prototypes we don't want syntax errors. */ | |
61 # define GdkAtom int | |
62 # define GdkEventExpose int | |
63 # define GdkEventFocus int | |
64 # define GdkEventVisibility int | |
65 # define GdkEventProperty int | |
66 # define GtkContainer int | |
67 # define GtkTargetEntry int | |
68 # define GtkType int | |
69 # define GtkWidget int | |
70 # define gint int | |
71 # define gpointer int | |
72 # define guint int | |
73 # define GdkEventKey int | |
74 # define GdkEventSelection int | |
75 # define GtkSelectionData int | |
76 # define GdkEventMotion int | |
77 # define GdkEventButton int | |
78 # define GdkDragContext int | |
79 # define GdkEventConfigure int | |
80 # define GdkEventClient int | |
81 #else | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
82 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
83 # include <gdk/gdkkeysyms-compat.h> |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
84 # include <gtk/gtkx.h> |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
85 # else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
86 # include <gdk/gdkkeysyms.h> |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
87 # endif |
7 | 88 # include <gdk/gdk.h> |
89 # ifdef WIN3264 | |
90 # include <gdk/gdkwin32.h> | |
91 # else | |
92 # include <gdk/gdkx.h> | |
93 # endif | |
94 # include <gtk/gtk.h> | |
95 # include "gui_gtk_f.h" | |
96 #endif | |
97 | |
98 #ifdef HAVE_X11_SUNKEYSYM_H | |
99 # include <X11/Sunkeysym.h> | |
2714 | 100 #endif |
101 | |
7 | 102 /* |
103 * Easy-to-use macro for multihead support. | |
104 */ | |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
105 #define GET_X_ATOM(atom) gdk_x11_atom_to_xatom_for_display( \ |
7 | 106 gtk_widget_get_display(gui.mainwin), atom) |
107 | |
108 /* Selection type distinguishers */ | |
109 enum | |
110 { | |
111 TARGET_TYPE_NONE, | |
112 TARGET_UTF8_STRING, | |
113 TARGET_STRING, | |
114 TARGET_COMPOUND_TEXT, | |
1904 | 115 TARGET_HTML, |
7 | 116 TARGET_TEXT, |
117 TARGET_TEXT_URI_LIST, | |
118 TARGET_TEXT_PLAIN, | |
119 TARGET_VIM, | |
120 TARGET_VIMENC | |
121 }; | |
122 | |
123 /* | |
124 * Table of selection targets supported by Vim. | |
125 * Note: Order matters, preferred types should come first. | |
126 */ | |
127 static const GtkTargetEntry selection_targets[] = | |
128 { | |
129 {VIMENC_ATOM_NAME, 0, TARGET_VIMENC}, | |
130 {VIM_ATOM_NAME, 0, TARGET_VIM}, | |
1904 | 131 {"text/html", 0, TARGET_HTML}, |
7 | 132 {"UTF8_STRING", 0, TARGET_UTF8_STRING}, |
133 {"COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT}, | |
134 {"TEXT", 0, TARGET_TEXT}, | |
135 {"STRING", 0, TARGET_STRING} | |
136 }; | |
137 #define N_SELECTION_TARGETS (sizeof(selection_targets) / sizeof(selection_targets[0])) | |
138 | |
139 #ifdef FEAT_DND | |
140 /* | |
141 * Table of DnD targets supported by Vim. | |
142 * Note: Order matters, preferred types should come first. | |
143 */ | |
144 static const GtkTargetEntry dnd_targets[] = | |
145 { | |
146 {"text/uri-list", 0, TARGET_TEXT_URI_LIST}, | |
1904 | 147 {"text/html", 0, TARGET_HTML}, |
7 | 148 {"UTF8_STRING", 0, TARGET_UTF8_STRING}, |
149 {"STRING", 0, TARGET_STRING}, | |
150 {"text/plain", 0, TARGET_TEXT_PLAIN} | |
151 }; | |
152 # define N_DND_TARGETS (sizeof(dnd_targets) / sizeof(dnd_targets[0])) | |
153 #endif | |
154 | |
155 | |
156 /* | |
157 * "Monospace" is a standard font alias that should be present | |
158 * on all proper Pango/fontconfig installations. | |
159 */ | |
160 # define DEFAULT_FONT "Monospace 10" | |
161 | |
162 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
163 /* | |
164 * Atoms used to communicate save-yourself from the X11 session manager. There | |
165 * is no need to move them into the GUI struct, since they should be constant. | |
166 */ | |
167 static GdkAtom wm_protocols_atom = GDK_NONE; | |
168 static GdkAtom save_yourself_atom = GDK_NONE; | |
169 #endif | |
170 | |
171 /* | |
172 * Atoms used to control/reference X11 selections. | |
173 */ | |
1904 | 174 static GdkAtom html_atom = GDK_NONE; |
7 | 175 static GdkAtom utf8_string_atom = GDK_NONE; |
176 static GdkAtom vim_atom = GDK_NONE; /* Vim's own special selection format */ | |
177 static GdkAtom vimenc_atom = GDK_NONE; /* Vim's extended selection format */ | |
178 | |
179 /* | |
180 * Keycodes recognized by vim. | |
181 * NOTE: when changing this, the table in gui_x11.c probably needs the same | |
182 * change! | |
183 */ | |
184 static struct special_key | |
185 { | |
186 guint key_sym; | |
187 char_u code0; | |
188 char_u code1; | |
189 } | |
190 const special_keys[] = | |
191 { | |
192 {GDK_Up, 'k', 'u'}, | |
193 {GDK_Down, 'k', 'd'}, | |
194 {GDK_Left, 'k', 'l'}, | |
195 {GDK_Right, 'k', 'r'}, | |
196 {GDK_F1, 'k', '1'}, | |
197 {GDK_F2, 'k', '2'}, | |
198 {GDK_F3, 'k', '3'}, | |
199 {GDK_F4, 'k', '4'}, | |
200 {GDK_F5, 'k', '5'}, | |
201 {GDK_F6, 'k', '6'}, | |
202 {GDK_F7, 'k', '7'}, | |
203 {GDK_F8, 'k', '8'}, | |
204 {GDK_F9, 'k', '9'}, | |
205 {GDK_F10, 'k', ';'}, | |
206 {GDK_F11, 'F', '1'}, | |
207 {GDK_F12, 'F', '2'}, | |
208 {GDK_F13, 'F', '3'}, | |
209 {GDK_F14, 'F', '4'}, | |
210 {GDK_F15, 'F', '5'}, | |
211 {GDK_F16, 'F', '6'}, | |
212 {GDK_F17, 'F', '7'}, | |
213 {GDK_F18, 'F', '8'}, | |
214 {GDK_F19, 'F', '9'}, | |
215 {GDK_F20, 'F', 'A'}, | |
216 {GDK_F21, 'F', 'B'}, | |
217 {GDK_Pause, 'F', 'B'}, /* Pause == F21 according to netbeans.txt */ | |
218 {GDK_F22, 'F', 'C'}, | |
219 {GDK_F23, 'F', 'D'}, | |
220 {GDK_F24, 'F', 'E'}, | |
221 {GDK_F25, 'F', 'F'}, | |
222 {GDK_F26, 'F', 'G'}, | |
223 {GDK_F27, 'F', 'H'}, | |
224 {GDK_F28, 'F', 'I'}, | |
225 {GDK_F29, 'F', 'J'}, | |
226 {GDK_F30, 'F', 'K'}, | |
227 {GDK_F31, 'F', 'L'}, | |
228 {GDK_F32, 'F', 'M'}, | |
229 {GDK_F33, 'F', 'N'}, | |
230 {GDK_F34, 'F', 'O'}, | |
231 {GDK_F35, 'F', 'P'}, | |
232 #ifdef SunXK_F36 | |
233 {SunXK_F36, 'F', 'Q'}, | |
234 {SunXK_F37, 'F', 'R'}, | |
235 #endif | |
236 {GDK_Help, '%', '1'}, | |
237 {GDK_Undo, '&', '8'}, | |
238 {GDK_BackSpace, 'k', 'b'}, | |
239 {GDK_Insert, 'k', 'I'}, | |
240 {GDK_Delete, 'k', 'D'}, | |
241 {GDK_3270_BackTab, 'k', 'B'}, | |
242 {GDK_Clear, 'k', 'C'}, | |
243 {GDK_Home, 'k', 'h'}, | |
244 {GDK_End, '@', '7'}, | |
245 {GDK_Prior, 'k', 'P'}, | |
246 {GDK_Next, 'k', 'N'}, | |
247 {GDK_Print, '%', '9'}, | |
248 /* Keypad keys: */ | |
249 {GDK_KP_Left, 'k', 'l'}, | |
250 {GDK_KP_Right, 'k', 'r'}, | |
251 {GDK_KP_Up, 'k', 'u'}, | |
252 {GDK_KP_Down, 'k', 'd'}, | |
253 {GDK_KP_Insert, KS_EXTRA, (char_u)KE_KINS}, | |
254 {GDK_KP_Delete, KS_EXTRA, (char_u)KE_KDEL}, | |
255 {GDK_KP_Home, 'K', '1'}, | |
256 {GDK_KP_End, 'K', '4'}, | |
257 {GDK_KP_Prior, 'K', '3'}, /* page up */ | |
258 {GDK_KP_Next, 'K', '5'}, /* page down */ | |
259 | |
260 {GDK_KP_Add, 'K', '6'}, | |
261 {GDK_KP_Subtract, 'K', '7'}, | |
262 {GDK_KP_Divide, 'K', '8'}, | |
263 {GDK_KP_Multiply, 'K', '9'}, | |
264 {GDK_KP_Enter, 'K', 'A'}, | |
265 {GDK_KP_Decimal, 'K', 'B'}, | |
266 | |
267 {GDK_KP_0, 'K', 'C'}, | |
268 {GDK_KP_1, 'K', 'D'}, | |
269 {GDK_KP_2, 'K', 'E'}, | |
270 {GDK_KP_3, 'K', 'F'}, | |
271 {GDK_KP_4, 'K', 'G'}, | |
272 {GDK_KP_5, 'K', 'H'}, | |
273 {GDK_KP_6, 'K', 'I'}, | |
274 {GDK_KP_7, 'K', 'J'}, | |
275 {GDK_KP_8, 'K', 'K'}, | |
276 {GDK_KP_9, 'K', 'L'}, | |
277 | |
278 /* End of list marker: */ | |
279 {0, 0, 0} | |
280 }; | |
281 | |
282 /* | |
283 * Flags for command line options table below. | |
284 */ | |
285 #define ARG_FONT 1 | |
286 #define ARG_GEOMETRY 2 | |
287 #define ARG_REVERSE 3 | |
288 #define ARG_NOREVERSE 4 | |
289 #define ARG_BACKGROUND 5 | |
290 #define ARG_FOREGROUND 6 | |
291 #define ARG_ICONIC 7 | |
292 #define ARG_ROLE 8 | |
293 #define ARG_NETBEANS 9 | |
294 #define ARG_XRM 10 /* ignored */ | |
295 #define ARG_MENUFONT 11 /* ignored */ | |
296 #define ARG_INDEX_MASK 0x00ff | |
297 #define ARG_HAS_VALUE 0x0100 /* a value is expected after the argument */ | |
298 #define ARG_NEEDS_GUI 0x0200 /* need to initialize the GUI for this */ | |
299 #define ARG_FOR_GTK 0x0400 /* argument is handled by GTK+ or GNOME */ | |
300 #define ARG_COMPAT_LONG 0x0800 /* accept -foo but substitute with --foo */ | |
301 #define ARG_KEEP 0x1000 /* don't remove argument from argv[] */ | |
302 | |
303 /* | |
304 * This table holds all the X GUI command line options allowed. This includes | |
305 * the standard ones so that we can skip them when Vim is started without the | |
306 * GUI (but the GUI might start up later). | |
307 * | |
308 * When changing this, also update doc/gui_x11.txt and the usage message!!! | |
309 */ | |
310 typedef struct | |
311 { | |
312 const char *name; | |
313 unsigned int flags; | |
314 } | |
315 cmdline_option_T; | |
316 | |
317 static const cmdline_option_T cmdline_options[] = | |
318 { | |
319 /* We handle these options ourselves */ | |
320 {"-fn", ARG_FONT|ARG_HAS_VALUE}, | |
321 {"-font", ARG_FONT|ARG_HAS_VALUE}, | |
322 {"-geom", ARG_GEOMETRY|ARG_HAS_VALUE}, | |
323 {"-geometry", ARG_GEOMETRY|ARG_HAS_VALUE}, | |
324 {"-rv", ARG_REVERSE}, | |
325 {"-reverse", ARG_REVERSE}, | |
326 {"+rv", ARG_NOREVERSE}, | |
327 {"+reverse", ARG_NOREVERSE}, | |
328 {"-bg", ARG_BACKGROUND|ARG_HAS_VALUE}, | |
329 {"-background", ARG_BACKGROUND|ARG_HAS_VALUE}, | |
330 {"-fg", ARG_FOREGROUND|ARG_HAS_VALUE}, | |
331 {"-foreground", ARG_FOREGROUND|ARG_HAS_VALUE}, | |
332 {"-iconic", ARG_ICONIC}, | |
333 {"--role", ARG_ROLE|ARG_HAS_VALUE}, | |
334 #ifdef FEAT_NETBEANS_INTG | |
335 {"-nb", ARG_NETBEANS}, /* non-standard value format */ | |
336 {"-xrm", ARG_XRM|ARG_HAS_VALUE}, /* not implemented */ | |
337 {"-mf", ARG_MENUFONT|ARG_HAS_VALUE}, /* not implemented */ | |
338 {"-menufont", ARG_MENUFONT|ARG_HAS_VALUE}, /* not implemented */ | |
339 #endif | |
340 /* Arguments handled by GTK (and GNOME) internally. */ | |
341 {"--g-fatal-warnings", ARG_FOR_GTK}, | |
342 {"--gdk-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
343 {"--gdk-no-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
344 {"--gtk-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
345 {"--gtk-no-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
346 {"--gtk-module", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
347 {"--sync", ARG_FOR_GTK}, | |
348 {"--display", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
349 {"--name", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
350 {"--class", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
351 {"--screen", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
352 {"--gxid-host", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
353 {"--gxid-port", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
354 #ifdef FEAT_GUI_GNOME | |
355 {"--load-modules", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
356 {"--sm-client-id", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
357 {"--sm-config-prefix", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
358 {"--sm-disable", ARG_FOR_GTK}, | |
359 {"--oaf-ior-fd", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
360 {"--oaf-activate-iid", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
361 {"--oaf-private", ARG_FOR_GTK}, | |
362 {"--enable-sound", ARG_FOR_GTK}, | |
363 {"--disable-sound", ARG_FOR_GTK}, | |
364 {"--espeaker", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
365 {"-?", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
366 {"--help", ARG_FOR_GTK|ARG_NEEDS_GUI|ARG_KEEP}, | |
367 {"--usage", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
368 # if 0 /* conflicts with Vim's own --version argument */ | |
369 {"--version", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
370 # endif | |
371 {"--disable-crash-dialog", ARG_FOR_GTK}, | |
372 #endif | |
373 {NULL, 0} | |
374 }; | |
375 | |
376 static int gui_argc = 0; | |
377 static char **gui_argv = NULL; | |
378 | |
379 static const char *role_argument = NULL; | |
380 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
381 static const char *restart_command = NULL; | |
1898 | 382 static char *abs_restart_command = NULL; |
7 | 383 #endif |
384 static int found_iconic_arg = FALSE; | |
385 | |
386 #ifdef FEAT_GUI_GNOME | |
387 /* | |
388 * Can't use Gnome if --socketid given | |
389 */ | |
390 static int using_gnome = 0; | |
391 #else | |
392 # define using_gnome 0 | |
393 #endif | |
394 | |
395 /* | |
396 * Parse the GUI related command-line arguments. Any arguments used are | |
397 * deleted from argv, and *argc is decremented accordingly. This is called | |
398 * when vim is started, whether or not the GUI has been started. | |
399 */ | |
400 void | |
401 gui_mch_prepare(int *argc, char **argv) | |
402 { | |
403 const cmdline_option_T *option; | |
404 int i = 0; | |
405 int len = 0; | |
406 | |
407 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
408 /* | |
409 * Determine the command used to invoke Vim, to be passed as restart | |
410 * command to the session manager. If argv[0] contains any directory | |
411 * components try building an absolute path, otherwise leave it as is. | |
412 */ | |
413 restart_command = argv[0]; | |
414 | |
415 if (strchr(argv[0], G_DIR_SEPARATOR) != NULL) | |
416 { | |
417 char_u buf[MAXPATHL]; | |
418 | |
419 if (mch_FullName((char_u *)argv[0], buf, (int)sizeof(buf), TRUE) == OK) | |
1898 | 420 { |
421 abs_restart_command = (char *)vim_strsave(buf); | |
422 restart_command = abs_restart_command; | |
423 } | |
7 | 424 } |
425 #endif | |
426 | |
427 /* | |
428 * Move all the entries in argv which are relevant to GTK+ and GNOME | |
429 * into gui_argv. Freed later in gui_mch_init(). | |
430 */ | |
431 gui_argc = 0; | |
432 gui_argv = (char **)alloc((unsigned)((*argc + 1) * sizeof(char *))); | |
433 | |
434 g_return_if_fail(gui_argv != NULL); | |
435 | |
436 gui_argv[gui_argc++] = argv[i++]; | |
437 | |
438 while (i < *argc) | |
439 { | |
440 /* Don't waste CPU cycles on non-option arguments. */ | |
441 if (argv[i][0] != '-' && argv[i][0] != '+') | |
442 { | |
443 ++i; | |
444 continue; | |
445 } | |
446 | |
447 /* Look for argv[i] in cmdline_options[] table. */ | |
448 for (option = &cmdline_options[0]; option->name != NULL; ++option) | |
449 { | |
450 len = strlen(option->name); | |
451 | |
452 if (strncmp(argv[i], option->name, len) == 0) | |
453 { | |
454 if (argv[i][len] == '\0') | |
455 break; | |
456 /* allow --foo=bar style */ | |
457 if (argv[i][len] == '=' && (option->flags & ARG_HAS_VALUE)) | |
458 break; | |
459 #ifdef FEAT_NETBEANS_INTG | |
460 /* darn, -nb has non-standard syntax */ | |
461 if (vim_strchr((char_u *)":=", argv[i][len]) != NULL | |
462 && (option->flags & ARG_INDEX_MASK) == ARG_NETBEANS) | |
463 break; | |
464 #endif | |
465 } | |
466 else if ((option->flags & ARG_COMPAT_LONG) | |
467 && strcmp(argv[i], option->name + 1) == 0) | |
468 { | |
469 /* Replace the standard X arguments "-name" and "-display" | |
470 * with their GNU-style long option counterparts. */ | |
471 argv[i] = (char *)option->name; | |
472 break; | |
473 } | |
474 } | |
475 if (option->name == NULL) /* no match */ | |
476 { | |
477 ++i; | |
478 continue; | |
479 } | |
480 | |
481 if (option->flags & ARG_FOR_GTK) | |
482 { | |
483 /* Move the argument into gui_argv, which | |
484 * will later be passed to gtk_init_check() */ | |
485 gui_argv[gui_argc++] = argv[i]; | |
486 } | |
487 else | |
488 { | |
489 char *value = NULL; | |
490 | |
491 /* Extract the option's value if there is one. | |
492 * Accept both "--foo bar" and "--foo=bar" style. */ | |
493 if (option->flags & ARG_HAS_VALUE) | |
494 { | |
495 if (argv[i][len] == '=') | |
496 value = &argv[i][len + 1]; | |
497 else if (i + 1 < *argc && strcmp(argv[i + 1], "--") != 0) | |
498 value = argv[i + 1]; | |
499 } | |
500 | |
501 /* Check for options handled by Vim itself */ | |
502 switch (option->flags & ARG_INDEX_MASK) | |
503 { | |
504 case ARG_REVERSE: | |
505 found_reverse_arg = TRUE; | |
506 break; | |
507 case ARG_NOREVERSE: | |
508 found_reverse_arg = FALSE; | |
509 break; | |
510 case ARG_FONT: | |
511 font_argument = value; | |
512 break; | |
513 case ARG_GEOMETRY: | |
514 if (value != NULL) | |
515 gui.geom = vim_strsave((char_u *)value); | |
516 break; | |
517 case ARG_BACKGROUND: | |
518 background_argument = value; | |
519 break; | |
520 case ARG_FOREGROUND: | |
521 foreground_argument = value; | |
522 break; | |
523 case ARG_ICONIC: | |
524 found_iconic_arg = TRUE; | |
525 break; | |
526 case ARG_ROLE: | |
527 role_argument = value; /* used later in gui_mch_open() */ | |
528 break; | |
529 #ifdef FEAT_NETBEANS_INTG | |
530 case ARG_NETBEANS: | |
531 gui.dofork = FALSE; /* don't fork() when starting GUI */ | |
532 netbeansArg = argv[i]; | |
533 break; | |
534 #endif | |
535 default: | |
536 break; | |
537 } | |
538 } | |
539 | |
540 /* These arguments make gnome_program_init() print a message and exit. | |
9836
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
541 * Must start the GUI for this, otherwise ":gui" will exit later! |
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
542 * Only when the GUI can start. */ |
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
543 if ((option->flags & ARG_NEEDS_GUI) |
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
544 && gui_mch_early_init_check(FALSE) == OK) |
7 | 545 gui.starting = TRUE; |
546 | |
547 if (option->flags & ARG_KEEP) | |
548 ++i; | |
549 else | |
550 { | |
551 /* Remove the flag from the argument vector. */ | |
552 if (--*argc > i) | |
553 { | |
554 int n_strip = 1; | |
555 | |
556 /* Move the argument's value as well, if there is one. */ | |
557 if ((option->flags & ARG_HAS_VALUE) | |
558 && argv[i][len] != '=' | |
559 && strcmp(argv[i + 1], "--") != 0) | |
560 { | |
561 ++n_strip; | |
562 --*argc; | |
563 if (option->flags & ARG_FOR_GTK) | |
564 gui_argv[gui_argc++] = argv[i + 1]; | |
565 } | |
566 | |
567 if (*argc > i) | |
568 mch_memmove(&argv[i], &argv[i + n_strip], | |
569 (*argc - i) * sizeof(char *)); | |
570 } | |
571 argv[*argc] = NULL; | |
572 } | |
573 } | |
574 | |
575 gui_argv[gui_argc] = NULL; | |
576 } | |
577 | |
359 | 578 #if defined(EXITFREE) || defined(PROTO) |
579 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
580 gui_mch_free_all(void) |
359 | 581 { |
582 vim_free(gui_argv); | |
1898 | 583 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) |
584 vim_free(abs_restart_command); | |
585 #endif | |
359 | 586 } |
587 #endif | |
588 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
589 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 590 /* |
591 * This should be maybe completely removed. | |
592 * Doesn't seem possible, since check_copy_area() relies on | |
593 * this information. --danielk | |
594 */ | |
595 static gint | |
1884 | 596 visibility_event(GtkWidget *widget UNUSED, |
597 GdkEventVisibility *event, | |
598 gpointer data UNUSED) | |
7 | 599 { |
600 gui.visibility = event->state; | |
601 /* | |
602 * When we do an gdk_window_copy_area(), and the window is partially | |
603 * obscured, we want to receive an event to tell us whether it worked | |
604 * or not. | |
605 */ | |
606 if (gui.text_gc != NULL) | |
607 gdk_gc_set_exposures(gui.text_gc, | |
608 gui.visibility != GDK_VISIBILITY_UNOBSCURED); | |
609 return FALSE; | |
610 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
611 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 612 |
613 /* | |
614 * Redraw the corresponding portions of the screen. | |
615 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
616 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
617 static gboolean is_key_pressed = FALSE; |
8412
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
618 static gboolean blink_mode = TRUE; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
619 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
620 static gboolean gui_gtk_is_blink_on(void); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
621 static void gui_gtk_window_clear(GdkWindow *win); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
622 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
623 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
624 gui_gtk3_redraw(int x, int y, int width, int height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
625 { |
10920
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
626 /* Range checks are left to gui_redraw_block() */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
627 gui_redraw_block(Y_2_ROW(y), X_2_COL(x), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
628 Y_2_ROW(y + height - 1), X_2_COL(x + width - 1), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
629 GUI_MON_NOCLEAR); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
630 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
631 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
632 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
633 gui_gtk3_update_cursor(cairo_t *cr) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
634 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
635 if (gui.row == gui.cursor_row) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
636 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
637 gui.by_signal = TRUE; |
8495
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
638 if (State & CMDLINE) |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
639 gui_update_cursor(TRUE, FALSE); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
640 else |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
641 gui_update_cursor(TRUE, TRUE); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
642 gui.by_signal = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
643 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
644 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
645 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
646 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
647 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
648 gui_gtk3_should_draw_cursor(void) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
649 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
650 unsigned int cond = 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
651 cond |= gui_gtk_is_blink_on(); |
8510
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
652 if (gui.cursor_col >= gui.col) |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
653 cond |= is_key_pressed; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
654 cond |= gui.in_focus == FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
655 return cond; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
656 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
657 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
658 static gboolean |
9232
a64e2a624fbe
commit https://github.com/vim/vim/commit/8e31fd52ec8be6ef1dc600b637d5f099d55e1715
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
659 draw_event(GtkWidget *widget UNUSED, |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
660 cairo_t *cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
661 gpointer user_data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
662 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
663 /* Skip this when the GUI isn't set up yet, will redraw later. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
664 if (gui.starting) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
665 return FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
666 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
667 out_flush(); /* make sure all output has been processed */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
668 /* for GTK+ 3, may induce other draw events. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
669 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
670 cairo_set_source_surface(cr, gui.surface, 0, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
671 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
672 /* Draw the window without the cursor. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
673 gui.by_signal = TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
674 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
675 cairo_rectangle_list_t *list = NULL; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
676 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
677 list = cairo_copy_clip_rectangle_list(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
678 if (list->status != CAIRO_STATUS_CLIP_NOT_REPRESENTABLE) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
679 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
680 int i; |
10920
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
681 |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
682 /* First clear all the blocks and then redraw them. Just in case |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
683 * some blocks overlap. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
684 for (i = 0; i < list->num_rectangles; i++) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
685 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
686 const cairo_rectangle_t rect = list->rectangles[i]; |
9232
a64e2a624fbe
commit https://github.com/vim/vim/commit/8e31fd52ec8be6ef1dc600b637d5f099d55e1715
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
687 |
10920
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
688 gui_mch_clear_block(Y_2_ROW((int)rect.y), 0, |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
689 Y_2_ROW((int)(rect.y + rect.height)) - 1, Columns - 1); |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
690 } |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
691 |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
692 for (i = 0; i < list->num_rectangles; i++) |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
693 { |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
694 const cairo_rectangle_t rect = list->rectangles[i]; |
9232
a64e2a624fbe
commit https://github.com/vim/vim/commit/8e31fd52ec8be6ef1dc600b637d5f099d55e1715
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
695 |
8412
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
696 if (blink_mode) |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
697 gui_gtk3_redraw(rect.x, rect.y, rect.width, rect.height); |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
698 else |
8510
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
699 { |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
700 if (get_real_state() & VISUAL) |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
701 gui_gtk3_redraw(rect.x, rect.y, |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
702 rect.width, rect.height); |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
703 else |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
704 gui_redraw(rect.x, rect.y, rect.width, rect.height); |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
705 } |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
706 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
707 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
708 cairo_rectangle_list_destroy(list); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
709 |
8510
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
710 if (get_real_state() & VISUAL) |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
711 { |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
712 if (gui.cursor_row == gui.row && gui.cursor_col >= gui.col) |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
713 gui_update_cursor(TRUE, TRUE); |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
714 } |
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
715 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
716 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
717 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
718 gui.by_signal = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
719 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
720 /* Add the cursor to the window if necessary.*/ |
8510
9f5bd031530d
commit https://github.com/vim/vim/commit/b4ebf9ae3b93d082ab3b9f4aab2f6729f77fa46a
Christian Brabandt <cb@256bit.org>
parents:
8495
diff
changeset
|
721 if (gui_gtk3_should_draw_cursor() && blink_mode) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
722 gui_gtk3_update_cursor(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
723 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
724 return FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
725 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
726 #else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 727 static gint |
1884 | 728 expose_event(GtkWidget *widget UNUSED, |
729 GdkEventExpose *event, | |
730 gpointer data UNUSED) | |
7 | 731 { |
732 /* Skip this when the GUI isn't set up yet, will redraw later. */ | |
733 if (gui.starting) | |
734 return FALSE; | |
735 | |
736 out_flush(); /* make sure all output has been processed */ | |
737 gui_redraw(event->area.x, event->area.y, | |
738 event->area.width, event->area.height); | |
739 | |
740 /* Clear the border areas if needed */ | |
741 if (event->area.x < FILL_X(0)) | |
742 gdk_window_clear_area(gui.drawarea->window, 0, 0, FILL_X(0), 0); | |
743 if (event->area.y < FILL_Y(0)) | |
744 gdk_window_clear_area(gui.drawarea->window, 0, 0, 0, FILL_Y(0)); | |
745 if (event->area.x > FILL_X(Columns)) | |
746 gdk_window_clear_area(gui.drawarea->window, | |
747 FILL_X((int)Columns), 0, 0, 0); | |
748 if (event->area.y > FILL_Y(Rows)) | |
749 gdk_window_clear_area(gui.drawarea->window, 0, FILL_Y((int)Rows), 0, 0); | |
750 | |
751 return FALSE; | |
752 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
753 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 754 |
755 #ifdef FEAT_CLIENTSERVER | |
756 /* | |
757 * Handle changes to the "Comm" property | |
758 */ | |
759 static gint | |
1884 | 760 property_event(GtkWidget *widget, |
761 GdkEventProperty *event, | |
762 gpointer data UNUSED) | |
7 | 763 { |
764 if (event->type == GDK_PROPERTY_NOTIFY | |
765 && event->state == (int)GDK_PROPERTY_NEW_VALUE | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
766 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
767 && GDK_WINDOW_XID(event->window) == commWindow |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
768 # else |
7 | 769 && GDK_WINDOW_XWINDOW(event->window) == commWindow |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
770 # endif |
7 | 771 && GET_X_ATOM(event->atom) == commProperty) |
772 { | |
773 XEvent xev; | |
774 | |
775 /* Translate to XLib */ | |
776 xev.xproperty.type = PropertyNotify; | |
777 xev.xproperty.atom = commProperty; | |
778 xev.xproperty.window = commWindow; | |
779 xev.xproperty.state = PropertyNewValue; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
780 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
781 serverEventProc(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(widget)), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
782 &xev, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
783 # else |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
784 serverEventProc(GDK_WINDOW_XDISPLAY(widget->window), &xev, 0); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
785 # endif |
7 | 786 } |
787 return FALSE; | |
788 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
789 #endif /* defined(FEAT_CLIENTSERVER) */ |
7 | 790 |
791 | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
792 #if GTK_CHECK_VERSION(3,0,0) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
793 typedef gboolean timeout_cb_type; |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
794 #else |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
795 typedef gint timeout_cb_type; |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
796 #endif |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
797 |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
798 /* |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
799 * Start a timer that will invoke the specified callback. |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
800 * Returns the ID of the timer. |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
801 */ |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
802 static guint |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
803 timeout_add(int time, timeout_cb_type (*callback)(gpointer), int *flagp) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
804 { |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
805 #if GTK_CHECK_VERSION(3,0,0) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
806 return g_timeout_add((guint)time, (GSourceFunc)callback, flagp); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
807 #else |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
808 return gtk_timeout_add((guint32)time, (GtkFunction)callback, flagp); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
809 #endif |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
810 } |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
811 |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
812 static void |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
813 timeout_remove(guint timer) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
814 { |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
815 #if GTK_CHECK_VERSION(3,0,0) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
816 g_source_remove(timer); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
817 #else |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
818 gtk_timeout_remove(timer); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
819 #endif |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
820 } |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
821 |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
822 |
7 | 823 /**************************************************************************** |
824 * Focus handlers: | |
825 */ | |
826 | |
827 | |
828 /* | |
829 * This is a simple state machine: | |
830 * BLINK_NONE not blinking at all | |
831 * BLINK_OFF blinking, cursor is not shown | |
832 * BLINK_ON blinking, cursor is shown | |
833 */ | |
834 | |
835 #define BLINK_NONE 0 | |
836 #define BLINK_OFF 1 | |
837 #define BLINK_ON 2 | |
838 | |
839 static int blink_state = BLINK_NONE; | |
840 static long_u blink_waittime = 700; | |
841 static long_u blink_ontime = 400; | |
842 static long_u blink_offtime = 250; | |
843 static guint blink_timer = 0; | |
844 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
845 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
846 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
847 gui_gtk_is_blink_on(void) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
848 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
849 return blink_state == BLINK_ON; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
850 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
851 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
852 |
9213
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
853 int |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
854 gui_mch_is_blinking(void) |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
855 { |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
856 return blink_state != BLINK_NONE; |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
857 } |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
858 |
9428
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
859 int |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
860 gui_mch_is_blink_off(void) |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
861 { |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
862 return blink_state == BLINK_OFF; |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
863 } |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9252
diff
changeset
|
864 |
7 | 865 void |
866 gui_mch_set_blinking(long waittime, long on, long off) | |
867 { | |
8412
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
868 #if GTK_CHECK_VERSION(3,0,0) |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
869 if (waittime == 0 || on == 0 || off == 0) |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
870 { |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
871 blink_mode = FALSE; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
872 |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
873 blink_waittime = 700; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
874 blink_ontime = 400; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
875 blink_offtime = 250; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
876 } |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
877 else |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
878 { |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
879 blink_mode = TRUE; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
880 |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
881 blink_waittime = waittime; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
882 blink_ontime = on; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
883 blink_offtime = off; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
884 } |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
885 #else |
7 | 886 blink_waittime = waittime; |
887 blink_ontime = on; | |
888 blink_offtime = off; | |
8412
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
889 #endif |
7 | 890 } |
891 | |
892 /* | |
893 * Stop the cursor blinking. Show the cursor if it wasn't shown. | |
894 */ | |
895 void | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
896 gui_mch_stop_blink(int may_call_gui_update_cursor) |
7 | 897 { |
898 if (blink_timer) | |
899 { | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
900 timeout_remove(blink_timer); |
7 | 901 blink_timer = 0; |
902 } | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
903 if (blink_state == BLINK_OFF && may_call_gui_update_cursor) |
9489
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
904 { |
7 | 905 gui_update_cursor(TRUE, FALSE); |
9489
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
906 gui_mch_flush(); |
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
907 } |
7 | 908 blink_state = BLINK_NONE; |
909 } | |
910 | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
911 static timeout_cb_type |
1884 | 912 blink_cb(gpointer data UNUSED) |
7 | 913 { |
914 if (blink_state == BLINK_ON) | |
915 { | |
916 gui_undraw_cursor(); | |
917 blink_state = BLINK_OFF; | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
918 blink_timer = timeout_add(blink_offtime, blink_cb, NULL); |
7 | 919 } |
920 else | |
921 { | |
922 gui_update_cursor(TRUE, FALSE); | |
923 blink_state = BLINK_ON; | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
924 blink_timer = timeout_add(blink_ontime, blink_cb, NULL); |
7 | 925 } |
9489
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
926 gui_mch_flush(); |
7 | 927 |
928 return FALSE; /* don't happen again */ | |
929 } | |
930 | |
931 /* | |
932 * Start the cursor blinking. If it was already blinking, this restarts the | |
933 * waiting time and shows the cursor. | |
934 */ | |
935 void | |
936 gui_mch_start_blink(void) | |
937 { | |
938 if (blink_timer) | |
5818 | 939 { |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
940 timeout_remove(blink_timer); |
5818 | 941 blink_timer = 0; |
942 } | |
7 | 943 /* Only switch blinking on if none of the times is zero */ |
944 if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus) | |
945 { | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
946 blink_timer = timeout_add(blink_waittime, blink_cb, NULL); |
7 | 947 blink_state = BLINK_ON; |
948 gui_update_cursor(TRUE, FALSE); | |
9489
c5f40fc2e3e0
commit https://github.com/vim/vim/commit/da3a77d9ec28407b8fa2aa014e76944d0a525662
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
949 gui_mch_flush(); |
7 | 950 } |
951 } | |
952 | |
953 static gint | |
1884 | 954 enter_notify_event(GtkWidget *widget UNUSED, |
955 GdkEventCrossing *event UNUSED, | |
956 gpointer data UNUSED) | |
7 | 957 { |
958 if (blink_state == BLINK_NONE) | |
959 gui_mch_start_blink(); | |
960 | |
961 /* make sure keyboard input goes there */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
962 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
963 if (gtk_socket_id == 0 || !gtk_widget_has_focus(gui.drawarea)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
964 #else |
7 | 965 if (gtk_socket_id == 0 || !GTK_WIDGET_HAS_FOCUS(gui.drawarea)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
966 #endif |
7 | 967 gtk_widget_grab_focus(gui.drawarea); |
968 | |
969 return FALSE; | |
970 } | |
971 | |
972 static gint | |
1884 | 973 leave_notify_event(GtkWidget *widget UNUSED, |
974 GdkEventCrossing *event UNUSED, | |
975 gpointer data UNUSED) | |
7 | 976 { |
977 if (blink_state != BLINK_NONE) | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
978 gui_mch_stop_blink(TRUE); |
7 | 979 |
980 return FALSE; | |
981 } | |
982 | |
983 static gint | |
1884 | 984 focus_in_event(GtkWidget *widget, |
985 GdkEventFocus *event UNUSED, | |
986 gpointer data UNUSED) | |
7 | 987 { |
988 gui_focus_change(TRUE); | |
989 | |
990 if (blink_state == BLINK_NONE) | |
991 gui_mch_start_blink(); | |
992 | |
1380 | 993 /* make sure keyboard input goes to the draw area (if this is focus for a |
994 * window) */ | |
791 | 995 if (widget != gui.drawarea) |
856 | 996 gtk_widget_grab_focus(gui.drawarea); |
7 | 997 |
998 return TRUE; | |
999 } | |
1000 | |
1001 static gint | |
1884 | 1002 focus_out_event(GtkWidget *widget UNUSED, |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2301
diff
changeset
|
1003 GdkEventFocus *event UNUSED, |
1884 | 1004 gpointer data UNUSED) |
7 | 1005 { |
1006 gui_focus_change(FALSE); | |
1007 | |
1008 if (blink_state != BLINK_NONE) | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
1009 gui_mch_stop_blink(TRUE); |
7 | 1010 |
1011 return TRUE; | |
1012 } | |
1013 | |
1014 | |
1015 /* | |
1016 * Translate a GDK key value to UTF-8 independently of the current locale. | |
1017 * The output is written to string, which must have room for at least 6 bytes | |
1018 * plus the NUL terminator. Returns the length in bytes. | |
1019 * | |
1020 * This function is used in the GTK+ 2 GUI only. The GTK+ 1 code makes use | |
1021 * of GdkEventKey::string instead. But event->string is evil; see here why: | |
1022 * http://developer.gnome.org/doc/API/2.0/gdk/gdk-Event-Structures.html#GdkEventKey | |
1023 */ | |
1024 static int | |
1025 keyval_to_string(unsigned int keyval, unsigned int state, char_u *string) | |
1026 { | |
1027 int len; | |
1028 guint32 uc; | |
1029 | |
1030 uc = gdk_keyval_to_unicode(keyval); | |
1031 if (uc != 0) | |
1032 { | |
1033 /* Check for CTRL-foo */ | |
1034 if ((state & GDK_CONTROL_MASK) && uc >= 0x20 && uc < 0x80) | |
1035 { | |
1036 /* These mappings look arbitrary at the first glance, but in fact | |
1037 * resemble quite exactly the behaviour of the GTK+ 1.2 GUI on my | |
1038 * machine. The only difference is BS vs. DEL for CTRL-8 (makes | |
1039 * more sense and is consistent with usual terminal behaviour). */ | |
1040 if (uc >= '@') | |
1041 string[0] = uc & 0x1F; | |
1042 else if (uc == '2') | |
1043 string[0] = NUL; | |
1044 else if (uc >= '3' && uc <= '7') | |
1045 string[0] = uc ^ 0x28; | |
1046 else if (uc == '8') | |
1047 string[0] = BS; | |
1048 else if (uc == '?') | |
1049 string[0] = DEL; | |
1050 else | |
1051 string[0] = uc; | |
1052 len = 1; | |
1053 } | |
1054 else | |
1055 { | |
1056 /* Translate a normal key to UTF-8. This doesn't work for dead | |
1057 * keys of course, you _have_ to use an input method for that. */ | |
1058 len = utf_char2bytes((int)uc, string); | |
1059 } | |
1060 } | |
1061 else | |
1062 { | |
1063 /* Translate keys which are represented by ASCII control codes in Vim. | |
1064 * There are only a few of those; most control keys are translated to | |
1065 * special terminal-like control sequences. */ | |
1066 len = 1; | |
1067 switch (keyval) | |
1068 { | |
1069 case GDK_Tab: case GDK_KP_Tab: case GDK_ISO_Left_Tab: | |
1070 string[0] = TAB; | |
1071 break; | |
1072 case GDK_Linefeed: | |
1073 string[0] = NL; | |
1074 break; | |
1075 case GDK_Return: case GDK_ISO_Enter: case GDK_3270_Enter: | |
1076 string[0] = CAR; | |
1077 break; | |
1078 case GDK_Escape: | |
1079 string[0] = ESC; | |
1080 break; | |
1081 default: | |
1082 len = 0; | |
1083 break; | |
1084 } | |
1085 } | |
1086 string[len] = NUL; | |
1087 | |
1088 return len; | |
1089 } | |
1090 | |
179 | 1091 static int |
1092 modifiers_gdk2vim(guint state) | |
1093 { | |
1094 int modifiers = 0; | |
1095 | |
1096 if (state & GDK_SHIFT_MASK) | |
1097 modifiers |= MOD_MASK_SHIFT; | |
1098 if (state & GDK_CONTROL_MASK) | |
1099 modifiers |= MOD_MASK_CTRL; | |
1100 if (state & GDK_MOD1_MASK) | |
1101 modifiers |= MOD_MASK_ALT; | |
2550
7c1f73452ea6
Fix #ifdef for GDK_SUPER_MASK.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
1102 #if GTK_CHECK_VERSION(2,10,0) |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1103 if (state & GDK_SUPER_MASK) |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1104 modifiers |= MOD_MASK_META; |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1105 #endif |
179 | 1106 if (state & GDK_MOD4_MASK) |
1107 modifiers |= MOD_MASK_META; | |
1108 | |
1109 return modifiers; | |
1110 } | |
1111 | |
1112 static int | |
1113 modifiers_gdk2mouse(guint state) | |
1114 { | |
1115 int modifiers = 0; | |
1116 | |
1117 if (state & GDK_SHIFT_MASK) | |
1118 modifiers |= MOUSE_SHIFT; | |
1119 if (state & GDK_CONTROL_MASK) | |
1120 modifiers |= MOUSE_CTRL; | |
1121 if (state & GDK_MOD1_MASK) | |
1122 modifiers |= MOUSE_ALT; | |
1123 | |
1124 return modifiers; | |
1125 } | |
1126 | |
7 | 1127 /* |
1128 * Main keyboard handler: | |
1129 */ | |
1130 static gint | |
1884 | 1131 key_press_event(GtkWidget *widget UNUSED, |
1132 GdkEventKey *event, | |
1133 gpointer data UNUSED) | |
7 | 1134 { |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1135 /* For GTK+ 2 we know for sure how large the string might get. |
7 | 1136 * (That is, up to 6 bytes + NUL + CSI escapes + safety measure.) */ |
1137 char_u string[32], string2[32]; | |
1138 guint key_sym; | |
1139 int len; | |
1140 int i; | |
1141 int modifiers; | |
1142 int key; | |
1143 guint state; | |
1144 char_u *s, *d; | |
1145 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1146 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1147 is_key_pressed = TRUE; |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
1148 gui_mch_stop_blink(TRUE); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1149 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1150 |
2923 | 1151 gui.event_time = event->time; |
7 | 1152 key_sym = event->keyval; |
1153 state = event->state; | |
1154 | |
1155 #ifdef FEAT_XIM | |
1156 if (xim_queue_key_press_event(event, TRUE)) | |
1157 return TRUE; | |
1158 #endif | |
1159 | |
1160 #ifdef FEAT_HANGULIN | |
1161 if (key_sym == GDK_space && (state & GDK_SHIFT_MASK)) | |
1162 { | |
1163 hangul_input_state_toggle(); | |
1164 return TRUE; | |
1165 } | |
1166 #endif | |
1167 | |
1168 #ifdef SunXK_F36 | |
1169 /* | |
1170 * These keys have bogus lookup strings, and trapping them here is | |
1171 * easier than trying to XRebindKeysym() on them with every possible | |
1172 * combination of modifiers. | |
1173 */ | |
1174 if (key_sym == SunXK_F36 || key_sym == SunXK_F37) | |
1175 len = 0; | |
1176 else | |
1177 #endif | |
1178 { | |
1179 len = keyval_to_string(key_sym, state, string2); | |
1180 | |
1181 /* Careful: convert_input() doesn't handle the NUL character. | |
1182 * No need to convert pure ASCII anyway, thus the len > 1 check. */ | |
1183 if (len > 1 && input_conv.vc_type != CONV_NONE) | |
1184 len = convert_input(string2, len, sizeof(string2)); | |
1185 | |
1186 s = string2; | |
1187 d = string; | |
1188 for (i = 0; i < len; ++i) | |
1189 { | |
1190 *d++ = s[i]; | |
1191 if (d[-1] == CSI && d + 2 < string + sizeof(string)) | |
1192 { | |
1193 /* Turn CSI into K_CSI. */ | |
1194 *d++ = KS_EXTRA; | |
1195 *d++ = (int)KE_CSI; | |
1196 } | |
1197 } | |
1198 len = d - string; | |
1199 } | |
1200 | |
1201 /* Shift-Tab results in Left_Tab, but we want <S-Tab> */ | |
1202 if (key_sym == GDK_ISO_Left_Tab) | |
1203 { | |
1204 key_sym = GDK_Tab; | |
1205 state |= GDK_SHIFT_MASK; | |
1206 } | |
1207 | |
1208 #ifdef FEAT_MENU | |
1209 /* If there is a menu and 'wak' is "yes", or 'wak' is "menu" and the key | |
1210 * is a menu shortcut, we ignore everything with the ALT modifier. */ | |
1211 if ((state & GDK_MOD1_MASK) | |
1212 && gui.menu_is_active | |
1213 && (*p_wak == 'y' | |
1214 || (*p_wak == 'm' | |
1215 && len == 1 | |
1216 && gui_is_menu_shortcut(string[0])))) | |
1217 /* For GTK2 we return false to signify that we haven't handled the | |
1218 * keypress, so that gtk will handle the mnemonic or accelerator. */ | |
1219 return FALSE; | |
1220 #endif | |
1221 | |
1222 /* Check for Alt/Meta key (Mod1Mask), but not for a BS, DEL or character | |
1223 * that already has the 8th bit set. | |
1224 * Don't do this for <S-M-Tab>, that should become K_S_TAB with ALT. | |
1225 * Don't do this for double-byte encodings, it turns the char into a lead | |
1226 * byte. */ | |
1227 if (len == 1 | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1228 && ((state & GDK_MOD1_MASK) |
2571
42bdbc2bbb59
Fix #ifdef for GDK_SUPER_MASK. (Stephan Schulz)
Bram Moolenaar <bram@vim.org>
parents:
2550
diff
changeset
|
1229 #if GTK_CHECK_VERSION(2,10,0) |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1230 || (state & GDK_SUPER_MASK) |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1231 #endif |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1232 ) |
7 | 1233 && !(key_sym == GDK_BackSpace || key_sym == GDK_Delete) |
1234 && (string[0] & 0x80) == 0 | |
1235 && !(key_sym == GDK_Tab && (state & GDK_SHIFT_MASK)) | |
1236 && !enc_dbcs | |
1237 ) | |
1238 { | |
1239 string[0] |= 0x80; | |
1240 state &= ~GDK_MOD1_MASK; /* don't use it again */ | |
1241 if (enc_utf8) /* convert to utf-8 */ | |
1242 { | |
1243 string[1] = string[0] & 0xbf; | |
1244 string[0] = ((unsigned)string[0] >> 6) + 0xc0; | |
1245 if (string[1] == CSI) | |
1246 { | |
1247 string[2] = KS_EXTRA; | |
1248 string[3] = (int)KE_CSI; | |
1249 len = 4; | |
1250 } | |
1251 else | |
1252 len = 2; | |
1253 } | |
1254 } | |
1255 | |
1256 /* Check for special keys. Also do this when len == 1 (key has an ASCII | |
1257 * value) to detect backspace, delete and keypad keys. */ | |
1258 if (len == 0 || len == 1) | |
1259 { | |
1260 for (i = 0; special_keys[i].key_sym != 0; i++) | |
1261 { | |
1262 if (special_keys[i].key_sym == key_sym) | |
1263 { | |
1264 string[0] = CSI; | |
1265 string[1] = special_keys[i].code0; | |
1266 string[2] = special_keys[i].code1; | |
1267 len = -3; | |
1268 break; | |
1269 } | |
1270 } | |
1271 } | |
1272 | |
1273 if (len == 0) /* Unrecognized key */ | |
1274 return TRUE; | |
1275 | |
1276 /* Special keys (and a few others) may have modifiers. Also when using a | |
1277 * double-byte encoding (can't set the 8th bit). */ | |
1278 if (len == -3 || key_sym == GDK_space || key_sym == GDK_Tab | |
1279 || key_sym == GDK_Return || key_sym == GDK_Linefeed | |
1280 || key_sym == GDK_Escape || key_sym == GDK_KP_Tab | |
1281 || key_sym == GDK_ISO_Enter || key_sym == GDK_3270_Enter | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1282 || (enc_dbcs && len == 1 && ((state & GDK_MOD1_MASK) |
2571
42bdbc2bbb59
Fix #ifdef for GDK_SUPER_MASK. (Stephan Schulz)
Bram Moolenaar <bram@vim.org>
parents:
2550
diff
changeset
|
1283 #if GTK_CHECK_VERSION(2,10,0) |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1284 || (state & GDK_SUPER_MASK) |
7 | 1285 #endif |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1286 ))) |
7 | 1287 { |
179 | 1288 modifiers = modifiers_gdk2vim(state); |
7 | 1289 |
1290 /* | |
1291 * For some keys a shift modifier is translated into another key | |
1292 * code. | |
1293 */ | |
1294 if (len == -3) | |
1295 key = TO_SPECIAL(string[1], string[2]); | |
1296 else | |
1297 key = string[0]; | |
1298 | |
1299 key = simplify_key(key, &modifiers); | |
1300 if (key == CSI) | |
1301 key = K_CSI; | |
1302 if (IS_SPECIAL(key)) | |
1303 { | |
1304 string[0] = CSI; | |
1305 string[1] = K_SECOND(key); | |
1306 string[2] = K_THIRD(key); | |
1307 len = 3; | |
1308 } | |
1309 else | |
1310 { | |
1311 string[0] = key; | |
1312 len = 1; | |
1313 } | |
1314 | |
1315 if (modifiers != 0) | |
1316 { | |
1317 string2[0] = CSI; | |
1318 string2[1] = KS_MODIFIER; | |
1319 string2[2] = modifiers; | |
1320 add_to_input_buf(string2, 3); | |
1321 } | |
1322 } | |
1323 | |
1324 if (len == 1 && ((string[0] == Ctrl_C && ctrl_c_interrupts) | |
1325 || (string[0] == intr_char && intr_char != Ctrl_C))) | |
1326 { | |
1327 trash_input_buf(); | |
1328 got_int = TRUE; | |
1329 } | |
1330 | |
1331 add_to_input_buf(string, len); | |
1332 | |
1333 /* blank out the pointer if necessary */ | |
1334 if (p_mh) | |
1335 gui_mch_mousehide(TRUE); | |
1336 | |
1337 return TRUE; | |
1338 } | |
1339 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1340 #if defined(FEAT_XIM) || GTK_CHECK_VERSION(3,0,0) |
7 | 1341 static gboolean |
1884 | 1342 key_release_event(GtkWidget *widget UNUSED, |
1343 GdkEventKey *event, | |
1344 gpointer data UNUSED) | |
7 | 1345 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1346 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1347 is_key_pressed = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1348 gui_mch_start_blink(); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1349 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1350 # if defined(FEAT_XIM) |
2923 | 1351 gui.event_time = event->time; |
7 | 1352 /* |
1353 * GTK+ 2 input methods may do fancy stuff on key release events too. | |
1354 * With the default IM for instance, you can enter any UCS code point | |
1355 * by holding down CTRL-SHIFT and typing hexadecimal digits. | |
1356 */ | |
1357 return xim_queue_key_press_event(event, FALSE); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1358 # else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1359 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1360 # endif |
7 | 1361 } |
1362 #endif | |
1363 | |
1364 | |
1365 /**************************************************************************** | |
1366 * Selection handlers: | |
1367 */ | |
1368 | |
1369 static gint | |
1884 | 1370 selection_clear_event(GtkWidget *widget UNUSED, |
7 | 1371 GdkEventSelection *event, |
1884 | 1372 gpointer user_data UNUSED) |
7 | 1373 { |
1374 if (event->selection == clip_plus.gtk_sel_atom) | |
1375 clip_lose_selection(&clip_plus); | |
1376 else | |
1377 clip_lose_selection(&clip_star); | |
1378 | |
1379 return TRUE; | |
1380 } | |
1381 | |
1382 #define RS_NONE 0 /* selection_received_cb() not called yet */ | |
1383 #define RS_OK 1 /* selection_received_cb() called and OK */ | |
1384 #define RS_FAIL 2 /* selection_received_cb() called and failed */ | |
1385 static int received_selection = RS_NONE; | |
1386 | |
1387 static void | |
1884 | 1388 selection_received_cb(GtkWidget *widget UNUSED, |
7 | 1389 GtkSelectionData *data, |
1884 | 1390 guint time_ UNUSED, |
1391 gpointer user_data UNUSED) | |
7 | 1392 { |
1393 VimClipboard *cbd; | |
1394 char_u *text; | |
1395 char_u *tmpbuf = NULL; | |
1396 guchar *tmpbuf_utf8 = NULL; | |
1397 int len; | |
2896 | 1398 int motion_type = MAUTO; |
7 | 1399 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1400 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1401 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
|
1402 #else |
7 | 1403 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
|
1404 #endif |
7 | 1405 cbd = &clip_plus; |
1406 else | |
1407 cbd = &clip_star; | |
1408 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1409 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1410 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
|
1411 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
|
1412 #else |
7 | 1413 text = (char_u *)data->data; |
1414 len = data->length; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1415 #endif |
7 | 1416 |
1417 if (text == NULL || len <= 0) | |
1418 { | |
1419 received_selection = RS_FAIL; | |
1420 /* clip_free_selection(cbd); ??? */ | |
1421 | |
1422 return; | |
1423 } | |
1424 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1425 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1426 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
|
1427 #else |
7 | 1428 if (data->type == vim_atom) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1429 #endif |
7 | 1430 { |
1431 motion_type = *text++; | |
1432 --len; | |
1433 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1434 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1435 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
|
1436 #else |
7 | 1437 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
|
1438 #endif |
7 | 1439 { |
1440 char_u *enc; | |
1441 vimconv_T conv; | |
1442 | |
1443 motion_type = *text++; | |
1444 --len; | |
1445 | |
1446 enc = text; | |
1447 text += STRLEN(text) + 1; | |
1448 len -= text - enc; | |
1449 | |
1450 /* If the encoding of the text is different from 'encoding', attempt | |
1451 * converting it. */ | |
1452 conv.vc_type = CONV_NONE; | |
1453 convert_setup(&conv, enc, p_enc); | |
1454 if (conv.vc_type != CONV_NONE) | |
1455 { | |
1456 tmpbuf = string_convert(&conv, text, &len); | |
1457 if (tmpbuf != NULL) | |
1458 text = tmpbuf; | |
1459 convert_setup(&conv, NULL, NULL); | |
1460 } | |
1461 } | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1462 |
7 | 1463 /* gtk_selection_data_get_text() handles all the nasty details |
1464 * and targets and encodings etc. This rocks so hard. */ | |
1465 else | |
1466 { | |
1467 tmpbuf_utf8 = gtk_selection_data_get_text(data); | |
1468 if (tmpbuf_utf8 != NULL) | |
1469 { | |
1470 len = STRLEN(tmpbuf_utf8); | |
1471 if (input_conv.vc_type != CONV_NONE) | |
1472 { | |
1473 tmpbuf = string_convert(&input_conv, tmpbuf_utf8, &len); | |
1474 if (tmpbuf != NULL) | |
1475 text = tmpbuf; | |
1476 } | |
1477 else | |
1478 text = tmpbuf_utf8; | |
1479 } | |
1904 | 1480 else if (len >= 2 && text[0] == 0xff && text[1] == 0xfe) |
1481 { | |
1482 vimconv_T conv; | |
1483 | |
1484 /* UTF-16, we get this for HTML */ | |
1485 conv.vc_type = CONV_NONE; | |
1486 convert_setup_ext(&conv, (char_u *)"utf-16le", FALSE, p_enc, TRUE); | |
1487 | |
1488 if (conv.vc_type != CONV_NONE) | |
1489 { | |
1490 text += 2; | |
1491 len -= 2; | |
1492 tmpbuf = string_convert(&conv, text, &len); | |
1493 convert_setup(&conv, NULL, NULL); | |
1494 } | |
1495 if (tmpbuf != NULL) | |
1496 text = tmpbuf; | |
1497 } | |
7 | 1498 } |
1499 | |
4352 | 1500 /* Chop off any trailing NUL bytes. OpenOffice sends these. */ |
2183 | 1501 while (len > 0 && text[len - 1] == NUL) |
1502 --len; | |
1503 | |
7 | 1504 clip_yank_selection(motion_type, text, (long)len, cbd); |
1505 received_selection = RS_OK; | |
1506 vim_free(tmpbuf); | |
1507 g_free(tmpbuf_utf8); | |
1508 } | |
1509 | |
1510 /* | |
1511 * Prepare our selection data for passing it to the external selection | |
1512 * client. | |
1513 */ | |
1514 static void | |
1884 | 1515 selection_get_cb(GtkWidget *widget UNUSED, |
7 | 1516 GtkSelectionData *selection_data, |
1517 guint info, | |
1884 | 1518 guint time_ UNUSED, |
1519 gpointer user_data UNUSED) | |
7 | 1520 { |
1521 char_u *string; | |
1522 char_u *tmpbuf; | |
1523 long_u tmplen; | |
1524 int length; | |
1525 int motion_type; | |
1526 GdkAtom type; | |
1527 VimClipboard *cbd; | |
1528 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1529 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1530 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
|
1531 == clip_plus.gtk_sel_atom) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1532 #else |
7 | 1533 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
|
1534 #endif |
7 | 1535 cbd = &clip_plus; |
1536 else | |
1537 cbd = &clip_star; | |
1538 | |
1539 if (!cbd->owned) | |
1540 return; /* Shouldn't ever happen */ | |
1541 | |
1542 if (info != (guint)TARGET_STRING | |
1904 | 1543 && (!clip_html || info != (guint)TARGET_HTML) |
7 | 1544 && info != (guint)TARGET_UTF8_STRING |
1545 && info != (guint)TARGET_VIMENC | |
1546 && info != (guint)TARGET_VIM | |
1547 && info != (guint)TARGET_COMPOUND_TEXT | |
1548 && info != (guint)TARGET_TEXT) | |
1549 return; | |
1550 | |
1551 /* get the selection from the '*'/'+' register */ | |
1552 clip_get_selection(cbd); | |
1553 | |
1554 motion_type = clip_convert_selection(&string, &tmplen, cbd); | |
1555 if (motion_type < 0 || string == NULL) | |
1556 return; | |
1557 /* Due to int arguments we can't handle more than G_MAXINT. Also | |
1558 * reserve one extra byte for NUL or the motion type; just in case. | |
1559 * (Not that pasting 2G of text is ever going to work, but... ;-) */ | |
1560 length = MIN(tmplen, (long_u)(G_MAXINT - 1)); | |
1561 | |
1562 if (info == (guint)TARGET_VIM) | |
1563 { | |
1564 tmpbuf = alloc((unsigned)length + 1); | |
1565 if (tmpbuf != NULL) | |
1566 { | |
1567 tmpbuf[0] = motion_type; | |
1568 mch_memmove(tmpbuf + 1, string, (size_t)length); | |
1569 } | |
1570 /* For our own format, the first byte contains the motion type */ | |
1571 ++length; | |
1572 vim_free(string); | |
1573 string = tmpbuf; | |
1574 type = vim_atom; | |
1575 } | |
1576 | |
1904 | 1577 else if (info == (guint)TARGET_HTML) |
1578 { | |
1579 vimconv_T conv; | |
1580 | |
1581 /* Since we get utf-16, we probably should set it as well. */ | |
1582 conv.vc_type = CONV_NONE; | |
1583 convert_setup_ext(&conv, p_enc, TRUE, (char_u *)"utf-16le", FALSE); | |
1584 if (conv.vc_type != CONV_NONE) | |
1585 { | |
1586 tmpbuf = string_convert(&conv, string, &length); | |
1587 convert_setup(&conv, NULL, NULL); | |
1588 vim_free(string); | |
1589 string = tmpbuf; | |
1590 } | |
1591 | |
1592 /* Prepend the BOM: "fffe" */ | |
1593 if (string != NULL) | |
1594 { | |
1595 tmpbuf = alloc(length + 2); | |
1596 tmpbuf[0] = 0xff; | |
1597 tmpbuf[1] = 0xfe; | |
1598 mch_memmove(tmpbuf + 2, string, (size_t)length); | |
1599 vim_free(string); | |
1600 string = tmpbuf; | |
1601 length += 2; | |
1602 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1603 #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
|
1604 /* 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
|
1605 * overwritten by gtk_selection_data_set() that follows. */ |
1904 | 1606 selection_data->type = selection_data->target; |
1607 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
|
1608 #endif |
1904 | 1609 gtk_selection_data_set(selection_data, html_atom, 16, |
1610 string, length); | |
1611 vim_free(string); | |
1612 } | |
1613 return; | |
1614 } | |
7 | 1615 else if (info == (guint)TARGET_VIMENC) |
1616 { | |
1617 int l = STRLEN(p_enc); | |
1618 | |
1619 /* contents: motion_type 'encoding' NUL text */ | |
1620 tmpbuf = alloc((unsigned)length + l + 2); | |
1621 if (tmpbuf != NULL) | |
1622 { | |
1623 tmpbuf[0] = motion_type; | |
1624 STRCPY(tmpbuf + 1, p_enc); | |
1625 mch_memmove(tmpbuf + l + 2, string, (size_t)length); | |
1626 } | |
1627 length += l + 2; | |
1628 vim_free(string); | |
1629 string = tmpbuf; | |
1630 type = vimenc_atom; | |
1631 } | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1632 |
7 | 1633 /* gtk_selection_data_set_text() handles everything for us. This is |
1634 * so easy and simple and cool, it'd be insane not to use it. */ | |
1635 else | |
1636 { | |
1637 if (output_conv.vc_type != CONV_NONE) | |
1638 { | |
1639 tmpbuf = string_convert(&output_conv, string, &length); | |
1640 vim_free(string); | |
1641 if (tmpbuf == NULL) | |
1642 return; | |
1643 string = tmpbuf; | |
1644 } | |
1645 /* Validate the string to avoid runtime warnings */ | |
1646 if (g_utf8_validate((const char *)string, (gssize)length, NULL)) | |
1647 { | |
1648 gtk_selection_data_set_text(selection_data, | |
1649 (const char *)string, length); | |
1650 } | |
1651 vim_free(string); | |
1652 return; | |
1653 } | |
1654 | |
1655 if (string != NULL) | |
1656 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1657 #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
|
1658 /* 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
|
1659 * overwritten by gtk_selection_data_set() that follows. */ |
7 | 1660 selection_data->type = selection_data->target; |
1661 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
|
1662 #endif |
7 | 1663 gtk_selection_data_set(selection_data, type, 8, string, length); |
1664 vim_free(string); | |
1665 } | |
1666 } | |
1667 | |
1668 /* | |
3518 | 1669 * Check if the GUI can be started. Called before gvimrc is sourced and |
1670 * before fork(). | |
1671 * Return OK or FAIL. | |
1672 */ | |
1673 int | |
9836
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
1674 gui_mch_early_init_check(int give_message) |
3518 | 1675 { |
1676 char_u *p; | |
1677 | |
1678 /* Guess that when $DISPLAY isn't set the GUI can't start. */ | |
1679 p = mch_getenv((char_u *)"DISPLAY"); | |
1680 if (p == NULL || *p == NUL) | |
1681 { | |
1682 gui.dying = TRUE; | |
9836
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
1683 if (give_message) |
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
1684 EMSG(_((char *)e_opendisp)); |
3518 | 1685 return FAIL; |
1686 } | |
1687 return OK; | |
1688 } | |
1689 | |
1690 /* | |
1691 * Check if the GUI can be started. Called before gvimrc is sourced but after | |
1692 * fork(). | |
7 | 1693 * Return OK or FAIL. |
1694 */ | |
1695 int | |
1696 gui_mch_init_check(void) | |
1697 { | |
7679
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1698 #ifdef USE_GRESOURCE |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1699 static int res_registered = FALSE; |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1700 |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1701 if (!res_registered) |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1702 { |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1703 /* 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
|
1704 * 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
|
1705 res_registered = TRUE; |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1706 gui_gtk_register_resource(); |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1707 } |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1708 #endif |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1709 |
8851
1b38596644ba
commit https://github.com/vim/vim/commit/f80663f17b2f2499b45eb4467088704c8298c385
Christian Brabandt <cb@256bit.org>
parents:
8510
diff
changeset
|
1710 #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
|
1711 /* 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
|
1712 * 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
|
1713 gdk_set_allowed_backends ("x11"); |
1b38596644ba
commit https://github.com/vim/vim/commit/f80663f17b2f2499b45eb4467088704c8298c385
Christian Brabandt <cb@256bit.org>
parents:
8510
diff
changeset
|
1714 #endif |
1b38596644ba
commit https://github.com/vim/vim/commit/f80663f17b2f2499b45eb4467088704c8298c385
Christian Brabandt <cb@256bit.org>
parents:
8510
diff
changeset
|
1715 |
7 | 1716 #ifdef FEAT_GUI_GNOME |
1717 if (gtk_socket_id == 0) | |
1718 using_gnome = 1; | |
1719 #endif | |
1720 | |
4474 | 1721 /* This defaults to argv[0], but we want it to match the name of the |
1722 * shipped gvim.desktop so that Vim's windows can be associated with this | |
1723 * file. */ | |
1724 g_set_prgname("gvim"); | |
1725 | |
7 | 1726 /* Don't use gtk_init() or gnome_init(), it exits on failure. */ |
1727 if (!gtk_init_check(&gui_argc, &gui_argv)) | |
1728 { | |
1729 gui.dying = TRUE; | |
1666 | 1730 EMSG(_((char *)e_opendisp)); |
7 | 1731 return FAIL; |
1732 } | |
1733 | |
1734 return OK; | |
1735 } | |
1736 | |
1737 /**************************************************************************** | |
1738 * Mouse handling callbacks | |
1739 */ | |
1740 | |
1741 | |
1742 static guint mouse_click_timer = 0; | |
1743 static int mouse_timed_out = TRUE; | |
1744 | |
1745 /* | |
1746 * Timer used to recognize multiple clicks of the mouse button | |
1747 */ | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
1748 static timeout_cb_type |
7 | 1749 mouse_click_timer_cb(gpointer data) |
1750 { | |
1751 /* we don't use this information currently */ | |
1752 int *timed_out = (int *) data; | |
1753 | |
1754 *timed_out = TRUE; | |
1755 return FALSE; /* don't happen again */ | |
1756 } | |
1757 | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
1758 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
|
1759 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
|
1760 static timeout_cb_type motion_repeat_timer_cb(gpointer); |
7 | 1761 |
1762 static void | |
1763 process_motion_notify(int x, int y, GdkModifierType state) | |
1764 { | |
1765 int button; | |
1766 int_u vim_modifiers; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1767 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1768 GtkAllocation allocation; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1769 #endif |
7 | 1770 |
1771 button = (state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | | |
1772 GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | | |
1773 GDK_BUTTON5_MASK)) | |
1774 ? MOUSE_DRAG : ' '; | |
1775 | |
1776 /* If our pointer is currently hidden, then we should show it. */ | |
1777 gui_mch_mousehide(FALSE); | |
1778 | |
1779 /* Just moving the rodent above the drawing area without any button | |
1780 * being pressed. */ | |
1781 if (button != MOUSE_DRAG) | |
1782 { | |
1783 gui_mouse_moved(x, y); | |
1784 return; | |
1785 } | |
1786 | |
1787 /* translate modifier coding between the main engine and GTK */ | |
179 | 1788 vim_modifiers = modifiers_gdk2mouse(state); |
7 | 1789 |
1226 | 1790 /* inform the editor engine about the occurrence of this event */ |
7 | 1791 gui_send_mouse_event(button, x, y, FALSE, vim_modifiers); |
1792 | |
1793 /* | |
1794 * Auto repeat timer handling. | |
1795 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1796 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1797 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
|
1798 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1799 if (x < 0 || y < 0 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1800 || x >= allocation.width |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1801 || y >= allocation.height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1802 #else |
7 | 1803 if (x < 0 || y < 0 |
1804 || x >= gui.drawarea->allocation.width | |
1805 || y >= gui.drawarea->allocation.height) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1806 #endif |
7 | 1807 { |
1808 | |
1809 int dx; | |
1810 int dy; | |
1811 int offshoot; | |
1812 int delay = 10; | |
1813 | |
1814 /* Calculate the maximal distance of the cursor from the drawing area. | |
1815 * (offshoot can't become negative here!). | |
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 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
|
1819 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
|
1820 #else |
7 | 1821 dx = x < 0 ? -x : x - gui.drawarea->allocation.width; |
1822 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
|
1823 #endif |
7 | 1824 |
1825 offshoot = dx > dy ? dx : dy; | |
1826 | |
1884 | 1827 /* Make a linearly decaying timer delay with a threshold of 5 at a |
7 | 1828 * distance of 127 pixels from the main window. |
1829 * | |
1830 * One could think endlessly about the most ergonomic variant here. | |
1831 * For example it could make sense to calculate the distance from the | |
1832 * drags start instead... | |
1833 * | |
1834 * Maybe a parabolic interpolation would suite us better here too... | |
1835 */ | |
1836 if (offshoot > 127) | |
1837 { | |
1838 /* 5 appears to be somehow near to my perceptual limits :-). */ | |
1839 delay = 5; | |
1840 } | |
1841 else | |
1842 { | |
1843 delay = (130 * (127 - offshoot)) / 127 + 5; | |
1844 } | |
1845 | |
1846 /* shoot again */ | |
1847 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
|
1848 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
|
1849 NULL); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1850 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1851 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1852 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1853 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1854 static GdkDevice * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1855 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
|
1856 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1857 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
|
1858 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
|
1859 # 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
|
1860 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
|
1861 return gdk_seat_get_pointer(seat); |
fc69eed19ba7
commit https://github.com/vim/vim/commit/30e12d259ee78272359f9da2655d0593a4f6a626
Christian Brabandt <cb@256bit.org>
parents:
8851
diff
changeset
|
1862 # else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1863 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
|
1864 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
|
1865 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1866 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1867 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1868 static GdkWindow * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1869 gui_gtk_get_pointer(GtkWidget *widget, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1870 gint *x, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1871 gint *y, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1872 GdkModifierType *state) |
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 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
|
1875 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
|
1876 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
|
1877 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1878 |
8397
1e58a938aafc
commit https://github.com/vim/vim/commit/2369c15407cf9a730a396ebf9709abb280c5ce48
Christian Brabandt <cb@256bit.org>
parents:
8301
diff
changeset
|
1879 # 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
|
1880 static GdkWindow * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1881 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
|
1882 gint *x, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1883 gint *y) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1884 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1885 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
|
1886 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
|
1887 } |
8397
1e58a938aafc
commit https://github.com/vim/vim/commit/2369c15407cf9a730a396ebf9709abb280c5ce48
Christian Brabandt <cb@256bit.org>
parents:
8301
diff
changeset
|
1888 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1889 #endif |
7 | 1890 |
1891 /* | |
1892 * Timer used to recognize multiple clicks of the mouse button. | |
1893 */ | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
1894 static timeout_cb_type |
1884 | 1895 motion_repeat_timer_cb(gpointer data UNUSED) |
7 | 1896 { |
1897 int x; | |
1898 int y; | |
1899 GdkModifierType state; | |
1900 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1901 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1902 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
|
1903 #else |
7 | 1904 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
|
1905 #endif |
7 | 1906 |
1907 if (!(state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | | |
1908 GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | | |
1909 GDK_BUTTON5_MASK))) | |
1910 { | |
1911 motion_repeat_timer = 0; | |
1912 return FALSE; | |
1913 } | |
1914 | |
1915 /* If there already is a mouse click in the input buffer, wait another | |
1916 * time (otherwise we would create a backlog of clicks) */ | |
1917 if (vim_used_in_input_buf() > 10) | |
1918 return TRUE; | |
1919 | |
1920 motion_repeat_timer = 0; | |
1921 | |
1922 /* | |
1923 * Fake a motion event. | |
1924 * Trick: Pretend the mouse moved to the next character on every other | |
1925 * event, otherwise drag events will be discarded, because they are still | |
1926 * in the same character. | |
1927 */ | |
1928 if (motion_repeat_offset) | |
1929 x += gui.char_width; | |
1930 | |
1931 motion_repeat_offset = !motion_repeat_offset; | |
1932 process_motion_notify(x, y, state); | |
1933 | |
1934 /* Don't happen again. We will get reinstalled in the synthetic event | |
1935 * if needed -- thus repeating should still work. */ | |
1936 return FALSE; | |
1937 } | |
1938 | |
1939 static gint | |
1884 | 1940 motion_notify_event(GtkWidget *widget, |
1941 GdkEventMotion *event, | |
1942 gpointer data UNUSED) | |
7 | 1943 { |
1944 if (event->is_hint) | |
1945 { | |
1946 int x; | |
1947 int y; | |
1948 GdkModifierType state; | |
1949 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1950 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1951 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
|
1952 #else |
7 | 1953 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
|
1954 #endif |
7 | 1955 process_motion_notify(x, y, state); |
1956 } | |
1957 else | |
1958 { | |
1959 process_motion_notify((int)event->x, (int)event->y, | |
1960 (GdkModifierType)event->state); | |
1961 } | |
1962 | |
1963 return TRUE; /* handled */ | |
1964 } | |
1965 | |
1966 | |
1967 /* | |
1968 * Mouse button handling. Note please that we are capturing multiple click's | |
1969 * by our own timeout mechanism instead of the one provided by GTK+ itself. | |
1970 * This is due to the way the generic VIM code is recognizing multiple clicks. | |
1971 */ | |
1972 static gint | |
1884 | 1973 button_press_event(GtkWidget *widget, |
1974 GdkEventButton *event, | |
1975 gpointer data UNUSED) | |
7 | 1976 { |
1977 int button; | |
1978 int repeated_click = FALSE; | |
1979 int x, y; | |
1980 int_u vim_modifiers; | |
1981 | |
2923 | 1982 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
|
1983 |
7 | 1984 /* 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
|
1985 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1986 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
|
1987 #else |
7 | 1988 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
|
1989 #endif |
7 | 1990 gtk_widget_grab_focus(widget); |
1991 | |
1992 /* | |
1993 * Don't let additional events about multiple clicks send by GTK to us | |
1994 * after the initial button press event confuse us. | |
1995 */ | |
1996 if (event->type != GDK_BUTTON_PRESS) | |
1997 return FALSE; | |
1998 | |
1999 x = event->x; | |
2000 y = event->y; | |
2001 | |
2002 /* Handle multiple clicks */ | |
2003 if (!mouse_timed_out && mouse_click_timer) | |
2004 { | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
2005 timeout_remove(mouse_click_timer); |
7 | 2006 mouse_click_timer = 0; |
2007 repeated_click = TRUE; | |
2008 } | |
2009 | |
2010 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
|
2011 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
|
2012 &mouse_timed_out); |
7 | 2013 |
2014 switch (event->button) | |
2015 { | |
7260
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2016 /* 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
|
2017 * 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
|
2018 case 1: button = MOUSE_LEFT; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2019 case 2: button = MOUSE_MIDDLE; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2020 case 3: button = MOUSE_RIGHT; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2021 case 8: button = MOUSE_X1; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2022 case 9: button = MOUSE_X2; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2023 default: |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
2024 return FALSE; /* Unknown button */ |
7 | 2025 } |
2026 | |
2027 #ifdef FEAT_XIM | |
2028 /* cancel any preediting */ | |
2029 if (im_is_preediting()) | |
2030 xim_reset(); | |
2031 #endif | |
2032 | |
179 | 2033 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 2034 |
2035 gui_send_mouse_event(button, x, y, repeated_click, vim_modifiers); | |
2036 | |
2037 return TRUE; | |
2038 } | |
2039 | |
2040 /* | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
2041 * GTK+ 2 abstracts scrolling via the GdkEventScroll. |
7 | 2042 */ |
2043 static gboolean | |
1884 | 2044 scroll_event(GtkWidget *widget, |
2045 GdkEventScroll *event, | |
2046 gpointer data UNUSED) | |
7 | 2047 { |
2048 int button; | |
179 | 2049 int_u vim_modifiers; |
7 | 2050 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2051 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2052 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
|
2053 #else |
7 | 2054 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
|
2055 #endif |
7 | 2056 gtk_widget_grab_focus(widget); |
2057 | |
2058 switch (event->direction) | |
2059 { | |
2060 case GDK_SCROLL_UP: | |
2061 button = MOUSE_4; | |
2062 break; | |
2063 case GDK_SCROLL_DOWN: | |
2064 button = MOUSE_5; | |
2065 break; | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2066 case GDK_SCROLL_LEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2067 button = MOUSE_7; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2068 break; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2069 case GDK_SCROLL_RIGHT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2070 button = MOUSE_6; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2071 break; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2072 default: /* This shouldn't happen */ |
7 | 2073 return FALSE; |
2074 } | |
2075 | |
2076 # ifdef FEAT_XIM | |
2077 /* cancel any preediting */ | |
2078 if (im_is_preediting()) | |
2079 xim_reset(); | |
2080 # endif | |
2081 | |
179 | 2082 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 2083 |
2084 gui_send_mouse_event(button, (int)event->x, (int)event->y, | |
2085 FALSE, vim_modifiers); | |
2086 | |
2087 return TRUE; | |
2088 } | |
2089 | |
2090 | |
2091 static gint | |
1884 | 2092 button_release_event(GtkWidget *widget UNUSED, |
2093 GdkEventButton *event, | |
2094 gpointer data UNUSED) | |
7 | 2095 { |
2096 int x, y; | |
2097 int_u vim_modifiers; | |
2098 | |
2923 | 2099 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
|
2100 |
7 | 2101 /* Remove any motion "machine gun" timers used for automatic further |
2102 extension of allocation areas if outside of the applications window | |
2103 area .*/ | |
2104 if (motion_repeat_timer) | |
2105 { | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
2106 timeout_remove(motion_repeat_timer); |
7 | 2107 motion_repeat_timer = 0; |
2108 } | |
2109 | |
2110 x = event->x; | |
2111 y = event->y; | |
2112 | |
179 | 2113 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 2114 |
2115 gui_send_mouse_event(MOUSE_RELEASE, x, y, FALSE, vim_modifiers); | |
2116 | |
2117 return TRUE; | |
2118 } | |
2119 | |
2120 | |
2121 #ifdef FEAT_DND | |
2122 /**************************************************************************** | |
2123 * Drag aNd Drop support handlers. | |
2124 */ | |
2125 | |
2126 /* | |
2127 * Count how many items there may be and separate them with a NUL. | |
2128 * Apparently the items are separated with \r\n. This is not documented, | |
2129 * thus be careful not to go past the end. Also allow separation with | |
2130 * NUL characters. | |
2131 */ | |
2132 static int | |
2133 count_and_decode_uri_list(char_u *out, char_u *raw, int len) | |
2134 { | |
2135 int i; | |
2136 char_u *p = out; | |
2137 int count = 0; | |
2138 | |
2139 for (i = 0; i < len; ++i) | |
2140 { | |
2141 if (raw[i] == NUL || raw[i] == '\n' || raw[i] == '\r') | |
2142 { | |
2143 if (p > out && p[-1] != NUL) | |
2144 { | |
2145 ++count; | |
2146 *p++ = NUL; | |
2147 } | |
2148 } | |
2149 else if (raw[i] == '%' && i + 2 < len && hexhex2nr(raw + i + 1) > 0) | |
2150 { | |
2151 *p++ = hexhex2nr(raw + i + 1); | |
2152 i += 2; | |
2153 } | |
2154 else | |
2155 *p++ = raw[i]; | |
2156 } | |
2157 if (p > out && p[-1] != NUL) | |
2158 { | |
2159 *p = NUL; /* last item didn't have \r or \n */ | |
2160 ++count; | |
2161 } | |
2162 return count; | |
2163 } | |
2164 | |
2165 /* | |
2166 * Parse NUL separated "src" strings. Make it an array "outlist" form. On | |
2167 * this process, URI which protocol is not "file:" are removed. Return | |
2168 * length of array (less than "max"). | |
2169 */ | |
2170 static int | |
2171 filter_uri_list(char_u **outlist, int max, char_u *src) | |
2172 { | |
2173 int i, j; | |
2174 | |
2175 for (i = j = 0; i < max; ++i) | |
2176 { | |
2177 outlist[i] = NULL; | |
2178 if (STRNCMP(src, "file:", 5) == 0) | |
2179 { | |
2180 src += 5; | |
2181 if (STRNCMP(src, "//localhost", 11) == 0) | |
2182 src += 11; | |
2183 while (src[0] == '/' && src[1] == '/') | |
2184 ++src; | |
2185 outlist[j++] = vim_strsave(src); | |
2186 } | |
2187 src += STRLEN(src) + 1; | |
2188 } | |
2189 return j; | |
2190 } | |
2191 | |
2192 static char_u ** | |
2193 parse_uri_list(int *count, char_u *data, int len) | |
2194 { | |
2195 int n = 0; | |
2196 char_u *tmp = NULL; | |
9252
c25898cc99c1
commit https://github.com/vim/vim/commit/945ec093cd4ddefab930239990564b12eb232153
Christian Brabandt <cb@256bit.org>
parents:
9232
diff
changeset
|
2197 char_u **array = NULL; |
7 | 2198 |
2199 if (data != NULL && len > 0 && (tmp = (char_u *)alloc(len + 1)) != NULL) | |
2200 { | |
2201 n = count_and_decode_uri_list(tmp, data, len); | |
2202 if (n > 0 && (array = (char_u **)alloc(n * sizeof(char_u *))) != NULL) | |
2203 n = filter_uri_list(array, n, tmp); | |
2204 } | |
2205 vim_free(tmp); | |
2206 *count = n; | |
2207 return array; | |
2208 } | |
2209 | |
2210 static void | |
2211 drag_handle_uri_list(GdkDragContext *context, | |
2212 GtkSelectionData *data, | |
2213 guint time_, | |
2214 GdkModifierType state, | |
2215 gint x, | |
2216 gint y) | |
2217 { | |
2218 char_u **fnames; | |
2219 int nfiles = 0; | |
2220 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2221 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2222 fnames = parse_uri_list(&nfiles, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2223 (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
|
2224 gtk_selection_data_get_length(data)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2225 # else |
7 | 2226 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
|
2227 # endif |
7 | 2228 |
2229 if (fnames != NULL && nfiles > 0) | |
2230 { | |
179 | 2231 int_u modifiers; |
7 | 2232 |
2233 gtk_drag_finish(context, TRUE, FALSE, time_); /* accept */ | |
2234 | |
179 | 2235 modifiers = modifiers_gdk2mouse(state); |
7 | 2236 |
2237 gui_handle_drop(x, y, modifiers, fnames, nfiles); | |
2238 } | |
840 | 2239 else |
2240 vim_free(fnames); | |
7 | 2241 } |
2242 | |
2243 static void | |
2244 drag_handle_text(GdkDragContext *context, | |
2245 GtkSelectionData *data, | |
2246 guint time_, | |
2247 GdkModifierType state) | |
2248 { | |
2249 char_u dropkey[6] = {CSI, KS_MODIFIER, 0, CSI, KS_EXTRA, (char_u)KE_DROP}; | |
2250 char_u *text; | |
2251 int len; | |
2252 char_u *tmpbuf = NULL; | |
2253 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2254 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2255 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
|
2256 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
|
2257 # else |
7 | 2258 text = data->data; |
2259 len = data->length; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2260 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2261 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2262 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2263 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
|
2264 # else |
7 | 2265 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
|
2266 # endif |
7 | 2267 { |
2268 if (input_conv.vc_type != CONV_NONE) | |
2269 tmpbuf = string_convert(&input_conv, text, &len); | |
2270 if (tmpbuf != NULL) | |
2271 text = tmpbuf; | |
2272 } | |
2273 | |
2274 dnd_yank_drag_data(text, (long)len); | |
2275 gtk_drag_finish(context, TRUE, FALSE, time_); /* accept */ | |
2276 vim_free(tmpbuf); | |
2277 | |
179 | 2278 dropkey[2] = modifiers_gdk2vim(state); |
7 | 2279 |
2280 if (dropkey[2] != 0) | |
2281 add_to_input_buf(dropkey, (int)sizeof(dropkey)); | |
2282 else | |
2283 add_to_input_buf(dropkey + 3, (int)(sizeof(dropkey) - 3)); | |
2284 } | |
2285 | |
2286 /* | |
2287 * DND receiver. | |
2288 */ | |
2289 static void | |
2290 drag_data_received_cb(GtkWidget *widget, | |
2291 GdkDragContext *context, | |
2292 gint x, | |
2293 gint y, | |
2294 GtkSelectionData *data, | |
2295 guint info, | |
2296 guint time_, | |
1884 | 2297 gpointer user_data UNUSED) |
7 | 2298 { |
2299 GdkModifierType state; | |
2300 | |
2301 /* Guard against trash */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2302 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2303 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
|
2304 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
|
2305 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
|
2306 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2307 if (data_data == NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2308 || data_length <= 0 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2309 || data_format != 8 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2310 || data_data[data_length] != '\0') |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2311 # else |
7 | 2312 if (data->data == NULL |
2313 || data->length <= 0 | |
2314 || data->format != 8 | |
2315 || data->data[data->length] != '\0') | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2316 # endif |
7 | 2317 { |
2318 gtk_drag_finish(context, FALSE, FALSE, time_); | |
2319 return; | |
2320 } | |
2321 | |
2322 /* Get the current modifier state for proper distinguishment between | |
2323 * different operations later. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2324 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2325 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
|
2326 # else |
7 | 2327 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
|
2328 # endif |
7 | 2329 |
2330 /* Not sure about the role of "text/plain" here... */ | |
2331 if (info == (guint)TARGET_TEXT_URI_LIST) | |
2332 drag_handle_uri_list(context, data, time_, state, x, y); | |
2333 else | |
2334 drag_handle_text(context, data, time_, state); | |
2335 | |
2336 } | |
2337 #endif /* FEAT_DND */ | |
2338 | |
2339 | |
2340 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
2341 /* | |
2342 * GnomeClient interact callback. Check for unsaved buffers that cannot | |
2343 * be abandoned and pop up a dialog asking the user for confirmation if | |
2344 * necessary. | |
2345 */ | |
2346 static void | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2347 sm_client_check_changed_any(GnomeClient *client UNUSED, |
7 | 2348 gint key, |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2349 GnomeDialogType type UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2350 gpointer data UNUSED) |
7 | 2351 { |
2352 cmdmod_T save_cmdmod; | |
2353 gboolean shutdown_cancelled; | |
2354 | |
2355 save_cmdmod = cmdmod; | |
2356 | |
2357 # ifdef FEAT_BROWSE | |
2358 cmdmod.browse = TRUE; | |
2359 # endif | |
2360 # if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
2361 cmdmod.confirm = TRUE; | |
2362 # endif | |
2363 /* | |
2364 * If there are changed buffers, present the user with | |
2365 * a dialog if possible, otherwise give an error message. | |
2366 */ | |
7469
15eefe1b0dad
commit https://github.com/vim/vim/commit/027387f70c671f62e3e08e0bdd09ec05b0232735
Christian Brabandt <cb@256bit.org>
parents:
7380
diff
changeset
|
2367 shutdown_cancelled = check_changed_any(FALSE, FALSE); |
7 | 2368 |
2369 exiting = FALSE; | |
2370 cmdmod = save_cmdmod; | |
2371 setcursor(); /* position the cursor */ | |
2372 out_flush(); | |
2373 /* | |
2374 * If the user hit the [Cancel] button the whole shutdown | |
2375 * will be cancelled. Wow, quite powerful feature (: | |
2376 */ | |
2377 gnome_interaction_key_return(key, shutdown_cancelled); | |
2378 } | |
2379 | |
2380 /* | |
2381 * Generate a script that can be used to restore the current editing session. | |
2382 * Save the value of v:this_session before running :mksession in order to make | |
2383 * automagic session save fully transparent. Return TRUE on success. | |
2384 */ | |
2385 static int | |
2386 write_session_file(char_u *filename) | |
2387 { | |
2388 char_u *escaped_filename; | |
2389 char *mksession_cmdline; | |
2390 unsigned int save_ssop_flags; | |
2391 int failed; | |
2392 | |
2393 /* | |
2394 * Build an ex command line to create a script that restores the current | |
2395 * session if executed. Escape the filename to avoid nasty surprises. | |
2396 */ | |
2397 escaped_filename = vim_strsave_escaped(filename, escape_chars); | |
2398 if (escaped_filename == NULL) | |
2399 return FALSE; | |
1296 | 2400 mksession_cmdline = g_strconcat("mksession ", (char *)escaped_filename, |
2401 NULL); | |
7 | 2402 vim_free(escaped_filename); |
1296 | 2403 |
7 | 2404 /* |
2405 * Use a reasonable hardcoded set of 'sessionoptions' flags to avoid | |
2406 * unpredictable effects when the session is saved automatically. Also, | |
2407 * we definitely need SSOP_GLOBALS to be able to restore v:this_session. | |
2408 * Don't use SSOP_BUFFERS to prevent the buffer list from becoming | |
2409 * enormously large if the GNOME session feature is used regularly. | |
2410 */ | |
2411 save_ssop_flags = ssop_flags; | |
2412 ssop_flags = (SSOP_BLANK|SSOP_CURDIR|SSOP_FOLDS|SSOP_GLOBALS | |
1296 | 2413 |SSOP_HELP|SSOP_OPTIONS|SSOP_WINSIZE|SSOP_TABPAGES); |
7 | 2414 |
2415 do_cmdline_cmd((char_u *)"let Save_VV_this_session = v:this_session"); | |
2416 failed = (do_cmdline_cmd((char_u *)mksession_cmdline) == FAIL); | |
2417 do_cmdline_cmd((char_u *)"let v:this_session = Save_VV_this_session"); | |
150 | 2418 do_unlet((char_u *)"Save_VV_this_session", TRUE); |
7 | 2419 |
2420 ssop_flags = save_ssop_flags; | |
2421 g_free(mksession_cmdline); | |
5905 | 2422 |
7 | 2423 /* |
2424 * Reopen the file and append a command to restore v:this_session, | |
2425 * as if this save never happened. This is to avoid conflicts with | |
2426 * the user's own sessions. FIXME: It's probably less hackish to add | |
2427 * a "stealth" flag to 'sessionoptions' -- gotta ask Bram. | |
2428 */ | |
2429 if (!failed) | |
2430 { | |
2431 FILE *fd; | |
2432 | |
2433 fd = open_exfile(filename, TRUE, APPENDBIN); | |
2434 | |
2435 failed = (fd == NULL | |
2436 || put_line(fd, "let v:this_session = Save_VV_this_session") == FAIL | |
2437 || put_line(fd, "unlet Save_VV_this_session") == FAIL); | |
2438 | |
2439 if (fd != NULL && fclose(fd) != 0) | |
2440 failed = TRUE; | |
2441 | |
2442 if (failed) | |
2443 mch_remove(filename); | |
2444 } | |
2445 | |
2446 return !failed; | |
2447 } | |
2448 | |
2449 /* | |
2450 * "save_yourself" signal handler. Initiate an interaction to ask the user | |
2451 * for confirmation if necessary. Save the current editing session and tell | |
2452 * the session manager how to restart Vim. | |
2453 */ | |
2454 static gboolean | |
2455 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
|
2456 gint phase UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2457 GnomeSaveStyle save_style UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2458 gboolean shutdown UNUSED, |
7 | 2459 GnomeInteractStyle interact_style, |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2460 gboolean fast UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2461 gpointer data UNUSED) |
7 | 2462 { |
2463 static const char suffix[] = "-session.vim"; | |
2464 char *session_file; | |
2465 unsigned int len; | |
2466 gboolean success; | |
2467 | |
2468 /* Always request an interaction if possible. check_changed_any() | |
2469 * won't actually show a dialog unless any buffers have been modified. | |
2470 * There doesn't seem to be an obvious way to check that without | |
2471 * automatically firing the dialog. Anyway, it works just fine. */ | |
2472 if (interact_style == GNOME_INTERACT_ANY) | |
2473 gnome_client_request_interaction(client, GNOME_DIALOG_NORMAL, | |
2474 &sm_client_check_changed_any, | |
2475 NULL); | |
2476 out_flush(); | |
2477 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
2478 | |
2479 /* The path is unique for each session save. We do neither know nor care | |
2480 * which session script will actually be used later. This decision is in | |
2481 * the domain of the session manager. */ | |
2482 session_file = gnome_config_get_real_path( | |
2483 gnome_client_get_config_prefix(client)); | |
2484 len = strlen(session_file); | |
2485 | |
2486 if (len > 0 && session_file[len-1] == G_DIR_SEPARATOR) | |
2487 --len; /* get rid of the superfluous trailing '/' */ | |
2488 | |
2489 session_file = g_renew(char, session_file, len + sizeof(suffix)); | |
2490 memcpy(session_file + len, suffix, sizeof(suffix)); | |
2491 | |
2492 success = write_session_file((char_u *)session_file); | |
2493 | |
2494 if (success) | |
2495 { | |
2496 const char *argv[8]; | |
2497 int i; | |
2498 | |
2499 /* Tell the session manager how to wipe out the stored session data. | |
2500 * This isn't as dangerous as it looks, don't worry :) session_file | |
2501 * is a unique absolute filename. Usually it'll be something like | |
2502 * `/home/user/.gnome2/vim-XXXXXX-session.vim'. */ | |
2503 i = 0; | |
2504 argv[i++] = "rm"; | |
2505 argv[i++] = session_file; | |
2506 argv[i] = NULL; | |
2507 | |
2508 gnome_client_set_discard_command(client, i, (char **)argv); | |
2509 | |
2510 /* Tell the session manager how to restore the just saved session. | |
2511 * This is easily done thanks to Vim's -S option. Pass the -f flag | |
2512 * since there's no need to fork -- it might even cause confusion. | |
2513 * Also pass the window role to give the WM something to match on. | |
2514 * The role is set in gui_mch_open(), thus should _never_ be NULL. */ | |
2515 i = 0; | |
2516 argv[i++] = restart_command; | |
2517 argv[i++] = "-f"; | |
2518 argv[i++] = "-g"; | |
2519 argv[i++] = "--role"; | |
2520 argv[i++] = gtk_window_get_role(GTK_WINDOW(gui.mainwin)); | |
2521 argv[i++] = "-S"; | |
2522 argv[i++] = session_file; | |
2523 argv[i] = NULL; | |
2524 | |
2525 gnome_client_set_restart_command(client, i, (char **)argv); | |
2526 gnome_client_set_clone_command(client, 0, NULL); | |
2527 } | |
2528 | |
2529 g_free(session_file); | |
2530 | |
2531 return success; | |
2532 } | |
2533 | |
2534 /* | |
2535 * Called when the session manager wants us to die. There isn't much to save | |
2536 * here since "save_yourself" has been emitted before (unless serious trouble | |
2537 * is happening). | |
2538 */ | |
2539 static void | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2540 sm_client_die(GnomeClient *client UNUSED, gpointer data UNUSED) |
7 | 2541 { |
2542 /* Don't write messages to the GUI anymore */ | |
2543 full_screen = FALSE; | |
2544 | |
1666 | 2545 vim_strncpy(IObuff, (char_u *) |
419 | 2546 _("Vim: Received \"die\" request from session manager\n"), |
1666 | 2547 IOSIZE - 1); |
7 | 2548 preserve_exit(); |
2549 } | |
2550 | |
2551 /* | |
2552 * Connect our signal handlers to be notified on session save and shutdown. | |
2553 */ | |
2554 static void | |
2555 setup_save_yourself(void) | |
2556 { | |
2557 GnomeClient *client; | |
2558 | |
2559 client = gnome_master_client(); | |
2560 | |
2561 if (client != NULL) | |
2562 { | |
2563 /* Must use the deprecated gtk_signal_connect() for compatibility | |
2564 * with GNOME 1. Arrgh, zombies! */ | |
2565 gtk_signal_connect(GTK_OBJECT(client), "save_yourself", | |
2566 GTK_SIGNAL_FUNC(&sm_client_save_yourself), NULL); | |
2567 gtk_signal_connect(GTK_OBJECT(client), "die", | |
2568 GTK_SIGNAL_FUNC(&sm_client_die), NULL); | |
2569 } | |
2570 } | |
2571 | |
2572 #else /* !(FEAT_GUI_GNOME && FEAT_SESSION) */ | |
2573 | |
2574 # ifdef USE_XSMP | |
2575 /* | |
2576 * GTK tells us that XSMP needs attention | |
2577 */ | |
2578 static gboolean | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2579 local_xsmp_handle_requests( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2580 GIOChannel *source UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2581 GIOCondition condition, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2582 gpointer data) |
7 | 2583 { |
2584 if (condition == G_IO_IN) | |
2585 { | |
2586 /* Do stuff; maybe close connection */ | |
2587 if (xsmp_handle_requests() == FAIL) | |
2588 g_io_channel_unref((GIOChannel *)data); | |
2589 return TRUE; | |
2590 } | |
2591 /* Error */ | |
2592 g_io_channel_unref((GIOChannel *)data); | |
2593 xsmp_close(); | |
2594 return TRUE; | |
2595 } | |
2596 # endif /* USE_XSMP */ | |
2597 | |
2598 /* | |
2599 * Setup the WM_PROTOCOLS to indicate we want the WM_SAVE_YOURSELF event. | |
2600 * This is an ugly use of X functions. GTK doesn't offer an alternative. | |
2601 */ | |
2602 static void | |
2603 setup_save_yourself(void) | |
2604 { | |
2605 Atom *existing_atoms = NULL; | |
2606 int count = 0; | |
2607 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2608 # ifdef USE_XSMP |
7 | 2609 if (xsmp_icefd != -1) |
2610 { | |
2611 /* | |
2612 * Use XSMP is preference to legacy WM_SAVE_YOURSELF; | |
2613 * set up GTK IO monitor | |
2614 */ | |
2615 GIOChannel *g_io = g_io_channel_unix_new(xsmp_icefd); | |
2616 | |
2617 g_io_add_watch(g_io, G_IO_IN | G_IO_ERR | G_IO_HUP, | |
2618 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
|
2619 g_io_channel_unref(g_io); |
7 | 2620 } |
2621 else | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2622 # endif |
7 | 2623 { |
2624 /* Fall back to old method */ | |
2625 | |
2626 /* first get the existing value */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2627 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2628 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
|
2629 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2630 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
|
2631 GDK_WINDOW_XID(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2632 &existing_atoms, &count)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2633 # else |
7 | 2634 if (XGetWMProtocols(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2635 GDK_WINDOW_XWINDOW(gui.mainwin->window), | |
2636 &existing_atoms, &count)) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2637 # endif |
7 | 2638 { |
2639 Atom *new_atoms; | |
2640 Atom save_yourself_xatom; | |
2641 int i; | |
2642 | |
2643 save_yourself_xatom = GET_X_ATOM(save_yourself_atom); | |
2644 | |
2645 /* check if WM_SAVE_YOURSELF isn't there yet */ | |
2646 for (i = 0; i < count; ++i) | |
2647 if (existing_atoms[i] == save_yourself_xatom) | |
2648 break; | |
2649 | |
2650 if (i == count) | |
2651 { | |
2652 /* allocate an Atoms array which is one item longer */ | |
2653 new_atoms = (Atom *)alloc((unsigned)((count + 1) | |
2654 * sizeof(Atom))); | |
2655 if (new_atoms != NULL) | |
2656 { | |
2657 memcpy(new_atoms, existing_atoms, count * sizeof(Atom)); | |
2658 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
|
2659 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2660 XSetWMProtocols(GDK_WINDOW_XDISPLAY(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2661 GDK_WINDOW_XID(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2662 # else |
7 | 2663 XSetWMProtocols(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2664 GDK_WINDOW_XWINDOW(gui.mainwin->window), | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2665 # endif |
7 | 2666 new_atoms, count + 1); |
2667 vim_free(new_atoms); | |
2668 } | |
2669 } | |
2670 XFree(existing_atoms); | |
2671 } | |
2672 } | |
2673 } | |
2674 | |
2675 /* | |
2676 * Installing a global event filter seems to be the only way to catch | |
2677 * client messages of type WM_PROTOCOLS without overriding GDK's own | |
2678 * client message event filter. Well, that's still better than trying | |
2679 * to guess what the GDK filter had done if it had been invoked instead | |
2680 * | |
2681 * GTK2_FIXME: This doesn't seem to work. For some reason we never | |
2682 * receive WM_SAVE_YOURSELF even though everything is set up correctly. | |
2683 * I have the nasty feeling modern session managers just don't send this | |
2684 * deprecated message anymore. Addition: confirmed by several people. | |
2685 * | |
2686 * The GNOME session support is much cooler anyway. Unlike this ugly | |
2687 * WM_SAVE_YOURSELF hack it actually stores the session... And yes, | |
2688 * it should work with KDE as well. | |
2689 */ | |
2690 static GdkFilterReturn | |
1884 | 2691 global_event_filter(GdkXEvent *xev, |
2692 GdkEvent *event UNUSED, | |
2693 gpointer data UNUSED) | |
7 | 2694 { |
2695 XEvent *xevent = (XEvent *)xev; | |
2696 | |
2697 if (xevent != NULL | |
2698 && xevent->type == ClientMessage | |
2699 && xevent->xclient.message_type == GET_X_ATOM(wm_protocols_atom) | |
1884 | 2700 && (long_u)xevent->xclient.data.l[0] |
2701 == GET_X_ATOM(save_yourself_atom)) | |
7 | 2702 { |
2703 out_flush(); | |
2704 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
2705 /* | |
2706 * Set the window's WM_COMMAND property, to let the window manager | |
2707 * know we are done saving ourselves. We don't want to be | |
2708 * restarted, thus set argv to NULL. | |
2709 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2710 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2711 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
|
2712 GDK_WINDOW_XID(gtk_widget_get_window(gui.mainwin)), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2713 # else |
7 | 2714 XSetCommand(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2715 GDK_WINDOW_XWINDOW(gui.mainwin->window), | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2716 # endif |
7 | 2717 NULL, 0); |
2718 return GDK_FILTER_REMOVE; | |
2719 } | |
2720 | |
2721 return GDK_FILTER_CONTINUE; | |
2722 } | |
2723 #endif /* !(FEAT_GUI_GNOME && FEAT_SESSION) */ | |
2724 | |
2725 | |
2726 /* | |
2727 * Setup the window icon & xcmdsrv comm after the main window has been realized. | |
2728 */ | |
2729 static void | |
1884 | 2730 mainwin_realize(GtkWidget *widget UNUSED, gpointer data UNUSED) |
7 | 2731 { |
2732 /* If you get an error message here, you still need to unpack the runtime | |
2733 * archive! */ | |
2734 #ifdef magick | |
2735 # undef magick | |
2736 #endif | |
2737 /* A bit hackish, but avoids casting later and allows optimization */ | |
2738 # define static static const | |
2739 #define magick vim32x32 | |
2740 #include "../runtime/vim32x32.xpm" | |
2741 #undef magick | |
2742 #define magick vim16x16 | |
2743 #include "../runtime/vim16x16.xpm" | |
2744 #undef magick | |
2745 #define magick vim48x48 | |
2746 #include "../runtime/vim48x48.xpm" | |
2747 #undef magick | |
2748 # undef static | |
2749 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2750 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2751 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
|
2752 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2753 |
7 | 2754 /* When started with "--echo-wid" argument, write window ID on stdout. */ |
2755 if (echo_wid_arg) | |
2756 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2757 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2758 printf("WID: %ld\n", (long)GDK_WINDOW_XID(mainwin_win)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2759 #else |
7 | 2760 printf("WID: %ld\n", (long)GDK_WINDOW_XWINDOW(gui.mainwin->window)); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2761 #endif |
7 | 2762 fflush(stdout); |
2763 } | |
2764 | |
2765 if (vim_strchr(p_go, GO_ICON) != NULL) | |
2766 { | |
2767 /* | |
2768 * Add an icon to the main window. For fun and convenience of the user. | |
2769 */ | |
2770 GList *icons = NULL; | |
2771 | |
2772 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim16x16)); | |
2773 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim32x32)); | |
2774 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim48x48)); | |
2775 | |
2776 gtk_window_set_icon_list(GTK_WINDOW(gui.mainwin), icons); | |
2777 | |
2778 g_list_foreach(icons, (GFunc)&g_object_unref, NULL); | |
2779 g_list_free(icons); | |
2780 } | |
2781 | |
2782 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
2783 /* Register a handler for WM_SAVE_YOURSELF with GDK's low-level X I/F */ | |
2784 gdk_window_add_filter(NULL, &global_event_filter, NULL); | |
2785 #endif | |
2786 /* Setup to indicate to the window manager that we want to catch the | |
2787 * WM_SAVE_YOURSELF event. For GNOME, this connects to the session | |
2788 * manager instead. */ | |
2789 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
2790 if (using_gnome) | |
2791 #endif | |
2792 setup_save_yourself(); | |
2793 | |
2794 #ifdef FEAT_CLIENTSERVER | |
2795 if (serverName == NULL && serverDelayedStartName != NULL) | |
2796 { | |
2797 /* 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
|
2798 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2799 commWindow = GDK_WINDOW_XID(mainwin_win); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2800 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2801 (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
|
2802 serverDelayedStartName); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2803 # else |
7 | 2804 commWindow = GDK_WINDOW_XWINDOW(gui.mainwin->window); |
2805 | |
2806 (void)serverRegisterName(GDK_WINDOW_XDISPLAY(gui.mainwin->window), | |
2807 serverDelayedStartName); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2808 # endif |
7 | 2809 } |
2810 else | |
2811 { | |
2812 /* | |
2813 * Cannot handle "XLib-only" windows with gtk event routines, we'll | |
2814 * 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
|
2815 * If we have not registered a name yet, remember the window. |
7 | 2816 */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2817 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2818 serverChangeRegisteredWindow(GDK_WINDOW_XDISPLAY(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2819 GDK_WINDOW_XID(mainwin_win)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2820 # else |
7 | 2821 serverChangeRegisteredWindow(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2822 GDK_WINDOW_XWINDOW(gui.mainwin->window)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2823 # endif |
7 | 2824 } |
2825 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
|
2826 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2827 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
|
2828 G_CALLBACK(property_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2829 # else |
7 | 2830 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "property_notify_event", |
2831 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
|
2832 # endif |
7 | 2833 #endif |
2834 } | |
2835 | |
2836 static GdkCursor * | |
2837 create_blank_pointer(void) | |
2838 { | |
2839 GdkWindow *root_window = NULL; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2840 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2841 GdkPixbuf *blank_mask; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2842 #else |
7 | 2843 GdkPixmap *blank_mask; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2844 #endif |
7 | 2845 GdkCursor *cursor; |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2846 #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
|
2847 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
|
2848 #else |
7 | 2849 GdkColor color = { 0, 0, 0, 0 }; |
2850 char blank_data[] = { 0x0 }; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2851 #endif |
7 | 2852 |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2853 #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
|
2854 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2855 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
|
2856 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
|
2857 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
|
2858 } |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2859 #else |
7 | 2860 root_window = gtk_widget_get_root_window(gui.mainwin); |
2861 #endif | |
2862 | |
2863 /* Create a pseudo blank pointer, which is in fact one pixel by one pixel | |
2864 * in size. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2865 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2866 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2867 cairo_surface_t *surf; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2868 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2869 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2870 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
|
2871 cr = cairo_create(surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2872 |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2873 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2874 color.red, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2875 color.green, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2876 color.blue, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
2877 color.alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2878 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
|
2879 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2880 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2881 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2882 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
|
2883 cairo_surface_destroy(surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2884 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2885 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
|
2886 blank_mask, 0, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2887 g_object_unref(blank_mask); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2888 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2889 #else |
7 | 2890 blank_mask = gdk_bitmap_create_from_data(root_window, blank_data, 1, 1); |
2891 cursor = gdk_cursor_new_from_pixmap(blank_mask, blank_mask, | |
2892 &color, &color, 0, 0); | |
2893 gdk_bitmap_unref(blank_mask); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2894 #endif |
7 | 2895 |
2896 return cursor; | |
2897 } | |
2898 | |
2899 static void | |
2900 mainwin_screen_changed_cb(GtkWidget *widget, | |
1884 | 2901 GdkScreen *previous_screen UNUSED, |
2902 gpointer data UNUSED) | |
7 | 2903 { |
2904 if (!gtk_widget_has_screen(widget)) | |
2905 return; | |
2906 | |
2907 /* | |
1226 | 2908 * Recreate the invisible mouse cursor. |
7 | 2909 */ |
2910 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
|
2911 #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
|
2912 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
|
2913 #else |
7 | 2914 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
|
2915 #endif |
7 | 2916 |
2917 gui.blank_pointer = create_blank_pointer(); | |
2918 | |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2919 #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
|
2920 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
|
2921 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
|
2922 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
|
2923 #else |
7 | 2924 if (gui.pointer_hidden && gui.drawarea->window != NULL) |
2925 gdk_window_set_cursor(gui.drawarea->window, gui.blank_pointer); | |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2926 #endif |
7 | 2927 |
2928 /* | |
2929 * Create a new PangoContext for this screen, and initialize it | |
2930 * with the current font if necessary. | |
2931 */ | |
2932 if (gui.text_context != NULL) | |
2933 g_object_unref(gui.text_context); | |
2934 | |
2935 gui.text_context = gtk_widget_create_pango_context(widget); | |
2936 pango_context_set_base_dir(gui.text_context, PANGO_DIRECTION_LTR); | |
2937 | |
2938 if (gui.norm_font != NULL) | |
2939 { | |
38 | 2940 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
|
2941 gui_set_shellsize(TRUE, FALSE, RESIZE_BOTH); |
7 | 2942 } |
2943 } | |
2944 | |
2945 /* | |
2946 * After the drawing area comes up, we calculate all colors and create the | |
2947 * dummy blank cursor. | |
2948 * | |
2949 * Don't try to set any VIM scrollbar sizes anywhere here. I'm relying on the | |
2950 * fact that the main VIM engine doesn't take them into account anywhere. | |
2951 */ | |
2952 static void | |
1884 | 2953 drawarea_realize_cb(GtkWidget *widget, gpointer data UNUSED) |
7 | 2954 { |
2955 GtkWidget *sbar; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2956 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2957 GtkAllocation allocation; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2958 #endif |
7 | 2959 |
2960 #ifdef FEAT_XIM | |
2961 xim_init(); | |
2962 #endif | |
2963 gui_mch_new_colors(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2964 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2965 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
|
2966 gtk_widget_get_window(widget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2967 CAIRO_CONTENT_COLOR_ALPHA, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2968 gtk_widget_get_allocated_width(widget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2969 gtk_widget_get_allocated_height(widget)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2970 #else |
7 | 2971 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
|
2972 #endif |
7 | 2973 |
2974 gui.blank_pointer = create_blank_pointer(); | |
2975 if (gui.pointer_hidden) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2976 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2977 gdk_window_set_cursor(gtk_widget_get_window(widget), gui.blank_pointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2978 #else |
7 | 2979 gdk_window_set_cursor(widget->window, gui.blank_pointer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2980 #endif |
7 | 2981 |
2982 /* get the actual size of the scrollbars, if they are realized */ | |
2983 sbar = firstwin->w_scrollbars[SBAR_LEFT].id; | |
2984 if (!sbar || (!gui.which_scrollbars[SBAR_LEFT] | |
2985 && firstwin->w_scrollbars[SBAR_RIGHT].id)) | |
2986 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
|
2987 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2988 gtk_widget_get_allocation(sbar, &allocation); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2989 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
|
2990 gui.scrollbar_width = allocation.width; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2991 #else |
7 | 2992 if (sbar && GTK_WIDGET_REALIZED(sbar) && sbar->allocation.width) |
2993 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
|
2994 #endif |
7 | 2995 |
2996 sbar = gui.bottom_sbar.id; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2997 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2998 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
|
2999 gui.scrollbar_height = allocation.height; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3000 #else |
7 | 3001 if (sbar && GTK_WIDGET_REALIZED(sbar) && sbar->allocation.height) |
3002 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
|
3003 #endif |
7 | 3004 } |
3005 | |
3006 /* | |
3007 * Properly clean up on shutdown. | |
3008 */ | |
3009 static void | |
1884 | 3010 drawarea_unrealize_cb(GtkWidget *widget UNUSED, gpointer data UNUSED) |
7 | 3011 { |
3012 /* Don't write messages to the GUI anymore */ | |
3013 full_screen = FALSE; | |
3014 | |
3015 #ifdef FEAT_XIM | |
3016 im_shutdown(); | |
3017 #endif | |
3018 if (gui.ascii_glyphs != NULL) | |
3019 { | |
3020 pango_glyph_string_free(gui.ascii_glyphs); | |
3021 gui.ascii_glyphs = NULL; | |
3022 } | |
3023 if (gui.ascii_font != NULL) | |
3024 { | |
3025 g_object_unref(gui.ascii_font); | |
3026 gui.ascii_font = NULL; | |
3027 } | |
3028 g_object_unref(gui.text_context); | |
3029 gui.text_context = NULL; | |
3030 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3031 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3032 if (gui.surface != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3033 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3034 cairo_surface_destroy(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3035 gui.surface = NULL; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3036 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3037 #else |
7 | 3038 g_object_unref(gui.text_gc); |
3039 gui.text_gc = NULL; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3040 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3041 |
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 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
|
3044 #else |
7 | 3045 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
|
3046 #endif |
7 | 3047 gui.blank_pointer = NULL; |
3048 } | |
3049 | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3050 #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
|
3051 static void |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3052 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
|
3053 gpointer data UNUSED) |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3054 #else |
7 | 3055 static void |
1884 | 3056 drawarea_style_set_cb(GtkWidget *widget UNUSED, |
3057 GtkStyle *previous_style UNUSED, | |
3058 gpointer data UNUSED) | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3059 #endif |
7 | 3060 { |
3061 gui_mch_new_colors(); | |
3062 } | |
3063 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3064 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3065 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3066 drawarea_configure_event_cb(GtkWidget *widget, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3067 GdkEventConfigure *event, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3068 gpointer data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3069 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3070 static int cur_width = 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3071 static int cur_height = 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3072 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3073 g_return_val_if_fail(event |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3074 && 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
|
3075 |
10402
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
3076 # 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
|
3077 /* 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
|
3078 * 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
|
3079 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3080 * 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
|
3081 * 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
|
3082 * 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
|
3083 * "native" one from non-native one. |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3084 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3085 * 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
|
3086 * 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
|
3087 * 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
|
3088 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3089 * 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
|
3090 * 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
|
3091 * configure_native_child(). |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3092 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3093 * 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
|
3094 * 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
|
3095 * 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
|
3096 */ |
10402
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
3097 /* Follow-up |
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
3098 * 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
|
3099 * 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
|
3100 * 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
|
3101 if (event->send_event == FALSE) |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3102 return TRUE; |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3103 # endif |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3104 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3105 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
|
3106 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3107 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3108 cur_width = event->width; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3109 cur_height = event->height; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3110 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3111 if (gui.surface != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3112 cairo_surface_destroy(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3113 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3114 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
|
3115 gtk_widget_get_window(widget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3116 CAIRO_CONTENT_COLOR_ALPHA, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3117 event->width, event->height); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3118 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3119 gtk_widget_queue_draw(widget); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3120 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3121 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3122 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3123 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3124 |
7 | 3125 /* |
3126 * Callback routine for the "delete_event" signal on the toplevel window. | |
3127 * Tries to vim gracefully, or refuses to exit with changed buffers. | |
3128 */ | |
3129 static gint | |
1884 | 3130 delete_event_cb(GtkWidget *widget UNUSED, |
3131 GdkEventAny *event UNUSED, | |
3132 gpointer data UNUSED) | |
7 | 3133 { |
3134 gui_shell_closed(); | |
3135 return TRUE; | |
3136 } | |
3137 | |
685 | 3138 #if defined(FEAT_MENU) || defined(FEAT_TOOLBAR) || defined(FEAT_GUI_TABLINE) |
3139 static int | |
3140 get_item_dimensions(GtkWidget *widget, GtkOrientation orientation) | |
3141 { | |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3142 # ifdef FEAT_GUI_GNOME |
685 | 3143 GtkOrientation item_orientation = GTK_ORIENTATION_HORIZONTAL; |
3144 | |
3145 if (using_gnome && widget != NULL) | |
3146 { | |
856 | 3147 GtkWidget *parent; |
685 | 3148 BonoboDockItem *dockitem; |
3149 | |
791 | 3150 parent = gtk_widget_get_parent(widget); |
856 | 3151 if (G_TYPE_FROM_INSTANCE(parent) == BONOBO_TYPE_DOCK_ITEM) |
3152 { | |
3153 /* Only menu & toolbar are dock items. Could tabline be? | |
3154 * Seem to be only the 2 defined in GNOME */ | |
3155 widget = parent; | |
3156 dockitem = BONOBO_DOCK_ITEM(widget); | |
3157 | |
3158 if (dockitem == NULL || dockitem->is_floating) | |
3159 return 0; | |
3160 item_orientation = bonobo_dock_item_get_orientation(dockitem); | |
3161 } | |
685 | 3162 } |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3163 # else |
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3164 # 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
|
3165 # endif |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3166 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3167 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3168 if (widget != NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3169 && item_orientation == orientation |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3170 && gtk_widget_get_realized(widget) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3171 && gtk_widget_get_visible(widget)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3172 # else |
685 | 3173 if (widget != NULL |
3174 && item_orientation == orientation | |
3175 && GTK_WIDGET_REALIZED(widget) | |
3176 && GTK_WIDGET_VISIBLE(widget)) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3177 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3178 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3179 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3180 GtkAllocation allocation; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3181 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3182 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
|
3183 return allocation.height; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3184 # else |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3185 # ifdef FEAT_GUI_GNOME |
685 | 3186 if (orientation == GTK_ORIENTATION_HORIZONTAL) |
3187 return widget->allocation.height; | |
3188 else | |
3189 return widget->allocation.width; | |
10767
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3190 # else |
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3191 return widget->allocation.height; |
a8ce0dbbb1d0
patch 8.0.0273: dead code detected by Coverity
Christian Brabandt <cb@256bit.org>
parents:
10544
diff
changeset
|
3192 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3193 # endif |
685 | 3194 } |
3195 return 0; | |
3196 } | |
3197 #endif | |
3198 | |
3199 static int | |
3200 get_menu_tool_width(void) | |
3201 { | |
3202 int width = 0; | |
3203 | |
3204 #ifdef FEAT_GUI_GNOME /* these are never vertical without GNOME */ | |
3205 # ifdef FEAT_MENU | |
3206 width += get_item_dimensions(gui.menubar, GTK_ORIENTATION_VERTICAL); | |
3207 # endif | |
3208 # ifdef FEAT_TOOLBAR | |
3209 width += get_item_dimensions(gui.toolbar, GTK_ORIENTATION_VERTICAL); | |
3210 # endif | |
3211 # ifdef FEAT_GUI_TABLINE | |
782 | 3212 if (gui.tabline != NULL) |
3213 width += get_item_dimensions(gui.tabline, GTK_ORIENTATION_VERTICAL); | |
685 | 3214 # endif |
3215 #endif | |
3216 | |
3217 return width; | |
3218 } | |
3219 | |
3220 static int | |
3221 get_menu_tool_height(void) | |
3222 { | |
3223 int height = 0; | |
3224 | |
3225 #ifdef FEAT_MENU | |
3226 height += get_item_dimensions(gui.menubar, GTK_ORIENTATION_HORIZONTAL); | |
3227 #endif | |
3228 #ifdef FEAT_TOOLBAR | |
3229 height += get_item_dimensions(gui.toolbar, GTK_ORIENTATION_HORIZONTAL); | |
3230 #endif | |
3231 #ifdef FEAT_GUI_TABLINE | |
782 | 3232 if (gui.tabline != NULL) |
3233 height += get_item_dimensions(gui.tabline, GTK_ORIENTATION_HORIZONTAL); | |
685 | 3234 #endif |
3235 | |
3236 return height; | |
3237 } | |
3238 | |
791 | 3239 /* This controls whether we can set the real window hints at |
3240 * start-up when in a GtkPlug. | |
3241 * 0 = normal processing (default) | |
3242 * 1 = init. hints set, no-one's tried to reset since last check | |
3243 * 2 = init. hints set, attempt made to change hints | |
3244 */ | |
3245 static int init_window_hints_state = 0; | |
3246 | |
685 | 3247 static void |
791 | 3248 update_window_manager_hints(int force_width, int force_height) |
685 | 3249 { |
3250 static int old_width = 0; | |
3251 static int old_height = 0; | |
791 | 3252 static int old_min_width = 0; |
3253 static int old_min_height = 0; | |
685 | 3254 static int old_char_width = 0; |
3255 static int old_char_height = 0; | |
3256 | |
3257 int width; | |
3258 int height; | |
791 | 3259 int min_width; |
3260 int min_height; | |
3261 | |
3262 /* At start-up, don't try to set the hints until the initial | |
3263 * values have been used (those that dictate our initial size) | |
1884 | 3264 * Let forced (i.e., correct) values through always. |
791 | 3265 */ |
3266 if (!(force_width && force_height) && init_window_hints_state > 0) | |
3267 { | |
856 | 3268 /* Don't do it! */ |
3269 init_window_hints_state = 2; | |
3270 return; | |
791 | 3271 } |
685 | 3272 |
3273 /* This also needs to be done when the main window isn't there yet, | |
3274 * otherwise the hints don't work. */ | |
3275 width = gui_get_base_width(); | |
3276 height = gui_get_base_height(); | |
3277 # ifdef FEAT_MENU | |
3278 height += tabline_height() * gui.char_height; | |
3279 # endif | |
3280 width += get_menu_tool_width(); | |
3281 height += get_menu_tool_height(); | |
3282 | |
791 | 3283 /* GtkSockets use GtkPlug's [gui,mainwin] min-size hints to determine |
1226 | 3284 * their actual widget size. When we set our size ourselves (e.g., |
791 | 3285 * 'set columns=' or init. -geom) we briefly set the min. to the size |
3286 * we wish to be instead of the legitimate minimum so that we actually | |
3287 * resize correctly. | |
3288 */ | |
3289 if (force_width && force_height) | |
3290 { | |
856 | 3291 min_width = force_width; |
3292 min_height = force_height; | |
791 | 3293 } |
3294 else | |
3295 { | |
856 | 3296 min_width = width + MIN_COLUMNS * gui.char_width; |
3297 min_height = height + MIN_LINES * gui.char_height; | |
791 | 3298 } |
3299 | |
685 | 3300 /* Avoid an expose event when the size didn't change. */ |
3301 if (width != old_width | |
3302 || height != old_height | |
856 | 3303 || min_width != old_min_width |
791 | 3304 || min_height != old_min_height |
685 | 3305 || gui.char_width != old_char_width |
3306 || gui.char_height != old_char_height) | |
3307 { | |
3308 GdkGeometry geometry; | |
3309 GdkWindowHints geometry_mask; | |
3310 | |
3311 geometry.width_inc = gui.char_width; | |
3312 geometry.height_inc = gui.char_height; | |
3313 geometry.base_width = width; | |
3314 geometry.base_height = height; | |
856 | 3315 geometry.min_width = min_width; |
3316 geometry.min_height = min_height; | |
685 | 3317 geometry_mask = GDK_HINT_BASE_SIZE|GDK_HINT_RESIZE_INC |
3318 |GDK_HINT_MIN_SIZE; | |
3319 /* Using gui.formwin as geometry widget doesn't work as expected | |
3320 * with GTK+ 2 -- dunno why. Presumably all the resizing hacks | |
3321 * in Vim confuse GTK+. */ | |
3322 gtk_window_set_geometry_hints(GTK_WINDOW(gui.mainwin), gui.mainwin, | |
3323 &geometry, geometry_mask); | |
856 | 3324 old_width = width; |
3325 old_height = height; | |
3326 old_min_width = min_width; | |
3327 old_min_height = min_height; | |
3328 old_char_width = gui.char_width; | |
3329 old_char_height = gui.char_height; | |
685 | 3330 } |
3331 } | |
3332 | |
7 | 3333 #ifdef FEAT_TOOLBAR |
3334 | |
3335 /* | |
3336 * This extra effort wouldn't be necessary if we only used stock icons in the | |
3337 * toolbar, as we do for all builtin icons. But user-defined toolbar icons | |
3338 * shouldn't be treated differently, thus we do need this. | |
3339 */ | |
3340 static void | |
3341 icon_size_changed_foreach(GtkWidget *widget, gpointer user_data) | |
3342 { | |
3343 if (GTK_IS_IMAGE(widget)) | |
3344 { | |
3345 GtkImage *image = (GtkImage *)widget; | |
3346 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3347 # 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
|
3348 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
|
3349 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3350 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
|
3351 const gchar *icon_name; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3352 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3353 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
|
3354 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3355 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
|
3356 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3357 # else |
7 | 3358 /* User-defined icons are stored in a GtkIconSet */ |
3359 if (gtk_image_get_storage_type(image) == GTK_IMAGE_ICON_SET) | |
3360 { | |
3361 GtkIconSet *icon_set; | |
3362 GtkIconSize icon_size; | |
3363 | |
3364 gtk_image_get_icon_set(image, &icon_set, &icon_size); | |
3365 icon_size = (GtkIconSize)(long)user_data; | |
3366 | |
3367 gtk_icon_set_ref(icon_set); | |
3368 gtk_image_set_from_icon_set(image, icon_set, icon_size); | |
3369 gtk_icon_set_unref(icon_set); | |
3370 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3371 # endif |
7 | 3372 } |
3373 else if (GTK_IS_CONTAINER(widget)) | |
3374 { | |
3375 gtk_container_foreach((GtkContainer *)widget, | |
3376 &icon_size_changed_foreach, | |
3377 user_data); | |
3378 } | |
3379 } | |
3380 | |
3381 static void | |
3382 set_toolbar_style(GtkToolbar *toolbar) | |
3383 { | |
3384 GtkToolbarStyle style; | |
3385 GtkIconSize size; | |
3386 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
|
3387 |
7 | 3388 if ((toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS | TOOLBAR_HORIZ)) |
3389 == (TOOLBAR_TEXT | TOOLBAR_ICONS | TOOLBAR_HORIZ)) | |
3390 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
|
3391 else if ((toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS)) |
7 | 3392 == (TOOLBAR_TEXT | TOOLBAR_ICONS)) |
3393 style = GTK_TOOLBAR_BOTH; | |
3394 else if (toolbar_flags & TOOLBAR_TEXT) | |
3395 style = GTK_TOOLBAR_TEXT; | |
3396 else | |
3397 style = GTK_TOOLBAR_ICONS; | |
3398 | |
3399 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
|
3400 # if !GTK_CHECK_VERSION(3,0,0) |
7 | 3401 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
|
3402 # endif |
7 | 3403 |
3404 switch (tbis_flags) | |
3405 { | |
3406 case TBIS_TINY: size = GTK_ICON_SIZE_MENU; break; | |
3407 case TBIS_SMALL: size = GTK_ICON_SIZE_SMALL_TOOLBAR; break; | |
3408 case TBIS_MEDIUM: size = GTK_ICON_SIZE_BUTTON; break; | |
3409 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
|
3410 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
|
3411 case TBIS_GIANT: size = GTK_ICON_SIZE_DIALOG; break; |
7 | 3412 default: size = GTK_ICON_SIZE_INVALID; break; |
3413 } | |
3414 oldsize = gtk_toolbar_get_icon_size(toolbar); | |
3415 | |
3416 if (size == GTK_ICON_SIZE_INVALID) | |
3417 { | |
3418 /* Let global user preferences decide the icon size. */ | |
3419 gtk_toolbar_unset_icon_size(toolbar); | |
3420 size = gtk_toolbar_get_icon_size(toolbar); | |
3421 } | |
3422 if (size != oldsize) | |
3423 { | |
3424 gtk_container_foreach(GTK_CONTAINER(toolbar), | |
3425 &icon_size_changed_foreach, | |
3426 GINT_TO_POINTER((int)size)); | |
3427 } | |
3428 gtk_toolbar_set_icon_size(toolbar, size); | |
3429 } | |
3430 | |
3431 #endif /* FEAT_TOOLBAR */ | |
3432 | |
685 | 3433 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
3434 static int ignore_tabline_evt = FALSE; | |
689 | 3435 static GtkWidget *tabline_menu; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3436 # if !GTK_CHECK_VERSION(3,0,0) |
846 | 3437 static GtkTooltips *tabline_tooltip; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3438 # endif |
689 | 3439 static int clicked_page; /* page clicked in tab line */ |
3440 | |
3441 /* | |
3442 * Handle selecting an item in the tab line popup menu. | |
3443 */ | |
3444 static void | |
1884 | 3445 tabline_menu_handler(GtkMenuItem *item UNUSED, gpointer user_data) |
689 | 3446 { |
3447 /* Add the string cmd into input buffer */ | |
824 | 3448 send_tabline_menu_event(clicked_page, (int)(long)user_data); |
689 | 3449 } |
3450 | |
851 | 3451 static void |
3452 add_tabline_menu_item(GtkWidget *menu, char_u *text, int resp) | |
3453 { | |
3454 GtkWidget *item; | |
3455 char_u *utf_text; | |
3456 | |
3457 utf_text = CONVERT_TO_UTF8(text); | |
3458 item = gtk_menu_item_new_with_label((const char *)utf_text); | |
3459 gtk_widget_show(item); | |
3460 CONVERT_TO_UTF8_FREE(utf_text); | |
3461 | |
3462 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
|
3463 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3464 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
|
3465 G_CALLBACK(tabline_menu_handler), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3466 GINT_TO_POINTER(resp)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3467 # else |
851 | 3468 gtk_signal_connect(GTK_OBJECT(item), "activate", |
3469 GTK_SIGNAL_FUNC(tabline_menu_handler), | |
1660 | 3470 (gpointer)(long)resp); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3471 # endif |
851 | 3472 } |
3473 | |
689 | 3474 /* |
3475 * Create a menu for the tab line. | |
3476 */ | |
3477 static GtkWidget * | |
3478 create_tabline_menu(void) | |
3479 { | |
851 | 3480 GtkWidget *menu; |
689 | 3481 |
3482 menu = gtk_menu_new(); | |
6819 | 3483 if (first_tabpage->tp_next != NULL) |
3484 add_tabline_menu_item(menu, (char_u *)_("Close tab"), | |
3485 TABLINE_MENU_CLOSE); | |
851 | 3486 add_tabline_menu_item(menu, (char_u *)_("New tab"), TABLINE_MENU_NEW); |
3487 add_tabline_menu_item(menu, (char_u *)_("Open Tab..."), TABLINE_MENU_OPEN); | |
689 | 3488 |
3489 return menu; | |
3490 } | |
3491 | |
3492 static gboolean | |
3493 on_tabline_menu(GtkWidget *widget, GdkEvent *event) | |
3494 { | |
3495 /* Was this button press event ? */ | |
3496 if (event->type == GDK_BUTTON_PRESS) | |
3497 { | |
3498 GdkEventButton *bevent = (GdkEventButton *)event; | |
3499 int x = bevent->x; | |
851 | 3500 int y = bevent->y; |
3501 GtkWidget *tabwidget; | |
3502 GdkWindow *tabwin; | |
689 | 3503 |
844 | 3504 /* When ignoring events return TRUE so that the selected page doesn't |
3505 * change. */ | |
3506 if (hold_gui_events | |
3507 # ifdef FEAT_CMDWIN | |
3508 || cmdwin_type != 0 | |
3509 # endif | |
3510 ) | |
3511 return TRUE; | |
3512 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3513 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3514 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
|
3515 # else |
851 | 3516 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
|
3517 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3518 |
851 | 3519 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
|
3520 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3521 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
|
3522 "tab_num")); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3523 # else |
851 | 3524 clicked_page = (int)(long)gtk_object_get_user_data( |
3525 GTK_OBJECT(tabwidget)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3526 # endif |
689 | 3527 |
3528 /* If the event was generated for 3rd button popup the menu. */ | |
3529 if (bevent->button == 3) | |
3530 { | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3531 # 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
|
3532 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
|
3533 # else |
689 | 3534 gtk_menu_popup(GTK_MENU(widget), NULL, NULL, NULL, NULL, |
3535 bevent->button, bevent->time); | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3536 # endif |
689 | 3537 /* We handled the event. */ |
3538 return TRUE; | |
3539 } | |
868 | 3540 else if (bevent->button == 1) |
693 | 3541 { |
868 | 3542 if (clicked_page == 0) |
3543 { | |
1394 | 3544 /* Click after all tabs moves to next tab page. When "x" is |
3545 * 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
|
3546 send_tabline_event(x < 50 ? -1 : 0); |
868 | 3547 } |
693 | 3548 } |
689 | 3549 } |
844 | 3550 |
689 | 3551 /* We didn't handle the event. */ |
3552 return FALSE; | |
3553 } | |
685 | 3554 |
3555 /* | |
3556 * Handle selecting one of the tabs. | |
3557 */ | |
3558 static void | |
3559 on_select_tab( | |
1884 | 3560 GtkNotebook *notebook UNUSED, |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3561 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3562 gpointer *page UNUSED, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3563 # else |
1884 | 3564 GtkNotebookPage *page UNUSED, |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3565 # endif |
944 | 3566 gint idx, |
1884 | 3567 gpointer data UNUSED) |
685 | 3568 { |
3569 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
|
3570 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
|
3571 } |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3572 |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3573 /* |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3574 * 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
|
3575 */ |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3576 static void |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3577 on_tab_reordered( |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3578 GtkNotebook *notebook UNUSED, |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3579 # 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
|
3580 gpointer *page UNUSED, |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3581 # else |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3582 GtkNotebookPage *page UNUSED, |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3583 # endif |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3584 gint idx, |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3585 gpointer data UNUSED) |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3586 { |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3587 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
|
3588 { |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3589 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
|
3590 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
|
3591 else |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3592 tabpage_move(idx); |
693 | 3593 } |
685 | 3594 } |
3595 | |
3596 /* | |
3597 * Show or hide the tabline. | |
3598 */ | |
3599 void | |
3600 gui_mch_show_tabline(int showit) | |
3601 { | |
3602 if (gui.tabline == NULL) | |
3603 return; | |
3604 | |
3605 if (!showit != !gtk_notebook_get_show_tabs(GTK_NOTEBOOK(gui.tabline))) | |
3606 { | |
708 | 3607 /* Note: this may cause a resize event */ |
685 | 3608 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gui.tabline), showit); |
791 | 3609 update_window_manager_hints(0, 0); |
868 | 3610 if (showit) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3611 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3612 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
|
3613 # else |
868 | 3614 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
|
3615 # endif |
868 | 3616 } |
3617 | |
3618 gui_mch_update(); | |
685 | 3619 } |
3620 | |
3621 /* | |
708 | 3622 * Return TRUE when tabline is displayed. |
3623 */ | |
3624 int | |
3625 gui_mch_showing_tabline(void) | |
3626 { | |
3627 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
|
3628 && gtk_notebook_get_show_tabs(GTK_NOTEBOOK(gui.tabline)); |
708 | 3629 } |
3630 | |
3631 /* | |
685 | 3632 * Update the labels of the tabline. |
3633 */ | |
3634 void | |
3635 gui_mch_update_tabline(void) | |
3636 { | |
3637 GtkWidget *page; | |
846 | 3638 GtkWidget *event_box; |
685 | 3639 GtkWidget *label; |
3640 tabpage_T *tp; | |
3641 int nr = 0; | |
851 | 3642 int tab_num; |
685 | 3643 int curtabidx = 0; |
836 | 3644 char_u *labeltext; |
685 | 3645 |
3646 if (gui.tabline == NULL) | |
3647 return; | |
3648 | |
3649 ignore_tabline_evt = TRUE; | |
3650 | |
3651 /* Add a label for each tab page. They all contain the same text area. */ | |
3652 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr) | |
3653 { | |
3654 if (tp == curtab) | |
3655 curtabidx = nr; | |
3656 | |
851 | 3657 tab_num = nr + 1; |
3658 | |
685 | 3659 page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr); |
3660 if (page == NULL) | |
3661 { | |
3662 /* Add notebook page */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3663 # 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
|
3664 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
|
3665 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
|
3666 # else |
685 | 3667 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
|
3668 # endif |
685 | 3669 gtk_widget_show(page); |
846 | 3670 event_box = gtk_event_box_new(); |
3671 gtk_widget_show(event_box); | |
685 | 3672 label = gtk_label_new("-Empty-"); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3673 # if !GTK_CHECK_VERSION(3,14,0) |
851 | 3674 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
|
3675 # endif |
846 | 3676 gtk_container_add(GTK_CONTAINER(event_box), label); |
685 | 3677 gtk_widget_show(label); |
3678 gtk_notebook_insert_page(GTK_NOTEBOOK(gui.tabline), | |
3679 page, | |
846 | 3680 event_box, |
685 | 3681 nr++); |
12666
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3682 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
|
3683 page, |
856a840679e3
patch 8.0.1211: cannot reorder tab pages with drag & drop
Christian Brabandt <cb@256bit.org>
parents:
12413
diff
changeset
|
3684 TRUE); |
685 | 3685 } |
3686 | |
846 | 3687 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
|
3688 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3689 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
|
3690 GINT_TO_POINTER(tab_num)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3691 # else |
1660 | 3692 gtk_object_set_user_data(GTK_OBJECT(event_box), |
3693 (gpointer)(long)tab_num); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3694 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3695 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3696 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
|
3697 # else |
846 | 3698 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
|
3699 # endif |
839 | 3700 get_tabline_label(tp, FALSE); |
836 | 3701 labeltext = CONVERT_TO_UTF8(NameBuff); |
846 | 3702 gtk_label_set_text(GTK_LABEL(label), (const char *)labeltext); |
836 | 3703 CONVERT_TO_UTF8_FREE(labeltext); |
846 | 3704 |
3705 get_tabline_label(tp, TRUE); | |
3706 labeltext = CONVERT_TO_UTF8(NameBuff); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3707 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3708 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
|
3709 # else |
846 | 3710 gtk_tooltips_set_tip(GTK_TOOLTIPS(tabline_tooltip), event_box, |
3711 (const char *)labeltext, NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3712 # endif |
846 | 3713 CONVERT_TO_UTF8_FREE(labeltext); |
685 | 3714 } |
3715 | |
3716 /* Remove any old labels. */ | |
3717 while (gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr) != NULL) | |
3718 gtk_notebook_remove_page(GTK_NOTEBOOK(gui.tabline), nr); | |
3719 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3720 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3721 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
|
3722 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
|
3723 # else |
685 | 3724 if (gtk_notebook_current_page(GTK_NOTEBOOK(gui.tabline)) != curtabidx) |
856 | 3725 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
|
3726 # endif |
685 | 3727 |
851 | 3728 /* Make sure everything is in place before drawing text. */ |
3729 gui_mch_update(); | |
3730 | |
685 | 3731 ignore_tabline_evt = FALSE; |
3732 } | |
3733 | |
3734 /* | |
3735 * Set the current tab to "nr". First tab is 1. | |
3736 */ | |
3737 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
3738 gui_mch_set_curtab(int nr) |
685 | 3739 { |
3740 if (gui.tabline == NULL) | |
3741 return; | |
3742 | |
3743 ignore_tabline_evt = TRUE; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3744 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3745 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
|
3746 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
|
3747 # else |
685 | 3748 if (gtk_notebook_current_page(GTK_NOTEBOOK(gui.tabline)) != nr - 1) |
856 | 3749 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
|
3750 # endif |
685 | 3751 ignore_tabline_evt = FALSE; |
3752 } | |
3753 | |
3754 #endif /* FEAT_GUI_TABLINE */ | |
3755 | |
7 | 3756 /* |
2183 | 3757 * Add selection targets for PRIMARY and CLIPBOARD selections. |
3758 */ | |
3759 void | |
3760 gui_gtk_set_selection_targets(void) | |
3761 { | |
3762 int i, j = 0; | |
3763 int n_targets = N_SELECTION_TARGETS; | |
3764 GtkTargetEntry targets[N_SELECTION_TARGETS]; | |
3765 | |
3766 for (i = 0; i < (int)N_SELECTION_TARGETS; ++i) | |
3767 { | |
3518 | 3768 /* OpenOffice tries to use TARGET_HTML and fails when we don't |
2183 | 3769 * return something, instead of trying another target. Therefore only |
3770 * offer TARGET_HTML when it works. */ | |
3771 if (!clip_html && selection_targets[i].info == TARGET_HTML) | |
3772 n_targets--; | |
3773 else | |
3774 targets[j++] = selection_targets[i]; | |
3775 } | |
3776 | |
3777 gtk_selection_clear_targets(gui.drawarea, (GdkAtom)GDK_SELECTION_PRIMARY); | |
3778 gtk_selection_clear_targets(gui.drawarea, (GdkAtom)clip_plus.gtk_sel_atom); | |
3779 gtk_selection_add_targets(gui.drawarea, | |
3780 (GdkAtom)GDK_SELECTION_PRIMARY, | |
3781 targets, n_targets); | |
3782 gtk_selection_add_targets(gui.drawarea, | |
3783 (GdkAtom)clip_plus.gtk_sel_atom, | |
3784 targets, n_targets); | |
3785 } | |
3786 | |
3787 /* | |
3788 * Set up for receiving DND items. | |
3789 */ | |
3790 void | |
3791 gui_gtk_set_dnd_targets(void) | |
3792 { | |
3793 int i, j = 0; | |
3794 int n_targets = N_DND_TARGETS; | |
3795 GtkTargetEntry targets[N_DND_TARGETS]; | |
3796 | |
3797 for (i = 0; i < (int)N_DND_TARGETS; ++i) | |
3798 { | |
3154 | 3799 if (!clip_html && dnd_targets[i].info == TARGET_HTML) |
2183 | 3800 n_targets--; |
3801 else | |
3802 targets[j++] = dnd_targets[i]; | |
3803 } | |
3804 | |
3805 gtk_drag_dest_unset(gui.drawarea); | |
3806 gtk_drag_dest_set(gui.drawarea, | |
3807 GTK_DEST_DEFAULT_ALL, | |
3808 targets, n_targets, | |
2718 | 3809 GDK_ACTION_COPY | GDK_ACTION_MOVE); |
2183 | 3810 } |
3811 | |
3812 /* | |
7 | 3813 * Initialize the GUI. Create all the windows, set up all the callbacks etc. |
3814 * Returns OK for success, FAIL when the GUI can't be started. | |
3815 */ | |
3816 int | |
3817 gui_mch_init(void) | |
3818 { | |
3819 GtkWidget *vbox; | |
3820 | |
3821 #ifdef FEAT_GUI_GNOME | |
3822 /* Initialize the GNOME libraries. gnome_program_init()/gnome_init() | |
3823 * exits on failure, but that's a non-issue because we already called | |
3824 * gtk_init_check() in gui_mch_init_check(). */ | |
3825 if (using_gnome) | |
4045 | 3826 { |
7 | 3827 gnome_program_init(VIMPACKAGE, VIM_VERSION_SHORT, |
3828 LIBGNOMEUI_MODULE, gui_argc, gui_argv, NULL); | |
4045 | 3829 # if defined(FEAT_FLOAT) && defined(LC_NUMERIC) |
5854 | 3830 { |
3831 char *p = setlocale(LC_NUMERIC, NULL); | |
3832 | |
3833 /* Make sure strtod() uses a decimal point, not a comma. Gnome | |
3834 * init may change it. */ | |
3835 if (p == NULL || strcmp(p, "C") != 0) | |
3836 setlocale(LC_NUMERIC, "C"); | |
3837 } | |
4045 | 3838 # endif |
3839 } | |
7 | 3840 #endif |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13152
diff
changeset
|
3841 VIM_CLEAR(gui_argv); |
7 | 3842 |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3843 #if GLIB_CHECK_VERSION(2,1,3) |
7 | 3844 /* Set the human-readable application name */ |
3845 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
|
3846 #endif |
7 | 3847 /* |
3848 * Force UTF-8 output no matter what the value of 'encoding' is. | |
3849 * did_set_string_option() in option.c prohibits changing 'termencoding' | |
3850 * to something else than UTF-8 if the GUI is in use. | |
3851 */ | |
3852 set_option_value((char_u *)"termencoding", 0L, (char_u *)"utf-8", 0); | |
3853 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3854 #ifdef FEAT_TOOLBAR |
7 | 3855 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
|
3856 #endif |
7 | 3857 /* FIXME: Need to install the classic icons and a gtkrc.classic file. |
3858 * 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
|
3859 #if !GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3860 # if 0 |
7 | 3861 gtk_rc_parse("gtkrc"); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3862 # endif |
7 | 3863 #endif |
3864 | |
3865 /* Initialize values */ | |
3866 gui.border_width = 2; | |
3867 gui.scrollbar_width = SB_DEFAULT_WIDTH; | |
3868 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
|
3869 #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
|
3870 gui.fgcolor = g_new(GdkRGBA, 1); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
3871 gui.bgcolor = g_new(GdkRGBA, 1); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
3872 gui.spcolor = g_new(GdkRGBA, 1); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
3873 #else |
136 | 3874 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
7 | 3875 gui.fgcolor = g_new0(GdkColor, 1); |
136 | 3876 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
7 | 3877 gui.bgcolor = g_new0(GdkColor, 1); |
207 | 3878 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
3879 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
|
3880 #endif |
7 | 3881 |
3882 /* Initialise atoms */ | |
1904 | 3883 html_atom = gdk_atom_intern("text/html", FALSE); |
7 | 3884 utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE); |
3885 | |
3886 /* Set default foreground and background colors. */ | |
3887 gui.norm_pixel = gui.def_norm_pixel; | |
3888 gui.back_pixel = gui.def_back_pixel; | |
3889 | |
3890 if (gtk_socket_id != 0) | |
3891 { | |
3892 GtkWidget *plug; | |
3893 | |
3894 /* Use GtkSocket from another app. */ | |
3895 plug = gtk_plug_new_for_display(gdk_display_get_default(), | |
3896 gtk_socket_id); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3897 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3898 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
|
3899 #else |
7 | 3900 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
|
3901 #endif |
7 | 3902 { |
3903 gui.mainwin = plug; | |
3904 } | |
3905 else | |
3906 { | |
3907 g_warning("Connection to GTK+ socket (ID %u) failed", | |
3908 (unsigned int)gtk_socket_id); | |
3909 /* Pretend we never wanted it if it failed (get own window) */ | |
3910 gtk_socket_id = 0; | |
3911 } | |
3912 } | |
3913 | |
3914 if (gtk_socket_id == 0) | |
3915 { | |
3916 #ifdef FEAT_GUI_GNOME | |
3917 if (using_gnome) | |
3918 { | |
3919 gui.mainwin = gnome_app_new("Vim", NULL); | |
3920 # ifdef USE_XSMP | |
3921 /* Use the GNOME save-yourself functionality now. */ | |
3922 xsmp_close(); | |
3923 # endif | |
3924 } | |
3925 else | |
3926 #endif | |
3927 gui.mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
3928 } | |
3929 | |
3930 gtk_widget_set_name(gui.mainwin, "vim-main-window"); | |
3931 | |
3932 /* Create the PangoContext used for drawing all text. */ | |
3933 gui.text_context = gtk_widget_create_pango_context(gui.mainwin); | |
3934 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
|
3935 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3936 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3937 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
|
3938 #else |
7 | 3939 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
|
3940 #endif |
7 | 3941 gtk_widget_add_events(gui.mainwin, GDK_VISIBILITY_NOTIFY_MASK); |
3942 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3943 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3944 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
|
3945 G_CALLBACK(&delete_event_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3946 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3947 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
|
3948 G_CALLBACK(&mainwin_realize), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3949 #else |
7 | 3950 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "delete_event", |
3951 GTK_SIGNAL_FUNC(&delete_event_cb), NULL); | |
3952 | |
3953 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "realize", | |
3954 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
|
3955 #endif |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3956 |
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3957 g_signal_connect(G_OBJECT(gui.mainwin), "screen-changed", |
7 | 3958 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
|
3959 |
7 | 3960 gui.accel_group = gtk_accel_group_new(); |
3961 gtk_window_add_accel_group(GTK_WINDOW(gui.mainwin), gui.accel_group); | |
3962 | |
685 | 3963 /* 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
|
3964 #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
|
3965 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
|
3966 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
|
3967 #else |
7 | 3968 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
|
3969 #endif |
7 | 3970 |
3971 #ifdef FEAT_GUI_GNOME | |
3972 if (using_gnome) | |
3973 { | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3974 # if defined(FEAT_MENU) |
7 | 3975 /* automagically restore menubar/toolbar placement */ |
3976 gnome_app_enable_layout_config(GNOME_APP(gui.mainwin), TRUE); | |
3977 # endif | |
3978 gnome_app_set_contents(GNOME_APP(gui.mainwin), vbox); | |
3979 } | |
3980 else | |
3981 #endif | |
3982 { | |
3983 gtk_container_add(GTK_CONTAINER(gui.mainwin), vbox); | |
3984 gtk_widget_show(vbox); | |
3985 } | |
3986 | |
3987 #ifdef FEAT_MENU | |
3988 /* | |
3989 * Create the menubar and handle | |
3990 */ | |
3991 gui.menubar = gtk_menu_bar_new(); | |
3992 gtk_widget_set_name(gui.menubar, "vim-menubar"); | |
3993 | |
36 | 3994 /* Avoid that GTK takes <F10> away from us. */ |
3995 { | |
3996 GtkSettings *gtk_settings; | |
3997 | |
3998 gtk_settings = gtk_settings_get_for_screen(gdk_screen_get_default()); | |
3999 g_object_set(gtk_settings, "gtk-menu-bar-accel", NULL, NULL); | |
4000 } | |
4001 | |
4002 | |
7 | 4003 # ifdef FEAT_GUI_GNOME |
4004 if (using_gnome) | |
4005 { | |
4006 BonoboDockItem *dockitem; | |
4007 | |
4008 gnome_app_set_menus(GNOME_APP(gui.mainwin), GTK_MENU_BAR(gui.menubar)); | |
4009 dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), | |
4010 GNOME_APP_MENUBAR_NAME); | |
798 | 4011 /* We don't want the menu to float. */ |
4012 bonobo_dock_item_set_behavior(dockitem, | |
4013 bonobo_dock_item_get_behavior(dockitem) | |
4014 | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); | |
7 | 4015 gui.menubar_h = GTK_WIDGET(dockitem); |
4016 } | |
4017 else | |
4018 # endif /* FEAT_GUI_GNOME */ | |
4019 { | |
827 | 4020 /* Always show the menubar, otherwise <F10> doesn't work. It may be |
4021 * disabled in gui_init() later. */ | |
4022 gtk_widget_show(gui.menubar); | |
7 | 4023 gtk_box_pack_start(GTK_BOX(vbox), gui.menubar, FALSE, FALSE, 0); |
4024 } | |
4025 #endif /* FEAT_MENU */ | |
4026 | |
4027 #ifdef FEAT_TOOLBAR | |
4028 /* | |
4029 * Create the toolbar and handle | |
4030 */ | |
4031 /* some aesthetics on the toolbar */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4032 # ifdef USE_GTK3 |
8301
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4033 /* 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
|
4034 /* 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
|
4035 * 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
|
4036 # else |
7 | 4037 gtk_rc_parse_string( |
4038 "style \"vim-toolbar-style\" {\n" | |
4039 " GtkToolbar::button_relief = GTK_RELIEF_NONE\n" | |
4040 "}\n" | |
4041 "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
|
4042 # endif |
7 | 4043 gui.toolbar = gtk_toolbar_new(); |
4044 gtk_widget_set_name(gui.toolbar, "vim-toolbar"); | |
4045 set_toolbar_style(GTK_TOOLBAR(gui.toolbar)); | |
4046 | |
4047 # ifdef FEAT_GUI_GNOME | |
4048 if (using_gnome) | |
4049 { | |
4050 BonoboDockItem *dockitem; | |
4051 | |
4052 gnome_app_set_toolbar(GNOME_APP(gui.mainwin), GTK_TOOLBAR(gui.toolbar)); | |
4053 dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), | |
4054 GNOME_APP_TOOLBAR_NAME); | |
4055 gui.toolbar_h = GTK_WIDGET(dockitem); | |
795 | 4056 /* When the toolbar is floating it gets stuck. So long as that isn't |
798 | 4057 * fixed let's disallow floating. */ |
795 | 4058 bonobo_dock_item_set_behavior(dockitem, |
798 | 4059 bonobo_dock_item_get_behavior(dockitem) |
4060 | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); | |
7 | 4061 gtk_container_set_border_width(GTK_CONTAINER(gui.toolbar), 0); |
4062 } | |
4063 else | |
4064 # endif /* FEAT_GUI_GNOME */ | |
4065 { | |
4066 if (vim_strchr(p_go, GO_TOOLBAR) != NULL | |
4067 && (toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS))) | |
4068 gtk_widget_show(gui.toolbar); | |
4069 gtk_box_pack_start(GTK_BOX(vbox), gui.toolbar, FALSE, FALSE, 0); | |
4070 } | |
4071 #endif /* FEAT_TOOLBAR */ | |
4072 | |
685 | 4073 #ifdef FEAT_GUI_TABLINE |
782 | 4074 /* |
4075 * Use a Notebook for the tab pages labels. The labels are hidden by | |
4076 * default. | |
4077 */ | |
791 | 4078 gui.tabline = gtk_notebook_new(); |
4079 gtk_widget_show(gui.tabline); | |
4080 gtk_box_pack_start(GTK_BOX(vbox), gui.tabline, FALSE, FALSE, 0); | |
4081 gtk_notebook_set_show_border(GTK_NOTEBOOK(gui.tabline), FALSE); | |
4082 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gui.tabline), FALSE); | |
841 | 4083 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
|
4084 # if !GTK_CHECK_VERSION(3,0,0) |
868 | 4085 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
|
4086 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4087 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4088 # if !GTK_CHECK_VERSION(3,0,0) |
846 | 4089 tabline_tooltip = gtk_tooltips_new(); |
4090 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
|
4091 # endif |
846 | 4092 |
4093 { | |
4094 GtkWidget *page, *label, *event_box; | |
791 | 4095 |
856 | 4096 /* Add the first tab. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4097 # 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
|
4098 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
|
4099 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
|
4100 # else |
846 | 4101 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
|
4102 # endif |
846 | 4103 gtk_widget_show(page); |
4104 gtk_container_add(GTK_CONTAINER(gui.tabline), page); | |
4105 label = gtk_label_new("-Empty-"); | |
4106 gtk_widget_show(label); | |
4107 event_box = gtk_event_box_new(); | |
4108 gtk_widget_show(event_box); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4109 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4110 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
|
4111 # else |
1660 | 4112 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
|
4113 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4114 # if !GTK_CHECK_VERSION(3,14,0) |
851 | 4115 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
|
4116 # endif |
846 | 4117 gtk_container_add(GTK_CONTAINER(event_box), label); |
4118 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
|
4119 gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(gui.tabline), page, TRUE); |
791 | 4120 } |
865 | 4121 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4122 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4123 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
|
4124 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
|
4125 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
|
4126 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
|
4127 # else |
791 | 4128 gtk_signal_connect(GTK_OBJECT(gui.tabline), "switch_page", |
856 | 4129 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
|
4130 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
|
4131 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
|
4132 # endif |
791 | 4133 |
4134 /* Create a popup menu for the tab line and connect it. */ | |
4135 tabline_menu = create_tabline_menu(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4136 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4137 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
|
4138 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
|
4139 # else |
791 | 4140 gtk_signal_connect_object(GTK_OBJECT(gui.tabline), "button_press_event", |
856 | 4141 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
|
4142 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4143 #endif /* FEAT_GUI_TABLINE */ |
685 | 4144 |
7 | 4145 gui.formwin = gtk_form_new(); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4146 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4147 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
|
4148 #else |
7 | 4149 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
|
4150 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4151 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 4152 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
|
4153 #endif |
7 | 4154 |
4155 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
|
4156 #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
|
4157 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
|
4158 #endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4159 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4160 gui.surface = NULL; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4161 gui.by_signal = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4162 #endif |
7 | 4163 |
4164 /* Determine which events we will filter. */ | |
4165 gtk_widget_set_events(gui.drawarea, | |
4166 GDK_EXPOSURE_MASK | | |
4167 GDK_ENTER_NOTIFY_MASK | | |
4168 GDK_LEAVE_NOTIFY_MASK | | |
4169 GDK_BUTTON_PRESS_MASK | | |
4170 GDK_BUTTON_RELEASE_MASK | | |
4171 GDK_SCROLL_MASK | | |
4172 GDK_KEY_PRESS_MASK | | |
4173 GDK_KEY_RELEASE_MASK | | |
4174 GDK_POINTER_MOTION_MASK | | |
4175 GDK_POINTER_MOTION_HINT_MASK); | |
4176 | |
4177 gtk_widget_show(gui.drawarea); | |
4178 gtk_form_put(GTK_FORM(gui.formwin), gui.drawarea, 0, 0); | |
4179 gtk_widget_show(gui.formwin); | |
4180 gtk_box_pack_start(GTK_BOX(vbox), gui.formwin, TRUE, TRUE, 0); | |
4181 | |
4182 /* For GtkSockets, key-presses must go to the focus widget (drawarea) | |
4183 * and not the window. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4184 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4185 g_signal_connect((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
|
4186 : G_OBJECT(gui.drawarea), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4187 "key-press-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4188 G_CALLBACK(key_press_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4189 #else |
7 | 4190 gtk_signal_connect((gtk_socket_id == 0) ? GTK_OBJECT(gui.mainwin) |
4191 : GTK_OBJECT(gui.drawarea), | |
4192 "key_press_event", | |
4193 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
|
4194 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4195 #if defined(FEAT_XIM) || GTK_CHECK_VERSION(3,0,0) |
7 | 4196 /* Also forward key release events for the benefit of GTK+ 2 input |
4197 * modules. Try CTRL-SHIFT-xdigits to enter a Unicode code point. */ | |
4198 g_signal_connect((gtk_socket_id == 0) ? G_OBJECT(gui.mainwin) | |
4199 : G_OBJECT(gui.drawarea), | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4200 "key-release-event", |
7 | 4201 G_CALLBACK(&key_release_event), NULL); |
4202 #endif | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4203 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4204 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
|
4205 G_CALLBACK(drawarea_realize_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4206 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
|
4207 G_CALLBACK(drawarea_unrealize_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4208 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
|
4209 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
|
4210 # 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
|
4211 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
|
4212 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
|
4213 # else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4214 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
|
4215 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
|
4216 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4217 #else |
7 | 4218 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "realize", |
4219 GTK_SIGNAL_FUNC(drawarea_realize_cb), NULL); | |
4220 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "unrealize", | |
4221 GTK_SIGNAL_FUNC(drawarea_unrealize_cb), NULL); | |
4222 | |
4223 gtk_signal_connect_after(GTK_OBJECT(gui.drawarea), "style_set", | |
4224 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
|
4225 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4226 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4227 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 4228 gui.visibility = GDK_VISIBILITY_UNOBSCURED; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4229 #endif |
7 | 4230 |
4231 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
4232 wm_protocols_atom = gdk_atom_intern("WM_PROTOCOLS", FALSE); | |
4233 save_yourself_atom = gdk_atom_intern("WM_SAVE_YOURSELF", FALSE); | |
4234 #endif | |
4235 | |
4236 if (gtk_socket_id != 0) | |
1884 | 4237 /* 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
|
4238 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4239 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
|
4240 #else |
7 | 4241 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
|
4242 #endif |
7 | 4243 |
4244 /* | |
4245 * Set clipboard specific atoms | |
4246 */ | |
4247 vim_atom = gdk_atom_intern(VIM_ATOM_NAME, FALSE); | |
4248 vimenc_atom = gdk_atom_intern(VIMENC_ATOM_NAME, FALSE); | |
4249 clip_star.gtk_sel_atom = GDK_SELECTION_PRIMARY; | |
4250 clip_plus.gtk_sel_atom = gdk_atom_intern("CLIPBOARD", FALSE); | |
4251 | |
4252 /* | |
4253 * Start out by adding the configured border width into the border offset. | |
4254 */ | |
4255 gui.border_offset = gui.border_width; | |
4256 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4257 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4258 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
|
4259 G_CALLBACK(draw_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4260 #else |
7 | 4261 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "visibility_notify_event", |
4262 GTK_SIGNAL_FUNC(visibility_event), NULL); | |
4263 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "expose_event", | |
4264 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
|
4265 #endif |
7 | 4266 |
4267 /* | |
4268 * Only install these enter/leave callbacks when 'p' in 'guioptions'. | |
4269 * Only needed for some window managers. | |
4270 */ | |
4271 if (vim_strchr(p_go, GO_POINTER) != NULL) | |
4272 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4273 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4274 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
|
4275 G_CALLBACK(leave_notify_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4276 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
|
4277 G_CALLBACK(enter_notify_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4278 #else |
7 | 4279 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "leave_notify_event", |
4280 GTK_SIGNAL_FUNC(leave_notify_event), NULL); | |
4281 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "enter_notify_event", | |
4282 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
|
4283 #endif |
7 | 4284 } |
4285 | |
791 | 4286 /* Real windows can get focus ... GtkPlug, being a mere container can't, |
4287 * only its widgets. Arguably, this could be common code and we not use | |
4288 * the window focus at all, but let's be safe. | |
4289 */ | |
4290 if (gtk_socket_id == 0) | |
4291 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4292 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4293 g_signal_connect(G_OBJECT(gui.mainwin), "focus-out-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4294 G_CALLBACK(focus_out_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4295 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
|
4296 G_CALLBACK(focus_in_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4297 #else |
856 | 4298 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "focus_out_event", |
4299 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
4300 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "focus_in_event", | |
4301 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
|
4302 #endif |
791 | 4303 } |
4304 else | |
4305 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4306 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4307 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
|
4308 G_CALLBACK(focus_out_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4309 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
|
4310 G_CALLBACK(focus_in_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4311 #else |
856 | 4312 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "focus_out_event", |
4313 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
4314 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "focus_in_event", | |
4315 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
|
4316 #endif |
791 | 4317 #ifdef FEAT_GUI_TABLINE |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4318 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4319 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
|
4320 G_CALLBACK(focus_out_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4321 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
|
4322 G_CALLBACK(focus_in_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4323 # else |
856 | 4324 gtk_signal_connect(GTK_OBJECT(gui.tabline), "focus_out_event", |
4325 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
4326 gtk_signal_connect(GTK_OBJECT(gui.tabline), "focus_in_event", | |
4327 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
|
4328 # endif |
791 | 4329 #endif /* FEAT_GUI_TABLINE */ |
4330 } | |
7 | 4331 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4332 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4333 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
|
4334 G_CALLBACK(motion_notify_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4335 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
|
4336 G_CALLBACK(button_press_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4337 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
|
4338 G_CALLBACK(button_release_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4339 g_signal_connect(G_OBJECT(gui.drawarea), "scroll-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4340 G_CALLBACK(&scroll_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4341 #else |
7 | 4342 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "motion_notify_event", |
4343 GTK_SIGNAL_FUNC(motion_notify_event), NULL); | |
4344 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "button_press_event", | |
4345 GTK_SIGNAL_FUNC(button_press_event), NULL); | |
4346 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "button_release_event", | |
4347 GTK_SIGNAL_FUNC(button_release_event), NULL); | |
4348 g_signal_connect(G_OBJECT(gui.drawarea), "scroll_event", | |
4349 G_CALLBACK(&scroll_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4350 #endif |
7 | 4351 |
4352 /* | |
4353 * Add selection handler functions. | |
4354 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4355 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4356 g_signal_connect(G_OBJECT(gui.drawarea), "selection-clear-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4357 G_CALLBACK(selection_clear_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4358 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
|
4359 G_CALLBACK(selection_received_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4360 #else |
7 | 4361 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_clear_event", |
4362 GTK_SIGNAL_FUNC(selection_clear_event), NULL); | |
4363 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_received", | |
4364 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
|
4365 #endif |
7 | 4366 |
2183 | 4367 gui_gtk_set_selection_targets(); |
7 | 4368 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4369 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4370 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
|
4371 G_CALLBACK(selection_get_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4372 #else |
7 | 4373 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_get", |
4374 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
|
4375 #endif |
7 | 4376 |
4377 /* Pretend we don't have input focus, we will get an event if we do. */ | |
4378 gui.in_focus = FALSE; | |
4379 | |
4380 return OK; | |
4381 } | |
4382 | |
4383 #if (defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) || defined(PROTO) | |
4384 /* | |
4385 * This is called from gui_start() after a fork() has been done. | |
4386 * We have to tell the session manager our new PID. | |
4387 */ | |
4388 void | |
4389 gui_mch_forked(void) | |
4390 { | |
4391 if (using_gnome) | |
4392 { | |
4393 GnomeClient *client; | |
4394 | |
4395 client = gnome_master_client(); | |
4396 | |
4397 if (client != NULL) | |
4398 gnome_client_set_process_id(client, getpid()); | |
4399 } | |
4400 } | |
4401 #endif /* FEAT_GUI_GNOME && FEAT_SESSION */ | |
4402 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4403 #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
|
4404 static GdkRGBA |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4405 color_to_rgba(guicolor_T color) |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4406 { |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4407 GdkRGBA rgba; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4408 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
|
4409 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
|
4410 rgba.blue = ((color & 0xff)) / 255.0; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4411 rgba.alpha = 1.0; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4412 return rgba; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4413 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4414 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4415 static void |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4416 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
|
4417 { |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4418 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
|
4419 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
|
4420 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4421 #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
|
4422 |
7 | 4423 /* |
4424 * Called when the foreground or background color has been changed. | |
4425 * This used to change the graphics contexts directly but we are | |
4426 * currently manipulating them where desired. | |
4427 */ | |
4428 void | |
4429 gui_mch_new_colors(void) | |
4430 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4431 #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
|
4432 # 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
|
4433 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
|
4434 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4435 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4436 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
|
4437 #else |
7 | 4438 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
|
4439 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4440 { |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4441 #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
|
4442 GtkStyleContext * const context |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4443 = 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
|
4444 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
|
4445 gchar * const css = g_strdup_printf( |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4446 "widget#vim-gui-drawarea {\n" |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4447 " background-color: #%.2lx%.2lx%.2lx;\n" |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4448 "}\n", |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4449 (gui.back_pixel >> 16) & 0xff, |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4450 (gui.back_pixel >> 8) & 0xff, |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4451 gui.back_pixel & 0xff); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4452 |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4453 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
|
4454 gtk_style_context_add_provider(context, |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4455 GTK_STYLE_PROVIDER(provider), G_MAXUINT); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4456 |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4457 g_free(css); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4458 g_object_unref(provider); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4459 #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
|
4460 GdkRGBA rgba; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4461 |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4462 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
|
4463 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4464 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
|
4465 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
|
4466 if (pat != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4467 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4468 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
|
4469 cairo_pattern_destroy(pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4470 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4471 else |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
4472 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
|
4473 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4474 #else /* !GTK_CHECK_VERSION(3,4,0) */ |
7 | 4475 GdkColor color = { 0, 0, 0, 0 }; |
4476 | |
4477 color.pixel = gui.back_pixel; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4478 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4479 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
|
4480 # else |
7 | 4481 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
|
4482 # endif |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4483 #endif /* !GTK_CHECK_VERSION(3,22,2) */ |
7 | 4484 } |
4485 } | |
4486 | |
4487 /* | |
4488 * This signal informs us about the need to rearrange our sub-widgets. | |
4489 */ | |
4490 static gint | |
1884 | 4491 form_configure_event(GtkWidget *widget UNUSED, |
4492 GdkEventConfigure *event, | |
4493 gpointer data UNUSED) | |
7 | 4494 { |
791 | 4495 int usable_height = event->height; |
4496 | |
10402
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
4497 #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
|
4498 /* 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
|
4499 * 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
|
4500 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4501 * 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
|
4502 * 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
|
4503 * 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
|
4504 * "native" one from non-native one. |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4505 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4506 * 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
|
4507 * 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
|
4508 * gui.formwin. |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4509 * |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4510 * 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
|
4511 * 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
|
4512 */ |
10402
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
4513 /* Follow-up |
65646e5652df
commit https://github.com/vim/vim/commit/182707ac10d77359bf7a87c6b23ce4025d5b0ad4
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
4514 * 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
|
4515 * 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
|
4516 * 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
|
4517 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
|
4518 return TRUE; |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4519 #endif |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4520 |
791 | 4521 /* When in a GtkPlug, we can't guarantee valid heights (as a round |
4522 * no. of char-heights), so we have to manually sanitise them. | |
4523 * Widths seem to sort themselves out, don't ask me why. | |
4524 */ | |
4525 if (gtk_socket_id != 0) | |
856 | 4526 usable_height -= (gui.char_height - (gui.char_height/2)); /* sic. */ |
791 | 4527 |
7 | 4528 gtk_form_freeze(GTK_FORM(gui.formwin)); |
791 | 4529 gui_resize_shell(event->width, usable_height); |
7 | 4530 gtk_form_thaw(GTK_FORM(gui.formwin)); |
4531 | |
4532 return TRUE; | |
4533 } | |
4534 | |
4535 /* | |
4536 * Function called when window already closed. | |
4537 * We can't do much more here than to trying to preserve what had been done, | |
4538 * since the window is already inevitably going away. | |
4539 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4540 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4541 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4542 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
|
4543 #else |
7 | 4544 static void |
1884 | 4545 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
|
4546 #endif |
7 | 4547 { |
4548 /* Don't write messages to the GUI anymore */ | |
4549 full_screen = FALSE; | |
4550 | |
4551 gui.mainwin = NULL; | |
4552 gui.drawarea = NULL; | |
4553 | |
4554 if (!exiting) /* only do anything if the destroy was unexpected */ | |
4555 { | |
419 | 4556 vim_strncpy(IObuff, |
4557 (char_u *)_("Vim: Main window unexpectedly destroyed\n"), | |
4558 IOSIZE - 1); | |
7 | 4559 preserve_exit(); |
4560 } | |
7380
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
4561 #ifdef USE_GRESOURCE |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
4562 gui_gtk_unregister_resource(); |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
4563 #endif |
7 | 4564 } |
4565 | |
791 | 4566 |
4567 /* | |
4568 * Bit of a hack to ensure we start GtkPlug windows with the correct window | |
4569 * hints (and thus the required size from -geom), but that after that we | |
4570 * put the hints back to normal (the actual minimum size) so we may | |
4571 * subsequently be resized smaller. GtkSocket (the parent end) uses the | |
1226 | 4572 * plug's window 'min hints to set *it's* minimum size, but that's also the |
791 | 4573 * only way we have of making ourselves bigger (by set lines/columns). |
4574 * 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
|
4575 * 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
|
4576 * scrollbar init.), actually do the standard hints and stop the timer. |
791 | 4577 * We'll not let the default hints be set while this timer's active. |
4578 */ | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
4579 static timeout_cb_type |
1884 | 4580 check_startup_plug_hints(gpointer data UNUSED) |
791 | 4581 { |
4582 if (init_window_hints_state == 1) | |
4583 { | |
856 | 4584 /* Safe to use normal hints now */ |
4585 init_window_hints_state = 0; | |
4586 update_window_manager_hints(0, 0); | |
4587 return FALSE; /* stop timer */ | |
791 | 4588 } |
4589 | |
4590 /* Keep on trying */ | |
4591 init_window_hints_state = 1; | |
4592 return TRUE; | |
4593 } | |
4594 | |
7 | 4595 /* |
4596 * Open the GUI window which was created by a call to gui_mch_init(). | |
4597 */ | |
4598 int | |
4599 gui_mch_open(void) | |
4600 { | |
4601 guicolor_T fg_pixel = INVALCOLOR; | |
4602 guicolor_T bg_pixel = INVALCOLOR; | |
1966 | 4603 guint pixel_width; |
4604 guint pixel_height; | |
7 | 4605 |
4606 /* | |
4607 * Allow setting a window role on the command line, or invent one | |
4608 * if none was specified. This is mainly useful for GNOME session | |
4609 * support; allowing the WM to restore window placement. | |
4610 */ | |
4611 if (role_argument != NULL) | |
4612 { | |
4613 gtk_window_set_role(GTK_WINDOW(gui.mainwin), role_argument); | |
4614 } | |
4615 else | |
4616 { | |
4617 char *role; | |
4618 | |
4619 /* Invent a unique-enough ID string for the role */ | |
4620 role = g_strdup_printf("vim-%u-%u-%u", | |
4621 (unsigned)mch_get_pid(), | |
4622 (unsigned)g_random_int(), | |
4623 (unsigned)time(NULL)); | |
4624 | |
4625 gtk_window_set_role(GTK_WINDOW(gui.mainwin), role); | |
4626 g_free(role); | |
4627 } | |
4628 | |
4629 if (gui_win_x != -1 && gui_win_y != -1) | |
4630 gtk_window_move(GTK_WINDOW(gui.mainwin), gui_win_x, gui_win_y); | |
4631 | |
4632 /* Determine user specified geometry, if present. */ | |
4633 if (gui.geom != NULL) | |
4634 { | |
4635 int mask; | |
4636 unsigned int w, h; | |
4637 int x = 0; | |
4638 int y = 0; | |
4639 | |
4640 mask = XParseGeometry((char *)gui.geom, &x, &y, &w, &h); | |
4641 | |
4642 if (mask & WidthValue) | |
4643 Columns = w; | |
4644 if (mask & HeightValue) | |
857 | 4645 { |
1884 | 4646 if (p_window > (long)h - 1 || !option_was_set((char_u *)"window")) |
857 | 4647 p_window = h - 1; |
7 | 4648 Rows = h; |
857 | 4649 } |
5070
cf52d2a8c05c
updated for version 7.3.1278
Bram Moolenaar <bram@vim.org>
parents:
4474
diff
changeset
|
4650 limit_screen_size(); |
1426 | 4651 |
4652 pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width); | |
4653 pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height); | |
4654 | |
4655 pixel_width += get_menu_tool_width(); | |
4656 pixel_height += get_menu_tool_height(); | |
4657 | |
7 | 4658 if (mask & (XValue | YValue)) |
1426 | 4659 { |
1757 | 4660 int ww, hh; |
4661 gui_mch_get_screen_dimensions(&ww, &hh); | |
4662 hh += p_ghr + get_menu_tool_height(); | |
4663 ww += get_menu_tool_width(); | |
1426 | 4664 if (mask & XNegative) |
1757 | 4665 x += ww - pixel_width; |
1426 | 4666 if (mask & YNegative) |
1757 | 4667 y += hh - pixel_height; |
7 | 4668 gtk_window_move(GTK_WINDOW(gui.mainwin), x, y); |
1426 | 4669 } |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13152
diff
changeset
|
4670 VIM_CLEAR(gui.geom); |
791 | 4671 |
856 | 4672 /* From now until everyone's stopped trying to set the window hints |
4673 * to their correct minimum values, stop them being set as we need | |
4674 * them to remain at our required size for the parent GtkSocket to | |
4675 * give us the right initial size. | |
4676 */ | |
791 | 4677 if (gtk_socket_id != 0 && (mask & WidthValue || mask & HeightValue)) |
856 | 4678 { |
4679 update_window_manager_hints(pixel_width, pixel_height); | |
4680 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
|
4681 timeout_add(1000, check_startup_plug_hints, NULL); |
856 | 4682 } |
7 | 4683 } |
4684 | |
1966 | 4685 pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width); |
4686 pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height); | |
4687 /* For GTK2 changing the size of the form widget doesn't cause window | |
4688 * resizing. */ | |
2254
4620acaf4814
One more fix for conceal patch.
Bram Moolenaar <bram@vim.org>
parents:
2248
diff
changeset
|
4689 if (gtk_socket_id == 0) |
1966 | 4690 gtk_window_resize(GTK_WINDOW(gui.mainwin), pixel_width, pixel_height); |
791 | 4691 update_window_manager_hints(0, 0); |
7 | 4692 |
4693 if (foreground_argument != NULL) | |
4694 fg_pixel = gui_get_color((char_u *)foreground_argument); | |
4695 if (fg_pixel == INVALCOLOR) | |
4696 fg_pixel = gui_get_color((char_u *)"Black"); | |
4697 | |
4698 if (background_argument != NULL) | |
4699 bg_pixel = gui_get_color((char_u *)background_argument); | |
4700 if (bg_pixel == INVALCOLOR) | |
4701 bg_pixel = gui_get_color((char_u *)"White"); | |
4702 | |
4703 if (found_reverse_arg) | |
4704 { | |
4705 gui.def_norm_pixel = bg_pixel; | |
4706 gui.def_back_pixel = fg_pixel; | |
4707 } | |
4708 else | |
4709 { | |
4710 gui.def_norm_pixel = fg_pixel; | |
4711 gui.def_back_pixel = bg_pixel; | |
4712 } | |
4713 | |
4714 /* Get the colors from the "Normal" and "Menu" group (set in syntax.c or | |
4715 * in a vimrc file) */ | |
4716 set_normal_colors(); | |
4717 | |
4718 /* Check that none of the colors are the same as the background color */ | |
4719 gui_check_colors(); | |
4720 | |
4721 /* Get the colors for the highlight groups (gui_check_colors() might have | |
4722 * changed them). */ | |
4723 highlight_gui_started(); /* re-init colors and fonts */ | |
4724 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4725 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4726 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
|
4727 G_CALLBACK(mainwin_destroy_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4728 #else |
7 | 4729 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "destroy", |
4730 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
|
4731 #endif |
7 | 4732 |
4733 #ifdef FEAT_HANGULIN | |
4734 hangul_keyboard_set(); | |
4735 #endif | |
4736 | |
4737 /* | |
4738 * Notify the fixed area about the need to resize the contents of the | |
4739 * gui.formwin, which we use for random positioning of the included | |
4740 * components. | |
4741 * | |
4742 * We connect this signal deferred finally after anything is in place, | |
4743 * since this is intended to handle resizements coming from the window | |
4744 * manager upon us and should not interfere with what VIM is requesting | |
4745 * upon startup. | |
4746 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4747 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4748 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
|
4749 G_CALLBACK(form_configure_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4750 #else |
7 | 4751 gtk_signal_connect(GTK_OBJECT(gui.formwin), "configure_event", |
4752 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
|
4753 #endif |
7 | 4754 |
4755 #ifdef FEAT_DND | |
2183 | 4756 /* Set up for receiving DND items. */ |
4757 gui_gtk_set_dnd_targets(); | |
7 | 4758 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4759 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4760 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
|
4761 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
|
4762 # else |
7 | 4763 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "drag_data_received", |
4764 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
|
4765 # endif |
7 | 4766 #endif |
4767 | |
4768 /* 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
|
4769 * to avoid mapping the window for a short time. */ |
7 | 4770 if (found_iconic_arg && gtk_socket_id == 0) |
4771 gui_mch_iconify(); | |
4772 | |
4773 { | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
4774 #if defined(FEAT_GUI_GNOME) && defined(FEAT_MENU) |
7 | 4775 unsigned long menu_handler = 0; |
4776 # ifdef FEAT_TOOLBAR | |
4777 unsigned long tool_handler = 0; | |
4778 # endif | |
4779 /* | |
4780 * Urgh hackish :/ For some reason BonoboDockLayout always forces a | |
4781 * show when restoring the saved layout configuration. We can't just | |
4782 * hide the widgets again after gtk_widget_show(gui.mainwin) since it's | |
4783 * a toplevel window and thus will be realized immediately. Instead, | |
4784 * connect signal handlers to hide the widgets just after they've been | |
4785 * marked visible, but before the main window is realized. | |
4786 */ | |
4787 if (using_gnome && vim_strchr(p_go, GO_MENUS) == NULL) | |
4788 menu_handler = g_signal_connect_after(gui.menubar_h, "show", | |
4789 G_CALLBACK(>k_widget_hide), | |
4790 NULL); | |
4791 # ifdef FEAT_TOOLBAR | |
4792 if (using_gnome && vim_strchr(p_go, GO_TOOLBAR) == NULL | |
4793 && (toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS))) | |
4794 tool_handler = g_signal_connect_after(gui.toolbar_h, "show", | |
4795 G_CALLBACK(>k_widget_hide), | |
4796 NULL); | |
4797 # endif | |
4798 #endif | |
4799 gtk_widget_show(gui.mainwin); | |
4800 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
4801 #if defined(FEAT_GUI_GNOME) && defined(FEAT_MENU) |
7 | 4802 if (menu_handler != 0) |
4803 g_signal_handler_disconnect(gui.menubar_h, menu_handler); | |
4804 # ifdef FEAT_TOOLBAR | |
4805 if (tool_handler != 0) | |
4806 g_signal_handler_disconnect(gui.toolbar_h, tool_handler); | |
4807 # endif | |
4808 #endif | |
4809 } | |
4810 | |
4811 return OK; | |
4812 } | |
4813 | |
4814 | |
4815 void | |
1884 | 4816 gui_mch_exit(int rc UNUSED) |
7 | 4817 { |
4818 if (gui.mainwin != NULL) | |
4819 gtk_widget_destroy(gui.mainwin); | |
4820 } | |
4821 | |
4822 /* | |
4823 * Get the position of the top left corner of the window. | |
4824 */ | |
4825 int | |
4826 gui_mch_get_winpos(int *x, int *y) | |
4827 { | |
4828 gtk_window_get_position(GTK_WINDOW(gui.mainwin), x, y); | |
4829 return OK; | |
4830 } | |
4831 | |
4832 /* | |
4833 * Set the position of the top left corner of the window to the given | |
4834 * coordinates. | |
4835 */ | |
4836 void | |
4837 gui_mch_set_winpos(int x, int y) | |
4838 { | |
4839 gtk_window_move(GTK_WINDOW(gui.mainwin), x, y); | |
4840 } | |
4841 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4842 #if !GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4843 # if 0 |
7 | 4844 static int resize_idle_installed = FALSE; |
4845 /* | |
4846 * Idle handler to force resize. Used by gui_mch_set_shellsize() to ensure | |
4847 * the shell size doesn't exceed the window size, i.e. if the window manager | |
4848 * ignored our size request. Usually this happens if the window is maximized. | |
4849 * | |
4850 * FIXME: It'd be nice if we could find a little more orthodox solution. | |
4851 * See also the remark below in gui_mch_set_shellsize(). | |
4852 * | |
4853 * DISABLED: When doing ":set lines+=1" this function would first invoke | |
4854 * gui_resize_shell() with the old size, then the normal callback would | |
4855 * report the new size through form_configure_event(). That caused the window | |
4856 * layout to be messed up. | |
4857 */ | |
4858 static gboolean | |
4859 force_shell_resize_idle(gpointer data) | |
4860 { | |
4861 if (gui.mainwin != NULL | |
4862 && GTK_WIDGET_REALIZED(gui.mainwin) | |
4863 && GTK_WIDGET_VISIBLE(gui.mainwin)) | |
4864 { | |
4865 int width; | |
4866 int height; | |
4867 | |
4868 gtk_window_get_size(GTK_WINDOW(gui.mainwin), &width, &height); | |
4869 | |
4870 width -= get_menu_tool_width(); | |
4871 height -= get_menu_tool_height(); | |
4872 | |
4873 gui_resize_shell(width, height); | |
4874 } | |
4875 | |
4876 resize_idle_installed = FALSE; | |
4877 return FALSE; /* don't call me again */ | |
4878 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4879 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4880 #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
|
4881 |
1967 | 4882 /* |
4883 * Return TRUE if the main window is maximized. | |
4884 */ | |
4885 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
4886 gui_mch_maximized(void) |
1967 | 4887 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4888 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4889 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
|
4890 && (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
|
4891 & GDK_WINDOW_STATE_MAXIMIZED)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4892 #else |
1967 | 4893 return (gui.mainwin != NULL && gui.mainwin->window != NULL |
4894 && (gdk_window_get_state(gui.mainwin->window) | |
4895 & GDK_WINDOW_STATE_MAXIMIZED)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4896 #endif |
1967 | 4897 } |
4898 | |
4899 /* | |
4900 * Unmaximize the main window | |
4901 */ | |
4902 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
4903 gui_mch_unmaximize(void) |
1967 | 4904 { |
4905 if (gui.mainwin != NULL) | |
4906 gtk_window_unmaximize(GTK_WINDOW(gui.mainwin)); | |
4907 } | |
4908 | |
7 | 4909 /* |
12802
29a728529f92
patch 8.0.1278: GUI window always resizes when adding scrollbar
Christian Brabandt <cb@256bit.org>
parents:
12666
diff
changeset
|
4910 * 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
|
4911 * 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
|
4912 * window. |
3014 | 4913 */ |
4914 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
4915 gui_mch_newfont(void) |
3014 | 4916 { |
4917 int w, h; | |
4918 | |
4919 gtk_window_get_size(GTK_WINDOW(gui.mainwin), &w, &h); | |
4920 w -= get_menu_tool_width(); | |
4921 h -= get_menu_tool_height(); | |
4922 gui_resize_shell(w, h); | |
4923 } | |
4924 | |
4925 /* | |
7 | 4926 * Set the windows size. |
4927 */ | |
4928 void | |
4929 gui_mch_set_shellsize(int width, int height, | |
1884 | 4930 int min_width UNUSED, int min_height UNUSED, |
4931 int base_width UNUSED, int base_height UNUSED, | |
4932 int direction UNUSED) | |
7 | 4933 { |
4934 /* give GTK+ a chance to put all widget's into place */ | |
4935 gui_mch_update(); | |
4936 | |
791 | 4937 /* this will cause the proper resizement to happen too */ |
4938 if (gtk_socket_id == 0) | |
856 | 4939 update_window_manager_hints(0, 0); |
791 | 4940 |
7 | 4941 /* With GTK+ 2, changing the size of the form widget doesn't resize |
791 | 4942 * the window. So let's do it the other way around and resize the |
7 | 4943 * main window instead. */ |
4944 width += get_menu_tool_width(); | |
4945 height += get_menu_tool_height(); | |
4946 | |
791 | 4947 if (gtk_socket_id == 0) |
856 | 4948 gtk_window_resize(GTK_WINDOW(gui.mainwin), width, height); |
791 | 4949 else |
856 | 4950 update_window_manager_hints(width, height); |
7 | 4951 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4952 # if !GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4953 # if 0 |
7 | 4954 if (!resize_idle_installed) |
4955 { | |
4956 g_idle_add_full(GDK_PRIORITY_EVENTS + 10, | |
4957 &force_shell_resize_idle, NULL, NULL); | |
4958 resize_idle_installed = TRUE; | |
4959 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4960 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4961 # endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 4962 /* |
4963 * Wait until all events are processed to prevent a crash because the | |
4964 * real size of the drawing area doesn't reflect Vim's internal ideas. | |
4965 * | |
4966 * This is a bit of a hack, since Vim is a terminal application with a GUI | |
4967 * on top, while the GUI expects to be the boss. | |
4968 */ | |
4969 gui_mch_update(); | |
4970 } | |
4971 | |
12409
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4972 void |
12413
ca7f2685e339
patch 8.0.1086: can't build with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
12409
diff
changeset
|
4973 gui_gtk_get_screen_size_of_win(GtkWidget *wid, int *width, int *height) |
12409
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4974 { |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4975 #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
|
4976 GdkDisplay *dpy = gtk_widget_get_display(wid); |
ca7f2685e339
patch 8.0.1086: can't build with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
12409
diff
changeset
|
4977 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
|
4978 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
|
4979 GdkRectangle geometry; |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4980 |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4981 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
|
4982 *width = geometry.width; |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4983 *height = geometry.height; |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4984 #else |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4985 GdkScreen* screen; |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4986 |
12413
ca7f2685e339
patch 8.0.1086: can't build with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
12409
diff
changeset
|
4987 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
|
4988 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
|
4989 else |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4990 screen = gdk_screen_get_default(); |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4991 *width = gdk_screen_get_width(screen); |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4992 *height = gdk_screen_get_height(screen); |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4993 #endif |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
4994 } |
7 | 4995 |
4996 /* | |
4997 * The screen size is used to make sure the initial window doesn't get bigger | |
4998 * than the screen. This subtracts some room for menubar, toolbar and window | |
4999 * decorations. | |
5000 */ | |
5001 void | |
5002 gui_mch_get_screen_dimensions(int *screen_w, int *screen_h) | |
5003 { | |
12409
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
5004 gui_gtk_get_screen_size_of_win(gui.mainwin, screen_w, screen_h); |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
5005 |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
5006 /* 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
|
5007 * 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
|
5008 *screen_h -= p_ghr; |
7 | 5009 |
5010 /* | |
5011 * FIXME: dirty trick: Because the gui_get_base_height() doesn't include | |
5012 * 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
|
5013 * height, so that the window size can be made to fit on the screen. |
7 | 5014 * This should be completely changed later. |
5015 */ | |
5016 *screen_w -= get_menu_tool_width(); | |
5017 *screen_h -= get_menu_tool_height(); | |
5018 } | |
5019 | |
5020 #if defined(FEAT_TITLE) || defined(PROTO) | |
5021 void | |
1884 | 5022 gui_mch_settitle(char_u *title, char_u *icon UNUSED) |
7 | 5023 { |
5024 if (title != NULL && output_conv.vc_type != CONV_NONE) | |
5025 title = string_convert(&output_conv, title, NULL); | |
5026 | |
5027 gtk_window_set_title(GTK_WINDOW(gui.mainwin), (const char *)title); | |
5028 | |
5029 if (output_conv.vc_type != CONV_NONE) | |
5030 vim_free(title); | |
5031 } | |
5032 #endif /* FEAT_TITLE */ | |
5033 | |
5034 #if defined(FEAT_MENU) || defined(PROTO) | |
5035 void | |
5036 gui_mch_enable_menu(int showit) | |
5037 { | |
5038 GtkWidget *widget; | |
5039 | |
5040 # ifdef FEAT_GUI_GNOME | |
5041 if (using_gnome) | |
5042 widget = gui.menubar_h; | |
5043 else | |
5044 # endif | |
5045 widget = gui.menubar; | |
5046 | |
827 | 5047 /* 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
|
5048 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5049 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
|
5050 # else |
827 | 5051 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
|
5052 # endif |
7 | 5053 { |
5054 if (showit) | |
5055 gtk_widget_show(widget); | |
5056 else | |
5057 gtk_widget_hide(widget); | |
5058 | |
791 | 5059 update_window_manager_hints(0, 0); |
7 | 5060 } |
5061 } | |
5062 #endif /* FEAT_MENU */ | |
5063 | |
5064 #if defined(FEAT_TOOLBAR) || defined(PROTO) | |
5065 void | |
5066 gui_mch_show_toolbar(int showit) | |
5067 { | |
5068 GtkWidget *widget; | |
5069 | |
5070 if (gui.toolbar == NULL) | |
5071 return; | |
5072 | |
5073 # ifdef FEAT_GUI_GNOME | |
5074 if (using_gnome) | |
5075 widget = gui.toolbar_h; | |
5076 else | |
5077 # endif | |
5078 widget = gui.toolbar; | |
5079 | |
5080 if (showit) | |
5081 set_toolbar_style(GTK_TOOLBAR(gui.toolbar)); | |
5082 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5083 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5084 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
|
5085 # else |
7 | 5086 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
|
5087 # endif |
7 | 5088 { |
5089 if (showit) | |
5090 gtk_widget_show(widget); | |
5091 else | |
5092 gtk_widget_hide(widget); | |
5093 | |
791 | 5094 update_window_manager_hints(0, 0); |
7 | 5095 } |
5096 } | |
5097 #endif /* FEAT_TOOLBAR */ | |
5098 | |
5099 /* | |
5100 * Check if a given font is a CJK font. This is done in a very crude manner. It | |
5101 * just see if U+04E00 for zh and ja and U+AC00 for ko are covered in a given | |
5102 * font. Consequently, this function cannot be used as a general purpose check | |
5103 * for CJK-ness for which fontconfig APIs should be used. This is only used by | |
5104 * gui_mch_init_font() to deal with 'CJK fixed width fonts'. | |
5105 */ | |
5106 static int | |
5107 is_cjk_font(PangoFontDescription *font_desc) | |
5108 { | |
5109 static const char * const cjk_langs[] = | |
5110 {"zh_CN", "zh_TW", "zh_HK", "ja", "ko"}; | |
5111 | |
5112 PangoFont *font; | |
5113 unsigned i; | |
5114 int is_cjk = FALSE; | |
5115 | |
5116 font = pango_context_load_font(gui.text_context, font_desc); | |
5117 | |
5118 if (font == NULL) | |
5119 return FALSE; | |
5120 | |
5121 for (i = 0; !is_cjk && i < G_N_ELEMENTS(cjk_langs); ++i) | |
5122 { | |
5123 PangoCoverage *coverage; | |
5124 gunichar uc; | |
5125 | |
5126 coverage = pango_font_get_coverage( | |
5127 font, pango_language_from_string(cjk_langs[i])); | |
5128 | |
5129 if (coverage != NULL) | |
5130 { | |
5131 uc = (cjk_langs[i][0] == 'k') ? 0xAC00 : 0x4E00; | |
5132 is_cjk = (pango_coverage_get(coverage, uc) == PANGO_COVERAGE_EXACT); | |
5133 pango_coverage_unref(coverage); | |
5134 } | |
5135 } | |
5136 | |
5137 g_object_unref(font); | |
5138 | |
5139 return is_cjk; | |
5140 } | |
5141 | |
445 | 5142 /* |
5143 * Adjust gui.char_height (after 'linespace' was changed). | |
5144 */ | |
7 | 5145 int |
445 | 5146 gui_mch_adjust_charheight(void) |
7 | 5147 { |
5148 PangoFontMetrics *metrics; | |
5149 int ascent; | |
5150 int descent; | |
5151 | |
5152 metrics = pango_context_get_metrics(gui.text_context, gui.norm_font, | |
5153 pango_context_get_language(gui.text_context)); | |
5154 ascent = pango_font_metrics_get_ascent(metrics); | |
5155 descent = pango_font_metrics_get_descent(metrics); | |
5156 | |
5157 pango_font_metrics_unref(metrics); | |
5158 | |
5159 gui.char_height = (ascent + descent + PANGO_SCALE - 1) / PANGO_SCALE | |
445 | 5160 + p_linespace; |
136 | 5161 /* LINTED: avoid warning: bitwise operation on signed value */ |
7 | 5162 gui.char_ascent = PANGO_PIXELS(ascent + p_linespace * PANGO_SCALE / 2); |
5163 | |
5164 /* A not-positive value of char_height may crash Vim. Only happens | |
5165 * if 'linespace' is negative (which does make sense sometimes). */ | |
5166 gui.char_ascent = MAX(gui.char_ascent, 0); | |
5167 gui.char_height = MAX(gui.char_height, gui.char_ascent + 1); | |
5168 | |
5169 return OK; | |
5170 } | |
5171 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5172 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5173 /* 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
|
5174 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5175 font_filter(const PangoFontFamily *family, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5176 const PangoFontFace *face UNUSED, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5177 gpointer data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5178 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5179 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
|
5180 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5181 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5182 |
7 | 5183 /* |
5184 * Put up a font dialog and return the selected font name in allocated memory. | |
5185 * "oldval" is the previous value. Return NULL when cancelled. | |
5186 * This should probably go into gui_gtk.c. Hmm. | |
5187 * FIXME: | |
5188 * The GTK2 font selection dialog has no filtering API. So we could either | |
5189 * a) implement our own (possibly copying the code from somewhere else) or | |
5190 * b) just live with it. | |
5191 */ | |
5192 char_u * | |
5193 gui_mch_font_dialog(char_u *oldval) | |
5194 { | |
5195 GtkWidget *dialog; | |
5196 int response; | |
5197 char_u *fontname = NULL; | |
5198 char_u *oldname; | |
5199 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5200 #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
|
5201 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
|
5202 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
|
5203 NULL, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5204 #else |
7 | 5205 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
|
5206 #endif |
7 | 5207 |
5208 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gui.mainwin)); | |
5209 gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); | |
5210 | |
5211 if (oldval != NULL && oldval[0] != NUL) | |
5212 { | |
5213 if (output_conv.vc_type != CONV_NONE) | |
5214 oldname = string_convert(&output_conv, oldval, NULL); | |
5215 else | |
5216 oldname = oldval; | |
5217 | |
5218 /* Annoying bug in GTK (or Pango): if the font name does not include a | |
5219 * size, zero is used. Use default point size ten. */ | |
5220 if (!vim_isdigit(oldname[STRLEN(oldname) - 1])) | |
5221 { | |
5222 char_u *p = vim_strnsave(oldname, STRLEN(oldname) + 3); | |
5223 | |
5224 if (p != NULL) | |
5225 { | |
5226 STRCPY(p + STRLEN(p), " 10"); | |
5227 if (oldname != oldval) | |
5228 vim_free(oldname); | |
5229 oldname = p; | |
5230 } | |
5231 } | |
5232 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5233 #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
|
5234 gtk_font_chooser_set_font( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5235 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
|
5236 #else |
7 | 5237 gtk_font_selection_dialog_set_font_name( |
5238 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
|
5239 #endif |
7 | 5240 |
5241 if (oldname != oldval) | |
100 | 5242 vim_free(oldname); |
7 | 5243 } |
1959 | 5244 else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5245 #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
|
5246 gtk_font_chooser_set_font( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5247 GTK_FONT_CHOOSER(dialog), DEFAULT_FONT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5248 #else |
1959 | 5249 gtk_font_selection_dialog_set_font_name( |
5250 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
|
5251 #endif |
7 | 5252 |
5253 response = gtk_dialog_run(GTK_DIALOG(dialog)); | |
5254 | |
5255 if (response == GTK_RESPONSE_OK) | |
5256 { | |
5257 char *name; | |
5258 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5259 #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
|
5260 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
|
5261 #else |
7 | 5262 name = gtk_font_selection_dialog_get_font_name( |
5263 GTK_FONT_SELECTION_DIALOG(dialog)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5264 #endif |
7 | 5265 if (name != NULL) |
5266 { | |
714 | 5267 char_u *p; |
5268 | |
5269 /* Apparently some font names include a comma, need to escape | |
5270 * that, because in 'guifont' it separates names. */ | |
5271 p = vim_strsave_escaped((char_u *)name, (char_u *)","); | |
5272 g_free(name); | |
840 | 5273 if (p != NULL && input_conv.vc_type != CONV_NONE) |
714 | 5274 { |
5275 fontname = string_convert(&input_conv, p, NULL); | |
5276 vim_free(p); | |
5277 } | |
7 | 5278 else |
714 | 5279 fontname = p; |
7 | 5280 } |
5281 } | |
5282 | |
5283 if (response != GTK_RESPONSE_NONE) | |
5284 gtk_widget_destroy(dialog); | |
5285 | |
5286 return fontname; | |
5287 } | |
5288 | |
5289 /* | |
5290 * Some monospace fonts don't support a bold weight, and fall back | |
5291 * silently to the regular weight. But this is no good since our text | |
5292 * drawing function can emulate bold by overstriking. So let's try | |
5293 * to detect whether bold weight is actually available and emulate it | |
5294 * otherwise. | |
5295 * | |
5296 * Note that we don't need to check for italic style since Xft can | |
5297 * emulate italic on its own, provided you have a proper fontconfig | |
5298 * setup. We wouldn't be able to emulate it in Vim anyway. | |
5299 */ | |
5300 static void | |
5301 get_styled_font_variants(void) | |
5302 { | |
5303 PangoFontDescription *bold_font_desc; | |
5304 PangoFont *plain_font; | |
5305 PangoFont *bold_font; | |
5306 | |
5307 gui.font_can_bold = FALSE; | |
5308 | |
5309 plain_font = pango_context_load_font(gui.text_context, gui.norm_font); | |
5310 | |
5311 if (plain_font == NULL) | |
5312 return; | |
5313 | |
5314 bold_font_desc = pango_font_description_copy_static(gui.norm_font); | |
5315 pango_font_description_set_weight(bold_font_desc, PANGO_WEIGHT_BOLD); | |
5316 | |
5317 bold_font = pango_context_load_font(gui.text_context, bold_font_desc); | |
5318 /* | |
5319 * The comparison relies on the unique handle nature of a PangoFont*, | |
5320 * i.e. it's assumed that a different PangoFont* won't refer to the | |
5321 * same font. Seems to work, and failing here isn't critical anyway. | |
5322 */ | |
5323 if (bold_font != NULL) | |
5324 { | |
5325 gui.font_can_bold = (bold_font != plain_font); | |
5326 g_object_unref(bold_font); | |
5327 } | |
5328 | |
5329 pango_font_description_free(bold_font_desc); | |
5330 g_object_unref(plain_font); | |
5331 } | |
5332 | |
5333 static PangoEngineShape *default_shape_engine = NULL; | |
5334 | |
5335 /* | |
5336 * Create a map from ASCII characters in the range [32,126] to glyphs | |
5337 * of the current font. This is used by gui_gtk2_draw_string() to skip | |
5338 * the itemize and shaping process for the most common case. | |
5339 */ | |
5340 static void | |
5341 ascii_glyph_table_init(void) | |
5342 { | |
9879
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5343 char_u ascii_chars[2 * 128]; |
7 | 5344 PangoAttrList *attr_list; |
5345 GList *item_list; | |
5346 int i; | |
5347 | |
5348 if (gui.ascii_glyphs != NULL) | |
5349 pango_glyph_string_free(gui.ascii_glyphs); | |
5350 if (gui.ascii_font != NULL) | |
5351 g_object_unref(gui.ascii_font); | |
5352 | |
5353 gui.ascii_glyphs = NULL; | |
5354 gui.ascii_font = NULL; | |
5355 | |
9879
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5356 /* 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
|
5357 * 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
|
5358 for (i = 0; i < 128; ++i) |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5359 { |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5360 if (i >= 32 && i < 127) |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5361 ascii_chars[2 * i] = i; |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5362 else |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5363 ascii_chars[2 * i] = '?'; |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5364 ascii_chars[2 * i + 1] = ' '; |
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
5365 } |
7 | 5366 |
5367 attr_list = pango_attr_list_new(); | |
5368 item_list = pango_itemize(gui.text_context, (const char *)ascii_chars, | |
5369 0, sizeof(ascii_chars), attr_list, NULL); | |
5370 | |
5371 if (item_list != NULL && item_list->next == NULL) /* play safe */ | |
5372 { | |
5373 PangoItem *item; | |
5374 int width; | |
5375 | |
5376 item = (PangoItem *)item_list->data; | |
5377 width = gui.char_width * PANGO_SCALE; | |
5378 | |
5379 /* Remember the shape engine used for ASCII. */ | |
5380 default_shape_engine = item->analysis.shape_engine; | |
5381 | |
5382 gui.ascii_font = item->analysis.font; | |
5383 g_object_ref(gui.ascii_font); | |
5384 | |
5385 gui.ascii_glyphs = pango_glyph_string_new(); | |
5386 | |
5387 pango_shape((const char *)ascii_chars, sizeof(ascii_chars), | |
5388 &item->analysis, gui.ascii_glyphs); | |
5389 | |
5390 g_return_if_fail(gui.ascii_glyphs->num_glyphs == sizeof(ascii_chars)); | |
5391 | |
5392 for (i = 0; i < gui.ascii_glyphs->num_glyphs; ++i) | |
5393 { | |
5394 PangoGlyphGeometry *geom; | |
5395 | |
5396 geom = &gui.ascii_glyphs->glyphs[i].geometry; | |
5397 geom->x_offset += MAX(0, width - geom->width) / 2; | |
5398 geom->width = width; | |
5399 } | |
5400 } | |
5401 | |
5402 g_list_foreach(item_list, (GFunc)&pango_item_free, NULL); | |
5403 g_list_free(item_list); | |
5404 pango_attr_list_unref(attr_list); | |
5405 } | |
5406 | |
5407 /* | |
5408 * Initialize Vim to use the font or fontset with the given name. | |
5409 * Return FAIL if the font could not be loaded, OK otherwise. | |
5410 */ | |
5411 int | |
1884 | 5412 gui_mch_init_font(char_u *font_name, int fontset UNUSED) |
7 | 5413 { |
5414 PangoFontDescription *font_desc; | |
5415 PangoLayout *layout; | |
5416 int width; | |
5417 | |
5418 /* If font_name is NULL, this means to use the default, which should | |
5419 * be present on all proper Pango/fontconfig installations. */ | |
5420 if (font_name == NULL) | |
5421 font_name = (char_u *)DEFAULT_FONT; | |
5422 | |
5423 font_desc = gui_mch_get_font(font_name, FALSE); | |
5424 | |
5425 if (font_desc == NULL) | |
5426 return FAIL; | |
5427 | |
5428 gui_mch_free_font(gui.norm_font); | |
5429 gui.norm_font = font_desc; | |
5430 | |
5431 pango_context_set_font_description(gui.text_context, font_desc); | |
5432 | |
5433 layout = pango_layout_new(gui.text_context); | |
5434 pango_layout_set_text(layout, "MW", 2); | |
5435 pango_layout_get_size(layout, &width, NULL); | |
5436 /* | |
5437 * Set char_width to half the width obtained from pango_layout_get_size() | |
5438 * for CJK fixed_width/bi-width fonts. An unpatched version of Xft leads | |
5439 * Pango to use the same width for both non-CJK characters (e.g. Latin | |
5440 * letters and numbers) and CJK characters. This results in 's p a c e d | |
5441 * o u t' rendering when a CJK 'fixed width' font is used. To work around | |
5442 * that, divide the width returned by Pango by 2 if cjk_width is equal to | |
5443 * width for CJK fonts. | |
5444 * | |
5445 * For related bugs, see: | |
5446 * http://bugzilla.gnome.org/show_bug.cgi?id=106618 | |
5447 * http://bugzilla.gnome.org/show_bug.cgi?id=106624 | |
5448 * | |
5449 * With this, for all four of the following cases, Vim works fine: | |
5450 * guifont=CJK_fixed_width_font | |
5451 * guifont=Non_CJK_fixed_font | |
5452 * guifont=Non_CJK_fixed_font,CJK_Fixed_font | |
5453 * guifont=Non_CJK_fixed_font guifontwide=CJK_fixed_font | |
5454 */ | |
5455 if (is_cjk_font(gui.norm_font)) | |
5456 { | |
5457 int cjk_width; | |
5458 | |
5459 /* Measure the text extent of U+4E00 and U+4E8C */ | |
5460 pango_layout_set_text(layout, "\344\270\200\344\272\214", -1); | |
5461 pango_layout_get_size(layout, &cjk_width, NULL); | |
5462 | |
5463 if (width == cjk_width) /* Xft not patched */ | |
5464 width /= 2; | |
5465 } | |
5466 g_object_unref(layout); | |
5467 | |
5468 gui.char_width = (width / 2 + PANGO_SCALE - 1) / PANGO_SCALE; | |
5469 | |
5470 /* A zero width may cause a crash. Happens for semi-invalid fontsets. */ | |
5471 if (gui.char_width <= 0) | |
5472 gui.char_width = 8; | |
5473 | |
445 | 5474 gui_mch_adjust_charheight(); |
7 | 5475 |
5476 /* Set the fontname, which will be used for information purposes */ | |
5477 hl_set_font_name(font_name); | |
5478 | |
5479 get_styled_font_variants(); | |
5480 ascii_glyph_table_init(); | |
5481 | |
5482 /* Avoid unnecessary overhead if 'guifontwide' is equal to 'guifont'. */ | |
5483 if (gui.wide_font != NULL | |
5484 && pango_font_description_equal(gui.norm_font, gui.wide_font)) | |
5485 { | |
5486 pango_font_description_free(gui.wide_font); | |
5487 gui.wide_font = NULL; | |
5488 } | |
5489 | |
1986 | 5490 if (gui_mch_maximized()) |
5491 { | |
5492 /* Update lines and columns in accordance with the new font, keep the | |
5493 * window maximized. */ | |
3014 | 5494 gui_mch_newfont(); |
1986 | 5495 } |
5496 else | |
5497 { | |
5498 /* Preserve the logical dimensions of the screen. */ | |
5499 update_window_manager_hints(0, 0); | |
5500 } | |
7 | 5501 |
5502 return OK; | |
5503 } | |
5504 | |
5505 /* | |
5506 * Get a reference to the font "name". | |
5507 * Return zero for failure. | |
5508 */ | |
5509 GuiFont | |
5510 gui_mch_get_font(char_u *name, int report_error) | |
5511 { | |
5512 PangoFontDescription *font; | |
5513 | |
5514 /* can't do this when GUI is not running */ | |
5515 if (!gui.in_use || name == NULL) | |
5516 return NULL; | |
5517 | |
5518 if (output_conv.vc_type != CONV_NONE) | |
5519 { | |
5520 char_u *buf; | |
5521 | |
5522 buf = string_convert(&output_conv, name, NULL); | |
5523 if (buf != NULL) | |
5524 { | |
5525 font = pango_font_description_from_string((const char *)buf); | |
5526 vim_free(buf); | |
5527 } | |
5528 else | |
5529 font = NULL; | |
5530 } | |
5531 else | |
5532 font = pango_font_description_from_string((const char *)name); | |
5533 | |
5534 if (font != NULL) | |
5535 { | |
5536 PangoFont *real_font; | |
5537 | |
5538 /* pango_context_load_font() bails out if no font size is set */ | |
5539 if (pango_font_description_get_size(font) <= 0) | |
5540 pango_font_description_set_size(font, 10 * PANGO_SCALE); | |
5541 | |
5542 real_font = pango_context_load_font(gui.text_context, font); | |
5543 | |
5544 if (real_font == NULL) | |
5545 { | |
5546 pango_font_description_free(font); | |
5547 font = NULL; | |
5548 } | |
5549 else | |
5550 g_object_unref(real_font); | |
5551 } | |
5552 | |
5553 if (font == NULL) | |
5554 { | |
5555 if (report_error) | |
1666 | 5556 EMSG2(_((char *)e_font), name); |
7 | 5557 return NULL; |
5558 } | |
5559 | |
5560 return font; | |
5561 } | |
5562 | |
39 | 5563 #if defined(FEAT_EVAL) || defined(PROTO) |
38 | 5564 /* |
5565 * Return the name of font "font" in allocated memory. | |
5566 */ | |
5567 char_u * | |
1884 | 5568 gui_mch_get_fontname(GuiFont font, char_u *name UNUSED) |
38 | 5569 { |
5570 if (font != NOFONT) | |
5571 { | |
944 | 5572 char *pangoname = pango_font_description_to_string(font); |
5573 | |
5574 if (pangoname != NULL) | |
38 | 5575 { |
944 | 5576 char_u *s = vim_strsave((char_u *)pangoname); |
5577 | |
5578 g_free(pangoname); | |
38 | 5579 return s; |
5580 } | |
5581 } | |
5582 return NULL; | |
5583 } | |
39 | 5584 #endif |
38 | 5585 |
7 | 5586 /* |
5587 * If a font is not going to be used, free its structure. | |
5588 */ | |
5589 void | |
5590 gui_mch_free_font(GuiFont font) | |
5591 { | |
5592 if (font != NOFONT) | |
5593 pango_font_description_free(font); | |
5594 } | |
5595 | |
5596 /* | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5597 * 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
|
5598 * |
7 | 5599 * Return INVALCOLOR for error. |
5600 */ | |
5601 guicolor_T | |
5602 gui_mch_get_color(char_u *name) | |
5603 { | |
5604 if (!gui.in_use) /* can't do this when GUI not running */ | |
5605 return INVALCOLOR; | |
5606 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5607 #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
|
5608 return name != NULL ? gui_get_color_cmn(name) : INVALCOLOR; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5609 #else |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5610 guicolor_T color; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5611 |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5612 color = (name != NULL) ? gui_get_color_cmn(name) : INVALCOLOR; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5613 if (color == INVALCOLOR) |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5614 return INVALCOLOR; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5615 |
11745
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5616 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
|
5617 (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
|
5618 (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
|
5619 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
|
5620 #endif |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5621 } |
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 /* |
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 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
|
5625 * 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
|
5626 */ |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5627 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
|
5628 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
|
5629 { |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5630 #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
|
5631 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
|
5632 #else |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5633 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
|
5634 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
|
5635 |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
5636 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
|
5637 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
|
5638 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
|
5639 |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5640 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
|
5641 &gcolor, FALSE, TRUE); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5642 |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5643 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
|
5644 #endif |
7 | 5645 } |
5646 | |
5647 /* | |
5648 * Set the current text foreground color. | |
5649 */ | |
5650 void | |
5651 gui_mch_set_fg_color(guicolor_T color) | |
5652 { | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5653 #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
|
5654 *gui.fgcolor = color_to_rgba(color); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5655 #else |
7 | 5656 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
|
5657 #endif |
7 | 5658 } |
5659 | |
5660 /* | |
5661 * Set the current text background color. | |
5662 */ | |
5663 void | |
5664 gui_mch_set_bg_color(guicolor_T color) | |
5665 { | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5666 #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
|
5667 *gui.bgcolor = color_to_rgba(color); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5668 #else |
7 | 5669 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
|
5670 #endif |
7 | 5671 } |
5672 | |
207 | 5673 /* |
5674 * Set the current text special color. | |
5675 */ | |
5676 void | |
5677 gui_mch_set_sp_color(guicolor_T color) | |
5678 { | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5679 #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
|
5680 *gui.spcolor = color_to_rgba(color); |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5681 #else |
207 | 5682 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
|
5683 #endif |
207 | 5684 } |
5685 | |
7 | 5686 /* |
5687 * Function-like convenience macro for the sake of efficiency. | |
5688 */ | |
5689 #define INSERT_PANGO_ATTR(Attribute, AttrList, Start, End) \ | |
5690 G_STMT_START{ \ | |
5691 PangoAttribute *tmp_attr_; \ | |
5692 tmp_attr_ = (Attribute); \ | |
5693 tmp_attr_->start_index = (Start); \ | |
5694 tmp_attr_->end_index = (End); \ | |
5695 pango_attr_list_insert((AttrList), tmp_attr_); \ | |
5696 }G_STMT_END | |
5697 | |
5698 static void | |
5699 apply_wide_font_attr(char_u *s, int len, PangoAttrList *attr_list) | |
5700 { | |
5701 char_u *start = NULL; | |
5702 char_u *p; | |
5703 int uc; | |
5704 | |
5705 for (p = s; p < s + len; p += utf_byte2len(*p)) | |
5706 { | |
5707 uc = utf_ptr2char(p); | |
5708 | |
5709 if (start == NULL) | |
5710 { | |
5711 if (uc >= 0x80 && utf_char2cells(uc) == 2) | |
5712 start = p; | |
5713 } | |
5714 else if (uc < 0x80 /* optimization shortcut */ | |
5715 || (utf_char2cells(uc) != 2 && !utf_iscomposing(uc))) | |
5716 { | |
5717 INSERT_PANGO_ATTR(pango_attr_font_desc_new(gui.wide_font), | |
5718 attr_list, start - s, p - s); | |
5719 start = NULL; | |
5720 } | |
5721 } | |
5722 | |
5723 if (start != NULL) | |
5724 INSERT_PANGO_ATTR(pango_attr_font_desc_new(gui.wide_font), | |
5725 attr_list, start - s, len); | |
5726 } | |
5727 | |
5728 static int | |
5729 count_cluster_cells(char_u *s, PangoItem *item, | |
5730 PangoGlyphString* glyphs, int i, | |
5731 int *cluster_width, | |
5732 int *last_glyph_rbearing) | |
5733 { | |
5734 char_u *p; | |
5735 int next; /* glyph start index of next cluster */ | |
5736 int start, end; /* string segment of current cluster */ | |
5737 int width; /* real cluster width in Pango units */ | |
5738 int uc; | |
5739 int cellcount = 0; | |
5740 | |
5741 width = glyphs->glyphs[i].geometry.width; | |
5742 | |
5743 for (next = i + 1; next < glyphs->num_glyphs; ++next) | |
5744 { | |
5745 if (glyphs->glyphs[next].attr.is_cluster_start) | |
5746 break; | |
5747 else if (glyphs->glyphs[next].geometry.width > width) | |
5748 width = glyphs->glyphs[next].geometry.width; | |
5749 } | |
5750 | |
5751 start = item->offset + glyphs->log_clusters[i]; | |
5752 end = item->offset + ((next < glyphs->num_glyphs) ? | |
5753 glyphs->log_clusters[next] : item->length); | |
5754 | |
5755 for (p = s + start; p < s + end; p += utf_byte2len(*p)) | |
5756 { | |
5757 uc = utf_ptr2char(p); | |
5758 if (uc < 0x80) | |
5759 ++cellcount; | |
5760 else if (!utf_iscomposing(uc)) | |
5761 cellcount += utf_char2cells(uc); | |
5762 } | |
5763 | |
5764 if (last_glyph_rbearing != NULL | |
5765 && cellcount > 0 && next == glyphs->num_glyphs) | |
5766 { | |
5767 PangoRectangle ink_rect; | |
5768 /* | |
5769 * If a certain combining mark had to be taken from a non-monospace | |
5770 * font, we have to compensate manually by adapting x_offset according | |
5771 * to the ink extents of the previous glyph. | |
5772 */ | |
5773 pango_font_get_glyph_extents(item->analysis.font, | |
5774 glyphs->glyphs[i].glyph, | |
5775 &ink_rect, NULL); | |
5776 | |
5777 if (PANGO_RBEARING(ink_rect) > 0) | |
5778 *last_glyph_rbearing = PANGO_RBEARING(ink_rect); | |
5779 } | |
5780 | |
5781 if (cellcount > 0) | |
5782 *cluster_width = width; | |
5783 | |
5784 return cellcount; | |
5785 } | |
5786 | |
5787 /* | |
5788 * If there are only combining characters in the cluster, we cannot just | |
5789 * change the width of the previous glyph since there is none. Therefore | |
5790 * some guesswork is needed. | |
5791 * | |
5792 * If ink_rect.x is negative Pango apparently has taken care of the composing | |
5793 * by itself. Actually setting x_offset = 0 should be sufficient then, but due | |
5794 * 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
|
5795 * x_offset to avoid ugliness. |
7 | 5796 * |
5797 * If ink_rect.x is not negative, force overstriking by pointing x_offset to | |
5798 * the position of the previous glyph. Apparently this happens only with old | |
5799 * X fonts which don't provide the special combining information needed by | |
5800 * Pango. | |
5801 */ | |
5802 static void | |
5803 setup_zero_width_cluster(PangoItem *item, PangoGlyphInfo *glyph, | |
5804 int last_cellcount, int last_cluster_width, | |
5805 int last_glyph_rbearing) | |
5806 { | |
5807 PangoRectangle ink_rect; | |
5808 PangoRectangle logical_rect; | |
5809 int width; | |
5810 | |
5811 width = last_cellcount * gui.char_width * PANGO_SCALE; | |
5812 glyph->geometry.x_offset = -width + MAX(0, width - last_cluster_width) / 2; | |
5813 glyph->geometry.width = 0; | |
5814 | |
5815 pango_font_get_glyph_extents(item->analysis.font, | |
5816 glyph->glyph, | |
5817 &ink_rect, &logical_rect); | |
5818 if (ink_rect.x < 0) | |
5819 { | |
5820 glyph->geometry.x_offset += last_glyph_rbearing; | |
5821 glyph->geometry.y_offset = logical_rect.height | |
5822 - (gui.char_height - p_linespace) * PANGO_SCALE; | |
5823 } | |
2507
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
5824 else |
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
5825 /* 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
|
5826 * 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
|
5827 glyph->geometry.x_offset = -width + MAX(0, width - ink_rect.width) / 2; |
7 | 5828 } |
5829 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5830 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5831 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5832 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
|
5833 PangoFont *font, PangoGlyphString *glyphs, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5834 cairo_t *cr) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5835 #else |
7 | 5836 static void |
5837 draw_glyph_string(int row, int col, int num_cells, int flags, | |
5838 PangoFont *font, PangoGlyphString *glyphs) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5839 #endif |
7 | 5840 { |
5841 if (!(flags & DRAW_TRANSP)) | |
5842 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5843 #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
|
5844 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5845 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
|
5846 gui.bgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5847 cairo_rectangle(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5848 FILL_X(col), FILL_Y(row), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5849 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
|
5850 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5851 #else |
7 | 5852 gdk_gc_set_foreground(gui.text_gc, gui.bgcolor); |
5853 | |
5854 gdk_draw_rectangle(gui.drawarea->window, | |
5855 gui.text_gc, | |
5856 TRUE, | |
5857 FILL_X(col), | |
5858 FILL_Y(row), | |
5859 num_cells * gui.char_width, | |
5860 gui.char_height); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5861 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5862 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5863 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5864 #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
|
5865 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5866 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
|
5867 gui.fgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5868 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
|
5869 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
|
5870 #else |
7 | 5871 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
5872 | |
5873 gdk_draw_glyphs(gui.drawarea->window, | |
5874 gui.text_gc, | |
5875 font, | |
5876 TEXT_X(col), | |
5877 TEXT_Y(row), | |
5878 glyphs); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5879 #endif |
7 | 5880 |
5881 /* redraw the contents with an offset of 1 to emulate bold */ | |
5882 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
|
5883 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5884 { |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5885 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5886 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
|
5887 gui.fgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5888 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
|
5889 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
|
5890 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5891 #else |
7 | 5892 gdk_draw_glyphs(gui.drawarea->window, |
5893 gui.text_gc, | |
5894 font, | |
5895 TEXT_X(col) + 1, | |
5896 TEXT_Y(row), | |
5897 glyphs); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5898 #endif |
7 | 5899 } |
5900 | |
207 | 5901 /* |
5902 * Draw underline and undercurl at the bottom of the character cell. | |
5903 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5904 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5905 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5906 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
|
5907 #else |
207 | 5908 static void |
5909 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
|
5910 #endif |
207 | 5911 { |
5912 int i; | |
5913 int offset; | |
1884 | 5914 static const int val[8] = {1, 0, 0, 0, 1, 2, 2, 2 }; |
207 | 5915 int y = FILL_Y(row + 1) - 1; |
5916 | |
5917 /* Undercurl: draw curl at the bottom of the character cell. */ | |
5918 if (flags & DRAW_UNDERC) | |
5919 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5920 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5921 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
|
5922 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
|
5923 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
5924 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
|
5925 gui.spcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5926 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
|
5927 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5928 offset = val[i % 8]; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5929 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
|
5930 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5931 cairo_stroke(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5932 #else |
207 | 5933 gdk_gc_set_foreground(gui.text_gc, gui.spcolor); |
5934 for (i = FILL_X(col); i < FILL_X(col + cells); ++i) | |
5935 { | |
5936 offset = val[i % 8]; | |
5937 gdk_draw_point(gui.drawarea->window, gui.text_gc, i, y - offset); | |
5938 } | |
5939 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
|
5940 #endif |
207 | 5941 } |
5942 | |
12317
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5943 /* Draw a strikethrough line */ |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5944 if (flags & DRAW_STRIKE) |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5945 { |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5946 #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
|
5947 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
|
5948 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
|
5949 cairo_set_source_rgba(cr, |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5950 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
|
5951 gui.spcolor->alpha); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5952 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
|
5953 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
|
5954 cairo_stroke(cr); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5955 #else |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5956 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
|
5957 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
|
5958 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
|
5959 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
|
5960 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
|
5961 #endif |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5962 } |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5963 |
207 | 5964 /* Underline: draw a line at the bottom of the character cell. */ |
5965 if (flags & DRAW_UNDERL) | |
5966 { | |
5967 /* When p_linespace is 0, overwrite the bottom row of pixels. | |
5968 * Otherwise put the line just below the character. */ | |
5969 if (p_linespace > 1) | |
5970 y -= p_linespace - 1; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5971 #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
|
5972 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
|
5973 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
|
5974 cairo_set_source_rgba(cr, |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5975 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
|
5976 gui.fgcolor->alpha); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
5977 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
|
5978 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
|
5979 cairo_stroke(cr); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5980 #else |
207 | 5981 gdk_draw_line(gui.drawarea->window, gui.text_gc, |
5982 FILL_X(col), y, | |
5983 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
|
5984 #endif |
207 | 5985 } |
5986 } | |
5987 | |
7 | 5988 int |
5989 gui_gtk2_draw_string(int row, int col, char_u *s, int len, int flags) | |
5990 { | |
5991 GdkRectangle area; /* area for clip mask */ | |
5992 PangoGlyphString *glyphs; /* glyphs of current item */ | |
5993 int column_offset = 0; /* column offset in cells */ | |
5994 int i; | |
5995 char_u *conv_buf = NULL; /* result of UTF-8 conversion */ | |
5996 char_u *new_conv_buf; | |
5997 int convlen; | |
5998 char_u *sp, *bp; | |
5999 int plen; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6000 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6001 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6002 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6003 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6004 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6005 if (gui.text_context == NULL || gtk_widget_get_window(gui.drawarea) == NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6006 #else |
7 | 6007 if (gui.text_context == NULL || gui.drawarea->window == NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6008 #endif |
7 | 6009 return len; |
6010 | |
6011 if (output_conv.vc_type != CONV_NONE) | |
6012 { | |
6013 /* | |
6014 * Convert characters from 'encoding' to 'termencoding', which is set | |
6015 * to UTF-8 by gui_mch_init(). did_set_string_option() in option.c | |
6016 * prohibits changing this to something else than UTF-8 if the GUI is | |
6017 * in use. | |
6018 */ | |
6019 convlen = len; | |
6020 conv_buf = string_convert(&output_conv, s, &convlen); | |
6021 g_return_val_if_fail(conv_buf != NULL, len); | |
6022 | |
6023 /* Correct for differences in char width: some chars are | |
6024 * double-wide in 'encoding' but single-wide in utf-8. Add a space to | |
6025 * compensate for that. */ | |
6026 for (sp = s, bp = conv_buf; sp < s + len && bp < conv_buf + convlen; ) | |
6027 { | |
474 | 6028 plen = utf_ptr2len(bp); |
7 | 6029 if ((*mb_ptr2cells)(sp) == 2 && utf_ptr2cells(bp) == 1) |
6030 { | |
6031 new_conv_buf = alloc(convlen + 2); | |
6032 if (new_conv_buf == NULL) | |
6033 return len; | |
6034 plen += bp - conv_buf; | |
6035 mch_memmove(new_conv_buf, conv_buf, plen); | |
6036 new_conv_buf[plen] = ' '; | |
6037 mch_memmove(new_conv_buf + plen + 1, conv_buf + plen, | |
6038 convlen - plen + 1); | |
6039 vim_free(conv_buf); | |
6040 conv_buf = new_conv_buf; | |
6041 ++convlen; | |
6042 bp = conv_buf + plen; | |
6043 plen = 1; | |
6044 } | |
474 | 6045 sp += (*mb_ptr2len)(sp); |
7 | 6046 bp += plen; |
6047 } | |
6048 s = conv_buf; | |
6049 len = convlen; | |
6050 } | |
6051 | |
6052 /* | |
6053 * Restrict all drawing to the current screen line in order to prevent | |
6054 * fuzzy font lookups from messing up the screen. | |
6055 */ | |
6056 area.x = gui.border_offset; | |
6057 area.y = FILL_Y(row); | |
6058 area.width = gui.num_cols * gui.char_width; | |
6059 area.height = gui.char_height; | |
6060 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6061 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6062 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6063 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
|
6064 cairo_clip(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6065 #else |
7 | 6066 gdk_gc_set_clip_origin(gui.text_gc, 0, 0); |
6067 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
|
6068 #endif |
7 | 6069 |
6070 glyphs = pango_glyph_string_new(); | |
6071 | |
6072 /* | |
6073 * Optimization hack: If possible, skip the itemize and shaping process | |
6074 * for pure ASCII strings. This optimization is particularly effective | |
6075 * because Vim draws space characters to clear parts of the screen. | |
6076 */ | |
6077 if (!(flags & DRAW_ITALIC) | |
6078 && !((flags & DRAW_BOLD) && gui.font_can_bold) | |
6079 && gui.ascii_glyphs != NULL) | |
6080 { | |
6081 char_u *p; | |
6082 | |
6083 for (p = s; p < s + len; ++p) | |
6084 if (*p & 0x80) | |
6085 goto not_ascii; | |
6086 | |
6087 pango_glyph_string_set_size(glyphs, len); | |
6088 | |
6089 for (i = 0; i < len; ++i) | |
6090 { | |
9879
5cd29e15f2f7
commit https://github.com/vim/vim/commit/16350cb97914bc86320185a9910b23c2b297d273
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
6091 glyphs->glyphs[i] = gui.ascii_glyphs->glyphs[2 * s[i]]; |
7 | 6092 glyphs->log_clusters[i] = i; |
6093 } | |
6094 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6095 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6096 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
|
6097 #else |
7 | 6098 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
|
6099 #endif |
7 | 6100 |
6101 column_offset = len; | |
6102 } | |
6103 else | |
6104 not_ascii: | |
6105 { | |
6106 PangoAttrList *attr_list; | |
6107 GList *item_list; | |
6108 int cluster_width; | |
6109 int last_glyph_rbearing; | |
6110 int cells = 0; /* cells occupied by current cluster */ | |
6111 | |
26 | 6112 /* Safety check: pango crashes when invoked with invalid utf-8 |
6113 * characters. */ | |
6114 if (!utf_valid_string(s, s + len)) | |
6115 { | |
6116 column_offset = len; | |
6117 goto skipitall; | |
6118 } | |
6119 | |
7 | 6120 /* original width of the current cluster */ |
6121 cluster_width = PANGO_SCALE * gui.char_width; | |
6122 | |
6123 /* right bearing of the last non-composing glyph */ | |
6124 last_glyph_rbearing = PANGO_SCALE * gui.char_width; | |
6125 | |
6126 attr_list = pango_attr_list_new(); | |
6127 | |
6128 /* If 'guifontwide' is set then use that for double-width characters. | |
6129 * Otherwise just go with 'guifont' and let Pango do its thing. */ | |
6130 if (gui.wide_font != NULL) | |
6131 apply_wide_font_attr(s, len, attr_list); | |
6132 | |
6133 if ((flags & DRAW_BOLD) && gui.font_can_bold) | |
6134 INSERT_PANGO_ATTR(pango_attr_weight_new(PANGO_WEIGHT_BOLD), | |
6135 attr_list, 0, len); | |
6136 if (flags & DRAW_ITALIC) | |
6137 INSERT_PANGO_ATTR(pango_attr_style_new(PANGO_STYLE_ITALIC), | |
6138 attr_list, 0, len); | |
6139 /* | |
6140 * Break the text into segments with consistent directional level | |
6141 * and shaping engine. Pure Latin text needs only a single segment, | |
6142 * so there's no need to worry about the loop's efficiency. Better | |
6143 * try to optimize elsewhere, e.g. reducing exposes and stuff :) | |
6144 */ | |
6145 item_list = pango_itemize(gui.text_context, | |
6146 (const char *)s, 0, len, attr_list, NULL); | |
6147 | |
6148 while (item_list != NULL) | |
6149 { | |
6150 PangoItem *item; | |
6151 int item_cells = 0; /* item length in cells */ | |
6152 | |
6153 item = (PangoItem *)item_list->data; | |
6154 item_list = g_list_delete_link(item_list, item_list); | |
6155 /* | |
6156 * Increment the bidirectional embedding level by 1 if it is not | |
6157 * even. An odd number means the output will be RTL, but we don't | |
6158 * want that since Vim handles right-to-left text on its own. It | |
6159 * would probably be sufficient to just set level = 0, but you can | |
6160 * never know :) | |
6161 * | |
6162 * Unfortunately we can't take advantage of Pango's ability to | |
6163 * render both LTR and RTL at the same time. In order to support | |
6164 * that, Vim's main screen engine would have to make use of Pango | |
6165 * functionality. | |
6166 */ | |
6167 item->analysis.level = (item->analysis.level + 1) & (~1U); | |
6168 | |
6169 /* HACK: Overrule the shape engine, we don't want shaping to be | |
6170 * done, because drawing the cursor would change the display. */ | |
6171 item->analysis.shape_engine = default_shape_engine; | |
6172 | |
7098
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6173 #ifdef HAVE_PANGO_SHAPE_FULL |
7086
3825da022231
commit https://github.com/vim/vim/commit/7e2ec008f5c5152205d0b8a7d88177b374225d8d
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
6174 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
|
6175 (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
|
6176 #else |
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6177 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
|
6178 &item->analysis, glyphs); |
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6179 #endif |
7 | 6180 /* |
6181 * Fixed-width hack: iterate over the array and assign a fixed | |
6182 * width to each glyph, thus overriding the choice made by the | |
6183 * shaping engine. We use utf_char2cells() to determine the | |
6184 * number of cells needed. | |
6185 * | |
6186 * Also perform all kind of dark magic to get composing | |
6187 * characters right (and pretty too of course). | |
6188 */ | |
6189 for (i = 0; i < glyphs->num_glyphs; ++i) | |
6190 { | |
6191 PangoGlyphInfo *glyph; | |
6192 | |
6193 glyph = &glyphs->glyphs[i]; | |
6194 | |
6195 if (glyph->attr.is_cluster_start) | |
6196 { | |
6197 int cellcount; | |
6198 | |
6199 cellcount = count_cluster_cells( | |
6200 s, item, glyphs, i, &cluster_width, | |
6201 (item_list != NULL) ? &last_glyph_rbearing : NULL); | |
6202 | |
6203 if (cellcount > 0) | |
6204 { | |
6205 int width; | |
6206 | |
6207 width = cellcount * gui.char_width * PANGO_SCALE; | |
6208 glyph->geometry.x_offset += | |
6209 MAX(0, width - cluster_width) / 2; | |
6210 glyph->geometry.width = width; | |
6211 } | |
6212 else | |
6213 { | |
6214 /* If there are only combining characters in the | |
6215 * cluster, we cannot just change the width of the | |
6216 * previous glyph since there is none. Therefore | |
6217 * some guesswork is needed. */ | |
6218 setup_zero_width_cluster(item, glyph, cells, | |
6219 cluster_width, | |
6220 last_glyph_rbearing); | |
6221 } | |
6222 | |
6223 item_cells += cellcount; | |
6224 cells = cellcount; | |
6225 } | |
6226 else if (i > 0) | |
6227 { | |
6228 int width; | |
6229 | |
6230 /* 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
|
6231 * characters the canonical way. |
2517
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6232 * 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
|
6233 * 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
|
6234 * and set the previous width to zero. |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6235 * 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
|
6236 * 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
|
6237 * 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
|
6238 * 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
|
6239 * 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
|
6240 if (glyph->geometry.x_offset >= 0) |
2517
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6241 { |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6242 glyphs->glyphs[i].geometry.width = |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6243 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
|
6244 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
|
6245 } |
7 | 6246 width = cells * gui.char_width * PANGO_SCALE; |
6247 glyph->geometry.x_offset += | |
6248 MAX(0, width - cluster_width) / 2; | |
6249 } | |
6250 else /* i == 0 "cannot happen" */ | |
6251 { | |
6252 glyph->geometry.width = 0; | |
6253 } | |
6254 } | |
6255 | |
6256 /*** Aaaaand action! ***/ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6257 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6258 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
|
6259 flags, item->analysis.font, glyphs, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6260 cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6261 #else |
7 | 6262 draw_glyph_string(row, col + column_offset, item_cells, |
6263 flags, item->analysis.font, glyphs); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6264 #endif |
7 | 6265 |
6266 pango_item_free(item); | |
6267 | |
6268 column_offset += item_cells; | |
6269 } | |
6270 | |
6271 pango_attr_list_unref(attr_list); | |
6272 } | |
6273 | |
26 | 6274 skipitall: |
207 | 6275 /* Draw underline and undercurl. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6276 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6277 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
|
6278 #else |
207 | 6279 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
|
6280 #endif |
7 | 6281 |
6282 pango_glyph_string_free(glyphs); | |
6283 vim_free(conv_buf); | |
6284 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6285 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6286 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6287 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6288 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
|
6289 &area, FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6290 #else |
7 | 6291 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
|
6292 #endif |
7 | 6293 |
6294 return column_offset; | |
6295 } | |
6296 | |
6297 /* | |
6298 * Return OK if the key with the termcap name "name" is supported. | |
6299 */ | |
6300 int | |
6301 gui_mch_haskey(char_u *name) | |
6302 { | |
6303 int i; | |
6304 | |
6305 for (i = 0; special_keys[i].key_sym != 0; i++) | |
6306 if (name[0] == special_keys[i].code0 | |
6307 && name[1] == special_keys[i].code1) | |
6308 return OK; | |
6309 return FAIL; | |
6310 } | |
6311 | |
4133 | 6312 #if defined(FEAT_TITLE) || defined(FEAT_EVAL) || defined(PROTO) |
7 | 6313 /* |
6314 * Return the text window-id and display. Only required for X-based GUI's | |
6315 */ | |
6316 int | |
6317 gui_get_x11_windis(Window *win, Display **dis) | |
6318 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6319 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6320 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
|
6321 #else |
7 | 6322 if (gui.mainwin != NULL && gui.mainwin->window != NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6323 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6324 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6325 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6326 *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
|
6327 *win = GDK_WINDOW_XID(gtk_widget_get_window(gui.mainwin)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6328 #else |
7 | 6329 *dis = GDK_WINDOW_XDISPLAY(gui.mainwin->window); |
6330 *win = GDK_WINDOW_XWINDOW(gui.mainwin->window); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6331 #endif |
7 | 6332 return OK; |
6333 } | |
6334 | |
6335 *dis = NULL; | |
6336 *win = 0; | |
6337 return FAIL; | |
6338 } | |
6339 #endif | |
6340 | |
6341 #if defined(FEAT_CLIENTSERVER) \ | |
6342 || (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO) | |
6343 | |
6344 Display * | |
6345 gui_mch_get_display(void) | |
6346 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6347 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6348 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
|
6349 return GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.mainwin)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6350 #else |
7 | 6351 if (gui.mainwin != NULL && gui.mainwin->window != NULL) |
6352 return GDK_WINDOW_XDISPLAY(gui.mainwin->window); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6353 #endif |
7 | 6354 else |
6355 return NULL; | |
6356 } | |
6357 #endif | |
6358 | |
6359 void | |
6360 gui_mch_beep(void) | |
6361 { | |
6362 GdkDisplay *display; | |
6363 | |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6364 #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
|
6365 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
|
6366 #else |
7 | 6367 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
|
6368 #endif |
7 | 6369 display = gtk_widget_get_display(gui.mainwin); |
6370 else | |
6371 display = gdk_display_get_default(); | |
6372 | |
6373 if (display != NULL) | |
6374 gdk_display_beep(display); | |
6375 } | |
6376 | |
6377 void | |
6378 gui_mch_flash(int msec) | |
6379 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6380 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6381 /* TODO Replace GdkGC with Cairo */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6382 (void)msec; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6383 #else |
7 | 6384 GdkGCValues values; |
6385 GdkGC *invert_gc; | |
6386 | |
6387 if (gui.drawarea->window == NULL) | |
6388 return; | |
6389 | |
6390 values.foreground.pixel = gui.norm_pixel ^ gui.back_pixel; | |
6391 values.background.pixel = gui.norm_pixel ^ gui.back_pixel; | |
6392 values.function = GDK_XOR; | |
6393 invert_gc = gdk_gc_new_with_values(gui.drawarea->window, | |
6394 &values, | |
6395 GDK_GC_FOREGROUND | | |
6396 GDK_GC_BACKGROUND | | |
6397 GDK_GC_FUNCTION); | |
6398 gdk_gc_set_exposures(invert_gc, | |
6399 gui.visibility != GDK_VISIBILITY_UNOBSCURED); | |
6400 /* | |
6401 * Do a visual beep by changing back and forth in some undetermined way, | |
6402 * the foreground and background colors. This is due to the fact that | |
6403 * there can't be really any prediction about the effects of XOR on | |
6404 * arbitrary X11 servers. However this seems to be enough for what we | |
6405 * intend it to do. | |
6406 */ | |
6407 gdk_draw_rectangle(gui.drawarea->window, invert_gc, | |
6408 TRUE, | |
6409 0, 0, | |
6410 FILL_X((int)Columns) + gui.border_offset, | |
6411 FILL_Y((int)Rows) + gui.border_offset); | |
6412 | |
6413 gui_mch_flush(); | |
6414 ui_delay((long)msec, TRUE); /* wait so many msec */ | |
6415 | |
6416 gdk_draw_rectangle(gui.drawarea->window, invert_gc, | |
6417 TRUE, | |
6418 0, 0, | |
6419 FILL_X((int)Columns) + gui.border_offset, | |
6420 FILL_Y((int)Rows) + gui.border_offset); | |
6421 | |
6422 gdk_gc_destroy(invert_gc); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6423 #endif |
7 | 6424 } |
6425 | |
6426 /* | |
6427 * Invert a rectangle from row r, column c, for nr rows and nc columns. | |
6428 */ | |
6429 void | |
6430 gui_mch_invert_rectangle(int r, int c, int nr, int nc) | |
6431 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6432 #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
|
6433 const GdkRectangle rect = { |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6434 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
|
6435 }; |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6436 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
|
6437 |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6438 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
|
6439 # 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
|
6440 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
|
6441 # else |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6442 /* 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
|
6443 # endif |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6444 gdk_cairo_rectangle(cr, &rect); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6445 cairo_fill(cr); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6446 |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6447 cairo_destroy(cr); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6448 |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6449 if (!gui.by_signal) |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6450 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
|
6451 rect.width, rect.height); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6452 #else |
7 | 6453 GdkGCValues values; |
6454 GdkGC *invert_gc; | |
6455 | |
6456 if (gui.drawarea->window == NULL) | |
6457 return; | |
6458 | |
944 | 6459 values.foreground.pixel = gui.norm_pixel ^ gui.back_pixel; |
6460 values.background.pixel = gui.norm_pixel ^ gui.back_pixel; | |
7 | 6461 values.function = GDK_XOR; |
6462 invert_gc = gdk_gc_new_with_values(gui.drawarea->window, | |
6463 &values, | |
6464 GDK_GC_FOREGROUND | | |
6465 GDK_GC_BACKGROUND | | |
6466 GDK_GC_FUNCTION); | |
944 | 6467 gdk_gc_set_exposures(invert_gc, gui.visibility != |
6468 GDK_VISIBILITY_UNOBSCURED); | |
7 | 6469 gdk_draw_rectangle(gui.drawarea->window, invert_gc, |
6470 TRUE, | |
6471 FILL_X(c), FILL_Y(r), | |
6472 (nc) * gui.char_width, (nr) * gui.char_height); | |
6473 gdk_gc_destroy(invert_gc); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6474 #endif |
7 | 6475 } |
6476 | |
6477 /* | |
6478 * Iconify the GUI window. | |
6479 */ | |
6480 void | |
6481 gui_mch_iconify(void) | |
6482 { | |
6483 gtk_window_iconify(GTK_WINDOW(gui.mainwin)); | |
6484 } | |
6485 | |
6486 #if defined(FEAT_EVAL) || defined(PROTO) | |
6487 /* | |
6488 * Bring the Vim window to the foreground. | |
6489 */ | |
6490 void | |
6491 gui_mch_set_foreground(void) | |
6492 { | |
6493 gtk_window_present(GTK_WINDOW(gui.mainwin)); | |
6494 } | |
6495 #endif | |
6496 | |
6497 /* | |
6498 * Draw a cursor without focus. | |
6499 */ | |
6500 void | |
6501 gui_mch_draw_hollow_cursor(guicolor_T color) | |
6502 { | |
6503 int i = 1; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6504 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6505 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6506 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6507 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6508 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6509 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
|
6510 #else |
7 | 6511 if (gui.drawarea->window == NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6512 #endif |
7 | 6513 return; |
6514 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6515 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6516 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6517 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6518 |
7 | 6519 gui_mch_set_fg_color(color); |
6520 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6521 #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
|
6522 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6523 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
|
6524 gui.fgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6525 #else |
7 | 6526 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
|
6527 #endif |
7 | 6528 if (mb_lefthalve(gui.row, gui.col)) |
6529 i = 2; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6530 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6531 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
|
6532 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
|
6533 cairo_rectangle(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6534 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
|
6535 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
|
6536 cairo_stroke(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6537 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6538 #else |
7 | 6539 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, |
6540 FALSE, | |
6541 FILL_X(gui.col), FILL_Y(gui.row), | |
6542 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
|
6543 #endif |
7 | 6544 } |
6545 | |
6546 /* | |
6547 * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using | |
6548 * color "color". | |
6549 */ | |
6550 void | |
6551 gui_mch_draw_part_cursor(int w, int h, guicolor_T color) | |
6552 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6553 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6554 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
|
6555 #else |
7 | 6556 if (gui.drawarea->window == NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6557 #endif |
7 | 6558 return; |
6559 | |
6560 gui_mch_set_fg_color(color); | |
6561 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6562 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6563 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6564 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6565 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6566 cr = cairo_create(gui.surface); |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6567 cairo_set_source_rgba(cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6568 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
|
6569 gui.fgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6570 cairo_rectangle(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6571 # ifdef FEAT_RIGHTLEFT |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6572 /* 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
|
6573 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
|
6574 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6575 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
|
6576 w, h); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6577 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6578 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6579 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6580 #else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6581 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
6582 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, | |
6583 TRUE, | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6584 # ifdef FEAT_RIGHTLEFT |
7 | 6585 /* vertical line should be on the right of current point */ |
6586 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
|
6587 # endif |
7 | 6588 FILL_X(gui.col), |
6589 FILL_Y(gui.row) + gui.char_height - h, | |
6590 w, h); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6591 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6592 } |
6593 | |
6594 | |
6595 /* | |
6596 * Catch up with any queued X11 events. This may put keyboard input into the | |
6597 * input buffer, call resize call-backs, trigger timers etc. If there is | |
6598 * nothing in the X11 event queue (& no timers pending), then we return | |
6599 * immediately. | |
6600 */ | |
6601 void | |
6602 gui_mch_update(void) | |
6603 { | |
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
|
6604 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
|
6605 g_main_context_iteration(NULL, TRUE); |
7 | 6606 } |
6607 | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6608 static timeout_cb_type |
7 | 6609 input_timer_cb(gpointer data) |
6610 { | |
6611 int *timed_out = (int *) data; | |
6612 | |
1226 | 6613 /* Just inform the caller about the occurrence of it */ |
7 | 6614 *timed_out = TRUE; |
6615 | |
6616 return FALSE; /* don't happen again */ | |
6617 } | |
6618 | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6619 #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
|
6620 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
|
6621 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
|
6622 { |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6623 /* 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
|
6624 * 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
|
6625 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
|
6626 parse_queued_messages(); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6627 |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6628 return TRUE; /* repeat */ |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6629 } |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6630 #endif |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6631 |
7 | 6632 /* |
6633 * GUI input routine called by gui_wait_for_chars(). Waits for a character | |
6634 * from the keyboard. | |
6635 * wtime == -1 Wait forever. | |
6636 * wtime == 0 This should never happen. | |
6637 * wtime > 0 Wait wtime milliseconds for a character. | |
6638 * Returns OK if a character was found to be available within the given time, | |
6639 * or FAIL otherwise. | |
6640 */ | |
6641 int | |
6642 gui_mch_wait_for_chars(long wtime) | |
6643 { | |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6644 int focus; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6645 guint timer; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6646 static int timed_out; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6647 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
|
6648 #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
|
6649 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
|
6650 #endif |
7 | 6651 |
6652 timed_out = FALSE; | |
6653 | |
6654 /* this timeout makes sure that we will return if no characters arrived in | |
6655 * time */ | |
6656 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
|
6657 timer = timeout_add(wtime, input_timer_cb, &timed_out); |
7 | 6658 else |
6659 timer = 0; | |
6660 | |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6661 #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
|
6662 /* 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
|
6663 * on them. */ |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6664 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
|
6665 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
|
6666 #endif |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6667 |
7 | 6668 focus = gui.in_focus; |
6669 | |
6670 do | |
6671 { | |
6672 /* Stop or start blinking when focus changes */ | |
6673 if (gui.in_focus != focus) | |
6674 { | |
6675 if (gui.in_focus) | |
6676 gui_mch_start_blink(); | |
6677 else | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
6678 gui_mch_stop_blink(TRUE); |
7 | 6679 focus = gui.in_focus; |
6680 } | |
6681 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
6682 #ifdef MESSAGE_QUEUE |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6683 # ifdef FEAT_TIMERS |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6684 did_add_timer = FALSE; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6685 # endif |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
6686 parse_queued_messages(); |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6687 # ifdef FEAT_TIMERS |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6688 if (did_add_timer) |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6689 /* Need to recompute the waiting time. */ |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6690 goto theend; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6691 # endif |
1624 | 6692 #endif |
6693 | |
7 | 6694 /* |
6695 * Loop in GTK+ processing until a timeout or input occurs. | |
22 | 6696 * Skip this if input is available anyway (can happen in rare |
6697 * situations, sort of race condition). | |
7 | 6698 */ |
22 | 6699 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
|
6700 g_main_context_iteration(NULL, TRUE); |
7 | 6701 |
6702 /* Got char, return immediately */ | |
6703 if (input_available()) | |
6704 { | |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6705 retval = OK; |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6706 goto theend; |
7 | 6707 } |
6708 } while (wtime < 0 || !timed_out); | |
6709 | |
6710 /* | |
6711 * Flush all eventually pending (drawing) events. | |
6712 */ | |
6713 gui_mch_update(); | |
6714 | |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6715 theend: |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6716 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
|
6717 timeout_remove(timer); |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
6718 #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
|
6719 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
|
6720 timeout_remove(channel_timer); |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6721 #endif |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6722 |
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
6723 return retval; |
7 | 6724 } |
6725 | |
6726 | |
6727 /**************************************************************************** | |
6728 * Output drawing routines. | |
6729 ****************************************************************************/ | |
6730 | |
6731 | |
6732 /* Flush any output to the screen */ | |
6733 void | |
6734 gui_mch_flush(void) | |
6735 { | |
11474
621e41f6dcc2
patch 8.0.0620: checking for HAVE_GTK_MULTIHEAD is not needed
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6736 #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
|
6737 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
|
6738 #else |
7 | 6739 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
|
6740 #endif |
9523
9d1abad90d6c
commit https://github.com/vim/vim/commit/fdadad994a6e8f6cc8b11519082e23200b96d0ba
Christian Brabandt <cb@256bit.org>
parents:
9489
diff
changeset
|
6741 gdk_display_flush(gtk_widget_get_display(gui.mainwin)); |
7 | 6742 } |
6743 | |
6744 /* | |
6745 * Clear a rectangular region of the screen from text pos (row1, col1) to | |
6746 * (row2, col2) inclusive. | |
6747 */ | |
6748 void | |
10920
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6749 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
|
6750 { |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6751 |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6752 int col1 = check_col(col1arg); |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6753 int col2 = check_col(col2arg); |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6754 int row1 = check_row(row1arg); |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6755 int row2 = check_row(row2arg); |
687833a3fadc
patch 8.0.0349: redrawing errors with GTK 3
Christian Brabandt <cb@256bit.org>
parents:
10773
diff
changeset
|
6756 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6757 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6758 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
|
6759 return; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6760 #else |
7 | 6761 GdkColor color; |
6762 | |
6763 if (gui.drawarea->window == NULL) | |
6764 return; | |
6765 | |
6766 color.pixel = gui.back_pixel; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6767 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6768 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6769 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6770 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6771 /* 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
|
6772 * bold glyph may sit there. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6773 const GdkRectangle rect = { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6774 FILL_X(col1), FILL_Y(row1), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6775 (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
|
6776 (row2 - row1 + 1) * gui.char_height |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6777 }; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6778 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
|
6779 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
|
6780 # 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
|
6781 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
|
6782 # else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6783 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
|
6784 if (pat != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6785 cairo_set_source(cr, pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6786 else |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6787 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
|
6788 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6789 gdk_cairo_rectangle(cr, &rect); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6790 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6791 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6792 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6793 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6794 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
|
6795 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6796 #else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6797 gdk_gc_set_foreground(gui.text_gc, &color); |
6798 | |
6799 /* Clear one extra pixel at the far right, for when bold characters have | |
6800 * spilled over to the window border. */ | |
6801 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, TRUE, | |
6802 FILL_X(col1), FILL_Y(row1), | |
6803 (col2 - col1 + 1) * gui.char_width | |
6804 + (col2 == Columns - 1), | |
6805 (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
|
6806 #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
|
6807 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6808 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6809 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6810 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6811 gui_gtk_window_clear(GdkWindow *win) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6812 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6813 const GdkRectangle rect = { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6814 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
|
6815 }; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6816 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
|
6817 # 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
|
6818 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
|
6819 # else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6820 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
|
6821 if (pat != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6822 cairo_set_source(cr, pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6823 else |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
6824 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
|
6825 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6826 gdk_cairo_rectangle(cr, &rect); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6827 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6828 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6829 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6830 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6831 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
|
6832 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6833 #endif |
7 | 6834 |
6835 void | |
6836 gui_mch_clear_all(void) | |
6837 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6838 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6839 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
|
6840 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
|
6841 #else |
7 | 6842 if (gui.drawarea->window != NULL) |
6843 gdk_window_clear(gui.drawarea->window); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6844 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6845 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6846 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6847 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 6848 /* |
6849 * Redraw any text revealed by scrolling up/down. | |
6850 */ | |
6851 static void | |
6852 check_copy_area(void) | |
6853 { | |
6854 GdkEvent *event; | |
6855 int expose_count; | |
6856 | |
6857 if (gui.visibility != GDK_VISIBILITY_PARTIAL) | |
6858 return; | |
6859 | |
6860 /* Avoid redrawing the cursor while scrolling or it'll end up where | |
6861 * we don't want it to be. I'm not sure if it's correct to call | |
6862 * gui_dont_update_cursor() at this point but it works as a quick | |
6863 * fix for now. */ | |
9848
664276833670
commit https://github.com/vim/vim/commit/107abd2ca53c31fd3bb40d77ff296e98eaae2975
Christian Brabandt <cb@256bit.org>
parents:
9836
diff
changeset
|
6864 gui_dont_update_cursor(TRUE); |
7 | 6865 |
6866 do | |
6867 { | |
6868 /* Wait to check whether the scroll worked or not. */ | |
6869 event = gdk_event_get_graphics_expose(gui.drawarea->window); | |
6870 | |
6871 if (event == NULL) | |
6872 break; /* received NoExpose event */ | |
6873 | |
6874 gui_redraw(event->expose.area.x, event->expose.area.y, | |
6875 event->expose.area.width, event->expose.area.height); | |
6876 | |
6877 expose_count = event->expose.count; | |
6878 gdk_event_free(event); | |
6879 } | |
6880 while (expose_count > 0); /* more events follow */ | |
6881 | |
6882 gui_can_update_cursor(); | |
6883 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6884 #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
|
6885 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6886 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6887 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6888 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
|
6889 int src_x, int src_y, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6890 int width, int height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6891 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6892 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
|
6893 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6894 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
|
6895 cairo_clip(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6896 cairo_push_group(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6897 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
|
6898 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6899 cairo_pop_group_to_source(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6900 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6901 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6902 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6903 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6904 #endif |
7 | 6905 |
6906 /* | |
6907 * Delete the given number of lines from the given row, scrolling up any | |
6908 * text further down within the scroll region. | |
6909 */ | |
6910 void | |
6911 gui_mch_delete_lines(int row, int num_lines) | |
6912 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6913 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6914 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
|
6915 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
|
6916 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
|
6917 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6918 gui_gtk_surface_copy_rect( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6919 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
|
6920 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
|
6921 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
|
6922 gui_clear_block( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6923 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
|
6924 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
|
6925 gui_gtk3_redraw( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6926 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
|
6927 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
|
6928 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6929 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
|
6930 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
|
6931 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
|
6932 #else |
7 | 6933 if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) |
6934 return; /* Can't see the window */ | |
6935 | |
6936 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
6937 gdk_gc_set_background(gui.text_gc, gui.bgcolor); | |
6938 | |
6939 /* copy one extra pixel, for when bold has spilled over */ | |
6940 gdk_window_copy_area(gui.drawarea->window, gui.text_gc, | |
6941 FILL_X(gui.scroll_region_left), FILL_Y(row), | |
6942 gui.drawarea->window, | |
6943 FILL_X(gui.scroll_region_left), | |
6944 FILL_Y(row + num_lines), | |
6945 gui.char_width * (gui.scroll_region_right | |
6946 - gui.scroll_region_left + 1) + 1, | |
6947 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1)); | |
6948 | |
6949 gui_clear_block(gui.scroll_region_bot - num_lines + 1, | |
6950 gui.scroll_region_left, | |
6951 gui.scroll_region_bot, gui.scroll_region_right); | |
6952 check_copy_area(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6953 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6954 } |
6955 | |
6956 /* | |
6957 * Insert the given number of lines before the given row, scrolling down any | |
6958 * following text within the scroll region. | |
6959 */ | |
6960 void | |
6961 gui_mch_insert_lines(int row, int num_lines) | |
6962 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6963 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6964 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
|
6965 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
|
6966 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
|
6967 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6968 gui_gtk_surface_copy_rect( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6969 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
|
6970 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
|
6971 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
|
6972 gui_mch_clear_block( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6973 row, gui.scroll_region_left, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6974 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
|
6975 gui_gtk3_redraw( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6976 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
|
6977 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
|
6978 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6979 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
|
6980 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
|
6981 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
|
6982 #else |
7 | 6983 if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) |
6984 return; /* Can't see the window */ | |
6985 | |
6986 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
6987 gdk_gc_set_background(gui.text_gc, gui.bgcolor); | |
6988 | |
6989 /* copy one extra pixel, for when bold has spilled over */ | |
6990 gdk_window_copy_area(gui.drawarea->window, gui.text_gc, | |
6991 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), | |
6992 gui.drawarea->window, | |
6993 FILL_X(gui.scroll_region_left), FILL_Y(row), | |
6994 gui.char_width * (gui.scroll_region_right | |
6995 - gui.scroll_region_left + 1) + 1, | |
6996 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1)); | |
6997 | |
6998 gui_clear_block(row, gui.scroll_region_left, | |
6999 row + num_lines - 1, gui.scroll_region_right); | |
7000 check_copy_area(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7001 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 7002 } |
7003 | |
7004 /* | |
7005 * X Selection stuff, for cutting and pasting text to other windows. | |
7006 */ | |
7007 void | |
7008 clip_mch_request_selection(VimClipboard *cbd) | |
7009 { | |
7010 GdkAtom target; | |
7011 unsigned i; | |
1494 | 7012 time_t start; |
7 | 7013 |
7014 for (i = 0; i < N_SELECTION_TARGETS; ++i) | |
7015 { | |
1904 | 7016 if (!clip_html && selection_targets[i].info == TARGET_HTML) |
7017 continue; | |
7 | 7018 received_selection = RS_NONE; |
7019 target = gdk_atom_intern(selection_targets[i].target, FALSE); | |
7020 | |
7021 gtk_selection_convert(gui.drawarea, | |
7022 cbd->gtk_sel_atom, target, | |
7023 (guint32)GDK_CURRENT_TIME); | |
7024 | |
1494 | 7025 /* Hack: Wait up to three seconds for the selection. A hang was |
7026 * noticed here when using the netrw plugin combined with ":gui" | |
7027 * during the FocusGained event. */ | |
7028 start = time(NULL); | |
7029 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
|
7030 g_main_context_iteration(NULL, TRUE); /* wait for selection_received_cb */ |
7 | 7031 |
7032 if (received_selection != RS_FAIL) | |
7033 return; | |
7034 } | |
7035 | |
7036 /* 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
|
7037 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7038 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
|
7039 cbd); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7040 #else |
1924 | 7041 yank_cut_buffer0(GDK_WINDOW_XDISPLAY(gui.mainwin->window), cbd); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7042 #endif |
7 | 7043 } |
7044 | |
7045 /* | |
7046 * Disown the selection. | |
7047 */ | |
7048 void | |
1884 | 7049 clip_mch_lose_selection(VimClipboard *cbd UNUSED) |
7 | 7050 { |
4209 | 7051 gtk_selection_owner_set(NULL, cbd->gtk_sel_atom, gui.event_time); |
7 | 7052 gui_mch_update(); |
7053 } | |
7054 | |
7055 /* | |
7056 * Own the selection and return OK if it worked. | |
7057 */ | |
7058 int | |
7059 clip_mch_own_selection(VimClipboard *cbd) | |
7060 { | |
7061 int success; | |
7062 | |
7063 success = gtk_selection_owner_set(gui.drawarea, cbd->gtk_sel_atom, | |
2923 | 7064 gui.event_time); |
7 | 7065 gui_mch_update(); |
7066 return (success) ? OK : FAIL; | |
7067 } | |
7068 | |
7069 /* | |
7070 * Send the current selection to the clipboard. Do nothing for X because we | |
7071 * will fill in the selection only when requested by another app. | |
7072 */ | |
7073 void | |
1884 | 7074 clip_mch_set_selection(VimClipboard *cbd UNUSED) |
7 | 7075 { |
7076 } | |
7077 | |
4209 | 7078 int |
7079 clip_gtk_owner_exists(VimClipboard *cbd) | |
7080 { | |
7081 return gdk_selection_owner_get(cbd->gtk_sel_atom) != NULL; | |
7082 } | |
7083 | |
7 | 7084 |
7085 #if defined(FEAT_MENU) || defined(PROTO) | |
7086 /* | |
7087 * Make a menu item appear either active or not active (grey or not grey). | |
7088 */ | |
7089 void | |
7090 gui_mch_menu_grey(vimmenu_T *menu, int grey) | |
7091 { | |
7092 if (menu->id == NULL) | |
7093 return; | |
7094 | |
7095 if (menu_is_separator(menu->name)) | |
7096 grey = TRUE; | |
7097 | |
7098 gui_mch_menu_hidden(menu, FALSE); | |
7099 /* 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
|
7100 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7101 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
|
7102 # else |
7 | 7103 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
|
7104 # endif |
7 | 7105 { |
7106 gtk_widget_set_sensitive(menu->id, !grey); | |
7107 gui_mch_update(); | |
7108 } | |
7109 } | |
7110 | |
7111 /* | |
7112 * Make menu item hidden or not hidden. | |
7113 */ | |
7114 void | |
7115 gui_mch_menu_hidden(vimmenu_T *menu, int hidden) | |
7116 { | |
7117 if (menu->id == 0) | |
7118 return; | |
7119 | |
7120 if (hidden) | |
7121 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7122 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7123 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
|
7124 # else |
7 | 7125 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
|
7126 # endif |
7 | 7127 { |
7128 gtk_widget_hide(menu->id); | |
7129 gui_mch_update(); | |
7130 } | |
7131 } | |
7132 else | |
7133 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7134 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7135 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
|
7136 # else |
7 | 7137 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
|
7138 # endif |
7 | 7139 { |
7140 gtk_widget_show(menu->id); | |
7141 gui_mch_update(); | |
7142 } | |
7143 } | |
7144 } | |
7145 | |
7146 /* | |
7147 * This is called after setting all the menus to grey/hidden or not. | |
7148 */ | |
7149 void | |
7150 gui_mch_draw_menubar(void) | |
7151 { | |
7152 /* just make sure that the visual changes get effect immediately */ | |
7153 gui_mch_update(); | |
7154 } | |
7155 #endif /* FEAT_MENU */ | |
7156 | |
7157 /* | |
7158 * Scrollbar stuff. | |
7159 */ | |
7160 void | |
7161 gui_mch_enable_scrollbar(scrollbar_T *sb, int flag) | |
7162 { | |
7163 if (sb->id == NULL) | |
7164 return; | |
7165 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7166 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7167 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
|
7168 #else |
7 | 7169 if (flag) |
7170 gtk_widget_show(sb->id); | |
7171 else | |
7172 gtk_widget_hide(sb->id); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7173 #endif |
7 | 7174 |
791 | 7175 update_window_manager_hints(0, 0); |
7 | 7176 } |
7177 | |
7178 | |
7179 /* | |
7180 * Return the RGB value of a pixel as long. | |
7181 */ | |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9879
diff
changeset
|
7182 guicolor_T |
7 | 7183 gui_mch_get_rgb(guicolor_T pixel) |
7184 { | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7185 #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
|
7186 return (long_u)pixel; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7187 #else |
7 | 7188 GdkColor color; |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7189 |
7 | 7190 gdk_colormap_query_color(gtk_widget_get_colormap(gui.drawarea), |
7191 (unsigned long)pixel, &color); | |
7192 | |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9879
diff
changeset
|
7193 return (guicolor_T)( |
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9879
diff
changeset
|
7194 (((unsigned)color.red & 0xff00) << 8) |
7 | 7195 | ((unsigned)color.green & 0xff00) |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9879
diff
changeset
|
7196 | (((unsigned)color.blue & 0xff00) >> 8)); |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7197 #endif |
7 | 7198 } |
7199 | |
7200 /* | |
88 | 7201 * Get current mouse coordinates in text window. |
7 | 7202 */ |
88 | 7203 void |
7204 gui_mch_getmouse(int *x, int *y) | |
7 | 7205 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7206 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7207 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
|
7208 #else |
88 | 7209 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
|
7210 #endif |
7 | 7211 } |
7212 | |
7213 void | |
7214 gui_mch_setmouse(int x, int y) | |
7215 { | |
7216 /* Sorry for the Xlib call, but we can't avoid it, since there is no | |
7217 * internal GDK mechanism present to accomplish this. (and for good | |
7218 * reason...) */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7219 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7220 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
|
7221 (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
|
7222 0, 0, 0U, 0U, x, y); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7223 #else |
7 | 7224 XWarpPointer(GDK_WINDOW_XDISPLAY(gui.drawarea->window), |
7225 (Window)0, GDK_WINDOW_XWINDOW(gui.drawarea->window), | |
7226 0, 0, 0U, 0U, x, y); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7227 #endif |
7 | 7228 } |
7229 | |
7230 | |
7231 #ifdef FEAT_MOUSESHAPE | |
7232 /* The last set mouse pointer shape is remembered, to be used when it goes | |
7233 * from hidden to not hidden. */ | |
7234 static int last_shape = 0; | |
7235 #endif | |
7236 | |
7237 /* | |
7238 * Use the blank mouse pointer or not. | |
7239 * | |
7240 * hide: TRUE = use blank ptr, FALSE = use parent ptr | |
7241 */ | |
7242 void | |
7243 gui_mch_mousehide(int hide) | |
7244 { | |
7245 if (gui.pointer_hidden != hide) | |
7246 { | |
7247 gui.pointer_hidden = hide; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7248 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7249 if (gtk_widget_get_window(gui.drawarea) && gui.blank_pointer != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7250 #else |
7 | 7251 if (gui.drawarea->window && gui.blank_pointer != NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7252 #endif |
7 | 7253 { |
7254 if (hide) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7255 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7256 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
|
7257 gui.blank_pointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7258 #else |
7 | 7259 gdk_window_set_cursor(gui.drawarea->window, gui.blank_pointer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7260 #endif |
7 | 7261 else |
7262 #ifdef FEAT_MOUSESHAPE | |
7263 mch_set_mouse_shape(last_shape); | |
8301
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7264 #elif GTK_CHECK_VERSION(3,0,0) |
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7265 gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), NULL); |
7 | 7266 #else |
7267 gdk_window_set_cursor(gui.drawarea->window, NULL); | |
7268 #endif | |
7269 } | |
7270 } | |
7271 } | |
7272 | |
7273 #if defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7274 | |
7275 /* Table for shape IDs. Keep in sync with the mshape_names[] table in | |
7276 * misc2.c! */ | |
7277 static const int mshape_ids[] = | |
7278 { | |
7279 GDK_LEFT_PTR, /* arrow */ | |
7280 GDK_CURSOR_IS_PIXMAP, /* blank */ | |
7281 GDK_XTERM, /* beam */ | |
7282 GDK_SB_V_DOUBLE_ARROW, /* updown */ | |
7283 GDK_SIZING, /* udsizing */ | |
7284 GDK_SB_H_DOUBLE_ARROW, /* leftright */ | |
7285 GDK_SIZING, /* lrsizing */ | |
7286 GDK_WATCH, /* busy */ | |
7287 GDK_X_CURSOR, /* no */ | |
7288 GDK_CROSSHAIR, /* crosshair */ | |
7289 GDK_HAND1, /* hand1 */ | |
7290 GDK_HAND2, /* hand2 */ | |
7291 GDK_PENCIL, /* pencil */ | |
7292 GDK_QUESTION_ARROW, /* question */ | |
7293 GDK_RIGHT_PTR, /* right-arrow */ | |
7294 GDK_CENTER_PTR, /* up-arrow */ | |
7295 GDK_LEFT_PTR /* last one */ | |
7296 }; | |
7297 | |
7298 void | |
7299 mch_set_mouse_shape(int shape) | |
7300 { | |
7301 int id; | |
7302 GdkCursor *c; | |
7303 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7304 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7305 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
|
7306 # else |
7 | 7307 if (gui.drawarea->window == NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7308 # endif |
7 | 7309 return; |
7310 | |
7311 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
|
7312 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7313 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
|
7314 gui.blank_pointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7315 # else |
7 | 7316 gdk_window_set_cursor(gui.drawarea->window, gui.blank_pointer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7317 # endif |
7 | 7318 else |
7319 { | |
7320 if (shape >= MSHAPE_NUMBERED) | |
7321 { | |
7322 id = shape - MSHAPE_NUMBERED; | |
7323 if (id >= GDK_LAST_CURSOR) | |
7324 id = GDK_LEFT_PTR; | |
7325 else | |
7326 id &= ~1; /* they are always even (why?) */ | |
7327 } | |
1884 | 7328 else if (shape < (int)(sizeof(mshape_ids) / sizeof(int))) |
7 | 7329 id = mshape_ids[shape]; |
842 | 7330 else |
7331 return; | |
7 | 7332 c = gdk_cursor_new_for_display( |
136 | 7333 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
|
7334 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7335 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
|
7336 # else |
7 | 7337 gdk_window_set_cursor(gui.drawarea->window, c); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7338 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7339 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7340 g_object_unref(G_OBJECT(c)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7341 # else |
7 | 7342 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
|
7343 # endif |
7 | 7344 } |
7345 if (shape != MSHAPE_HIDE) | |
7346 last_shape = shape; | |
7347 } | |
7348 #endif /* FEAT_MOUSESHAPE */ | |
7349 | |
7350 | |
7351 #if defined(FEAT_SIGN_ICONS) || defined(PROTO) | |
7352 /* | |
7353 * Signs are currently always 2 chars wide. With GTK+ 2, the image will be | |
7354 * scaled down if the current font is not big enough, or scaled up if the image | |
7355 * size is less than 3/4 of the maximum sign size. With GTK+ 1, the pixmap | |
7356 * will be cut off if the current font is not big enough, or centered if it's | |
7357 * too small. | |
7358 */ | |
7359 # define SIGN_WIDTH (2 * gui.char_width) | |
7360 # define SIGN_HEIGHT (gui.char_height) | |
7361 # define SIGN_ASPECT ((double)SIGN_HEIGHT / (double)SIGN_WIDTH) | |
7362 | |
7363 void | |
7364 gui_mch_drawsign(int row, int col, int typenr) | |
7365 { | |
7366 GdkPixbuf *sign; | |
7367 | |
7368 sign = (GdkPixbuf *)sign_get_image(typenr); | |
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 if (sign != NULL && gui.drawarea != NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7372 && 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
|
7373 # else |
7 | 7374 if (sign != NULL && gui.drawarea != NULL && gui.drawarea->window != NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7375 # endif |
7 | 7376 { |
7377 int width; | |
7378 int height; | |
7379 int xoffset; | |
7380 int yoffset; | |
7381 int need_scale; | |
7382 | |
7383 width = gdk_pixbuf_get_width(sign); | |
7384 height = gdk_pixbuf_get_height(sign); | |
7385 /* | |
7386 * Decide whether we need to scale. Allow one pixel of border | |
7387 * width to be cut off, in order to avoid excessive scaling for | |
7388 * tiny differences in font size. | |
5983 | 7389 * Do scale to fit the height to avoid gaps because of linespacing. |
7 | 7390 */ |
7391 need_scale = (width > SIGN_WIDTH + 2 | |
5983 | 7392 || height != SIGN_HEIGHT |
7 | 7393 || (width < 3 * SIGN_WIDTH / 4 |
7394 && height < 3 * SIGN_HEIGHT / 4)); | |
7395 if (need_scale) | |
7396 { | |
5983 | 7397 double aspect; |
7398 int w = width; | |
7399 int h = height; | |
7 | 7400 |
7401 /* Keep the original aspect ratio */ | |
7402 aspect = (double)height / (double)width; | |
7403 width = (double)SIGN_WIDTH * SIGN_ASPECT / aspect; | |
7404 width = MIN(width, SIGN_WIDTH); | |
5983 | 7405 if (((double)(MAX(height, SIGN_HEIGHT)) / |
7406 (double)(MIN(height, SIGN_HEIGHT))) < 1.15) | |
7407 { | |
7408 /* Change the aspect ratio by at most 15% to fill the | |
7409 * available space completly. */ | |
7410 height = (double)SIGN_HEIGHT * SIGN_ASPECT / aspect; | |
7411 height = MIN(height, SIGN_HEIGHT); | |
7412 } | |
7413 else | |
7414 height = (double)width * aspect; | |
7415 | |
7416 if (w == width && h == height) | |
7417 { | |
7418 /* no change in dimensions; don't decrease reference counter | |
7419 * (below) */ | |
7420 need_scale = FALSE; | |
7421 } | |
7422 else | |
7423 { | |
7424 /* This doesn't seem to be worth caching, and doing so would | |
7425 * complicate the code quite a bit. */ | |
7426 sign = gdk_pixbuf_scale_simple(sign, width, height, | |
7427 GDK_INTERP_BILINEAR); | |
7428 if (sign == NULL) | |
7429 return; /* out of memory */ | |
7430 } | |
7 | 7431 } |
7432 | |
7433 /* The origin is the upper-left corner of the pixmap. Therefore | |
7434 * these offset may become negative if the pixmap is smaller than | |
7435 * the 2x1 cells reserved for the sign icon. */ | |
7436 xoffset = (width - SIGN_WIDTH) / 2; | |
7437 yoffset = (height - SIGN_HEIGHT) / 2; | |
7438 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7439 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7440 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7441 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7442 cairo_surface_t *bg_surf; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7443 cairo_t *bg_cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7444 cairo_surface_t *sign_surf; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7445 cairo_t *sign_cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7446 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7447 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7448 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7449 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
|
7450 cairo_surface_get_content(gui.surface), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7451 SIGN_WIDTH, SIGN_HEIGHT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7452 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
|
7453 cairo_set_source_rgba(bg_cr, |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9523
diff
changeset
|
7454 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
|
7455 gui.bgcolor->alpha); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7456 cairo_paint(bg_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7457 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7458 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
|
7459 cairo_surface_get_content(gui.surface), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7460 SIGN_WIDTH, SIGN_HEIGHT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7461 sign_cr = cairo_create(sign_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7462 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
|
7463 cairo_paint(sign_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7464 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7465 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
|
7466 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
|
7467 cairo_paint(sign_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7468 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7469 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
|
7470 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7471 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7472 cairo_destroy(sign_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7473 cairo_surface_destroy(sign_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7474 cairo_destroy(bg_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7475 cairo_surface_destroy(bg_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7476 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7477 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7478 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7479 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
|
7480 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
|
7481 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7482 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7483 # else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 7484 gdk_gc_set_foreground(gui.text_gc, gui.bgcolor); |
7485 | |
7486 gdk_draw_rectangle(gui.drawarea->window, | |
7487 gui.text_gc, | |
7488 TRUE, | |
7489 FILL_X(col), | |
7490 FILL_Y(row), | |
7491 SIGN_WIDTH, | |
7492 SIGN_HEIGHT); | |
7493 | |
7494 gdk_pixbuf_render_to_drawable_alpha(sign, | |
7495 gui.drawarea->window, | |
7496 MAX(0, xoffset), | |
7497 MAX(0, yoffset), | |
7498 FILL_X(col) - MIN(0, xoffset), | |
7499 FILL_Y(row) - MIN(0, yoffset), | |
7500 MIN(width, SIGN_WIDTH), | |
7501 MIN(height, SIGN_HEIGHT), | |
7502 GDK_PIXBUF_ALPHA_BILEVEL, | |
7503 127, | |
7504 GDK_RGB_DITHER_NORMAL, | |
7505 0, 0); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7506 # endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 7507 if (need_scale) |
7508 g_object_unref(sign); | |
7509 } | |
7510 } | |
7511 | |
7512 void * | |
7513 gui_mch_register_sign(char_u *signfile) | |
7514 { | |
7515 if (signfile[0] != NUL && signfile[0] != '-' && gui.in_use) | |
7516 { | |
7517 GdkPixbuf *sign; | |
7518 GError *error = NULL; | |
7519 char_u *message; | |
7520 | |
7521 sign = gdk_pixbuf_new_from_file((const char *)signfile, &error); | |
7522 | |
7523 if (error == NULL) | |
7524 return sign; | |
7525 | |
7526 message = (char_u *)error->message; | |
7527 | |
7528 if (message != NULL && input_conv.vc_type != CONV_NONE) | |
7529 message = string_convert(&input_conv, message, NULL); | |
7530 | |
7531 if (message != NULL) | |
7532 { | |
7533 /* The error message is already translated and will be more | |
7534 * descriptive than anything we could possibly do ourselves. */ | |
7535 EMSG2("E255: %s", message); | |
7536 | |
7537 if (input_conv.vc_type != CONV_NONE) | |
7538 vim_free(message); | |
7539 } | |
7540 g_error_free(error); | |
7541 } | |
7542 | |
7543 return NULL; | |
7544 } | |
7545 | |
7546 void | |
7547 gui_mch_destroy_sign(void *sign) | |
7548 { | |
7549 if (sign != NULL) | |
7550 g_object_unref(sign); | |
7551 } | |
7552 | |
7553 #endif /* FEAT_SIGN_ICONS */ |