Bram Moolenaar | edf3f97 | 2016-08-29 22:49:24 +0200 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4 noet: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | * |
Bram Moolenaar | 0a56cb8 | 2005-01-04 21:45:14 +0000 | [diff] [blame] | 13 | * (C) 1998,1999,2000 by Marcin Dalecki <martin@dalecki.de> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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> |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 22 | * |
| 23 | * Support for GTK+ 3 was added by: |
| 24 | * |
| 25 | * 2016 Kazunobu Kuriyama <kazunobu.kuriyama@gmail.com> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #include "vim.h" |
Bram Moolenaar | 36e294c | 2015-12-29 18:55:46 +0100 | [diff] [blame] | 29 | #ifdef USE_GRESOURCE |
| 30 | #include "auto/gui_gtk_gresources.h" |
| 31 | #endif |
Bram Moolenaar | c93e791 | 2008-07-08 10:46:08 +0000 | [diff] [blame] | 32 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | a2dd900 | 2007-05-14 17:38:30 +0000 | [diff] [blame] | 47 | # ifdef bind_textdomain_codeset |
| 48 | # undef bind_textdomain_codeset |
Bram Moolenaar | 4932594 | 2007-05-10 19:19:59 +0000 | [diff] [blame] | 49 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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" |
Bram Moolenaar | db552d60 | 2006-03-23 22:59:57 +0000 | [diff] [blame] | 55 | /* missing prototype in bonobo-dock-item.h */ |
| 56 | extern void bonobo_dock_item_set_behavior(BonoboDockItem *dock_item, BonoboDockItemBehavior beh); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 82 | # if GTK_CHECK_VERSION(3,0,0) |
| 83 | # include <gdk/gdkkeysyms-compat.h> |
| 84 | # include <gtk/gtkx.h> |
| 85 | # else |
| 86 | # include <gdk/gdkkeysyms.h> |
| 87 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 88 | # include <gdk/gdk.h> |
| 89 | # ifdef WIN3264 |
| 90 | # include <gdk/gdkwin32.h> |
| 91 | # else |
| 92 | # include <gdk/gdkx.h> |
| 93 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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> |
| 100 | #endif |
| 101 | |
| 102 | /* |
| 103 | * Easy-to-use macro for multihead support. |
| 104 | */ |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 105 | #define GET_X_ATOM(atom) gdk_x11_atom_to_xatom_for_display( \ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 106 | gtk_widget_get_display(gui.mainwin), atom) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 107 | |
| 108 | /* Selection type distinguishers */ |
| 109 | enum |
| 110 | { |
| 111 | TARGET_TYPE_NONE, |
| 112 | TARGET_UTF8_STRING, |
| 113 | TARGET_STRING, |
| 114 | TARGET_COMPOUND_TEXT, |
Bram Moolenaar | 3a6eaa5 | 2009-06-16 13:23:06 +0000 | [diff] [blame] | 115 | TARGET_HTML, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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}, |
Bram Moolenaar | 3a6eaa5 | 2009-06-16 13:23:06 +0000 | [diff] [blame] | 131 | {"text/html", 0, TARGET_HTML}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 132 | {"UTF8_STRING", 0, TARGET_UTF8_STRING}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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}, |
Bram Moolenaar | 3a6eaa5 | 2009-06-16 13:23:06 +0000 | [diff] [blame] | 147 | {"text/html", 0, TARGET_HTML}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 148 | {"UTF8_STRING", 0, TARGET_UTF8_STRING}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | */ |
Bram Moolenaar | 3a6eaa5 | 2009-06-16 13:23:06 +0000 | [diff] [blame] | 174 | static GdkAtom html_atom = GDK_NONE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 175 | static GdkAtom utf8_string_atom = GDK_NONE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 176 | static GdkAtom vim_atom = GDK_NONE; /* Vim's own special selection format */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 177 | static GdkAtom vimenc_atom = GDK_NONE; /* Vim's extended selection format */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 333 | {"--role", ARG_ROLE|ARG_HAS_VALUE}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 379 | static const char *role_argument = NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 380 | #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) |
| 381 | static const char *restart_command = NULL; |
Bram Moolenaar | 9085f80 | 2009-06-03 14:20:21 +0000 | [diff] [blame] | 382 | static char *abs_restart_command = NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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) |
Bram Moolenaar | 9085f80 | 2009-06-03 14:20:21 +0000 | [diff] [blame] | 420 | { |
| 421 | abs_restart_command = (char *)vim_strsave(buf); |
| 422 | restart_command = abs_restart_command; |
| 423 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 526 | case ARG_ROLE: |
| 527 | role_argument = value; /* used later in gui_mch_open() */ |
| 528 | break; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 529 | #ifdef FEAT_NETBEANS_INTG |
| 530 | case ARG_NETBEANS: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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. |
Bram Moolenaar | 717e196 | 2016-08-10 21:28:44 +0200 | [diff] [blame] | 541 | * Must start the GUI for this, otherwise ":gui" will exit later! |
| 542 | * Only when the GUI can start. */ |
| 543 | if ((option->flags & ARG_NEEDS_GUI) |
| 544 | && gui_mch_early_init_check(FALSE) == OK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 578 | #if defined(EXITFREE) || defined(PROTO) |
| 579 | void |
Bram Moolenaar | 66f948e | 2016-01-30 16:39:25 +0100 | [diff] [blame] | 580 | gui_mch_free_all(void) |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 581 | { |
| 582 | vim_free(gui_argv); |
Bram Moolenaar | 9085f80 | 2009-06-03 14:20:21 +0000 | [diff] [blame] | 583 | #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) |
| 584 | vim_free(abs_restart_command); |
| 585 | #endif |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 586 | } |
| 587 | #endif |
| 588 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 589 | #if !GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 590 | /* |
| 591 | * This should be maybe completely removed. |
| 592 | * Doesn't seem possible, since check_copy_area() relies on |
| 593 | * this information. --danielk |
| 594 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 595 | static gint |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 596 | visibility_event(GtkWidget *widget UNUSED, |
| 597 | GdkEventVisibility *event, |
| 598 | gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | } |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 611 | #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 612 | |
| 613 | /* |
| 614 | * Redraw the corresponding portions of the screen. |
| 615 | */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 616 | #if GTK_CHECK_VERSION(3,0,0) |
| 617 | static gboolean is_key_pressed = FALSE; |
Bram Moolenaar | 0ecbe33 | 2016-03-05 22:40:52 +0100 | [diff] [blame] | 618 | static gboolean blink_mode = TRUE; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 619 | |
| 620 | static gboolean gui_gtk_is_blink_on(void); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 621 | static void gui_gtk_window_clear(GdkWindow *win); |
| 622 | |
| 623 | static void |
| 624 | gui_gtk3_redraw(int x, int y, int width, int height) |
| 625 | { |
Bram Moolenaar | fe344a9 | 2017-02-23 12:20:35 +0100 | [diff] [blame] | 626 | /* Range checks are left to gui_redraw_block() */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 627 | gui_redraw_block(Y_2_ROW(y), X_2_COL(x), |
| 628 | Y_2_ROW(y + height - 1), X_2_COL(x + width - 1), |
| 629 | GUI_MON_NOCLEAR); |
| 630 | } |
| 631 | |
| 632 | static void |
| 633 | gui_gtk3_update_cursor(cairo_t *cr) |
| 634 | { |
| 635 | if (gui.row == gui.cursor_row) |
| 636 | { |
| 637 | gui.by_signal = TRUE; |
Bram Moolenaar | 4fc563b | 2016-03-12 12:40:58 +0100 | [diff] [blame] | 638 | if (State & CMDLINE) |
| 639 | gui_update_cursor(TRUE, FALSE); |
| 640 | else |
| 641 | gui_update_cursor(TRUE, TRUE); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 642 | gui.by_signal = FALSE; |
| 643 | cairo_paint(cr); |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | static gboolean |
| 648 | gui_gtk3_should_draw_cursor(void) |
| 649 | { |
| 650 | unsigned int cond = 0; |
| 651 | cond |= gui_gtk_is_blink_on(); |
Bram Moolenaar | b4ebf9a | 2016-03-12 16:28:18 +0100 | [diff] [blame] | 652 | if (gui.cursor_col >= gui.col) |
| 653 | cond |= is_key_pressed; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 654 | cond |= gui.in_focus == FALSE; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 655 | return cond; |
| 656 | } |
| 657 | |
| 658 | static gboolean |
Bram Moolenaar | 8e31fd5 | 2016-06-04 22:18:13 +0200 | [diff] [blame] | 659 | draw_event(GtkWidget *widget UNUSED, |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 660 | cairo_t *cr, |
| 661 | gpointer user_data UNUSED) |
| 662 | { |
| 663 | /* Skip this when the GUI isn't set up yet, will redraw later. */ |
| 664 | if (gui.starting) |
| 665 | return FALSE; |
| 666 | |
| 667 | out_flush(); /* make sure all output has been processed */ |
| 668 | /* for GTK+ 3, may induce other draw events. */ |
| 669 | |
| 670 | cairo_set_source_surface(cr, gui.surface, 0, 0); |
| 671 | |
| 672 | /* Draw the window without the cursor. */ |
| 673 | gui.by_signal = TRUE; |
| 674 | { |
| 675 | cairo_rectangle_list_t *list = NULL; |
| 676 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 677 | list = cairo_copy_clip_rectangle_list(cr); |
| 678 | if (list->status != CAIRO_STATUS_CLIP_NOT_REPRESENTABLE) |
| 679 | { |
| 680 | int i; |
Bram Moolenaar | fe344a9 | 2017-02-23 12:20:35 +0100 | [diff] [blame] | 681 | |
| 682 | /* First clear all the blocks and then redraw them. Just in case |
| 683 | * some blocks overlap. */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 684 | for (i = 0; i < list->num_rectangles; i++) |
| 685 | { |
| 686 | const cairo_rectangle_t rect = list->rectangles[i]; |
Bram Moolenaar | 8e31fd5 | 2016-06-04 22:18:13 +0200 | [diff] [blame] | 687 | |
Bram Moolenaar | fe344a9 | 2017-02-23 12:20:35 +0100 | [diff] [blame] | 688 | gui_mch_clear_block(Y_2_ROW((int)rect.y), 0, |
| 689 | Y_2_ROW((int)(rect.y + rect.height)) - 1, Columns - 1); |
| 690 | } |
| 691 | |
| 692 | for (i = 0; i < list->num_rectangles; i++) |
| 693 | { |
| 694 | const cairo_rectangle_t rect = list->rectangles[i]; |
Bram Moolenaar | 8e31fd5 | 2016-06-04 22:18:13 +0200 | [diff] [blame] | 695 | |
Bram Moolenaar | 0ecbe33 | 2016-03-05 22:40:52 +0100 | [diff] [blame] | 696 | if (blink_mode) |
| 697 | gui_gtk3_redraw(rect.x, rect.y, rect.width, rect.height); |
| 698 | else |
Bram Moolenaar | b4ebf9a | 2016-03-12 16:28:18 +0100 | [diff] [blame] | 699 | { |
| 700 | if (get_real_state() & VISUAL) |
| 701 | gui_gtk3_redraw(rect.x, rect.y, |
| 702 | rect.width, rect.height); |
| 703 | else |
| 704 | gui_redraw(rect.x, rect.y, rect.width, rect.height); |
| 705 | } |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | cairo_rectangle_list_destroy(list); |
| 709 | |
Bram Moolenaar | b4ebf9a | 2016-03-12 16:28:18 +0100 | [diff] [blame] | 710 | if (get_real_state() & VISUAL) |
| 711 | { |
| 712 | if (gui.cursor_row == gui.row && gui.cursor_col >= gui.col) |
| 713 | gui_update_cursor(TRUE, TRUE); |
| 714 | } |
| 715 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 716 | cairo_paint(cr); |
| 717 | } |
| 718 | gui.by_signal = FALSE; |
| 719 | |
| 720 | /* Add the cursor to the window if necessary.*/ |
Bram Moolenaar | b4ebf9a | 2016-03-12 16:28:18 +0100 | [diff] [blame] | 721 | if (gui_gtk3_should_draw_cursor() && blink_mode) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 722 | gui_gtk3_update_cursor(cr); |
| 723 | |
| 724 | return FALSE; |
| 725 | } |
| 726 | #else /* !GTK_CHECK_VERSION(3,0,0) */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 727 | static gint |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 728 | expose_event(GtkWidget *widget UNUSED, |
| 729 | GdkEventExpose *event, |
| 730 | gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | } |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 753 | #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 754 | |
| 755 | #ifdef FEAT_CLIENTSERVER |
| 756 | /* |
| 757 | * Handle changes to the "Comm" property |
| 758 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 759 | static gint |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 760 | property_event(GtkWidget *widget, |
| 761 | GdkEventProperty *event, |
| 762 | gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 763 | { |
| 764 | if (event->type == GDK_PROPERTY_NOTIFY |
| 765 | && event->state == (int)GDK_PROPERTY_NEW_VALUE |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 766 | # if GTK_CHECK_VERSION(3,0,0) |
| 767 | && GDK_WINDOW_XID(event->window) == commWindow |
| 768 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 769 | && GDK_WINDOW_XWINDOW(event->window) == commWindow |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 770 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 780 | # if GTK_CHECK_VERSION(3,0,0) |
| 781 | serverEventProc(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(widget)), |
| 782 | &xev, 0); |
| 783 | # else |
Bram Moolenaar | 93c88e0 | 2015-09-15 14:12:05 +0200 | [diff] [blame] | 784 | serverEventProc(GDK_WINDOW_XDISPLAY(widget->window), &xev, 0); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 785 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 786 | } |
| 787 | return FALSE; |
| 788 | } |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 789 | #endif /* defined(FEAT_CLIENTSERVER) */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 790 | |
| 791 | |
| 792 | /**************************************************************************** |
| 793 | * Focus handlers: |
| 794 | */ |
| 795 | |
| 796 | |
| 797 | /* |
| 798 | * This is a simple state machine: |
| 799 | * BLINK_NONE not blinking at all |
| 800 | * BLINK_OFF blinking, cursor is not shown |
| 801 | * BLINK_ON blinking, cursor is shown |
| 802 | */ |
| 803 | |
| 804 | #define BLINK_NONE 0 |
| 805 | #define BLINK_OFF 1 |
| 806 | #define BLINK_ON 2 |
| 807 | |
| 808 | static int blink_state = BLINK_NONE; |
| 809 | static long_u blink_waittime = 700; |
| 810 | static long_u blink_ontime = 400; |
| 811 | static long_u blink_offtime = 250; |
| 812 | static guint blink_timer = 0; |
| 813 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 814 | #if GTK_CHECK_VERSION(3,0,0) |
| 815 | static gboolean |
| 816 | gui_gtk_is_blink_on(void) |
| 817 | { |
| 818 | return blink_state == BLINK_ON; |
| 819 | } |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 820 | #endif |
| 821 | |
Bram Moolenaar | 703a804 | 2016-06-04 16:24:32 +0200 | [diff] [blame] | 822 | int |
| 823 | gui_mch_is_blinking(void) |
| 824 | { |
| 825 | return blink_state != BLINK_NONE; |
| 826 | } |
| 827 | |
Bram Moolenaar | 9d5d3c9 | 2016-07-07 16:43:02 +0200 | [diff] [blame] | 828 | int |
| 829 | gui_mch_is_blink_off(void) |
| 830 | { |
| 831 | return blink_state == BLINK_OFF; |
| 832 | } |
| 833 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 834 | void |
| 835 | gui_mch_set_blinking(long waittime, long on, long off) |
| 836 | { |
Bram Moolenaar | 0ecbe33 | 2016-03-05 22:40:52 +0100 | [diff] [blame] | 837 | #if GTK_CHECK_VERSION(3,0,0) |
| 838 | if (waittime == 0 || on == 0 || off == 0) |
| 839 | { |
| 840 | blink_mode = FALSE; |
| 841 | |
| 842 | blink_waittime = 700; |
| 843 | blink_ontime = 400; |
| 844 | blink_offtime = 250; |
| 845 | } |
| 846 | else |
| 847 | { |
| 848 | blink_mode = TRUE; |
| 849 | |
| 850 | blink_waittime = waittime; |
| 851 | blink_ontime = on; |
| 852 | blink_offtime = off; |
| 853 | } |
| 854 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 855 | blink_waittime = waittime; |
| 856 | blink_ontime = on; |
| 857 | blink_offtime = off; |
Bram Moolenaar | 0ecbe33 | 2016-03-05 22:40:52 +0100 | [diff] [blame] | 858 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | /* |
| 862 | * Stop the cursor blinking. Show the cursor if it wasn't shown. |
| 863 | */ |
| 864 | void |
| 865 | gui_mch_stop_blink(void) |
| 866 | { |
| 867 | if (blink_timer) |
| 868 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 869 | #if GTK_CHECK_VERSION(3,0,0) |
| 870 | g_source_remove(blink_timer); |
| 871 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 872 | gtk_timeout_remove(blink_timer); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 873 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 874 | blink_timer = 0; |
| 875 | } |
| 876 | if (blink_state == BLINK_OFF) |
Bram Moolenaar | da3a77d | 2016-07-10 23:16:09 +0200 | [diff] [blame] | 877 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 878 | gui_update_cursor(TRUE, FALSE); |
Bram Moolenaar | da3a77d | 2016-07-10 23:16:09 +0200 | [diff] [blame] | 879 | gui_mch_flush(); |
| 880 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 881 | blink_state = BLINK_NONE; |
| 882 | } |
| 883 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 884 | #if GTK_CHECK_VERSION(3,0,0) |
| 885 | static gboolean |
| 886 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 887 | static gint |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 888 | #endif |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 889 | blink_cb(gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 890 | { |
| 891 | if (blink_state == BLINK_ON) |
| 892 | { |
| 893 | gui_undraw_cursor(); |
| 894 | blink_state = BLINK_OFF; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 895 | #if GTK_CHECK_VERSION(3,0,0) |
| 896 | blink_timer = g_timeout_add((guint)blink_offtime, |
| 897 | (GSourceFunc) blink_cb, NULL); |
| 898 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 899 | blink_timer = gtk_timeout_add((guint32)blink_offtime, |
| 900 | (GtkFunction) blink_cb, NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 901 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 902 | } |
| 903 | else |
| 904 | { |
| 905 | gui_update_cursor(TRUE, FALSE); |
| 906 | blink_state = BLINK_ON; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 907 | #if GTK_CHECK_VERSION(3,0,0) |
| 908 | blink_timer = g_timeout_add((guint)blink_ontime, |
| 909 | (GSourceFunc) blink_cb, NULL); |
| 910 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 911 | blink_timer = gtk_timeout_add((guint32)blink_ontime, |
| 912 | (GtkFunction) blink_cb, NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 913 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 914 | } |
Bram Moolenaar | da3a77d | 2016-07-10 23:16:09 +0200 | [diff] [blame] | 915 | gui_mch_flush(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 916 | |
| 917 | return FALSE; /* don't happen again */ |
| 918 | } |
| 919 | |
| 920 | /* |
| 921 | * Start the cursor blinking. If it was already blinking, this restarts the |
| 922 | * waiting time and shows the cursor. |
| 923 | */ |
| 924 | void |
| 925 | gui_mch_start_blink(void) |
| 926 | { |
| 927 | if (blink_timer) |
Bram Moolenaar | 7bcdb7d | 2014-04-06 21:08:45 +0200 | [diff] [blame] | 928 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 929 | #if GTK_CHECK_VERSION(3,0,0) |
| 930 | g_source_remove(blink_timer); |
| 931 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 932 | gtk_timeout_remove(blink_timer); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 933 | #endif |
Bram Moolenaar | 7bcdb7d | 2014-04-06 21:08:45 +0200 | [diff] [blame] | 934 | blink_timer = 0; |
| 935 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 936 | /* Only switch blinking on if none of the times is zero */ |
| 937 | if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus) |
| 938 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 939 | #if GTK_CHECK_VERSION(3,0,0) |
| 940 | blink_timer = g_timeout_add((guint)blink_waittime, |
| 941 | (GSourceFunc) blink_cb, NULL); |
| 942 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 943 | blink_timer = gtk_timeout_add((guint32)blink_waittime, |
| 944 | (GtkFunction) blink_cb, NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 945 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 946 | blink_state = BLINK_ON; |
| 947 | gui_update_cursor(TRUE, FALSE); |
Bram Moolenaar | da3a77d | 2016-07-10 23:16:09 +0200 | [diff] [blame] | 948 | gui_mch_flush(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 949 | } |
| 950 | } |
| 951 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 952 | static gint |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 953 | enter_notify_event(GtkWidget *widget UNUSED, |
| 954 | GdkEventCrossing *event UNUSED, |
| 955 | gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 956 | { |
| 957 | if (blink_state == BLINK_NONE) |
| 958 | gui_mch_start_blink(); |
| 959 | |
| 960 | /* make sure keyboard input goes there */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 961 | #if GTK_CHECK_VERSION(3,0,0) |
| 962 | if (gtk_socket_id == 0 || !gtk_widget_has_focus(gui.drawarea)) |
| 963 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 964 | if (gtk_socket_id == 0 || !GTK_WIDGET_HAS_FOCUS(gui.drawarea)) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 965 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 966 | gtk_widget_grab_focus(gui.drawarea); |
| 967 | |
| 968 | return FALSE; |
| 969 | } |
| 970 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 971 | static gint |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 972 | leave_notify_event(GtkWidget *widget UNUSED, |
| 973 | GdkEventCrossing *event UNUSED, |
| 974 | gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 975 | { |
| 976 | if (blink_state != BLINK_NONE) |
| 977 | gui_mch_stop_blink(); |
| 978 | |
| 979 | return FALSE; |
| 980 | } |
| 981 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 982 | static gint |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 983 | focus_in_event(GtkWidget *widget, |
| 984 | GdkEventFocus *event UNUSED, |
| 985 | gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 986 | { |
| 987 | gui_focus_change(TRUE); |
| 988 | |
| 989 | if (blink_state == BLINK_NONE) |
| 990 | gui_mch_start_blink(); |
| 991 | |
Bram Moolenaar | 9c8791f | 2007-09-05 19:47:23 +0000 | [diff] [blame] | 992 | /* make sure keyboard input goes to the draw area (if this is focus for a |
| 993 | * window) */ |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 994 | if (widget != gui.drawarea) |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 995 | gtk_widget_grab_focus(gui.drawarea); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 996 | |
| 997 | return TRUE; |
| 998 | } |
| 999 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1000 | static gint |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 1001 | focus_out_event(GtkWidget *widget UNUSED, |
Bram Moolenaar | cc448b3 | 2010-07-14 16:52:17 +0200 | [diff] [blame] | 1002 | GdkEventFocus *event UNUSED, |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 1003 | gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1004 | { |
| 1005 | gui_focus_change(FALSE); |
| 1006 | |
| 1007 | if (blink_state != BLINK_NONE) |
| 1008 | gui_mch_stop_blink(); |
| 1009 | |
| 1010 | return TRUE; |
| 1011 | } |
| 1012 | |
| 1013 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1014 | /* |
| 1015 | * Translate a GDK key value to UTF-8 independently of the current locale. |
| 1016 | * The output is written to string, which must have room for at least 6 bytes |
| 1017 | * plus the NUL terminator. Returns the length in bytes. |
| 1018 | * |
| 1019 | * This function is used in the GTK+ 2 GUI only. The GTK+ 1 code makes use |
| 1020 | * of GdkEventKey::string instead. But event->string is evil; see here why: |
| 1021 | * http://developer.gnome.org/doc/API/2.0/gdk/gdk-Event-Structures.html#GdkEventKey |
| 1022 | */ |
| 1023 | static int |
| 1024 | keyval_to_string(unsigned int keyval, unsigned int state, char_u *string) |
| 1025 | { |
| 1026 | int len; |
| 1027 | guint32 uc; |
| 1028 | |
| 1029 | uc = gdk_keyval_to_unicode(keyval); |
| 1030 | if (uc != 0) |
| 1031 | { |
| 1032 | /* Check for CTRL-foo */ |
| 1033 | if ((state & GDK_CONTROL_MASK) && uc >= 0x20 && uc < 0x80) |
| 1034 | { |
| 1035 | /* These mappings look arbitrary at the first glance, but in fact |
| 1036 | * resemble quite exactly the behaviour of the GTK+ 1.2 GUI on my |
| 1037 | * machine. The only difference is BS vs. DEL for CTRL-8 (makes |
| 1038 | * more sense and is consistent with usual terminal behaviour). */ |
| 1039 | if (uc >= '@') |
| 1040 | string[0] = uc & 0x1F; |
| 1041 | else if (uc == '2') |
| 1042 | string[0] = NUL; |
| 1043 | else if (uc >= '3' && uc <= '7') |
| 1044 | string[0] = uc ^ 0x28; |
| 1045 | else if (uc == '8') |
| 1046 | string[0] = BS; |
| 1047 | else if (uc == '?') |
| 1048 | string[0] = DEL; |
| 1049 | else |
| 1050 | string[0] = uc; |
| 1051 | len = 1; |
| 1052 | } |
| 1053 | else |
| 1054 | { |
| 1055 | /* Translate a normal key to UTF-8. This doesn't work for dead |
| 1056 | * keys of course, you _have_ to use an input method for that. */ |
| 1057 | len = utf_char2bytes((int)uc, string); |
| 1058 | } |
| 1059 | } |
| 1060 | else |
| 1061 | { |
| 1062 | /* Translate keys which are represented by ASCII control codes in Vim. |
| 1063 | * There are only a few of those; most control keys are translated to |
| 1064 | * special terminal-like control sequences. */ |
| 1065 | len = 1; |
| 1066 | switch (keyval) |
| 1067 | { |
| 1068 | case GDK_Tab: case GDK_KP_Tab: case GDK_ISO_Left_Tab: |
| 1069 | string[0] = TAB; |
| 1070 | break; |
| 1071 | case GDK_Linefeed: |
| 1072 | string[0] = NL; |
| 1073 | break; |
| 1074 | case GDK_Return: case GDK_ISO_Enter: case GDK_3270_Enter: |
| 1075 | string[0] = CAR; |
| 1076 | break; |
| 1077 | case GDK_Escape: |
| 1078 | string[0] = ESC; |
| 1079 | break; |
| 1080 | default: |
| 1081 | len = 0; |
| 1082 | break; |
| 1083 | } |
| 1084 | } |
| 1085 | string[len] = NUL; |
| 1086 | |
| 1087 | return len; |
| 1088 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1089 | |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 1090 | static int |
| 1091 | modifiers_gdk2vim(guint state) |
| 1092 | { |
| 1093 | int modifiers = 0; |
| 1094 | |
| 1095 | if (state & GDK_SHIFT_MASK) |
| 1096 | modifiers |= MOD_MASK_SHIFT; |
| 1097 | if (state & GDK_CONTROL_MASK) |
| 1098 | modifiers |= MOD_MASK_CTRL; |
| 1099 | if (state & GDK_MOD1_MASK) |
| 1100 | modifiers |= MOD_MASK_ALT; |
Bram Moolenaar | 580061a | 2010-08-13 13:57:13 +0200 | [diff] [blame] | 1101 | #if GTK_CHECK_VERSION(2,10,0) |
Bram Moolenaar | 30bb414 | 2010-05-17 22:07:15 +0200 | [diff] [blame] | 1102 | if (state & GDK_SUPER_MASK) |
| 1103 | modifiers |= MOD_MASK_META; |
| 1104 | #endif |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 1105 | if (state & GDK_MOD4_MASK) |
| 1106 | modifiers |= MOD_MASK_META; |
| 1107 | |
| 1108 | return modifiers; |
| 1109 | } |
| 1110 | |
| 1111 | static int |
| 1112 | modifiers_gdk2mouse(guint state) |
| 1113 | { |
| 1114 | int modifiers = 0; |
| 1115 | |
| 1116 | if (state & GDK_SHIFT_MASK) |
| 1117 | modifiers |= MOUSE_SHIFT; |
| 1118 | if (state & GDK_CONTROL_MASK) |
| 1119 | modifiers |= MOUSE_CTRL; |
| 1120 | if (state & GDK_MOD1_MASK) |
| 1121 | modifiers |= MOUSE_ALT; |
| 1122 | |
| 1123 | return modifiers; |
| 1124 | } |
| 1125 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1126 | /* |
| 1127 | * Main keyboard handler: |
| 1128 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1129 | static gint |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 1130 | key_press_event(GtkWidget *widget UNUSED, |
| 1131 | GdkEventKey *event, |
| 1132 | gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1133 | { |
Bram Moolenaar | 182c5be | 2010-06-25 05:37:59 +0200 | [diff] [blame] | 1134 | /* For GTK+ 2 we know for sure how large the string might get. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1135 | * (That is, up to 6 bytes + NUL + CSI escapes + safety measure.) */ |
| 1136 | char_u string[32], string2[32]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1137 | guint key_sym; |
| 1138 | int len; |
| 1139 | int i; |
| 1140 | int modifiers; |
| 1141 | int key; |
| 1142 | guint state; |
| 1143 | char_u *s, *d; |
| 1144 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1145 | #if GTK_CHECK_VERSION(3,0,0) |
| 1146 | is_key_pressed = TRUE; |
| 1147 | gui_mch_stop_blink(); |
| 1148 | #endif |
| 1149 | |
Bram Moolenaar | 20892c1 | 2011-06-26 04:49:00 +0200 | [diff] [blame] | 1150 | gui.event_time = event->time; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1151 | key_sym = event->keyval; |
| 1152 | state = event->state; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1153 | |
| 1154 | #ifdef FEAT_XIM |
| 1155 | if (xim_queue_key_press_event(event, TRUE)) |
| 1156 | return TRUE; |
| 1157 | #endif |
| 1158 | |
| 1159 | #ifdef FEAT_HANGULIN |
| 1160 | if (key_sym == GDK_space && (state & GDK_SHIFT_MASK)) |
| 1161 | { |
| 1162 | hangul_input_state_toggle(); |
| 1163 | return TRUE; |
| 1164 | } |
| 1165 | #endif |
| 1166 | |
| 1167 | #ifdef SunXK_F36 |
| 1168 | /* |
| 1169 | * These keys have bogus lookup strings, and trapping them here is |
| 1170 | * easier than trying to XRebindKeysym() on them with every possible |
| 1171 | * combination of modifiers. |
| 1172 | */ |
| 1173 | if (key_sym == SunXK_F36 || key_sym == SunXK_F37) |
| 1174 | len = 0; |
| 1175 | else |
| 1176 | #endif |
| 1177 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1178 | len = keyval_to_string(key_sym, state, string2); |
| 1179 | |
| 1180 | /* Careful: convert_input() doesn't handle the NUL character. |
| 1181 | * No need to convert pure ASCII anyway, thus the len > 1 check. */ |
| 1182 | if (len > 1 && input_conv.vc_type != CONV_NONE) |
| 1183 | len = convert_input(string2, len, sizeof(string2)); |
| 1184 | |
| 1185 | s = string2; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1186 | d = string; |
| 1187 | for (i = 0; i < len; ++i) |
| 1188 | { |
| 1189 | *d++ = s[i]; |
| 1190 | if (d[-1] == CSI && d + 2 < string + sizeof(string)) |
| 1191 | { |
| 1192 | /* Turn CSI into K_CSI. */ |
| 1193 | *d++ = KS_EXTRA; |
| 1194 | *d++ = (int)KE_CSI; |
| 1195 | } |
| 1196 | } |
| 1197 | len = d - string; |
| 1198 | } |
| 1199 | |
| 1200 | /* Shift-Tab results in Left_Tab, but we want <S-Tab> */ |
| 1201 | if (key_sym == GDK_ISO_Left_Tab) |
| 1202 | { |
| 1203 | key_sym = GDK_Tab; |
| 1204 | state |= GDK_SHIFT_MASK; |
| 1205 | } |
| 1206 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1207 | #ifdef FEAT_MENU |
| 1208 | /* If there is a menu and 'wak' is "yes", or 'wak' is "menu" and the key |
| 1209 | * is a menu shortcut, we ignore everything with the ALT modifier. */ |
| 1210 | if ((state & GDK_MOD1_MASK) |
| 1211 | && gui.menu_is_active |
| 1212 | && (*p_wak == 'y' |
| 1213 | || (*p_wak == 'm' |
| 1214 | && len == 1 |
| 1215 | && gui_is_menu_shortcut(string[0])))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1216 | /* For GTK2 we return false to signify that we haven't handled the |
| 1217 | * keypress, so that gtk will handle the mnemonic or accelerator. */ |
| 1218 | return FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1219 | #endif |
| 1220 | |
| 1221 | /* Check for Alt/Meta key (Mod1Mask), but not for a BS, DEL or character |
| 1222 | * that already has the 8th bit set. |
| 1223 | * Don't do this for <S-M-Tab>, that should become K_S_TAB with ALT. |
| 1224 | * Don't do this for double-byte encodings, it turns the char into a lead |
| 1225 | * byte. */ |
| 1226 | if (len == 1 |
Bram Moolenaar | 30bb414 | 2010-05-17 22:07:15 +0200 | [diff] [blame] | 1227 | && ((state & GDK_MOD1_MASK) |
Bram Moolenaar | 35f330c | 2010-08-15 13:53:58 +0200 | [diff] [blame] | 1228 | #if GTK_CHECK_VERSION(2,10,0) |
Bram Moolenaar | 30bb414 | 2010-05-17 22:07:15 +0200 | [diff] [blame] | 1229 | || (state & GDK_SUPER_MASK) |
| 1230 | #endif |
| 1231 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1232 | && !(key_sym == GDK_BackSpace || key_sym == GDK_Delete) |
| 1233 | && (string[0] & 0x80) == 0 |
| 1234 | && !(key_sym == GDK_Tab && (state & GDK_SHIFT_MASK)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1235 | && !enc_dbcs |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1236 | ) |
| 1237 | { |
| 1238 | string[0] |= 0x80; |
| 1239 | state &= ~GDK_MOD1_MASK; /* don't use it again */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1240 | if (enc_utf8) /* convert to utf-8 */ |
| 1241 | { |
| 1242 | string[1] = string[0] & 0xbf; |
| 1243 | string[0] = ((unsigned)string[0] >> 6) + 0xc0; |
| 1244 | if (string[1] == CSI) |
| 1245 | { |
| 1246 | string[2] = KS_EXTRA; |
| 1247 | string[3] = (int)KE_CSI; |
| 1248 | len = 4; |
| 1249 | } |
| 1250 | else |
| 1251 | len = 2; |
| 1252 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | /* Check for special keys. Also do this when len == 1 (key has an ASCII |
| 1256 | * value) to detect backspace, delete and keypad keys. */ |
| 1257 | if (len == 0 || len == 1) |
| 1258 | { |
| 1259 | for (i = 0; special_keys[i].key_sym != 0; i++) |
| 1260 | { |
| 1261 | if (special_keys[i].key_sym == key_sym) |
| 1262 | { |
| 1263 | string[0] = CSI; |
| 1264 | string[1] = special_keys[i].code0; |
| 1265 | string[2] = special_keys[i].code1; |
| 1266 | len = -3; |
| 1267 | break; |
| 1268 | } |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | if (len == 0) /* Unrecognized key */ |
| 1273 | return TRUE; |
| 1274 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1275 | /* Special keys (and a few others) may have modifiers. Also when using a |
| 1276 | * double-byte encoding (can't set the 8th bit). */ |
| 1277 | if (len == -3 || key_sym == GDK_space || key_sym == GDK_Tab |
| 1278 | || key_sym == GDK_Return || key_sym == GDK_Linefeed |
| 1279 | || key_sym == GDK_Escape || key_sym == GDK_KP_Tab |
| 1280 | || key_sym == GDK_ISO_Enter || key_sym == GDK_3270_Enter |
Bram Moolenaar | 30bb414 | 2010-05-17 22:07:15 +0200 | [diff] [blame] | 1281 | || (enc_dbcs && len == 1 && ((state & GDK_MOD1_MASK) |
Bram Moolenaar | 35f330c | 2010-08-15 13:53:58 +0200 | [diff] [blame] | 1282 | #if GTK_CHECK_VERSION(2,10,0) |
Bram Moolenaar | 30bb414 | 2010-05-17 22:07:15 +0200 | [diff] [blame] | 1283 | || (state & GDK_SUPER_MASK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1284 | #endif |
Bram Moolenaar | 182c5be | 2010-06-25 05:37:59 +0200 | [diff] [blame] | 1285 | ))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1286 | { |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 1287 | modifiers = modifiers_gdk2vim(state); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1288 | |
| 1289 | /* |
| 1290 | * For some keys a shift modifier is translated into another key |
| 1291 | * code. |
| 1292 | */ |
| 1293 | if (len == -3) |
| 1294 | key = TO_SPECIAL(string[1], string[2]); |
| 1295 | else |
| 1296 | key = string[0]; |
| 1297 | |
| 1298 | key = simplify_key(key, &modifiers); |
| 1299 | if (key == CSI) |
| 1300 | key = K_CSI; |
| 1301 | if (IS_SPECIAL(key)) |
| 1302 | { |
| 1303 | string[0] = CSI; |
| 1304 | string[1] = K_SECOND(key); |
| 1305 | string[2] = K_THIRD(key); |
| 1306 | len = 3; |
| 1307 | } |
| 1308 | else |
| 1309 | { |
| 1310 | string[0] = key; |
| 1311 | len = 1; |
| 1312 | } |
| 1313 | |
| 1314 | if (modifiers != 0) |
| 1315 | { |
| 1316 | string2[0] = CSI; |
| 1317 | string2[1] = KS_MODIFIER; |
| 1318 | string2[2] = modifiers; |
| 1319 | add_to_input_buf(string2, 3); |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | if (len == 1 && ((string[0] == Ctrl_C && ctrl_c_interrupts) |
| 1324 | || (string[0] == intr_char && intr_char != Ctrl_C))) |
| 1325 | { |
| 1326 | trash_input_buf(); |
| 1327 | got_int = TRUE; |
| 1328 | } |
| 1329 | |
| 1330 | add_to_input_buf(string, len); |
| 1331 | |
| 1332 | /* blank out the pointer if necessary */ |
| 1333 | if (p_mh) |
| 1334 | gui_mch_mousehide(TRUE); |
| 1335 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1336 | return TRUE; |
| 1337 | } |
| 1338 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1339 | #if defined(FEAT_XIM) || GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1340 | static gboolean |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 1341 | key_release_event(GtkWidget *widget UNUSED, |
| 1342 | GdkEventKey *event, |
| 1343 | gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1344 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1345 | # if GTK_CHECK_VERSION(3,0,0) |
| 1346 | is_key_pressed = FALSE; |
| 1347 | gui_mch_start_blink(); |
| 1348 | # endif |
| 1349 | # if defined(FEAT_XIM) |
Bram Moolenaar | 20892c1 | 2011-06-26 04:49:00 +0200 | [diff] [blame] | 1350 | gui.event_time = event->time; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1351 | /* |
| 1352 | * GTK+ 2 input methods may do fancy stuff on key release events too. |
| 1353 | * With the default IM for instance, you can enter any UCS code point |
| 1354 | * by holding down CTRL-SHIFT and typing hexadecimal digits. |
| 1355 | */ |
| 1356 | return xim_queue_key_press_event(event, FALSE); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1357 | # else |
| 1358 | return TRUE; |
| 1359 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1360 | } |
| 1361 | #endif |
| 1362 | |
| 1363 | |
| 1364 | /**************************************************************************** |
| 1365 | * Selection handlers: |
| 1366 | */ |
| 1367 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1368 | static gint |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 1369 | selection_clear_event(GtkWidget *widget UNUSED, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1370 | GdkEventSelection *event, |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 1371 | gpointer user_data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1372 | { |
| 1373 | if (event->selection == clip_plus.gtk_sel_atom) |
| 1374 | clip_lose_selection(&clip_plus); |
| 1375 | else |
| 1376 | clip_lose_selection(&clip_star); |
| 1377 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1378 | return TRUE; |
| 1379 | } |
| 1380 | |
| 1381 | #define RS_NONE 0 /* selection_received_cb() not called yet */ |
| 1382 | #define RS_OK 1 /* selection_received_cb() called and OK */ |
| 1383 | #define RS_FAIL 2 /* selection_received_cb() called and failed */ |
| 1384 | static int received_selection = RS_NONE; |
| 1385 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1386 | static void |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 1387 | selection_received_cb(GtkWidget *widget UNUSED, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1388 | GtkSelectionData *data, |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 1389 | guint time_ UNUSED, |
| 1390 | gpointer user_data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1391 | { |
| 1392 | VimClipboard *cbd; |
| 1393 | char_u *text; |
| 1394 | char_u *tmpbuf = NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1395 | guchar *tmpbuf_utf8 = NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1396 | int len; |
Bram Moolenaar | d44347f | 2011-06-19 01:14:29 +0200 | [diff] [blame] | 1397 | int motion_type = MAUTO; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1398 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1399 | #if GTK_CHECK_VERSION(3,0,0) |
| 1400 | if (gtk_selection_data_get_selection(data) == clip_plus.gtk_sel_atom) |
| 1401 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1402 | if (data->selection == clip_plus.gtk_sel_atom) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1403 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1404 | cbd = &clip_plus; |
| 1405 | else |
| 1406 | cbd = &clip_star; |
| 1407 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1408 | #if GTK_CHECK_VERSION(3,0,0) |
| 1409 | text = (char_u *)gtk_selection_data_get_data(data); |
| 1410 | len = gtk_selection_data_get_length(data); |
| 1411 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1412 | text = (char_u *)data->data; |
| 1413 | len = data->length; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1414 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1415 | |
| 1416 | if (text == NULL || len <= 0) |
| 1417 | { |
| 1418 | received_selection = RS_FAIL; |
| 1419 | /* clip_free_selection(cbd); ??? */ |
| 1420 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1421 | return; |
| 1422 | } |
| 1423 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1424 | #if GTK_CHECK_VERSION(3,0,0) |
| 1425 | if (gtk_selection_data_get_data_type(data) == vim_atom) |
| 1426 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1427 | if (data->type == vim_atom) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1428 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1429 | { |
| 1430 | motion_type = *text++; |
| 1431 | --len; |
| 1432 | } |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1433 | #if GTK_CHECK_VERSION(3,0,0) |
| 1434 | else if (gtk_selection_data_get_data_type(data) == vimenc_atom) |
| 1435 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1436 | else if (data->type == vimenc_atom) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1437 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1438 | { |
| 1439 | char_u *enc; |
| 1440 | vimconv_T conv; |
| 1441 | |
| 1442 | motion_type = *text++; |
| 1443 | --len; |
| 1444 | |
| 1445 | enc = text; |
| 1446 | text += STRLEN(text) + 1; |
| 1447 | len -= text - enc; |
| 1448 | |
| 1449 | /* If the encoding of the text is different from 'encoding', attempt |
| 1450 | * converting it. */ |
| 1451 | conv.vc_type = CONV_NONE; |
| 1452 | convert_setup(&conv, enc, p_enc); |
| 1453 | if (conv.vc_type != CONV_NONE) |
| 1454 | { |
| 1455 | tmpbuf = string_convert(&conv, text, &len); |
| 1456 | if (tmpbuf != NULL) |
| 1457 | text = tmpbuf; |
| 1458 | convert_setup(&conv, NULL, NULL); |
| 1459 | } |
| 1460 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1461 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1462 | /* gtk_selection_data_get_text() handles all the nasty details |
| 1463 | * and targets and encodings etc. This rocks so hard. */ |
| 1464 | else |
| 1465 | { |
| 1466 | tmpbuf_utf8 = gtk_selection_data_get_text(data); |
| 1467 | if (tmpbuf_utf8 != NULL) |
| 1468 | { |
| 1469 | len = STRLEN(tmpbuf_utf8); |
| 1470 | if (input_conv.vc_type != CONV_NONE) |
| 1471 | { |
| 1472 | tmpbuf = string_convert(&input_conv, tmpbuf_utf8, &len); |
| 1473 | if (tmpbuf != NULL) |
| 1474 | text = tmpbuf; |
| 1475 | } |
| 1476 | else |
| 1477 | text = tmpbuf_utf8; |
| 1478 | } |
Bram Moolenaar | 3a6eaa5 | 2009-06-16 13:23:06 +0000 | [diff] [blame] | 1479 | else if (len >= 2 && text[0] == 0xff && text[1] == 0xfe) |
| 1480 | { |
| 1481 | vimconv_T conv; |
| 1482 | |
| 1483 | /* UTF-16, we get this for HTML */ |
| 1484 | conv.vc_type = CONV_NONE; |
| 1485 | convert_setup_ext(&conv, (char_u *)"utf-16le", FALSE, p_enc, TRUE); |
| 1486 | |
| 1487 | if (conv.vc_type != CONV_NONE) |
| 1488 | { |
| 1489 | text += 2; |
| 1490 | len -= 2; |
| 1491 | tmpbuf = string_convert(&conv, text, &len); |
| 1492 | convert_setup(&conv, NULL, NULL); |
| 1493 | } |
| 1494 | if (tmpbuf != NULL) |
| 1495 | text = tmpbuf; |
| 1496 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1497 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1498 | |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 1499 | /* Chop off any trailing NUL bytes. OpenOffice sends these. */ |
Bram Moolenaar | a76638f | 2010-06-05 12:49:46 +0200 | [diff] [blame] | 1500 | while (len > 0 && text[len - 1] == NUL) |
| 1501 | --len; |
| 1502 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1503 | clip_yank_selection(motion_type, text, (long)len, cbd); |
| 1504 | received_selection = RS_OK; |
| 1505 | vim_free(tmpbuf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1506 | g_free(tmpbuf_utf8); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | /* |
| 1510 | * Prepare our selection data for passing it to the external selection |
| 1511 | * client. |
| 1512 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1513 | static void |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 1514 | selection_get_cb(GtkWidget *widget UNUSED, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1515 | GtkSelectionData *selection_data, |
| 1516 | guint info, |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 1517 | guint time_ UNUSED, |
| 1518 | gpointer user_data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1519 | { |
| 1520 | char_u *string; |
| 1521 | char_u *tmpbuf; |
| 1522 | long_u tmplen; |
| 1523 | int length; |
| 1524 | int motion_type; |
| 1525 | GdkAtom type; |
| 1526 | VimClipboard *cbd; |
| 1527 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1528 | #if GTK_CHECK_VERSION(3,0,0) |
| 1529 | if (gtk_selection_data_get_selection(selection_data) |
| 1530 | == clip_plus.gtk_sel_atom) |
| 1531 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1532 | if (selection_data->selection == clip_plus.gtk_sel_atom) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1533 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1534 | cbd = &clip_plus; |
| 1535 | else |
| 1536 | cbd = &clip_star; |
| 1537 | |
| 1538 | if (!cbd->owned) |
| 1539 | return; /* Shouldn't ever happen */ |
| 1540 | |
| 1541 | if (info != (guint)TARGET_STRING |
Bram Moolenaar | 3a6eaa5 | 2009-06-16 13:23:06 +0000 | [diff] [blame] | 1542 | && (!clip_html || info != (guint)TARGET_HTML) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1543 | && info != (guint)TARGET_UTF8_STRING |
| 1544 | && info != (guint)TARGET_VIMENC |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1545 | && info != (guint)TARGET_VIM |
| 1546 | && info != (guint)TARGET_COMPOUND_TEXT |
| 1547 | && info != (guint)TARGET_TEXT) |
| 1548 | return; |
| 1549 | |
| 1550 | /* get the selection from the '*'/'+' register */ |
| 1551 | clip_get_selection(cbd); |
| 1552 | |
| 1553 | motion_type = clip_convert_selection(&string, &tmplen, cbd); |
| 1554 | if (motion_type < 0 || string == NULL) |
| 1555 | return; |
| 1556 | /* Due to int arguments we can't handle more than G_MAXINT. Also |
| 1557 | * reserve one extra byte for NUL or the motion type; just in case. |
| 1558 | * (Not that pasting 2G of text is ever going to work, but... ;-) */ |
| 1559 | length = MIN(tmplen, (long_u)(G_MAXINT - 1)); |
| 1560 | |
| 1561 | if (info == (guint)TARGET_VIM) |
| 1562 | { |
| 1563 | tmpbuf = alloc((unsigned)length + 1); |
| 1564 | if (tmpbuf != NULL) |
| 1565 | { |
| 1566 | tmpbuf[0] = motion_type; |
| 1567 | mch_memmove(tmpbuf + 1, string, (size_t)length); |
| 1568 | } |
| 1569 | /* For our own format, the first byte contains the motion type */ |
| 1570 | ++length; |
| 1571 | vim_free(string); |
| 1572 | string = tmpbuf; |
| 1573 | type = vim_atom; |
| 1574 | } |
| 1575 | |
Bram Moolenaar | 3a6eaa5 | 2009-06-16 13:23:06 +0000 | [diff] [blame] | 1576 | else if (info == (guint)TARGET_HTML) |
| 1577 | { |
| 1578 | vimconv_T conv; |
| 1579 | |
| 1580 | /* Since we get utf-16, we probably should set it as well. */ |
| 1581 | conv.vc_type = CONV_NONE; |
| 1582 | convert_setup_ext(&conv, p_enc, TRUE, (char_u *)"utf-16le", FALSE); |
| 1583 | if (conv.vc_type != CONV_NONE) |
| 1584 | { |
| 1585 | tmpbuf = string_convert(&conv, string, &length); |
| 1586 | convert_setup(&conv, NULL, NULL); |
| 1587 | vim_free(string); |
| 1588 | string = tmpbuf; |
| 1589 | } |
| 1590 | |
| 1591 | /* Prepend the BOM: "fffe" */ |
| 1592 | if (string != NULL) |
| 1593 | { |
| 1594 | tmpbuf = alloc(length + 2); |
| 1595 | tmpbuf[0] = 0xff; |
| 1596 | tmpbuf[1] = 0xfe; |
| 1597 | mch_memmove(tmpbuf + 2, string, (size_t)length); |
| 1598 | vim_free(string); |
| 1599 | string = tmpbuf; |
| 1600 | length += 2; |
| 1601 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1602 | #if !GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 3f2a5d8 | 2016-02-27 22:08:16 +0100 | [diff] [blame] | 1603 | /* Looks redundant even for GTK2 because these values are |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1604 | * overwritten by gtk_selection_data_set() that follows. */ |
Bram Moolenaar | 3a6eaa5 | 2009-06-16 13:23:06 +0000 | [diff] [blame] | 1605 | selection_data->type = selection_data->target; |
| 1606 | selection_data->format = 16; /* 16 bits per char */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1607 | #endif |
Bram Moolenaar | 3a6eaa5 | 2009-06-16 13:23:06 +0000 | [diff] [blame] | 1608 | gtk_selection_data_set(selection_data, html_atom, 16, |
| 1609 | string, length); |
| 1610 | vim_free(string); |
| 1611 | } |
| 1612 | return; |
| 1613 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1614 | else if (info == (guint)TARGET_VIMENC) |
| 1615 | { |
| 1616 | int l = STRLEN(p_enc); |
| 1617 | |
| 1618 | /* contents: motion_type 'encoding' NUL text */ |
| 1619 | tmpbuf = alloc((unsigned)length + l + 2); |
| 1620 | if (tmpbuf != NULL) |
| 1621 | { |
| 1622 | tmpbuf[0] = motion_type; |
| 1623 | STRCPY(tmpbuf + 1, p_enc); |
| 1624 | mch_memmove(tmpbuf + l + 2, string, (size_t)length); |
| 1625 | } |
| 1626 | length += l + 2; |
| 1627 | vim_free(string); |
| 1628 | string = tmpbuf; |
| 1629 | type = vimenc_atom; |
| 1630 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1631 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1632 | /* gtk_selection_data_set_text() handles everything for us. This is |
| 1633 | * so easy and simple and cool, it'd be insane not to use it. */ |
| 1634 | else |
| 1635 | { |
| 1636 | if (output_conv.vc_type != CONV_NONE) |
| 1637 | { |
| 1638 | tmpbuf = string_convert(&output_conv, string, &length); |
| 1639 | vim_free(string); |
| 1640 | if (tmpbuf == NULL) |
| 1641 | return; |
| 1642 | string = tmpbuf; |
| 1643 | } |
| 1644 | /* Validate the string to avoid runtime warnings */ |
| 1645 | if (g_utf8_validate((const char *)string, (gssize)length, NULL)) |
| 1646 | { |
| 1647 | gtk_selection_data_set_text(selection_data, |
| 1648 | (const char *)string, length); |
| 1649 | } |
| 1650 | vim_free(string); |
| 1651 | return; |
| 1652 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1653 | |
| 1654 | if (string != NULL) |
| 1655 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1656 | #if !GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 3f2a5d8 | 2016-02-27 22:08:16 +0100 | [diff] [blame] | 1657 | /* Looks redundant even for GTK2 because these values are |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1658 | * overwritten by gtk_selection_data_set() that follows. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1659 | selection_data->type = selection_data->target; |
| 1660 | selection_data->format = 8; /* 8 bits per char */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1661 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1662 | gtk_selection_data_set(selection_data, type, 8, string, length); |
| 1663 | vim_free(string); |
| 1664 | } |
| 1665 | } |
| 1666 | |
| 1667 | /* |
Bram Moolenaar | 2969570 | 2012-05-18 17:03:18 +0200 | [diff] [blame] | 1668 | * Check if the GUI can be started. Called before gvimrc is sourced and |
| 1669 | * before fork(). |
| 1670 | * Return OK or FAIL. |
| 1671 | */ |
| 1672 | int |
Bram Moolenaar | 717e196 | 2016-08-10 21:28:44 +0200 | [diff] [blame] | 1673 | gui_mch_early_init_check(int give_message) |
Bram Moolenaar | 2969570 | 2012-05-18 17:03:18 +0200 | [diff] [blame] | 1674 | { |
| 1675 | char_u *p; |
| 1676 | |
| 1677 | /* Guess that when $DISPLAY isn't set the GUI can't start. */ |
| 1678 | p = mch_getenv((char_u *)"DISPLAY"); |
| 1679 | if (p == NULL || *p == NUL) |
| 1680 | { |
| 1681 | gui.dying = TRUE; |
Bram Moolenaar | 717e196 | 2016-08-10 21:28:44 +0200 | [diff] [blame] | 1682 | if (give_message) |
| 1683 | EMSG(_((char *)e_opendisp)); |
Bram Moolenaar | 2969570 | 2012-05-18 17:03:18 +0200 | [diff] [blame] | 1684 | return FAIL; |
| 1685 | } |
| 1686 | return OK; |
| 1687 | } |
| 1688 | |
| 1689 | /* |
| 1690 | * Check if the GUI can be started. Called before gvimrc is sourced but after |
| 1691 | * fork(). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1692 | * Return OK or FAIL. |
| 1693 | */ |
| 1694 | int |
| 1695 | gui_mch_init_check(void) |
| 1696 | { |
Bram Moolenaar | 3a466a8 | 2016-01-19 17:47:25 +0100 | [diff] [blame] | 1697 | #ifdef USE_GRESOURCE |
| 1698 | static int res_registered = FALSE; |
| 1699 | |
| 1700 | if (!res_registered) |
| 1701 | { |
| 1702 | /* Call this function in the GUI process; otherwise, the resources |
| 1703 | * won't be available. Don't call it twice. */ |
| 1704 | res_registered = TRUE; |
| 1705 | gui_gtk_register_resource(); |
| 1706 | } |
| 1707 | #endif |
| 1708 | |
Bram Moolenaar | f80663f | 2016-04-05 21:56:06 +0200 | [diff] [blame] | 1709 | #if GTK_CHECK_VERSION(3,10,0) |
| 1710 | /* Vim currently assumes that Gtk means X11, so it cannot use native Gtk |
| 1711 | * support for other backends such as Wayland. */ |
| 1712 | gdk_set_allowed_backends ("x11"); |
| 1713 | #endif |
| 1714 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1715 | #ifdef FEAT_GUI_GNOME |
| 1716 | if (gtk_socket_id == 0) |
| 1717 | using_gnome = 1; |
| 1718 | #endif |
| 1719 | |
Bram Moolenaar | 8dd7901 | 2013-05-21 12:52:04 +0200 | [diff] [blame] | 1720 | /* This defaults to argv[0], but we want it to match the name of the |
| 1721 | * shipped gvim.desktop so that Vim's windows can be associated with this |
| 1722 | * file. */ |
| 1723 | g_set_prgname("gvim"); |
| 1724 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1725 | /* Don't use gtk_init() or gnome_init(), it exits on failure. */ |
| 1726 | if (!gtk_init_check(&gui_argc, &gui_argv)) |
| 1727 | { |
| 1728 | gui.dying = TRUE; |
Bram Moolenaar | c93e791 | 2008-07-08 10:46:08 +0000 | [diff] [blame] | 1729 | EMSG(_((char *)e_opendisp)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1730 | return FAIL; |
| 1731 | } |
| 1732 | |
| 1733 | return OK; |
| 1734 | } |
| 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 | */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1748 | #if GTK_CHECK_VERSION(3,0,0) |
| 1749 | static gboolean |
| 1750 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1751 | static gint |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1752 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1753 | mouse_click_timer_cb(gpointer data) |
| 1754 | { |
| 1755 | /* we don't use this information currently */ |
| 1756 | int *timed_out = (int *) data; |
| 1757 | |
| 1758 | *timed_out = TRUE; |
| 1759 | return FALSE; /* don't happen again */ |
| 1760 | } |
| 1761 | |
| 1762 | static guint motion_repeat_timer = 0; |
| 1763 | static int motion_repeat_offset = FALSE; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1764 | #ifdef GTK_DEST_DEFAULT_ALL |
| 1765 | static gboolean motion_repeat_timer_cb(gpointer); |
| 1766 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1767 | static gint motion_repeat_timer_cb(gpointer); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1768 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1769 | |
| 1770 | static void |
| 1771 | process_motion_notify(int x, int y, GdkModifierType state) |
| 1772 | { |
| 1773 | int button; |
| 1774 | int_u vim_modifiers; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1775 | #if GTK_CHECK_VERSION(3,0,0) |
| 1776 | GtkAllocation allocation; |
| 1777 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1778 | |
| 1779 | button = (state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | |
| 1780 | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | |
| 1781 | GDK_BUTTON5_MASK)) |
| 1782 | ? MOUSE_DRAG : ' '; |
| 1783 | |
| 1784 | /* If our pointer is currently hidden, then we should show it. */ |
| 1785 | gui_mch_mousehide(FALSE); |
| 1786 | |
| 1787 | /* Just moving the rodent above the drawing area without any button |
| 1788 | * being pressed. */ |
| 1789 | if (button != MOUSE_DRAG) |
| 1790 | { |
| 1791 | gui_mouse_moved(x, y); |
| 1792 | return; |
| 1793 | } |
| 1794 | |
| 1795 | /* translate modifier coding between the main engine and GTK */ |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 1796 | vim_modifiers = modifiers_gdk2mouse(state); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1797 | |
Bram Moolenaar | 4932594 | 2007-05-10 19:19:59 +0000 | [diff] [blame] | 1798 | /* inform the editor engine about the occurrence of this event */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1799 | gui_send_mouse_event(button, x, y, FALSE, vim_modifiers); |
| 1800 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1801 | /* |
| 1802 | * Auto repeat timer handling. |
| 1803 | */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1804 | #if GTK_CHECK_VERSION(3,0,0) |
| 1805 | gtk_widget_get_allocation(gui.drawarea, &allocation); |
| 1806 | |
| 1807 | if (x < 0 || y < 0 |
| 1808 | || x >= allocation.width |
| 1809 | || y >= allocation.height) |
| 1810 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1811 | if (x < 0 || y < 0 |
| 1812 | || x >= gui.drawarea->allocation.width |
| 1813 | || y >= gui.drawarea->allocation.height) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1814 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1815 | { |
| 1816 | |
| 1817 | int dx; |
| 1818 | int dy; |
| 1819 | int offshoot; |
| 1820 | int delay = 10; |
| 1821 | |
| 1822 | /* Calculate the maximal distance of the cursor from the drawing area. |
| 1823 | * (offshoot can't become negative here!). |
| 1824 | */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1825 | #if GTK_CHECK_VERSION(3,0,0) |
| 1826 | dx = x < 0 ? -x : x - allocation.width; |
| 1827 | dy = y < 0 ? -y : y - allocation.height; |
| 1828 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1829 | dx = x < 0 ? -x : x - gui.drawarea->allocation.width; |
| 1830 | dy = y < 0 ? -y : y - gui.drawarea->allocation.height; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1831 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1832 | |
| 1833 | offshoot = dx > dy ? dx : dy; |
| 1834 | |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 1835 | /* Make a linearly decaying timer delay with a threshold of 5 at a |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1836 | * distance of 127 pixels from the main window. |
| 1837 | * |
| 1838 | * One could think endlessly about the most ergonomic variant here. |
| 1839 | * For example it could make sense to calculate the distance from the |
| 1840 | * drags start instead... |
| 1841 | * |
| 1842 | * Maybe a parabolic interpolation would suite us better here too... |
| 1843 | */ |
| 1844 | if (offshoot > 127) |
| 1845 | { |
| 1846 | /* 5 appears to be somehow near to my perceptual limits :-). */ |
| 1847 | delay = 5; |
| 1848 | } |
| 1849 | else |
| 1850 | { |
| 1851 | delay = (130 * (127 - offshoot)) / 127 + 5; |
| 1852 | } |
| 1853 | |
| 1854 | /* shoot again */ |
| 1855 | if (!motion_repeat_timer) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1856 | #if GTK_CHECK_VERSION(3,0,0) |
| 1857 | motion_repeat_timer = g_timeout_add((guint)delay, |
| 1858 | motion_repeat_timer_cb, NULL); |
| 1859 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1860 | motion_repeat_timer = gtk_timeout_add((guint32)delay, |
| 1861 | motion_repeat_timer_cb, NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1862 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1863 | } |
| 1864 | } |
| 1865 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1866 | #if GTK_CHECK_VERSION(3,0,0) |
| 1867 | static GdkDevice * |
| 1868 | gui_gtk_get_pointer_device(GtkWidget *widget) |
| 1869 | { |
| 1870 | GdkWindow * const win = gtk_widget_get_window(widget); |
| 1871 | GdkDisplay * const dpy = gdk_window_get_display(win); |
Bram Moolenaar | 30e12d2 | 2016-04-17 20:49:53 +0200 | [diff] [blame] | 1872 | # if GTK_CHECK_VERSION(3,20,0) |
| 1873 | GdkSeat * const seat = gdk_display_get_default_seat(dpy); |
| 1874 | return gdk_seat_get_pointer(seat); |
| 1875 | # else |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1876 | GdkDeviceManager * const mngr = gdk_display_get_device_manager(dpy); |
| 1877 | return gdk_device_manager_get_client_pointer(mngr); |
Bram Moolenaar | 30e12d2 | 2016-04-17 20:49:53 +0200 | [diff] [blame] | 1878 | # endif |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | static GdkWindow * |
| 1882 | gui_gtk_get_pointer(GtkWidget *widget, |
| 1883 | gint *x, |
| 1884 | gint *y, |
| 1885 | GdkModifierType *state) |
| 1886 | { |
| 1887 | GdkWindow * const win = gtk_widget_get_window(widget); |
| 1888 | GdkDevice * const dev = gui_gtk_get_pointer_device(widget); |
| 1889 | return gdk_window_get_device_position(win, dev , x, y, state); |
| 1890 | } |
| 1891 | |
Bram Moolenaar | 2369c15 | 2016-03-04 23:08:25 +0100 | [diff] [blame] | 1892 | # if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1893 | static GdkWindow * |
| 1894 | gui_gtk_window_at_position(GtkWidget *widget, |
| 1895 | gint *x, |
| 1896 | gint *y) |
| 1897 | { |
| 1898 | GdkDevice * const dev = gui_gtk_get_pointer_device(widget); |
| 1899 | return gdk_device_get_window_at_position(dev, x, y); |
| 1900 | } |
Bram Moolenaar | 2369c15 | 2016-03-04 23:08:25 +0100 | [diff] [blame] | 1901 | # endif |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1902 | #endif |
| 1903 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1904 | /* |
| 1905 | * Timer used to recognize multiple clicks of the mouse button. |
| 1906 | */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1907 | #if GTK_CHECK_VERSION(3,0,0) |
| 1908 | static gboolean |
| 1909 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1910 | static gint |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1911 | #endif |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 1912 | motion_repeat_timer_cb(gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1913 | { |
| 1914 | int x; |
| 1915 | int y; |
| 1916 | GdkModifierType state; |
| 1917 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1918 | #if GTK_CHECK_VERSION(3,0,0) |
| 1919 | gui_gtk_get_pointer(gui.drawarea, &x, &y, &state); |
| 1920 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1921 | gdk_window_get_pointer(gui.drawarea->window, &x, &y, &state); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1922 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1923 | |
| 1924 | if (!(state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | |
| 1925 | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | |
| 1926 | GDK_BUTTON5_MASK))) |
| 1927 | { |
| 1928 | motion_repeat_timer = 0; |
| 1929 | return FALSE; |
| 1930 | } |
| 1931 | |
| 1932 | /* If there already is a mouse click in the input buffer, wait another |
| 1933 | * time (otherwise we would create a backlog of clicks) */ |
| 1934 | if (vim_used_in_input_buf() > 10) |
| 1935 | return TRUE; |
| 1936 | |
| 1937 | motion_repeat_timer = 0; |
| 1938 | |
| 1939 | /* |
| 1940 | * Fake a motion event. |
| 1941 | * Trick: Pretend the mouse moved to the next character on every other |
| 1942 | * event, otherwise drag events will be discarded, because they are still |
| 1943 | * in the same character. |
| 1944 | */ |
| 1945 | if (motion_repeat_offset) |
| 1946 | x += gui.char_width; |
| 1947 | |
| 1948 | motion_repeat_offset = !motion_repeat_offset; |
| 1949 | process_motion_notify(x, y, state); |
| 1950 | |
| 1951 | /* Don't happen again. We will get reinstalled in the synthetic event |
| 1952 | * if needed -- thus repeating should still work. */ |
| 1953 | return FALSE; |
| 1954 | } |
| 1955 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1956 | static gint |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 1957 | motion_notify_event(GtkWidget *widget, |
| 1958 | GdkEventMotion *event, |
| 1959 | gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1960 | { |
| 1961 | if (event->is_hint) |
| 1962 | { |
| 1963 | int x; |
| 1964 | int y; |
| 1965 | GdkModifierType state; |
| 1966 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1967 | #if GTK_CHECK_VERSION(3,0,0) |
| 1968 | gui_gtk_get_pointer(widget, &x, &y, &state); |
| 1969 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1970 | gdk_window_get_pointer(widget->window, &x, &y, &state); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 1971 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1972 | process_motion_notify(x, y, state); |
| 1973 | } |
| 1974 | else |
| 1975 | { |
| 1976 | process_motion_notify((int)event->x, (int)event->y, |
| 1977 | (GdkModifierType)event->state); |
| 1978 | } |
| 1979 | |
| 1980 | return TRUE; /* handled */ |
| 1981 | } |
| 1982 | |
| 1983 | |
| 1984 | /* |
| 1985 | * Mouse button handling. Note please that we are capturing multiple click's |
| 1986 | * by our own timeout mechanism instead of the one provided by GTK+ itself. |
| 1987 | * This is due to the way the generic VIM code is recognizing multiple clicks. |
| 1988 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1989 | static gint |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 1990 | button_press_event(GtkWidget *widget, |
| 1991 | GdkEventButton *event, |
| 1992 | gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1993 | { |
| 1994 | int button; |
| 1995 | int repeated_click = FALSE; |
| 1996 | int x, y; |
| 1997 | int_u vim_modifiers; |
| 1998 | |
Bram Moolenaar | 20892c1 | 2011-06-26 04:49:00 +0200 | [diff] [blame] | 1999 | gui.event_time = event->time; |
Bram Moolenaar | 7cfea75 | 2010-06-22 06:07:12 +0200 | [diff] [blame] | 2000 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2001 | /* Make sure we have focus now we've been selected */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2002 | #if GTK_CHECK_VERSION(3,0,0) |
| 2003 | if (gtk_socket_id != 0 && !gtk_widget_has_focus(widget)) |
| 2004 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2005 | if (gtk_socket_id != 0 && !GTK_WIDGET_HAS_FOCUS(widget)) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2006 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2007 | gtk_widget_grab_focus(widget); |
| 2008 | |
| 2009 | /* |
| 2010 | * Don't let additional events about multiple clicks send by GTK to us |
| 2011 | * after the initial button press event confuse us. |
| 2012 | */ |
| 2013 | if (event->type != GDK_BUTTON_PRESS) |
| 2014 | return FALSE; |
| 2015 | |
| 2016 | x = event->x; |
| 2017 | y = event->y; |
| 2018 | |
| 2019 | /* Handle multiple clicks */ |
| 2020 | if (!mouse_timed_out && mouse_click_timer) |
| 2021 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2022 | #if GTK_CHECK_VERSION(3,0,0) |
| 2023 | g_source_remove(mouse_click_timer); |
| 2024 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2025 | gtk_timeout_remove(mouse_click_timer); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2026 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2027 | mouse_click_timer = 0; |
| 2028 | repeated_click = TRUE; |
| 2029 | } |
| 2030 | |
| 2031 | mouse_timed_out = FALSE; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2032 | #if GTK_CHECK_VERSION(3,0,0) |
| 2033 | mouse_click_timer = g_timeout_add((guint)p_mouset, |
| 2034 | mouse_click_timer_cb, &mouse_timed_out); |
| 2035 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2036 | mouse_click_timer = gtk_timeout_add((guint32)p_mouset, |
| 2037 | mouse_click_timer_cb, &mouse_timed_out); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2038 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2039 | |
| 2040 | switch (event->button) |
| 2041 | { |
Bram Moolenaar | 88e484b | 2015-11-24 15:38:44 +0100 | [diff] [blame] | 2042 | /* Keep in sync with gui_x11.c. |
| 2043 | * Buttons 4-7 are handled in scroll_event() */ |
| 2044 | case 1: button = MOUSE_LEFT; break; |
| 2045 | case 2: button = MOUSE_MIDDLE; break; |
| 2046 | case 3: button = MOUSE_RIGHT; break; |
| 2047 | case 8: button = MOUSE_X1; break; |
| 2048 | case 9: button = MOUSE_X2; break; |
| 2049 | default: |
| 2050 | return FALSE; /* Unknown button */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | #ifdef FEAT_XIM |
| 2054 | /* cancel any preediting */ |
| 2055 | if (im_is_preediting()) |
| 2056 | xim_reset(); |
| 2057 | #endif |
| 2058 | |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 2059 | vim_modifiers = modifiers_gdk2mouse(event->state); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2060 | |
| 2061 | gui_send_mouse_event(button, x, y, repeated_click, vim_modifiers); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2062 | |
| 2063 | return TRUE; |
| 2064 | } |
| 2065 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2066 | /* |
Bram Moolenaar | 182c5be | 2010-06-25 05:37:59 +0200 | [diff] [blame] | 2067 | * GTK+ 2 abstracts scrolling via the GdkEventScroll. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2068 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2069 | static gboolean |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 2070 | scroll_event(GtkWidget *widget, |
| 2071 | GdkEventScroll *event, |
| 2072 | gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2073 | { |
| 2074 | int button; |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 2075 | int_u vim_modifiers; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2076 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2077 | #if GTK_CHECK_VERSION(3,0,0) |
| 2078 | if (gtk_socket_id != 0 && !gtk_widget_has_focus(widget)) |
| 2079 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2080 | if (gtk_socket_id != 0 && !GTK_WIDGET_HAS_FOCUS(widget)) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2081 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2082 | gtk_widget_grab_focus(widget); |
| 2083 | |
| 2084 | switch (event->direction) |
| 2085 | { |
| 2086 | case GDK_SCROLL_UP: |
| 2087 | button = MOUSE_4; |
| 2088 | break; |
| 2089 | case GDK_SCROLL_DOWN: |
| 2090 | button = MOUSE_5; |
| 2091 | break; |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 2092 | case GDK_SCROLL_LEFT: |
| 2093 | button = MOUSE_7; |
| 2094 | break; |
| 2095 | case GDK_SCROLL_RIGHT: |
| 2096 | button = MOUSE_6; |
| 2097 | break; |
| 2098 | default: /* This shouldn't happen */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2099 | return FALSE; |
| 2100 | } |
| 2101 | |
| 2102 | # ifdef FEAT_XIM |
| 2103 | /* cancel any preediting */ |
| 2104 | if (im_is_preediting()) |
| 2105 | xim_reset(); |
| 2106 | # endif |
| 2107 | |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 2108 | vim_modifiers = modifiers_gdk2mouse(event->state); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2109 | |
| 2110 | gui_send_mouse_event(button, (int)event->x, (int)event->y, |
| 2111 | FALSE, vim_modifiers); |
| 2112 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2113 | return TRUE; |
| 2114 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2115 | |
| 2116 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2117 | static gint |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 2118 | button_release_event(GtkWidget *widget UNUSED, |
| 2119 | GdkEventButton *event, |
| 2120 | gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2121 | { |
| 2122 | int x, y; |
| 2123 | int_u vim_modifiers; |
| 2124 | |
Bram Moolenaar | 20892c1 | 2011-06-26 04:49:00 +0200 | [diff] [blame] | 2125 | gui.event_time = event->time; |
Bram Moolenaar | 7cfea75 | 2010-06-22 06:07:12 +0200 | [diff] [blame] | 2126 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2127 | /* Remove any motion "machine gun" timers used for automatic further |
| 2128 | extension of allocation areas if outside of the applications window |
| 2129 | area .*/ |
| 2130 | if (motion_repeat_timer) |
| 2131 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2132 | #if GTK_CHECK_VERSION(3,0,0) |
| 2133 | g_source_remove(motion_repeat_timer); |
| 2134 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2135 | gtk_timeout_remove(motion_repeat_timer); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2136 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2137 | motion_repeat_timer = 0; |
| 2138 | } |
| 2139 | |
| 2140 | x = event->x; |
| 2141 | y = event->y; |
| 2142 | |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 2143 | vim_modifiers = modifiers_gdk2mouse(event->state); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2144 | |
| 2145 | gui_send_mouse_event(MOUSE_RELEASE, x, y, FALSE, vim_modifiers); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2146 | |
| 2147 | return TRUE; |
| 2148 | } |
| 2149 | |
| 2150 | |
| 2151 | #ifdef FEAT_DND |
| 2152 | /**************************************************************************** |
| 2153 | * Drag aNd Drop support handlers. |
| 2154 | */ |
| 2155 | |
| 2156 | /* |
| 2157 | * Count how many items there may be and separate them with a NUL. |
| 2158 | * Apparently the items are separated with \r\n. This is not documented, |
| 2159 | * thus be careful not to go past the end. Also allow separation with |
| 2160 | * NUL characters. |
| 2161 | */ |
| 2162 | static int |
| 2163 | count_and_decode_uri_list(char_u *out, char_u *raw, int len) |
| 2164 | { |
| 2165 | int i; |
| 2166 | char_u *p = out; |
| 2167 | int count = 0; |
| 2168 | |
| 2169 | for (i = 0; i < len; ++i) |
| 2170 | { |
| 2171 | if (raw[i] == NUL || raw[i] == '\n' || raw[i] == '\r') |
| 2172 | { |
| 2173 | if (p > out && p[-1] != NUL) |
| 2174 | { |
| 2175 | ++count; |
| 2176 | *p++ = NUL; |
| 2177 | } |
| 2178 | } |
| 2179 | else if (raw[i] == '%' && i + 2 < len && hexhex2nr(raw + i + 1) > 0) |
| 2180 | { |
| 2181 | *p++ = hexhex2nr(raw + i + 1); |
| 2182 | i += 2; |
| 2183 | } |
| 2184 | else |
| 2185 | *p++ = raw[i]; |
| 2186 | } |
| 2187 | if (p > out && p[-1] != NUL) |
| 2188 | { |
| 2189 | *p = NUL; /* last item didn't have \r or \n */ |
| 2190 | ++count; |
| 2191 | } |
| 2192 | return count; |
| 2193 | } |
| 2194 | |
| 2195 | /* |
| 2196 | * Parse NUL separated "src" strings. Make it an array "outlist" form. On |
| 2197 | * this process, URI which protocol is not "file:" are removed. Return |
| 2198 | * length of array (less than "max"). |
| 2199 | */ |
| 2200 | static int |
| 2201 | filter_uri_list(char_u **outlist, int max, char_u *src) |
| 2202 | { |
| 2203 | int i, j; |
| 2204 | |
| 2205 | for (i = j = 0; i < max; ++i) |
| 2206 | { |
| 2207 | outlist[i] = NULL; |
| 2208 | if (STRNCMP(src, "file:", 5) == 0) |
| 2209 | { |
| 2210 | src += 5; |
| 2211 | if (STRNCMP(src, "//localhost", 11) == 0) |
| 2212 | src += 11; |
| 2213 | while (src[0] == '/' && src[1] == '/') |
| 2214 | ++src; |
| 2215 | outlist[j++] = vim_strsave(src); |
| 2216 | } |
| 2217 | src += STRLEN(src) + 1; |
| 2218 | } |
| 2219 | return j; |
| 2220 | } |
| 2221 | |
| 2222 | static char_u ** |
| 2223 | parse_uri_list(int *count, char_u *data, int len) |
| 2224 | { |
| 2225 | int n = 0; |
| 2226 | char_u *tmp = NULL; |
Bram Moolenaar | 945ec09 | 2016-06-08 21:17:43 +0200 | [diff] [blame] | 2227 | char_u **array = NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2228 | |
| 2229 | if (data != NULL && len > 0 && (tmp = (char_u *)alloc(len + 1)) != NULL) |
| 2230 | { |
| 2231 | n = count_and_decode_uri_list(tmp, data, len); |
| 2232 | if (n > 0 && (array = (char_u **)alloc(n * sizeof(char_u *))) != NULL) |
| 2233 | n = filter_uri_list(array, n, tmp); |
| 2234 | } |
| 2235 | vim_free(tmp); |
| 2236 | *count = n; |
| 2237 | return array; |
| 2238 | } |
| 2239 | |
| 2240 | static void |
| 2241 | drag_handle_uri_list(GdkDragContext *context, |
| 2242 | GtkSelectionData *data, |
| 2243 | guint time_, |
| 2244 | GdkModifierType state, |
| 2245 | gint x, |
| 2246 | gint y) |
| 2247 | { |
| 2248 | char_u **fnames; |
| 2249 | int nfiles = 0; |
| 2250 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2251 | # if GTK_CHECK_VERSION(3,0,0) |
| 2252 | fnames = parse_uri_list(&nfiles, |
| 2253 | (char_u *)gtk_selection_data_get_data(data), |
| 2254 | gtk_selection_data_get_length(data)); |
| 2255 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2256 | fnames = parse_uri_list(&nfiles, data->data, data->length); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2257 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2258 | |
| 2259 | if (fnames != NULL && nfiles > 0) |
| 2260 | { |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 2261 | int_u modifiers; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2262 | |
| 2263 | gtk_drag_finish(context, TRUE, FALSE, time_); /* accept */ |
| 2264 | |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 2265 | modifiers = modifiers_gdk2mouse(state); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2266 | |
| 2267 | gui_handle_drop(x, y, modifiers, fnames, nfiles); |
| 2268 | } |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 2269 | else |
| 2270 | vim_free(fnames); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2271 | } |
| 2272 | |
| 2273 | static void |
| 2274 | drag_handle_text(GdkDragContext *context, |
| 2275 | GtkSelectionData *data, |
| 2276 | guint time_, |
| 2277 | GdkModifierType state) |
| 2278 | { |
| 2279 | char_u dropkey[6] = {CSI, KS_MODIFIER, 0, CSI, KS_EXTRA, (char_u)KE_DROP}; |
| 2280 | char_u *text; |
| 2281 | int len; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2282 | char_u *tmpbuf = NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2283 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2284 | # if GTK_CHECK_VERSION(3,0,0) |
| 2285 | text = (char_u *)gtk_selection_data_get_data(data); |
| 2286 | len = gtk_selection_data_get_length(data); |
| 2287 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2288 | text = data->data; |
| 2289 | len = data->length; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2290 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2291 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2292 | # if GTK_CHECK_VERSION(3,0,0) |
| 2293 | if (gtk_selection_data_get_data_type(data) == utf8_string_atom) |
| 2294 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2295 | if (data->type == utf8_string_atom) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2296 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2297 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2298 | if (input_conv.vc_type != CONV_NONE) |
| 2299 | tmpbuf = string_convert(&input_conv, text, &len); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2300 | if (tmpbuf != NULL) |
| 2301 | text = tmpbuf; |
| 2302 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2303 | |
| 2304 | dnd_yank_drag_data(text, (long)len); |
| 2305 | gtk_drag_finish(context, TRUE, FALSE, time_); /* accept */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2306 | vim_free(tmpbuf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2307 | |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 2308 | dropkey[2] = modifiers_gdk2vim(state); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2309 | |
| 2310 | if (dropkey[2] != 0) |
| 2311 | add_to_input_buf(dropkey, (int)sizeof(dropkey)); |
| 2312 | else |
| 2313 | add_to_input_buf(dropkey + 3, (int)(sizeof(dropkey) - 3)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2314 | } |
| 2315 | |
| 2316 | /* |
| 2317 | * DND receiver. |
| 2318 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2319 | static void |
| 2320 | drag_data_received_cb(GtkWidget *widget, |
| 2321 | GdkDragContext *context, |
| 2322 | gint x, |
| 2323 | gint y, |
| 2324 | GtkSelectionData *data, |
| 2325 | guint info, |
| 2326 | guint time_, |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 2327 | gpointer user_data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2328 | { |
| 2329 | GdkModifierType state; |
| 2330 | |
| 2331 | /* Guard against trash */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2332 | # if GTK_CHECK_VERSION(3,0,0) |
| 2333 | const guchar * const data_data = gtk_selection_data_get_data(data); |
| 2334 | const gint data_length = gtk_selection_data_get_length(data); |
| 2335 | const gint data_format = gtk_selection_data_get_format(data); |
| 2336 | |
| 2337 | if (data_data == NULL |
| 2338 | || data_length <= 0 |
| 2339 | || data_format != 8 |
| 2340 | || data_data[data_length] != '\0') |
| 2341 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2342 | if (data->data == NULL |
| 2343 | || data->length <= 0 |
| 2344 | || data->format != 8 |
| 2345 | || data->data[data->length] != '\0') |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2346 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2347 | { |
| 2348 | gtk_drag_finish(context, FALSE, FALSE, time_); |
| 2349 | return; |
| 2350 | } |
| 2351 | |
| 2352 | /* Get the current modifier state for proper distinguishment between |
| 2353 | * different operations later. */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2354 | #if GTK_CHECK_VERSION(3,0,0) |
| 2355 | gui_gtk_get_pointer(widget, NULL, NULL, &state); |
| 2356 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2357 | gdk_window_get_pointer(widget->window, NULL, NULL, &state); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2358 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2359 | |
| 2360 | /* Not sure about the role of "text/plain" here... */ |
| 2361 | if (info == (guint)TARGET_TEXT_URI_LIST) |
| 2362 | drag_handle_uri_list(context, data, time_, state, x, y); |
| 2363 | else |
| 2364 | drag_handle_text(context, data, time_, state); |
| 2365 | |
| 2366 | } |
| 2367 | #endif /* FEAT_DND */ |
| 2368 | |
| 2369 | |
| 2370 | #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) |
| 2371 | /* |
| 2372 | * GnomeClient interact callback. Check for unsaved buffers that cannot |
| 2373 | * be abandoned and pop up a dialog asking the user for confirmation if |
| 2374 | * necessary. |
| 2375 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2376 | static void |
Bram Moolenaar | 30bb414 | 2010-05-17 22:07:15 +0200 | [diff] [blame] | 2377 | sm_client_check_changed_any(GnomeClient *client UNUSED, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2378 | gint key, |
Bram Moolenaar | 30bb414 | 2010-05-17 22:07:15 +0200 | [diff] [blame] | 2379 | GnomeDialogType type UNUSED, |
| 2380 | gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2381 | { |
| 2382 | cmdmod_T save_cmdmod; |
| 2383 | gboolean shutdown_cancelled; |
| 2384 | |
| 2385 | save_cmdmod = cmdmod; |
| 2386 | |
| 2387 | # ifdef FEAT_BROWSE |
| 2388 | cmdmod.browse = TRUE; |
| 2389 | # endif |
| 2390 | # if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) |
| 2391 | cmdmod.confirm = TRUE; |
| 2392 | # endif |
| 2393 | /* |
| 2394 | * If there are changed buffers, present the user with |
| 2395 | * a dialog if possible, otherwise give an error message. |
| 2396 | */ |
Bram Moolenaar | 027387f | 2016-01-02 22:25:52 +0100 | [diff] [blame] | 2397 | shutdown_cancelled = check_changed_any(FALSE, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2398 | |
| 2399 | exiting = FALSE; |
| 2400 | cmdmod = save_cmdmod; |
| 2401 | setcursor(); /* position the cursor */ |
| 2402 | out_flush(); |
| 2403 | /* |
| 2404 | * If the user hit the [Cancel] button the whole shutdown |
| 2405 | * will be cancelled. Wow, quite powerful feature (: |
| 2406 | */ |
| 2407 | gnome_interaction_key_return(key, shutdown_cancelled); |
| 2408 | } |
| 2409 | |
| 2410 | /* |
| 2411 | * Generate a script that can be used to restore the current editing session. |
| 2412 | * Save the value of v:this_session before running :mksession in order to make |
| 2413 | * automagic session save fully transparent. Return TRUE on success. |
| 2414 | */ |
| 2415 | static int |
| 2416 | write_session_file(char_u *filename) |
| 2417 | { |
| 2418 | char_u *escaped_filename; |
| 2419 | char *mksession_cmdline; |
| 2420 | unsigned int save_ssop_flags; |
| 2421 | int failed; |
| 2422 | |
| 2423 | /* |
| 2424 | * Build an ex command line to create a script that restores the current |
| 2425 | * session if executed. Escape the filename to avoid nasty surprises. |
| 2426 | */ |
| 2427 | escaped_filename = vim_strsave_escaped(filename, escape_chars); |
| 2428 | if (escaped_filename == NULL) |
| 2429 | return FALSE; |
Bram Moolenaar | dc3213d | 2007-06-19 16:03:50 +0000 | [diff] [blame] | 2430 | mksession_cmdline = g_strconcat("mksession ", (char *)escaped_filename, |
| 2431 | NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2432 | vim_free(escaped_filename); |
Bram Moolenaar | dc3213d | 2007-06-19 16:03:50 +0000 | [diff] [blame] | 2433 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2434 | /* |
| 2435 | * Use a reasonable hardcoded set of 'sessionoptions' flags to avoid |
| 2436 | * unpredictable effects when the session is saved automatically. Also, |
| 2437 | * we definitely need SSOP_GLOBALS to be able to restore v:this_session. |
| 2438 | * Don't use SSOP_BUFFERS to prevent the buffer list from becoming |
| 2439 | * enormously large if the GNOME session feature is used regularly. |
| 2440 | */ |
| 2441 | save_ssop_flags = ssop_flags; |
| 2442 | ssop_flags = (SSOP_BLANK|SSOP_CURDIR|SSOP_FOLDS|SSOP_GLOBALS |
Bram Moolenaar | dc3213d | 2007-06-19 16:03:50 +0000 | [diff] [blame] | 2443 | |SSOP_HELP|SSOP_OPTIONS|SSOP_WINSIZE|SSOP_TABPAGES); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2444 | |
| 2445 | do_cmdline_cmd((char_u *)"let Save_VV_this_session = v:this_session"); |
| 2446 | failed = (do_cmdline_cmd((char_u *)mksession_cmdline) == FAIL); |
| 2447 | do_cmdline_cmd((char_u *)"let v:this_session = Save_VV_this_session"); |
Bram Moolenaar | 485db9b | 2005-01-31 19:23:41 +0000 | [diff] [blame] | 2448 | do_unlet((char_u *)"Save_VV_this_session", TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2449 | |
| 2450 | ssop_flags = save_ssop_flags; |
| 2451 | g_free(mksession_cmdline); |
Bram Moolenaar | 24dc230 | 2014-05-13 20:19:58 +0200 | [diff] [blame] | 2452 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2453 | /* |
| 2454 | * Reopen the file and append a command to restore v:this_session, |
| 2455 | * as if this save never happened. This is to avoid conflicts with |
| 2456 | * the user's own sessions. FIXME: It's probably less hackish to add |
| 2457 | * a "stealth" flag to 'sessionoptions' -- gotta ask Bram. |
| 2458 | */ |
| 2459 | if (!failed) |
| 2460 | { |
| 2461 | FILE *fd; |
| 2462 | |
| 2463 | fd = open_exfile(filename, TRUE, APPENDBIN); |
| 2464 | |
| 2465 | failed = (fd == NULL |
| 2466 | || put_line(fd, "let v:this_session = Save_VV_this_session") == FAIL |
| 2467 | || put_line(fd, "unlet Save_VV_this_session") == FAIL); |
| 2468 | |
| 2469 | if (fd != NULL && fclose(fd) != 0) |
| 2470 | failed = TRUE; |
| 2471 | |
| 2472 | if (failed) |
| 2473 | mch_remove(filename); |
| 2474 | } |
| 2475 | |
| 2476 | return !failed; |
| 2477 | } |
| 2478 | |
| 2479 | /* |
| 2480 | * "save_yourself" signal handler. Initiate an interaction to ask the user |
| 2481 | * for confirmation if necessary. Save the current editing session and tell |
| 2482 | * the session manager how to restart Vim. |
| 2483 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2484 | static gboolean |
| 2485 | sm_client_save_yourself(GnomeClient *client, |
Bram Moolenaar | 30bb414 | 2010-05-17 22:07:15 +0200 | [diff] [blame] | 2486 | gint phase UNUSED, |
| 2487 | GnomeSaveStyle save_style UNUSED, |
| 2488 | gboolean shutdown UNUSED, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2489 | GnomeInteractStyle interact_style, |
Bram Moolenaar | 30bb414 | 2010-05-17 22:07:15 +0200 | [diff] [blame] | 2490 | gboolean fast UNUSED, |
| 2491 | gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2492 | { |
| 2493 | static const char suffix[] = "-session.vim"; |
| 2494 | char *session_file; |
| 2495 | unsigned int len; |
| 2496 | gboolean success; |
| 2497 | |
| 2498 | /* Always request an interaction if possible. check_changed_any() |
| 2499 | * won't actually show a dialog unless any buffers have been modified. |
| 2500 | * There doesn't seem to be an obvious way to check that without |
| 2501 | * automatically firing the dialog. Anyway, it works just fine. */ |
| 2502 | if (interact_style == GNOME_INTERACT_ANY) |
| 2503 | gnome_client_request_interaction(client, GNOME_DIALOG_NORMAL, |
| 2504 | &sm_client_check_changed_any, |
| 2505 | NULL); |
| 2506 | out_flush(); |
| 2507 | ml_sync_all(FALSE, FALSE); /* preserve all swap files */ |
| 2508 | |
| 2509 | /* The path is unique for each session save. We do neither know nor care |
| 2510 | * which session script will actually be used later. This decision is in |
| 2511 | * the domain of the session manager. */ |
| 2512 | session_file = gnome_config_get_real_path( |
| 2513 | gnome_client_get_config_prefix(client)); |
| 2514 | len = strlen(session_file); |
| 2515 | |
| 2516 | if (len > 0 && session_file[len-1] == G_DIR_SEPARATOR) |
| 2517 | --len; /* get rid of the superfluous trailing '/' */ |
| 2518 | |
| 2519 | session_file = g_renew(char, session_file, len + sizeof(suffix)); |
| 2520 | memcpy(session_file + len, suffix, sizeof(suffix)); |
| 2521 | |
| 2522 | success = write_session_file((char_u *)session_file); |
| 2523 | |
| 2524 | if (success) |
| 2525 | { |
| 2526 | const char *argv[8]; |
| 2527 | int i; |
| 2528 | |
| 2529 | /* Tell the session manager how to wipe out the stored session data. |
| 2530 | * This isn't as dangerous as it looks, don't worry :) session_file |
| 2531 | * is a unique absolute filename. Usually it'll be something like |
| 2532 | * `/home/user/.gnome2/vim-XXXXXX-session.vim'. */ |
| 2533 | i = 0; |
| 2534 | argv[i++] = "rm"; |
| 2535 | argv[i++] = session_file; |
| 2536 | argv[i] = NULL; |
| 2537 | |
| 2538 | gnome_client_set_discard_command(client, i, (char **)argv); |
| 2539 | |
| 2540 | /* Tell the session manager how to restore the just saved session. |
| 2541 | * This is easily done thanks to Vim's -S option. Pass the -f flag |
| 2542 | * since there's no need to fork -- it might even cause confusion. |
| 2543 | * Also pass the window role to give the WM something to match on. |
| 2544 | * The role is set in gui_mch_open(), thus should _never_ be NULL. */ |
| 2545 | i = 0; |
| 2546 | argv[i++] = restart_command; |
| 2547 | argv[i++] = "-f"; |
| 2548 | argv[i++] = "-g"; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2549 | argv[i++] = "--role"; |
| 2550 | argv[i++] = gtk_window_get_role(GTK_WINDOW(gui.mainwin)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2551 | argv[i++] = "-S"; |
| 2552 | argv[i++] = session_file; |
| 2553 | argv[i] = NULL; |
| 2554 | |
| 2555 | gnome_client_set_restart_command(client, i, (char **)argv); |
| 2556 | gnome_client_set_clone_command(client, 0, NULL); |
| 2557 | } |
| 2558 | |
| 2559 | g_free(session_file); |
| 2560 | |
| 2561 | return success; |
| 2562 | } |
| 2563 | |
| 2564 | /* |
| 2565 | * Called when the session manager wants us to die. There isn't much to save |
| 2566 | * here since "save_yourself" has been emitted before (unless serious trouble |
| 2567 | * is happening). |
| 2568 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2569 | static void |
Bram Moolenaar | 30bb414 | 2010-05-17 22:07:15 +0200 | [diff] [blame] | 2570 | sm_client_die(GnomeClient *client UNUSED, gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2571 | { |
| 2572 | /* Don't write messages to the GUI anymore */ |
| 2573 | full_screen = FALSE; |
| 2574 | |
Bram Moolenaar | c93e791 | 2008-07-08 10:46:08 +0000 | [diff] [blame] | 2575 | vim_strncpy(IObuff, (char_u *) |
Bram Moolenaar | ce0842a | 2005-07-18 21:58:11 +0000 | [diff] [blame] | 2576 | _("Vim: Received \"die\" request from session manager\n"), |
Bram Moolenaar | c93e791 | 2008-07-08 10:46:08 +0000 | [diff] [blame] | 2577 | IOSIZE - 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2578 | preserve_exit(); |
| 2579 | } |
| 2580 | |
| 2581 | /* |
| 2582 | * Connect our signal handlers to be notified on session save and shutdown. |
| 2583 | */ |
| 2584 | static void |
| 2585 | setup_save_yourself(void) |
| 2586 | { |
| 2587 | GnomeClient *client; |
| 2588 | |
| 2589 | client = gnome_master_client(); |
| 2590 | |
| 2591 | if (client != NULL) |
| 2592 | { |
| 2593 | /* Must use the deprecated gtk_signal_connect() for compatibility |
| 2594 | * with GNOME 1. Arrgh, zombies! */ |
| 2595 | gtk_signal_connect(GTK_OBJECT(client), "save_yourself", |
| 2596 | GTK_SIGNAL_FUNC(&sm_client_save_yourself), NULL); |
| 2597 | gtk_signal_connect(GTK_OBJECT(client), "die", |
| 2598 | GTK_SIGNAL_FUNC(&sm_client_die), NULL); |
| 2599 | } |
| 2600 | } |
| 2601 | |
| 2602 | #else /* !(FEAT_GUI_GNOME && FEAT_SESSION) */ |
| 2603 | |
| 2604 | # ifdef USE_XSMP |
| 2605 | /* |
| 2606 | * GTK tells us that XSMP needs attention |
| 2607 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2608 | static gboolean |
Bram Moolenaar | 66f948e | 2016-01-30 16:39:25 +0100 | [diff] [blame] | 2609 | local_xsmp_handle_requests( |
| 2610 | GIOChannel *source UNUSED, |
| 2611 | GIOCondition condition, |
| 2612 | gpointer data) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2613 | { |
| 2614 | if (condition == G_IO_IN) |
| 2615 | { |
| 2616 | /* Do stuff; maybe close connection */ |
| 2617 | if (xsmp_handle_requests() == FAIL) |
| 2618 | g_io_channel_unref((GIOChannel *)data); |
| 2619 | return TRUE; |
| 2620 | } |
| 2621 | /* Error */ |
| 2622 | g_io_channel_unref((GIOChannel *)data); |
| 2623 | xsmp_close(); |
| 2624 | return TRUE; |
| 2625 | } |
| 2626 | # endif /* USE_XSMP */ |
| 2627 | |
| 2628 | /* |
| 2629 | * Setup the WM_PROTOCOLS to indicate we want the WM_SAVE_YOURSELF event. |
| 2630 | * This is an ugly use of X functions. GTK doesn't offer an alternative. |
| 2631 | */ |
| 2632 | static void |
| 2633 | setup_save_yourself(void) |
| 2634 | { |
| 2635 | Atom *existing_atoms = NULL; |
| 2636 | int count = 0; |
| 2637 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2638 | # ifdef USE_XSMP |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2639 | if (xsmp_icefd != -1) |
| 2640 | { |
| 2641 | /* |
| 2642 | * Use XSMP is preference to legacy WM_SAVE_YOURSELF; |
| 2643 | * set up GTK IO monitor |
| 2644 | */ |
| 2645 | GIOChannel *g_io = g_io_channel_unix_new(xsmp_icefd); |
| 2646 | |
| 2647 | g_io_add_watch(g_io, G_IO_IN | G_IO_ERR | G_IO_HUP, |
| 2648 | local_xsmp_handle_requests, (gpointer)g_io); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2649 | g_io_channel_unref(g_io); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2650 | } |
| 2651 | else |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2652 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2653 | { |
| 2654 | /* Fall back to old method */ |
| 2655 | |
| 2656 | /* first get the existing value */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2657 | # if GTK_CHECK_VERSION(3,0,0) |
| 2658 | GdkWindow * const mainwin_win = gtk_widget_get_window(gui.mainwin); |
| 2659 | |
| 2660 | if (XGetWMProtocols(GDK_WINDOW_XDISPLAY(mainwin_win), |
| 2661 | GDK_WINDOW_XID(mainwin_win), |
| 2662 | &existing_atoms, &count)) |
| 2663 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2664 | if (XGetWMProtocols(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
| 2665 | GDK_WINDOW_XWINDOW(gui.mainwin->window), |
| 2666 | &existing_atoms, &count)) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2667 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2668 | { |
| 2669 | Atom *new_atoms; |
| 2670 | Atom save_yourself_xatom; |
| 2671 | int i; |
| 2672 | |
| 2673 | save_yourself_xatom = GET_X_ATOM(save_yourself_atom); |
| 2674 | |
| 2675 | /* check if WM_SAVE_YOURSELF isn't there yet */ |
| 2676 | for (i = 0; i < count; ++i) |
| 2677 | if (existing_atoms[i] == save_yourself_xatom) |
| 2678 | break; |
| 2679 | |
| 2680 | if (i == count) |
| 2681 | { |
| 2682 | /* allocate an Atoms array which is one item longer */ |
| 2683 | new_atoms = (Atom *)alloc((unsigned)((count + 1) |
| 2684 | * sizeof(Atom))); |
| 2685 | if (new_atoms != NULL) |
| 2686 | { |
| 2687 | memcpy(new_atoms, existing_atoms, count * sizeof(Atom)); |
| 2688 | new_atoms[count] = save_yourself_xatom; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2689 | # if GTK_CHECK_VERSION(3,0,0) |
| 2690 | XSetWMProtocols(GDK_WINDOW_XDISPLAY(mainwin_win), |
| 2691 | GDK_WINDOW_XID(mainwin_win), |
| 2692 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2693 | XSetWMProtocols(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
| 2694 | GDK_WINDOW_XWINDOW(gui.mainwin->window), |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2695 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2696 | new_atoms, count + 1); |
| 2697 | vim_free(new_atoms); |
| 2698 | } |
| 2699 | } |
| 2700 | XFree(existing_atoms); |
| 2701 | } |
| 2702 | } |
| 2703 | } |
| 2704 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2705 | /* |
| 2706 | * Installing a global event filter seems to be the only way to catch |
| 2707 | * client messages of type WM_PROTOCOLS without overriding GDK's own |
| 2708 | * client message event filter. Well, that's still better than trying |
| 2709 | * to guess what the GDK filter had done if it had been invoked instead |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2710 | * |
| 2711 | * GTK2_FIXME: This doesn't seem to work. For some reason we never |
| 2712 | * receive WM_SAVE_YOURSELF even though everything is set up correctly. |
| 2713 | * I have the nasty feeling modern session managers just don't send this |
| 2714 | * deprecated message anymore. Addition: confirmed by several people. |
| 2715 | * |
| 2716 | * The GNOME session support is much cooler anyway. Unlike this ugly |
| 2717 | * WM_SAVE_YOURSELF hack it actually stores the session... And yes, |
| 2718 | * it should work with KDE as well. |
| 2719 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2720 | static GdkFilterReturn |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 2721 | global_event_filter(GdkXEvent *xev, |
| 2722 | GdkEvent *event UNUSED, |
| 2723 | gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2724 | { |
| 2725 | XEvent *xevent = (XEvent *)xev; |
| 2726 | |
| 2727 | if (xevent != NULL |
| 2728 | && xevent->type == ClientMessage |
| 2729 | && xevent->xclient.message_type == GET_X_ATOM(wm_protocols_atom) |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 2730 | && (long_u)xevent->xclient.data.l[0] |
| 2731 | == GET_X_ATOM(save_yourself_atom)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2732 | { |
| 2733 | out_flush(); |
| 2734 | ml_sync_all(FALSE, FALSE); /* preserve all swap files */ |
| 2735 | /* |
| 2736 | * Set the window's WM_COMMAND property, to let the window manager |
| 2737 | * know we are done saving ourselves. We don't want to be |
| 2738 | * restarted, thus set argv to NULL. |
| 2739 | */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2740 | # if GTK_CHECK_VERSION(3,0,0) |
| 2741 | XSetCommand(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.mainwin)), |
| 2742 | GDK_WINDOW_XID(gtk_widget_get_window(gui.mainwin)), |
| 2743 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2744 | XSetCommand(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
| 2745 | GDK_WINDOW_XWINDOW(gui.mainwin->window), |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2746 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2747 | NULL, 0); |
| 2748 | return GDK_FILTER_REMOVE; |
| 2749 | } |
| 2750 | |
| 2751 | return GDK_FILTER_CONTINUE; |
| 2752 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2753 | #endif /* !(FEAT_GUI_GNOME && FEAT_SESSION) */ |
| 2754 | |
| 2755 | |
| 2756 | /* |
| 2757 | * Setup the window icon & xcmdsrv comm after the main window has been realized. |
| 2758 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2759 | static void |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 2760 | mainwin_realize(GtkWidget *widget UNUSED, gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2761 | { |
| 2762 | /* If you get an error message here, you still need to unpack the runtime |
| 2763 | * archive! */ |
| 2764 | #ifdef magick |
| 2765 | # undef magick |
| 2766 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2767 | /* A bit hackish, but avoids casting later and allows optimization */ |
| 2768 | # define static static const |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2769 | #define magick vim32x32 |
| 2770 | #include "../runtime/vim32x32.xpm" |
| 2771 | #undef magick |
| 2772 | #define magick vim16x16 |
| 2773 | #include "../runtime/vim16x16.xpm" |
| 2774 | #undef magick |
| 2775 | #define magick vim48x48 |
| 2776 | #include "../runtime/vim48x48.xpm" |
| 2777 | #undef magick |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2778 | # undef static |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2779 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2780 | #if GTK_CHECK_VERSION(3,0,0) |
| 2781 | GdkWindow * const mainwin_win = gtk_widget_get_window(gui.mainwin); |
| 2782 | #endif |
| 2783 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2784 | /* When started with "--echo-wid" argument, write window ID on stdout. */ |
| 2785 | if (echo_wid_arg) |
| 2786 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2787 | #if GTK_CHECK_VERSION(3,0,0) |
| 2788 | printf("WID: %ld\n", (long)GDK_WINDOW_XID(mainwin_win)); |
| 2789 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2790 | printf("WID: %ld\n", (long)GDK_WINDOW_XWINDOW(gui.mainwin->window)); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2791 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2792 | fflush(stdout); |
| 2793 | } |
| 2794 | |
| 2795 | if (vim_strchr(p_go, GO_ICON) != NULL) |
| 2796 | { |
| 2797 | /* |
| 2798 | * Add an icon to the main window. For fun and convenience of the user. |
| 2799 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2800 | GList *icons = NULL; |
| 2801 | |
| 2802 | icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim16x16)); |
| 2803 | icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim32x32)); |
| 2804 | icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim48x48)); |
| 2805 | |
| 2806 | gtk_window_set_icon_list(GTK_WINDOW(gui.mainwin), icons); |
| 2807 | |
| 2808 | g_list_foreach(icons, (GFunc)&g_object_unref, NULL); |
| 2809 | g_list_free(icons); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2810 | } |
| 2811 | |
| 2812 | #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) |
| 2813 | /* Register a handler for WM_SAVE_YOURSELF with GDK's low-level X I/F */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2814 | gdk_window_add_filter(NULL, &global_event_filter, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2815 | #endif |
| 2816 | /* Setup to indicate to the window manager that we want to catch the |
| 2817 | * WM_SAVE_YOURSELF event. For GNOME, this connects to the session |
| 2818 | * manager instead. */ |
| 2819 | #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) |
| 2820 | if (using_gnome) |
| 2821 | #endif |
| 2822 | setup_save_yourself(); |
| 2823 | |
| 2824 | #ifdef FEAT_CLIENTSERVER |
| 2825 | if (serverName == NULL && serverDelayedStartName != NULL) |
| 2826 | { |
| 2827 | /* This is a :gui command in a plain vim with no previous server */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2828 | # if GTK_CHECK_VERSION(3,0,0) |
| 2829 | commWindow = GDK_WINDOW_XID(mainwin_win); |
| 2830 | |
| 2831 | (void)serverRegisterName(GDK_WINDOW_XDISPLAY(mainwin_win), |
| 2832 | serverDelayedStartName); |
| 2833 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2834 | commWindow = GDK_WINDOW_XWINDOW(gui.mainwin->window); |
| 2835 | |
| 2836 | (void)serverRegisterName(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
| 2837 | serverDelayedStartName); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2838 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2839 | } |
| 2840 | else |
| 2841 | { |
| 2842 | /* |
| 2843 | * Cannot handle "XLib-only" windows with gtk event routines, we'll |
| 2844 | * have to change the "server" registration to that of the main window |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 2845 | * If we have not registered a name yet, remember the window. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2846 | */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2847 | # if GTK_CHECK_VERSION(3,0,0) |
| 2848 | serverChangeRegisteredWindow(GDK_WINDOW_XDISPLAY(mainwin_win), |
| 2849 | GDK_WINDOW_XID(mainwin_win)); |
| 2850 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2851 | serverChangeRegisteredWindow(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
| 2852 | GDK_WINDOW_XWINDOW(gui.mainwin->window)); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2853 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2854 | } |
| 2855 | gtk_widget_add_events(gui.mainwin, GDK_PROPERTY_CHANGE_MASK); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2856 | # if GTK_CHECK_VERSION(3,0,0) |
| 2857 | g_signal_connect(G_OBJECT(gui.mainwin), "property-notify-event", |
| 2858 | G_CALLBACK(property_event), NULL); |
| 2859 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2860 | gtk_signal_connect(GTK_OBJECT(gui.mainwin), "property_notify_event", |
| 2861 | GTK_SIGNAL_FUNC(property_event), NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2862 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2863 | #endif |
| 2864 | } |
| 2865 | |
| 2866 | static GdkCursor * |
| 2867 | create_blank_pointer(void) |
| 2868 | { |
| 2869 | GdkWindow *root_window = NULL; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2870 | #if GTK_CHECK_VERSION(3,0,0) |
| 2871 | GdkPixbuf *blank_mask; |
| 2872 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2873 | GdkPixmap *blank_mask; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2874 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2875 | GdkCursor *cursor; |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 2876 | #if GTK_CHECK_VERSION(3,0,0) |
| 2877 | GdkRGBA color = { 0.0, 0.0, 0.0, 1.0 }; |
| 2878 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2879 | GdkColor color = { 0, 0, 0, 0 }; |
| 2880 | char blank_data[] = { 0x0 }; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2881 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2882 | |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 2883 | #if GTK_CHECK_VERSION(3,12,0) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2884 | { |
| 2885 | GdkWindow * const win = gtk_widget_get_window(gui.mainwin); |
| 2886 | GdkScreen * const scrn = gdk_window_get_screen(win); |
| 2887 | root_window = gdk_screen_get_root_window(scrn); |
| 2888 | } |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 2889 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2890 | root_window = gtk_widget_get_root_window(gui.mainwin); |
| 2891 | #endif |
| 2892 | |
| 2893 | /* Create a pseudo blank pointer, which is in fact one pixel by one pixel |
| 2894 | * in size. */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2895 | #if GTK_CHECK_VERSION(3,0,0) |
| 2896 | { |
| 2897 | cairo_surface_t *surf; |
| 2898 | cairo_t *cr; |
| 2899 | |
| 2900 | surf = cairo_image_surface_create(CAIRO_FORMAT_A1, 1, 1); |
| 2901 | cr = cairo_create(surf); |
| 2902 | |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 2903 | cairo_set_source_rgba(cr, |
| 2904 | color.red, |
| 2905 | color.green, |
| 2906 | color.blue, |
| 2907 | color.alpha); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2908 | cairo_rectangle(cr, 0, 0, 1, 1); |
| 2909 | cairo_fill(cr); |
| 2910 | cairo_destroy(cr); |
| 2911 | |
| 2912 | blank_mask = gdk_pixbuf_get_from_surface(surf, 0, 0, 1, 1); |
| 2913 | cairo_surface_destroy(surf); |
| 2914 | |
| 2915 | cursor = gdk_cursor_new_from_pixbuf(gdk_window_get_display(root_window), |
| 2916 | blank_mask, 0, 0); |
| 2917 | g_object_unref(blank_mask); |
| 2918 | } |
| 2919 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2920 | blank_mask = gdk_bitmap_create_from_data(root_window, blank_data, 1, 1); |
| 2921 | cursor = gdk_cursor_new_from_pixmap(blank_mask, blank_mask, |
| 2922 | &color, &color, 0, 0); |
| 2923 | gdk_bitmap_unref(blank_mask); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2924 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2925 | |
| 2926 | return cursor; |
| 2927 | } |
| 2928 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2929 | static void |
| 2930 | mainwin_screen_changed_cb(GtkWidget *widget, |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 2931 | GdkScreen *previous_screen UNUSED, |
| 2932 | gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2933 | { |
| 2934 | if (!gtk_widget_has_screen(widget)) |
| 2935 | return; |
| 2936 | |
| 2937 | /* |
Bram Moolenaar | 4932594 | 2007-05-10 19:19:59 +0000 | [diff] [blame] | 2938 | * Recreate the invisible mouse cursor. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2939 | */ |
| 2940 | if (gui.blank_pointer != NULL) |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 2941 | #if GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2942 | g_object_unref(G_OBJECT(gui.blank_pointer)); |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 2943 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2944 | gdk_cursor_unref(gui.blank_pointer); |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 2945 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2946 | |
| 2947 | gui.blank_pointer = create_blank_pointer(); |
| 2948 | |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 2949 | #if GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2950 | if (gui.pointer_hidden && gtk_widget_get_window(gui.drawarea) != NULL) |
| 2951 | gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), |
| 2952 | gui.blank_pointer); |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 2953 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2954 | if (gui.pointer_hidden && gui.drawarea->window != NULL) |
| 2955 | gdk_window_set_cursor(gui.drawarea->window, gui.blank_pointer); |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 2956 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2957 | |
| 2958 | /* |
| 2959 | * Create a new PangoContext for this screen, and initialize it |
| 2960 | * with the current font if necessary. |
| 2961 | */ |
| 2962 | if (gui.text_context != NULL) |
| 2963 | g_object_unref(gui.text_context); |
| 2964 | |
| 2965 | gui.text_context = gtk_widget_create_pango_context(widget); |
| 2966 | pango_context_set_base_dir(gui.text_context, PANGO_DIRECTION_LTR); |
| 2967 | |
| 2968 | if (gui.norm_font != NULL) |
| 2969 | { |
Bram Moolenaar | 46c9c73 | 2004-12-12 11:37:09 +0000 | [diff] [blame] | 2970 | gui_mch_init_font(p_guifont, FALSE); |
Bram Moolenaar | 04a9d45 | 2006-03-27 21:03:26 +0000 | [diff] [blame] | 2971 | gui_set_shellsize(FALSE, FALSE, RESIZE_BOTH); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2972 | } |
| 2973 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2974 | |
| 2975 | /* |
| 2976 | * After the drawing area comes up, we calculate all colors and create the |
| 2977 | * dummy blank cursor. |
| 2978 | * |
| 2979 | * Don't try to set any VIM scrollbar sizes anywhere here. I'm relying on the |
| 2980 | * fact that the main VIM engine doesn't take them into account anywhere. |
| 2981 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2982 | static void |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 2983 | drawarea_realize_cb(GtkWidget *widget, gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2984 | { |
| 2985 | GtkWidget *sbar; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2986 | #if GTK_CHECK_VERSION(3,0,0) |
| 2987 | GtkAllocation allocation; |
| 2988 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2989 | |
| 2990 | #ifdef FEAT_XIM |
| 2991 | xim_init(); |
| 2992 | #endif |
| 2993 | gui_mch_new_colors(); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 2994 | #if GTK_CHECK_VERSION(3,0,0) |
| 2995 | gui.surface = gdk_window_create_similar_surface( |
| 2996 | gtk_widget_get_window(widget), |
| 2997 | CAIRO_CONTENT_COLOR_ALPHA, |
| 2998 | gtk_widget_get_allocated_width(widget), |
| 2999 | gtk_widget_get_allocated_height(widget)); |
| 3000 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3001 | gui.text_gc = gdk_gc_new(gui.drawarea->window); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3002 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3003 | |
| 3004 | gui.blank_pointer = create_blank_pointer(); |
| 3005 | if (gui.pointer_hidden) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3006 | #if GTK_CHECK_VERSION(3,0,0) |
| 3007 | gdk_window_set_cursor(gtk_widget_get_window(widget), gui.blank_pointer); |
| 3008 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3009 | gdk_window_set_cursor(widget->window, gui.blank_pointer); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3010 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3011 | |
| 3012 | /* get the actual size of the scrollbars, if they are realized */ |
| 3013 | sbar = firstwin->w_scrollbars[SBAR_LEFT].id; |
| 3014 | if (!sbar || (!gui.which_scrollbars[SBAR_LEFT] |
| 3015 | && firstwin->w_scrollbars[SBAR_RIGHT].id)) |
| 3016 | sbar = firstwin->w_scrollbars[SBAR_RIGHT].id; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3017 | #if GTK_CHECK_VERSION(3,0,0) |
| 3018 | gtk_widget_get_allocation(sbar, &allocation); |
| 3019 | if (sbar && gtk_widget_get_realized(sbar) && allocation.width) |
| 3020 | gui.scrollbar_width = allocation.width; |
| 3021 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3022 | if (sbar && GTK_WIDGET_REALIZED(sbar) && sbar->allocation.width) |
| 3023 | gui.scrollbar_width = sbar->allocation.width; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3024 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3025 | |
| 3026 | sbar = gui.bottom_sbar.id; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3027 | #if GTK_CHECK_VERSION(3,0,0) |
| 3028 | if (sbar && gtk_widget_get_realized(sbar) && allocation.height) |
| 3029 | gui.scrollbar_height = allocation.height; |
| 3030 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3031 | if (sbar && GTK_WIDGET_REALIZED(sbar) && sbar->allocation.height) |
| 3032 | gui.scrollbar_height = sbar->allocation.height; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3033 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3034 | } |
| 3035 | |
| 3036 | /* |
| 3037 | * Properly clean up on shutdown. |
| 3038 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3039 | static void |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 3040 | drawarea_unrealize_cb(GtkWidget *widget UNUSED, gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3041 | { |
| 3042 | /* Don't write messages to the GUI anymore */ |
| 3043 | full_screen = FALSE; |
| 3044 | |
| 3045 | #ifdef FEAT_XIM |
| 3046 | im_shutdown(); |
| 3047 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3048 | if (gui.ascii_glyphs != NULL) |
| 3049 | { |
| 3050 | pango_glyph_string_free(gui.ascii_glyphs); |
| 3051 | gui.ascii_glyphs = NULL; |
| 3052 | } |
| 3053 | if (gui.ascii_font != NULL) |
| 3054 | { |
| 3055 | g_object_unref(gui.ascii_font); |
| 3056 | gui.ascii_font = NULL; |
| 3057 | } |
| 3058 | g_object_unref(gui.text_context); |
| 3059 | gui.text_context = NULL; |
| 3060 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3061 | #if GTK_CHECK_VERSION(3,0,0) |
| 3062 | if (gui.surface != NULL) |
| 3063 | { |
| 3064 | cairo_surface_destroy(gui.surface); |
| 3065 | gui.surface = NULL; |
| 3066 | } |
| 3067 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3068 | g_object_unref(gui.text_gc); |
| 3069 | gui.text_gc = NULL; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3070 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3071 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3072 | #if GTK_CHECK_VERSION(3,0,0) |
| 3073 | g_object_unref(G_OBJECT(gui.blank_pointer)); |
| 3074 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3075 | gdk_cursor_unref(gui.blank_pointer); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3076 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3077 | gui.blank_pointer = NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3078 | } |
| 3079 | |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 3080 | #if GTK_CHECK_VERSION(3,22,2) |
| 3081 | static void |
| 3082 | drawarea_style_updated_cb(GtkWidget *widget UNUSED, |
| 3083 | gpointer data UNUSED) |
| 3084 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3085 | static void |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 3086 | drawarea_style_set_cb(GtkWidget *widget UNUSED, |
| 3087 | GtkStyle *previous_style UNUSED, |
| 3088 | gpointer data UNUSED) |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 3089 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3090 | { |
| 3091 | gui_mch_new_colors(); |
| 3092 | } |
| 3093 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3094 | #if GTK_CHECK_VERSION(3,0,0) |
| 3095 | static gboolean |
| 3096 | drawarea_configure_event_cb(GtkWidget *widget, |
| 3097 | GdkEventConfigure *event, |
| 3098 | gpointer data UNUSED) |
| 3099 | { |
| 3100 | static int cur_width = 0; |
| 3101 | static int cur_height = 0; |
| 3102 | |
| 3103 | g_return_val_if_fail(event |
| 3104 | && event->width >= 1 && event->height >= 1, TRUE); |
| 3105 | |
Bram Moolenaar | 182707a | 2016-11-21 20:55:58 +0100 | [diff] [blame] | 3106 | # if GTK_CHECK_VERSION(3,22,2) && !GTK_CHECK_VERSION(3,22,4) |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 3107 | /* As of 3.22.2, GdkWindows have started distributing configure events to |
| 3108 | * their "native" children (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=12579fe71b3b8f79eb9c1b80e429443bcc437dd0). |
| 3109 | * |
| 3110 | * As can be seen from the implementation of move_native_children() and |
| 3111 | * configure_native_child() in gdkwindow.c, those functions actually |
| 3112 | * propagate configure events to every child, failing to distinguish |
| 3113 | * "native" one from non-native one. |
| 3114 | * |
| 3115 | * Naturally, configure events propagated to here like that are fallacious |
| 3116 | * and, as a matter of fact, they trigger a geometric collapse of |
| 3117 | * gui.drawarea in fullscreen and miximized modes. |
| 3118 | * |
| 3119 | * To filter out such nuisance events, we are making use of the fact that |
| 3120 | * the field send_event of such GdkEventConfigures is set to FALSE in |
| 3121 | * configure_native_child(). |
| 3122 | * |
| 3123 | * Obviously, this is a terrible hack making GVim depend on GTK's |
| 3124 | * implementation details. Therefore, watch out any relevant internal |
| 3125 | * changes happening in GTK in the feature (sigh). |
| 3126 | */ |
Bram Moolenaar | 182707a | 2016-11-21 20:55:58 +0100 | [diff] [blame] | 3127 | /* Follow-up |
| 3128 | * After a few weeks later, the GdkWindow change mentioned above was |
| 3129 | * reverted (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=f70039cb9603a02d2369fec4038abf40a1711155). |
| 3130 | * The corresponding official release is 3.22.4. */ |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 3131 | if (event->send_event == FALSE) |
| 3132 | return TRUE; |
| 3133 | # endif |
| 3134 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3135 | if (event->width == cur_width && event->height == cur_height) |
| 3136 | return TRUE; |
| 3137 | |
| 3138 | cur_width = event->width; |
| 3139 | cur_height = event->height; |
| 3140 | |
| 3141 | if (gui.surface != NULL) |
| 3142 | cairo_surface_destroy(gui.surface); |
| 3143 | |
| 3144 | gui.surface = gdk_window_create_similar_surface( |
| 3145 | gtk_widget_get_window(widget), |
| 3146 | CAIRO_CONTENT_COLOR_ALPHA, |
| 3147 | event->width, event->height); |
| 3148 | |
| 3149 | gtk_widget_queue_draw(widget); |
| 3150 | |
| 3151 | return TRUE; |
| 3152 | } |
| 3153 | #endif |
| 3154 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3155 | /* |
| 3156 | * Callback routine for the "delete_event" signal on the toplevel window. |
| 3157 | * Tries to vim gracefully, or refuses to exit with changed buffers. |
| 3158 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3159 | static gint |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 3160 | delete_event_cb(GtkWidget *widget UNUSED, |
| 3161 | GdkEventAny *event UNUSED, |
| 3162 | gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3163 | { |
| 3164 | gui_shell_closed(); |
| 3165 | return TRUE; |
| 3166 | } |
| 3167 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3168 | #if defined(FEAT_MENU) || defined(FEAT_TOOLBAR) || defined(FEAT_GUI_TABLINE) |
| 3169 | static int |
| 3170 | get_item_dimensions(GtkWidget *widget, GtkOrientation orientation) |
| 3171 | { |
Bram Moolenaar | c4a249a | 2017-01-30 22:56:48 +0100 | [diff] [blame] | 3172 | # ifdef FEAT_GUI_GNOME |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3173 | GtkOrientation item_orientation = GTK_ORIENTATION_HORIZONTAL; |
| 3174 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3175 | if (using_gnome && widget != NULL) |
| 3176 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 3177 | GtkWidget *parent; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3178 | BonoboDockItem *dockitem; |
| 3179 | |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 3180 | parent = gtk_widget_get_parent(widget); |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 3181 | if (G_TYPE_FROM_INSTANCE(parent) == BONOBO_TYPE_DOCK_ITEM) |
| 3182 | { |
| 3183 | /* Only menu & toolbar are dock items. Could tabline be? |
| 3184 | * Seem to be only the 2 defined in GNOME */ |
| 3185 | widget = parent; |
| 3186 | dockitem = BONOBO_DOCK_ITEM(widget); |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3187 | |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 3188 | if (dockitem == NULL || dockitem->is_floating) |
| 3189 | return 0; |
| 3190 | item_orientation = bonobo_dock_item_get_orientation(dockitem); |
| 3191 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3192 | } |
Bram Moolenaar | c4a249a | 2017-01-30 22:56:48 +0100 | [diff] [blame] | 3193 | # else |
| 3194 | # define item_orientation GTK_ORIENTATION_HORIZONTAL |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3195 | # endif |
Bram Moolenaar | c4a249a | 2017-01-30 22:56:48 +0100 | [diff] [blame] | 3196 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3197 | # if GTK_CHECK_VERSION(3,0,0) |
| 3198 | if (widget != NULL |
| 3199 | && item_orientation == orientation |
| 3200 | && gtk_widget_get_realized(widget) |
| 3201 | && gtk_widget_get_visible(widget)) |
| 3202 | # else |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3203 | if (widget != NULL |
| 3204 | && item_orientation == orientation |
| 3205 | && GTK_WIDGET_REALIZED(widget) |
| 3206 | && GTK_WIDGET_VISIBLE(widget)) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3207 | # endif |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3208 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3209 | # if GTK_CHECK_VERSION(3,0,0) |
| 3210 | GtkAllocation allocation; |
| 3211 | |
| 3212 | gtk_widget_get_allocation(widget, &allocation); |
Bram Moolenaar | c4a249a | 2017-01-30 22:56:48 +0100 | [diff] [blame] | 3213 | return allocation.height; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3214 | # else |
Bram Moolenaar | c4a249a | 2017-01-30 22:56:48 +0100 | [diff] [blame] | 3215 | # ifdef FEAT_GUI_GNOME |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3216 | if (orientation == GTK_ORIENTATION_HORIZONTAL) |
| 3217 | return widget->allocation.height; |
| 3218 | else |
| 3219 | return widget->allocation.width; |
Bram Moolenaar | c4a249a | 2017-01-30 22:56:48 +0100 | [diff] [blame] | 3220 | # else |
| 3221 | return widget->allocation.height; |
| 3222 | # endif |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3223 | # endif |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3224 | } |
| 3225 | return 0; |
| 3226 | } |
| 3227 | #endif |
| 3228 | |
| 3229 | static int |
| 3230 | get_menu_tool_width(void) |
| 3231 | { |
| 3232 | int width = 0; |
| 3233 | |
| 3234 | #ifdef FEAT_GUI_GNOME /* these are never vertical without GNOME */ |
| 3235 | # ifdef FEAT_MENU |
| 3236 | width += get_item_dimensions(gui.menubar, GTK_ORIENTATION_VERTICAL); |
| 3237 | # endif |
| 3238 | # ifdef FEAT_TOOLBAR |
| 3239 | width += get_item_dimensions(gui.toolbar, GTK_ORIENTATION_VERTICAL); |
| 3240 | # endif |
| 3241 | # ifdef FEAT_GUI_TABLINE |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 3242 | if (gui.tabline != NULL) |
| 3243 | width += get_item_dimensions(gui.tabline, GTK_ORIENTATION_VERTICAL); |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3244 | # endif |
| 3245 | #endif |
| 3246 | |
| 3247 | return width; |
| 3248 | } |
| 3249 | |
| 3250 | static int |
| 3251 | get_menu_tool_height(void) |
| 3252 | { |
| 3253 | int height = 0; |
| 3254 | |
| 3255 | #ifdef FEAT_MENU |
| 3256 | height += get_item_dimensions(gui.menubar, GTK_ORIENTATION_HORIZONTAL); |
| 3257 | #endif |
| 3258 | #ifdef FEAT_TOOLBAR |
| 3259 | height += get_item_dimensions(gui.toolbar, GTK_ORIENTATION_HORIZONTAL); |
| 3260 | #endif |
| 3261 | #ifdef FEAT_GUI_TABLINE |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 3262 | if (gui.tabline != NULL) |
| 3263 | height += get_item_dimensions(gui.tabline, GTK_ORIENTATION_HORIZONTAL); |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3264 | #endif |
| 3265 | |
| 3266 | return height; |
| 3267 | } |
| 3268 | |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 3269 | /* This controls whether we can set the real window hints at |
| 3270 | * start-up when in a GtkPlug. |
| 3271 | * 0 = normal processing (default) |
| 3272 | * 1 = init. hints set, no-one's tried to reset since last check |
| 3273 | * 2 = init. hints set, attempt made to change hints |
| 3274 | */ |
| 3275 | static int init_window_hints_state = 0; |
| 3276 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3277 | static void |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 3278 | update_window_manager_hints(int force_width, int force_height) |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3279 | { |
| 3280 | static int old_width = 0; |
| 3281 | static int old_height = 0; |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 3282 | static int old_min_width = 0; |
| 3283 | static int old_min_height = 0; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3284 | static int old_char_width = 0; |
| 3285 | static int old_char_height = 0; |
| 3286 | |
| 3287 | int width; |
| 3288 | int height; |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 3289 | int min_width; |
| 3290 | int min_height; |
| 3291 | |
| 3292 | /* At start-up, don't try to set the hints until the initial |
| 3293 | * values have been used (those that dictate our initial size) |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 3294 | * Let forced (i.e., correct) values through always. |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 3295 | */ |
| 3296 | if (!(force_width && force_height) && init_window_hints_state > 0) |
| 3297 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 3298 | /* Don't do it! */ |
| 3299 | init_window_hints_state = 2; |
| 3300 | return; |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 3301 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3302 | |
| 3303 | /* This also needs to be done when the main window isn't there yet, |
| 3304 | * otherwise the hints don't work. */ |
| 3305 | width = gui_get_base_width(); |
| 3306 | height = gui_get_base_height(); |
| 3307 | # ifdef FEAT_MENU |
| 3308 | height += tabline_height() * gui.char_height; |
| 3309 | # endif |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3310 | width += get_menu_tool_width(); |
| 3311 | height += get_menu_tool_height(); |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3312 | |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 3313 | /* GtkSockets use GtkPlug's [gui,mainwin] min-size hints to determine |
Bram Moolenaar | 4932594 | 2007-05-10 19:19:59 +0000 | [diff] [blame] | 3314 | * their actual widget size. When we set our size ourselves (e.g., |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 3315 | * 'set columns=' or init. -geom) we briefly set the min. to the size |
| 3316 | * we wish to be instead of the legitimate minimum so that we actually |
| 3317 | * resize correctly. |
| 3318 | */ |
| 3319 | if (force_width && force_height) |
| 3320 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 3321 | min_width = force_width; |
| 3322 | min_height = force_height; |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 3323 | } |
| 3324 | else |
| 3325 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 3326 | min_width = width + MIN_COLUMNS * gui.char_width; |
| 3327 | min_height = height + MIN_LINES * gui.char_height; |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 3328 | } |
| 3329 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3330 | /* Avoid an expose event when the size didn't change. */ |
| 3331 | if (width != old_width |
| 3332 | || height != old_height |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 3333 | || min_width != old_min_width |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 3334 | || min_height != old_min_height |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3335 | || gui.char_width != old_char_width |
| 3336 | || gui.char_height != old_char_height) |
| 3337 | { |
| 3338 | GdkGeometry geometry; |
| 3339 | GdkWindowHints geometry_mask; |
| 3340 | |
| 3341 | geometry.width_inc = gui.char_width; |
| 3342 | geometry.height_inc = gui.char_height; |
| 3343 | geometry.base_width = width; |
| 3344 | geometry.base_height = height; |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 3345 | geometry.min_width = min_width; |
| 3346 | geometry.min_height = min_height; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3347 | geometry_mask = GDK_HINT_BASE_SIZE|GDK_HINT_RESIZE_INC |
| 3348 | |GDK_HINT_MIN_SIZE; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3349 | /* Using gui.formwin as geometry widget doesn't work as expected |
| 3350 | * with GTK+ 2 -- dunno why. Presumably all the resizing hacks |
| 3351 | * in Vim confuse GTK+. */ |
| 3352 | gtk_window_set_geometry_hints(GTK_WINDOW(gui.mainwin), gui.mainwin, |
| 3353 | &geometry, geometry_mask); |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 3354 | old_width = width; |
| 3355 | old_height = height; |
| 3356 | old_min_width = min_width; |
| 3357 | old_min_height = min_height; |
| 3358 | old_char_width = gui.char_width; |
| 3359 | old_char_height = gui.char_height; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3360 | } |
| 3361 | } |
| 3362 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3363 | #ifdef FEAT_TOOLBAR |
| 3364 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3365 | /* |
| 3366 | * This extra effort wouldn't be necessary if we only used stock icons in the |
| 3367 | * toolbar, as we do for all builtin icons. But user-defined toolbar icons |
| 3368 | * shouldn't be treated differently, thus we do need this. |
| 3369 | */ |
| 3370 | static void |
| 3371 | icon_size_changed_foreach(GtkWidget *widget, gpointer user_data) |
| 3372 | { |
| 3373 | if (GTK_IS_IMAGE(widget)) |
| 3374 | { |
| 3375 | GtkImage *image = (GtkImage *)widget; |
| 3376 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3377 | # if GTK_CHECK_VERSION(3,10,0) |
| 3378 | if (gtk_image_get_storage_type(image) == GTK_IMAGE_ICON_NAME) |
| 3379 | { |
| 3380 | const GtkIconSize icon_size = GPOINTER_TO_INT(user_data); |
| 3381 | const gchar *icon_name; |
| 3382 | |
| 3383 | gtk_image_get_icon_name(image, &icon_name, NULL); |
| 3384 | |
| 3385 | gtk_image_set_from_icon_name(image, icon_name, icon_size); |
| 3386 | } |
| 3387 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3388 | /* User-defined icons are stored in a GtkIconSet */ |
| 3389 | if (gtk_image_get_storage_type(image) == GTK_IMAGE_ICON_SET) |
| 3390 | { |
| 3391 | GtkIconSet *icon_set; |
| 3392 | GtkIconSize icon_size; |
| 3393 | |
| 3394 | gtk_image_get_icon_set(image, &icon_set, &icon_size); |
| 3395 | icon_size = (GtkIconSize)(long)user_data; |
| 3396 | |
| 3397 | gtk_icon_set_ref(icon_set); |
| 3398 | gtk_image_set_from_icon_set(image, icon_set, icon_size); |
| 3399 | gtk_icon_set_unref(icon_set); |
| 3400 | } |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3401 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3402 | } |
| 3403 | else if (GTK_IS_CONTAINER(widget)) |
| 3404 | { |
| 3405 | gtk_container_foreach((GtkContainer *)widget, |
| 3406 | &icon_size_changed_foreach, |
| 3407 | user_data); |
| 3408 | } |
| 3409 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3410 | |
| 3411 | static void |
| 3412 | set_toolbar_style(GtkToolbar *toolbar) |
| 3413 | { |
| 3414 | GtkToolbarStyle style; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3415 | GtkIconSize size; |
| 3416 | GtkIconSize oldsize; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3417 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3418 | if ((toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS | TOOLBAR_HORIZ)) |
| 3419 | == (TOOLBAR_TEXT | TOOLBAR_ICONS | TOOLBAR_HORIZ)) |
| 3420 | style = GTK_TOOLBAR_BOTH_HORIZ; |
Bram Moolenaar | 182c5be | 2010-06-25 05:37:59 +0200 | [diff] [blame] | 3421 | else if ((toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3422 | == (TOOLBAR_TEXT | TOOLBAR_ICONS)) |
| 3423 | style = GTK_TOOLBAR_BOTH; |
| 3424 | else if (toolbar_flags & TOOLBAR_TEXT) |
| 3425 | style = GTK_TOOLBAR_TEXT; |
| 3426 | else |
| 3427 | style = GTK_TOOLBAR_ICONS; |
| 3428 | |
| 3429 | gtk_toolbar_set_style(toolbar, style); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3430 | # if !GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3431 | gtk_toolbar_set_tooltips(toolbar, (toolbar_flags & TOOLBAR_TOOLTIPS) != 0); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3432 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3433 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3434 | switch (tbis_flags) |
| 3435 | { |
| 3436 | case TBIS_TINY: size = GTK_ICON_SIZE_MENU; break; |
| 3437 | case TBIS_SMALL: size = GTK_ICON_SIZE_SMALL_TOOLBAR; break; |
| 3438 | case TBIS_MEDIUM: size = GTK_ICON_SIZE_BUTTON; break; |
| 3439 | case TBIS_LARGE: size = GTK_ICON_SIZE_LARGE_TOOLBAR; break; |
Bram Moolenaar | beb003b | 2016-03-08 22:47:17 +0100 | [diff] [blame] | 3440 | case TBIS_HUGE: size = GTK_ICON_SIZE_DND; break; |
| 3441 | case TBIS_GIANT: size = GTK_ICON_SIZE_DIALOG; break; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3442 | default: size = GTK_ICON_SIZE_INVALID; break; |
| 3443 | } |
| 3444 | oldsize = gtk_toolbar_get_icon_size(toolbar); |
| 3445 | |
| 3446 | if (size == GTK_ICON_SIZE_INVALID) |
| 3447 | { |
| 3448 | /* Let global user preferences decide the icon size. */ |
| 3449 | gtk_toolbar_unset_icon_size(toolbar); |
| 3450 | size = gtk_toolbar_get_icon_size(toolbar); |
| 3451 | } |
| 3452 | if (size != oldsize) |
| 3453 | { |
| 3454 | gtk_container_foreach(GTK_CONTAINER(toolbar), |
| 3455 | &icon_size_changed_foreach, |
| 3456 | GINT_TO_POINTER((int)size)); |
| 3457 | } |
| 3458 | gtk_toolbar_set_icon_size(toolbar, size); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3459 | } |
| 3460 | |
| 3461 | #endif /* FEAT_TOOLBAR */ |
| 3462 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3463 | #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
| 3464 | static int ignore_tabline_evt = FALSE; |
Bram Moolenaar | a562149 | 2006-02-25 21:55:24 +0000 | [diff] [blame] | 3465 | static GtkWidget *tabline_menu; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3466 | # if !GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 3467 | static GtkTooltips *tabline_tooltip; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3468 | # endif |
Bram Moolenaar | a562149 | 2006-02-25 21:55:24 +0000 | [diff] [blame] | 3469 | static int clicked_page; /* page clicked in tab line */ |
| 3470 | |
| 3471 | /* |
| 3472 | * Handle selecting an item in the tab line popup menu. |
| 3473 | */ |
Bram Moolenaar | a562149 | 2006-02-25 21:55:24 +0000 | [diff] [blame] | 3474 | static void |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 3475 | tabline_menu_handler(GtkMenuItem *item UNUSED, gpointer user_data) |
Bram Moolenaar | a562149 | 2006-02-25 21:55:24 +0000 | [diff] [blame] | 3476 | { |
Bram Moolenaar | a562149 | 2006-02-25 21:55:24 +0000 | [diff] [blame] | 3477 | /* Add the string cmd into input buffer */ |
Bram Moolenaar | c6fe919 | 2006-04-09 21:54:49 +0000 | [diff] [blame] | 3478 | send_tabline_menu_event(clicked_page, (int)(long)user_data); |
Bram Moolenaar | a562149 | 2006-02-25 21:55:24 +0000 | [diff] [blame] | 3479 | } |
| 3480 | |
Bram Moolenaar | 8ea9123 | 2006-04-28 22:41:43 +0000 | [diff] [blame] | 3481 | static void |
| 3482 | add_tabline_menu_item(GtkWidget *menu, char_u *text, int resp) |
| 3483 | { |
| 3484 | GtkWidget *item; |
| 3485 | char_u *utf_text; |
| 3486 | |
| 3487 | utf_text = CONVERT_TO_UTF8(text); |
| 3488 | item = gtk_menu_item_new_with_label((const char *)utf_text); |
| 3489 | gtk_widget_show(item); |
| 3490 | CONVERT_TO_UTF8_FREE(utf_text); |
| 3491 | |
| 3492 | gtk_container_add(GTK_CONTAINER(menu), item); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3493 | # if GTK_CHECK_VERSION(3,0,0) |
| 3494 | g_signal_connect(G_OBJECT(item), "activate", |
| 3495 | G_CALLBACK(tabline_menu_handler), |
| 3496 | GINT_TO_POINTER(resp)); |
| 3497 | # else |
Bram Moolenaar | 8ea9123 | 2006-04-28 22:41:43 +0000 | [diff] [blame] | 3498 | gtk_signal_connect(GTK_OBJECT(item), "activate", |
| 3499 | GTK_SIGNAL_FUNC(tabline_menu_handler), |
Bram Moolenaar | 47b46d7 | 2008-07-02 19:05:48 +0000 | [diff] [blame] | 3500 | (gpointer)(long)resp); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3501 | # endif |
Bram Moolenaar | 8ea9123 | 2006-04-28 22:41:43 +0000 | [diff] [blame] | 3502 | } |
| 3503 | |
Bram Moolenaar | a562149 | 2006-02-25 21:55:24 +0000 | [diff] [blame] | 3504 | /* |
Bram Moolenaar | a562149 | 2006-02-25 21:55:24 +0000 | [diff] [blame] | 3505 | * Create a menu for the tab line. |
| 3506 | */ |
| 3507 | static GtkWidget * |
| 3508 | create_tabline_menu(void) |
| 3509 | { |
Bram Moolenaar | 8ea9123 | 2006-04-28 22:41:43 +0000 | [diff] [blame] | 3510 | GtkWidget *menu; |
Bram Moolenaar | a562149 | 2006-02-25 21:55:24 +0000 | [diff] [blame] | 3511 | |
| 3512 | menu = gtk_menu_new(); |
Bram Moolenaar | 7098ee5 | 2015-06-09 19:14:24 +0200 | [diff] [blame] | 3513 | if (first_tabpage->tp_next != NULL) |
| 3514 | add_tabline_menu_item(menu, (char_u *)_("Close tab"), |
| 3515 | TABLINE_MENU_CLOSE); |
Bram Moolenaar | 8ea9123 | 2006-04-28 22:41:43 +0000 | [diff] [blame] | 3516 | add_tabline_menu_item(menu, (char_u *)_("New tab"), TABLINE_MENU_NEW); |
| 3517 | add_tabline_menu_item(menu, (char_u *)_("Open Tab..."), TABLINE_MENU_OPEN); |
Bram Moolenaar | a562149 | 2006-02-25 21:55:24 +0000 | [diff] [blame] | 3518 | |
| 3519 | return menu; |
| 3520 | } |
| 3521 | |
| 3522 | static gboolean |
| 3523 | on_tabline_menu(GtkWidget *widget, GdkEvent *event) |
| 3524 | { |
| 3525 | /* Was this button press event ? */ |
| 3526 | if (event->type == GDK_BUTTON_PRESS) |
| 3527 | { |
| 3528 | GdkEventButton *bevent = (GdkEventButton *)event; |
| 3529 | int x = bevent->x; |
Bram Moolenaar | 8ea9123 | 2006-04-28 22:41:43 +0000 | [diff] [blame] | 3530 | int y = bevent->y; |
| 3531 | GtkWidget *tabwidget; |
| 3532 | GdkWindow *tabwin; |
Bram Moolenaar | a562149 | 2006-02-25 21:55:24 +0000 | [diff] [blame] | 3533 | |
Bram Moolenaar | f193fff | 2006-04-27 00:02:13 +0000 | [diff] [blame] | 3534 | /* When ignoring events return TRUE so that the selected page doesn't |
| 3535 | * change. */ |
| 3536 | if (hold_gui_events |
| 3537 | # ifdef FEAT_CMDWIN |
| 3538 | || cmdwin_type != 0 |
| 3539 | # endif |
| 3540 | ) |
| 3541 | return TRUE; |
| 3542 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3543 | # if GTK_CHECK_VERSION(3,0,0) |
| 3544 | tabwin = gui_gtk_window_at_position(gui.mainwin, &x, &y); |
| 3545 | # else |
Bram Moolenaar | 8ea9123 | 2006-04-28 22:41:43 +0000 | [diff] [blame] | 3546 | tabwin = gdk_window_at_pointer(&x, &y); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3547 | # endif |
| 3548 | |
Bram Moolenaar | 8ea9123 | 2006-04-28 22:41:43 +0000 | [diff] [blame] | 3549 | gdk_window_get_user_data(tabwin, (gpointer)&tabwidget); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3550 | # if GTK_CHECK_VERSION(3,0,0) |
| 3551 | clicked_page = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(tabwidget), |
| 3552 | "tab_num")); |
| 3553 | # else |
Bram Moolenaar | 8ea9123 | 2006-04-28 22:41:43 +0000 | [diff] [blame] | 3554 | clicked_page = (int)(long)gtk_object_get_user_data( |
| 3555 | GTK_OBJECT(tabwidget)); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3556 | # endif |
Bram Moolenaar | a562149 | 2006-02-25 21:55:24 +0000 | [diff] [blame] | 3557 | |
| 3558 | /* If the event was generated for 3rd button popup the menu. */ |
| 3559 | if (bevent->button == 3) |
| 3560 | { |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 3561 | # if GTK_CHECK_VERSION(3,22,2) |
| 3562 | gtk_menu_popup_at_pointer(GTK_MENU(widget), event); |
| 3563 | # else |
Bram Moolenaar | a562149 | 2006-02-25 21:55:24 +0000 | [diff] [blame] | 3564 | gtk_menu_popup(GTK_MENU(widget), NULL, NULL, NULL, NULL, |
| 3565 | bevent->button, bevent->time); |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 3566 | # endif |
Bram Moolenaar | a562149 | 2006-02-25 21:55:24 +0000 | [diff] [blame] | 3567 | /* We handled the event. */ |
| 3568 | return TRUE; |
| 3569 | } |
Bram Moolenaar | 9635157 | 2006-05-05 21:16:59 +0000 | [diff] [blame] | 3570 | else if (bevent->button == 1) |
Bram Moolenaar | eddf53b | 2006-02-27 00:11:10 +0000 | [diff] [blame] | 3571 | { |
Bram Moolenaar | 9635157 | 2006-05-05 21:16:59 +0000 | [diff] [blame] | 3572 | if (clicked_page == 0) |
| 3573 | { |
Bram Moolenaar | 0735454 | 2007-09-15 12:07:46 +0000 | [diff] [blame] | 3574 | /* Click after all tabs moves to next tab page. When "x" is |
| 3575 | * small guess it's the left button. */ |
Bram Moolenaar | a3f4166 | 2010-07-11 19:01:06 +0200 | [diff] [blame] | 3576 | send_tabline_event(x < 50 ? -1 : 0); |
Bram Moolenaar | 9635157 | 2006-05-05 21:16:59 +0000 | [diff] [blame] | 3577 | } |
Bram Moolenaar | eddf53b | 2006-02-27 00:11:10 +0000 | [diff] [blame] | 3578 | } |
Bram Moolenaar | a562149 | 2006-02-25 21:55:24 +0000 | [diff] [blame] | 3579 | } |
Bram Moolenaar | f193fff | 2006-04-27 00:02:13 +0000 | [diff] [blame] | 3580 | |
Bram Moolenaar | a562149 | 2006-02-25 21:55:24 +0000 | [diff] [blame] | 3581 | /* We didn't handle the event. */ |
| 3582 | return FALSE; |
| 3583 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3584 | |
| 3585 | /* |
| 3586 | * Handle selecting one of the tabs. |
| 3587 | */ |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3588 | static void |
| 3589 | on_select_tab( |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 3590 | GtkNotebook *notebook UNUSED, |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3591 | # if GTK_CHECK_VERSION(3,0,0) |
| 3592 | gpointer *page UNUSED, |
| 3593 | # else |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 3594 | GtkNotebookPage *page UNUSED, |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3595 | # endif |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 3596 | gint idx, |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 3597 | gpointer data UNUSED) |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3598 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3599 | if (!ignore_tabline_evt) |
Bram Moolenaar | eddf53b | 2006-02-27 00:11:10 +0000 | [diff] [blame] | 3600 | { |
Bram Moolenaar | a3f4166 | 2010-07-11 19:01:06 +0200 | [diff] [blame] | 3601 | send_tabline_event(idx + 1); |
Bram Moolenaar | eddf53b | 2006-02-27 00:11:10 +0000 | [diff] [blame] | 3602 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3603 | } |
| 3604 | |
| 3605 | /* |
| 3606 | * Show or hide the tabline. |
| 3607 | */ |
| 3608 | void |
| 3609 | gui_mch_show_tabline(int showit) |
| 3610 | { |
| 3611 | if (gui.tabline == NULL) |
| 3612 | return; |
| 3613 | |
| 3614 | if (!showit != !gtk_notebook_get_show_tabs(GTK_NOTEBOOK(gui.tabline))) |
| 3615 | { |
Bram Moolenaar | 3517bb1 | 2006-03-03 22:58:45 +0000 | [diff] [blame] | 3616 | /* Note: this may cause a resize event */ |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3617 | gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gui.tabline), showit); |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 3618 | update_window_manager_hints(0, 0); |
Bram Moolenaar | 9635157 | 2006-05-05 21:16:59 +0000 | [diff] [blame] | 3619 | if (showit) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3620 | # if GTK_CHECK_VERSION(3,0,0) |
| 3621 | gtk_widget_set_can_focus(GTK_WIDGET(gui.tabline), FALSE); |
| 3622 | # else |
Bram Moolenaar | 9635157 | 2006-05-05 21:16:59 +0000 | [diff] [blame] | 3623 | GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(gui.tabline), GTK_CAN_FOCUS); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3624 | # endif |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3625 | } |
Bram Moolenaar | 9635157 | 2006-05-05 21:16:59 +0000 | [diff] [blame] | 3626 | |
| 3627 | gui_mch_update(); |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3628 | } |
| 3629 | |
| 3630 | /* |
Bram Moolenaar | 3517bb1 | 2006-03-03 22:58:45 +0000 | [diff] [blame] | 3631 | * Return TRUE when tabline is displayed. |
| 3632 | */ |
| 3633 | int |
| 3634 | gui_mch_showing_tabline(void) |
| 3635 | { |
| 3636 | return gui.tabline != NULL |
Bram Moolenaar | 182c5be | 2010-06-25 05:37:59 +0200 | [diff] [blame] | 3637 | && gtk_notebook_get_show_tabs(GTK_NOTEBOOK(gui.tabline)); |
Bram Moolenaar | 3517bb1 | 2006-03-03 22:58:45 +0000 | [diff] [blame] | 3638 | } |
| 3639 | |
| 3640 | /* |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3641 | * Update the labels of the tabline. |
| 3642 | */ |
| 3643 | void |
| 3644 | gui_mch_update_tabline(void) |
| 3645 | { |
| 3646 | GtkWidget *page; |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 3647 | GtkWidget *event_box; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3648 | GtkWidget *label; |
| 3649 | tabpage_T *tp; |
| 3650 | int nr = 0; |
Bram Moolenaar | 8ea9123 | 2006-04-28 22:41:43 +0000 | [diff] [blame] | 3651 | int tab_num; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3652 | int curtabidx = 0; |
Bram Moolenaar | c1e3790 | 2006-04-18 21:55:01 +0000 | [diff] [blame] | 3653 | char_u *labeltext; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3654 | |
| 3655 | if (gui.tabline == NULL) |
| 3656 | return; |
| 3657 | |
| 3658 | ignore_tabline_evt = TRUE; |
| 3659 | |
| 3660 | /* Add a label for each tab page. They all contain the same text area. */ |
| 3661 | for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr) |
| 3662 | { |
| 3663 | if (tp == curtab) |
| 3664 | curtabidx = nr; |
| 3665 | |
Bram Moolenaar | 8ea9123 | 2006-04-28 22:41:43 +0000 | [diff] [blame] | 3666 | tab_num = nr + 1; |
| 3667 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3668 | page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr); |
| 3669 | if (page == NULL) |
| 3670 | { |
| 3671 | /* Add notebook page */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3672 | # if GTK_CHECK_VERSION(3,2,0) |
| 3673 | page = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); |
| 3674 | gtk_box_set_homogeneous(GTK_BOX(page), FALSE); |
| 3675 | # else |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3676 | page = gtk_vbox_new(FALSE, 0); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3677 | # endif |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3678 | gtk_widget_show(page); |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 3679 | event_box = gtk_event_box_new(); |
| 3680 | gtk_widget_show(event_box); |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3681 | label = gtk_label_new("-Empty-"); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3682 | # if !GTK_CHECK_VERSION(3,14,0) |
Bram Moolenaar | 8ea9123 | 2006-04-28 22:41:43 +0000 | [diff] [blame] | 3683 | gtk_misc_set_padding(GTK_MISC(label), 2, 2); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3684 | # endif |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 3685 | gtk_container_add(GTK_CONTAINER(event_box), label); |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3686 | gtk_widget_show(label); |
| 3687 | gtk_notebook_insert_page(GTK_NOTEBOOK(gui.tabline), |
| 3688 | page, |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 3689 | event_box, |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3690 | nr++); |
| 3691 | } |
| 3692 | |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 3693 | event_box = gtk_notebook_get_tab_label(GTK_NOTEBOOK(gui.tabline), page); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3694 | # if GTK_CHECK_VERSION(3,0,0) |
| 3695 | g_object_set_data(G_OBJECT(event_box), "tab_num", |
| 3696 | GINT_TO_POINTER(tab_num)); |
| 3697 | # else |
Bram Moolenaar | 47b46d7 | 2008-07-02 19:05:48 +0000 | [diff] [blame] | 3698 | gtk_object_set_user_data(GTK_OBJECT(event_box), |
| 3699 | (gpointer)(long)tab_num); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3700 | # endif |
| 3701 | # if GTK_CHECK_VERSION(3,0,0) |
| 3702 | label = gtk_bin_get_child(GTK_BIN(event_box)); |
| 3703 | # else |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 3704 | label = GTK_BIN(event_box)->child; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3705 | # endif |
Bram Moolenaar | 57657d8 | 2006-04-21 22:12:41 +0000 | [diff] [blame] | 3706 | get_tabline_label(tp, FALSE); |
Bram Moolenaar | c1e3790 | 2006-04-18 21:55:01 +0000 | [diff] [blame] | 3707 | labeltext = CONVERT_TO_UTF8(NameBuff); |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 3708 | gtk_label_set_text(GTK_LABEL(label), (const char *)labeltext); |
Bram Moolenaar | c1e3790 | 2006-04-18 21:55:01 +0000 | [diff] [blame] | 3709 | CONVERT_TO_UTF8_FREE(labeltext); |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 3710 | |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 3711 | get_tabline_label(tp, TRUE); |
| 3712 | labeltext = CONVERT_TO_UTF8(NameBuff); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3713 | # if GTK_CHECK_VERSION(3,0,0) |
| 3714 | gtk_widget_set_tooltip_text(event_box, (const gchar *)labeltext); |
| 3715 | # else |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 3716 | gtk_tooltips_set_tip(GTK_TOOLTIPS(tabline_tooltip), event_box, |
| 3717 | (const char *)labeltext, NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3718 | # endif |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 3719 | CONVERT_TO_UTF8_FREE(labeltext); |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3720 | } |
| 3721 | |
| 3722 | /* Remove any old labels. */ |
| 3723 | while (gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr) != NULL) |
| 3724 | gtk_notebook_remove_page(GTK_NOTEBOOK(gui.tabline), nr); |
| 3725 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3726 | # if GTK_CHECK_VERSION(3,0,0) |
| 3727 | if (gtk_notebook_get_current_page(GTK_NOTEBOOK(gui.tabline)) != curtabidx) |
| 3728 | gtk_notebook_set_current_page(GTK_NOTEBOOK(gui.tabline), curtabidx); |
| 3729 | # else |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3730 | if (gtk_notebook_current_page(GTK_NOTEBOOK(gui.tabline)) != curtabidx) |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 3731 | gtk_notebook_set_page(GTK_NOTEBOOK(gui.tabline), curtabidx); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3732 | # endif |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3733 | |
Bram Moolenaar | 8ea9123 | 2006-04-28 22:41:43 +0000 | [diff] [blame] | 3734 | /* Make sure everything is in place before drawing text. */ |
| 3735 | gui_mch_update(); |
| 3736 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3737 | ignore_tabline_evt = FALSE; |
| 3738 | } |
| 3739 | |
| 3740 | /* |
| 3741 | * Set the current tab to "nr". First tab is 1. |
| 3742 | */ |
| 3743 | void |
Bram Moolenaar | 66f948e | 2016-01-30 16:39:25 +0100 | [diff] [blame] | 3744 | gui_mch_set_curtab(int nr) |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3745 | { |
| 3746 | if (gui.tabline == NULL) |
| 3747 | return; |
| 3748 | |
| 3749 | ignore_tabline_evt = TRUE; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3750 | # if GTK_CHECK_VERSION(3,0,0) |
| 3751 | if (gtk_notebook_get_current_page(GTK_NOTEBOOK(gui.tabline)) != nr - 1) |
| 3752 | gtk_notebook_set_current_page(GTK_NOTEBOOK(gui.tabline), nr - 1); |
| 3753 | # else |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3754 | if (gtk_notebook_current_page(GTK_NOTEBOOK(gui.tabline)) != nr - 1) |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 3755 | gtk_notebook_set_page(GTK_NOTEBOOK(gui.tabline), nr - 1); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3756 | # endif |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3757 | ignore_tabline_evt = FALSE; |
| 3758 | } |
| 3759 | |
| 3760 | #endif /* FEAT_GUI_TABLINE */ |
| 3761 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3762 | /* |
Bram Moolenaar | a76638f | 2010-06-05 12:49:46 +0200 | [diff] [blame] | 3763 | * Add selection targets for PRIMARY and CLIPBOARD selections. |
| 3764 | */ |
| 3765 | void |
| 3766 | gui_gtk_set_selection_targets(void) |
| 3767 | { |
| 3768 | int i, j = 0; |
| 3769 | int n_targets = N_SELECTION_TARGETS; |
| 3770 | GtkTargetEntry targets[N_SELECTION_TARGETS]; |
| 3771 | |
| 3772 | for (i = 0; i < (int)N_SELECTION_TARGETS; ++i) |
| 3773 | { |
Bram Moolenaar | 2969570 | 2012-05-18 17:03:18 +0200 | [diff] [blame] | 3774 | /* OpenOffice tries to use TARGET_HTML and fails when we don't |
Bram Moolenaar | a76638f | 2010-06-05 12:49:46 +0200 | [diff] [blame] | 3775 | * return something, instead of trying another target. Therefore only |
| 3776 | * offer TARGET_HTML when it works. */ |
| 3777 | if (!clip_html && selection_targets[i].info == TARGET_HTML) |
| 3778 | n_targets--; |
| 3779 | else |
Bram Moolenaar | a76638f | 2010-06-05 12:49:46 +0200 | [diff] [blame] | 3780 | targets[j++] = selection_targets[i]; |
| 3781 | } |
| 3782 | |
| 3783 | gtk_selection_clear_targets(gui.drawarea, (GdkAtom)GDK_SELECTION_PRIMARY); |
| 3784 | gtk_selection_clear_targets(gui.drawarea, (GdkAtom)clip_plus.gtk_sel_atom); |
| 3785 | gtk_selection_add_targets(gui.drawarea, |
| 3786 | (GdkAtom)GDK_SELECTION_PRIMARY, |
| 3787 | targets, n_targets); |
| 3788 | gtk_selection_add_targets(gui.drawarea, |
| 3789 | (GdkAtom)clip_plus.gtk_sel_atom, |
| 3790 | targets, n_targets); |
| 3791 | } |
| 3792 | |
| 3793 | /* |
| 3794 | * Set up for receiving DND items. |
| 3795 | */ |
| 3796 | void |
| 3797 | gui_gtk_set_dnd_targets(void) |
| 3798 | { |
| 3799 | int i, j = 0; |
| 3800 | int n_targets = N_DND_TARGETS; |
| 3801 | GtkTargetEntry targets[N_DND_TARGETS]; |
| 3802 | |
| 3803 | for (i = 0; i < (int)N_DND_TARGETS; ++i) |
| 3804 | { |
Bram Moolenaar | b931d74 | 2011-10-26 11:36:25 +0200 | [diff] [blame] | 3805 | if (!clip_html && dnd_targets[i].info == TARGET_HTML) |
Bram Moolenaar | a76638f | 2010-06-05 12:49:46 +0200 | [diff] [blame] | 3806 | n_targets--; |
| 3807 | else |
Bram Moolenaar | a76638f | 2010-06-05 12:49:46 +0200 | [diff] [blame] | 3808 | targets[j++] = dnd_targets[i]; |
| 3809 | } |
| 3810 | |
| 3811 | gtk_drag_dest_unset(gui.drawarea); |
| 3812 | gtk_drag_dest_set(gui.drawarea, |
| 3813 | GTK_DEST_DEFAULT_ALL, |
| 3814 | targets, n_targets, |
Bram Moolenaar | ba7cc9f | 2011-02-25 17:10:27 +0100 | [diff] [blame] | 3815 | GDK_ACTION_COPY | GDK_ACTION_MOVE); |
Bram Moolenaar | a76638f | 2010-06-05 12:49:46 +0200 | [diff] [blame] | 3816 | } |
| 3817 | |
| 3818 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3819 | * Initialize the GUI. Create all the windows, set up all the callbacks etc. |
| 3820 | * Returns OK for success, FAIL when the GUI can't be started. |
| 3821 | */ |
| 3822 | int |
| 3823 | gui_mch_init(void) |
| 3824 | { |
| 3825 | GtkWidget *vbox; |
| 3826 | |
| 3827 | #ifdef FEAT_GUI_GNOME |
| 3828 | /* Initialize the GNOME libraries. gnome_program_init()/gnome_init() |
| 3829 | * exits on failure, but that's a non-issue because we already called |
| 3830 | * gtk_init_check() in gui_mch_init_check(). */ |
| 3831 | if (using_gnome) |
Bram Moolenaar | 3be71ce | 2013-01-23 16:00:11 +0100 | [diff] [blame] | 3832 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3833 | gnome_program_init(VIMPACKAGE, VIM_VERSION_SHORT, |
| 3834 | LIBGNOMEUI_MODULE, gui_argc, gui_argv, NULL); |
Bram Moolenaar | 3be71ce | 2013-01-23 16:00:11 +0100 | [diff] [blame] | 3835 | # if defined(FEAT_FLOAT) && defined(LC_NUMERIC) |
Bram Moolenaar | 1ff32c5 | 2014-04-29 15:11:43 +0200 | [diff] [blame] | 3836 | { |
| 3837 | char *p = setlocale(LC_NUMERIC, NULL); |
| 3838 | |
| 3839 | /* Make sure strtod() uses a decimal point, not a comma. Gnome |
| 3840 | * init may change it. */ |
| 3841 | if (p == NULL || strcmp(p, "C") != 0) |
| 3842 | setlocale(LC_NUMERIC, "C"); |
| 3843 | } |
Bram Moolenaar | 3be71ce | 2013-01-23 16:00:11 +0100 | [diff] [blame] | 3844 | # endif |
| 3845 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3846 | #endif |
| 3847 | vim_free(gui_argv); |
| 3848 | gui_argv = NULL; |
| 3849 | |
Bram Moolenaar | 182c5be | 2010-06-25 05:37:59 +0200 | [diff] [blame] | 3850 | #if GLIB_CHECK_VERSION(2,1,3) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3851 | /* Set the human-readable application name */ |
| 3852 | g_set_application_name("Vim"); |
Bram Moolenaar | 182c5be | 2010-06-25 05:37:59 +0200 | [diff] [blame] | 3853 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3854 | /* |
| 3855 | * Force UTF-8 output no matter what the value of 'encoding' is. |
| 3856 | * did_set_string_option() in option.c prohibits changing 'termencoding' |
| 3857 | * to something else than UTF-8 if the GUI is in use. |
| 3858 | */ |
| 3859 | set_option_value((char_u *)"termencoding", 0L, (char_u *)"utf-8", 0); |
| 3860 | |
Bram Moolenaar | 182c5be | 2010-06-25 05:37:59 +0200 | [diff] [blame] | 3861 | #ifdef FEAT_TOOLBAR |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3862 | gui_gtk_register_stock_icons(); |
Bram Moolenaar | 182c5be | 2010-06-25 05:37:59 +0200 | [diff] [blame] | 3863 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3864 | /* FIXME: Need to install the classic icons and a gtkrc.classic file. |
| 3865 | * The hard part is deciding install locations and the Makefile magic. */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3866 | #if !GTK_CHECK_VERSION(3,0,0) |
| 3867 | # if 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3868 | gtk_rc_parse("gtkrc"); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3869 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3870 | #endif |
| 3871 | |
| 3872 | /* Initialize values */ |
| 3873 | gui.border_width = 2; |
| 3874 | gui.scrollbar_width = SB_DEFAULT_WIDTH; |
| 3875 | gui.scrollbar_height = SB_DEFAULT_WIDTH; |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 3876 | #if GTK_CHECK_VERSION(3,0,0) |
| 3877 | gui.fgcolor = g_new(GdkRGBA, 1); |
| 3878 | gui.bgcolor = g_new(GdkRGBA, 1); |
| 3879 | gui.spcolor = g_new(GdkRGBA, 1); |
| 3880 | #else |
Bram Moolenaar | b71ec9f | 2005-01-25 22:22:02 +0000 | [diff] [blame] | 3881 | /* LINTED: avoid warning: conversion to 'unsigned long' */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3882 | gui.fgcolor = g_new0(GdkColor, 1); |
Bram Moolenaar | b71ec9f | 2005-01-25 22:22:02 +0000 | [diff] [blame] | 3883 | /* LINTED: avoid warning: conversion to 'unsigned long' */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3884 | gui.bgcolor = g_new0(GdkColor, 1); |
Bram Moolenaar | f36d369 | 2005-03-15 22:48:14 +0000 | [diff] [blame] | 3885 | /* LINTED: avoid warning: conversion to 'unsigned long' */ |
| 3886 | gui.spcolor = g_new0(GdkColor, 1); |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 3887 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3888 | |
| 3889 | /* Initialise atoms */ |
Bram Moolenaar | 3a6eaa5 | 2009-06-16 13:23:06 +0000 | [diff] [blame] | 3890 | html_atom = gdk_atom_intern("text/html", FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3891 | utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3892 | |
| 3893 | /* Set default foreground and background colors. */ |
| 3894 | gui.norm_pixel = gui.def_norm_pixel; |
| 3895 | gui.back_pixel = gui.def_back_pixel; |
| 3896 | |
| 3897 | if (gtk_socket_id != 0) |
| 3898 | { |
| 3899 | GtkWidget *plug; |
| 3900 | |
| 3901 | /* Use GtkSocket from another app. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3902 | plug = gtk_plug_new_for_display(gdk_display_get_default(), |
| 3903 | gtk_socket_id); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3904 | #if GTK_CHECK_VERSION(3,0,0) |
| 3905 | if (plug != NULL && gtk_plug_get_socket_window(GTK_PLUG(plug)) != NULL) |
| 3906 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3907 | if (plug != NULL && GTK_PLUG(plug)->socket_window != NULL) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3908 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3909 | { |
| 3910 | gui.mainwin = plug; |
| 3911 | } |
| 3912 | else |
| 3913 | { |
| 3914 | g_warning("Connection to GTK+ socket (ID %u) failed", |
| 3915 | (unsigned int)gtk_socket_id); |
| 3916 | /* Pretend we never wanted it if it failed (get own window) */ |
| 3917 | gtk_socket_id = 0; |
| 3918 | } |
| 3919 | } |
| 3920 | |
| 3921 | if (gtk_socket_id == 0) |
| 3922 | { |
| 3923 | #ifdef FEAT_GUI_GNOME |
| 3924 | if (using_gnome) |
| 3925 | { |
| 3926 | gui.mainwin = gnome_app_new("Vim", NULL); |
| 3927 | # ifdef USE_XSMP |
| 3928 | /* Use the GNOME save-yourself functionality now. */ |
| 3929 | xsmp_close(); |
| 3930 | # endif |
| 3931 | } |
| 3932 | else |
| 3933 | #endif |
| 3934 | gui.mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
| 3935 | } |
| 3936 | |
| 3937 | gtk_widget_set_name(gui.mainwin, "vim-main-window"); |
| 3938 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3939 | /* Create the PangoContext used for drawing all text. */ |
| 3940 | gui.text_context = gtk_widget_create_pango_context(gui.mainwin); |
| 3941 | pango_context_set_base_dir(gui.text_context, PANGO_DIRECTION_LTR); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3942 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3943 | #if GTK_CHECK_VERSION(3,0,0) |
| 3944 | gtk_container_set_border_width(GTK_CONTAINER(gui.mainwin), 0); |
| 3945 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3946 | gtk_container_border_width(GTK_CONTAINER(gui.mainwin), 0); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3947 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3948 | gtk_widget_add_events(gui.mainwin, GDK_VISIBILITY_NOTIFY_MASK); |
| 3949 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3950 | #if GTK_CHECK_VERSION(3,0,0) |
| 3951 | g_signal_connect(G_OBJECT(gui.mainwin), "delete-event", |
| 3952 | G_CALLBACK(&delete_event_cb), NULL); |
| 3953 | |
| 3954 | g_signal_connect(G_OBJECT(gui.mainwin), "realize", |
| 3955 | G_CALLBACK(&mainwin_realize), NULL); |
| 3956 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3957 | gtk_signal_connect(GTK_OBJECT(gui.mainwin), "delete_event", |
| 3958 | GTK_SIGNAL_FUNC(&delete_event_cb), NULL); |
| 3959 | |
| 3960 | gtk_signal_connect(GTK_OBJECT(gui.mainwin), "realize", |
| 3961 | GTK_SIGNAL_FUNC(&mainwin_realize), NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3962 | #endif |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 3963 | |
| 3964 | g_signal_connect(G_OBJECT(gui.mainwin), "screen-changed", |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3965 | G_CALLBACK(&mainwin_screen_changed_cb), NULL); |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 3966 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3967 | gui.accel_group = gtk_accel_group_new(); |
| 3968 | gtk_window_add_accel_group(GTK_WINDOW(gui.mainwin), gui.accel_group); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3969 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 3970 | /* A vertical box holds the menubar, toolbar and main text window. */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3971 | #if GTK_CHECK_VERSION(3,2,0) |
| 3972 | vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); |
| 3973 | gtk_box_set_homogeneous(GTK_BOX(vbox), FALSE); |
| 3974 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3975 | vbox = gtk_vbox_new(FALSE, 0); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 3976 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3977 | |
| 3978 | #ifdef FEAT_GUI_GNOME |
| 3979 | if (using_gnome) |
| 3980 | { |
Bram Moolenaar | 182c5be | 2010-06-25 05:37:59 +0200 | [diff] [blame] | 3981 | # if defined(FEAT_MENU) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3982 | /* automagically restore menubar/toolbar placement */ |
| 3983 | gnome_app_enable_layout_config(GNOME_APP(gui.mainwin), TRUE); |
| 3984 | # endif |
| 3985 | gnome_app_set_contents(GNOME_APP(gui.mainwin), vbox); |
| 3986 | } |
| 3987 | else |
| 3988 | #endif |
| 3989 | { |
| 3990 | gtk_container_add(GTK_CONTAINER(gui.mainwin), vbox); |
| 3991 | gtk_widget_show(vbox); |
| 3992 | } |
| 3993 | |
| 3994 | #ifdef FEAT_MENU |
| 3995 | /* |
| 3996 | * Create the menubar and handle |
| 3997 | */ |
| 3998 | gui.menubar = gtk_menu_bar_new(); |
| 3999 | gtk_widget_set_name(gui.menubar, "vim-menubar"); |
| 4000 | |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4001 | /* Avoid that GTK takes <F10> away from us. */ |
| 4002 | { |
| 4003 | GtkSettings *gtk_settings; |
| 4004 | |
| 4005 | gtk_settings = gtk_settings_get_for_screen(gdk_screen_get_default()); |
| 4006 | g_object_set(gtk_settings, "gtk-menu-bar-accel", NULL, NULL); |
| 4007 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4008 | |
| 4009 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4010 | # ifdef FEAT_GUI_GNOME |
| 4011 | if (using_gnome) |
| 4012 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4013 | BonoboDockItem *dockitem; |
| 4014 | |
| 4015 | gnome_app_set_menus(GNOME_APP(gui.mainwin), GTK_MENU_BAR(gui.menubar)); |
| 4016 | dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), |
| 4017 | GNOME_APP_MENUBAR_NAME); |
Bram Moolenaar | db552d60 | 2006-03-23 22:59:57 +0000 | [diff] [blame] | 4018 | /* We don't want the menu to float. */ |
| 4019 | bonobo_dock_item_set_behavior(dockitem, |
| 4020 | bonobo_dock_item_get_behavior(dockitem) |
| 4021 | | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4022 | gui.menubar_h = GTK_WIDGET(dockitem); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4023 | } |
| 4024 | else |
| 4025 | # endif /* FEAT_GUI_GNOME */ |
| 4026 | { |
Bram Moolenaar | 18144c8 | 2006-04-12 21:52:12 +0000 | [diff] [blame] | 4027 | /* Always show the menubar, otherwise <F10> doesn't work. It may be |
| 4028 | * disabled in gui_init() later. */ |
| 4029 | gtk_widget_show(gui.menubar); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4030 | gtk_box_pack_start(GTK_BOX(vbox), gui.menubar, FALSE, FALSE, 0); |
| 4031 | } |
| 4032 | #endif /* FEAT_MENU */ |
| 4033 | |
| 4034 | #ifdef FEAT_TOOLBAR |
| 4035 | /* |
| 4036 | * Create the toolbar and handle |
| 4037 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4038 | /* some aesthetics on the toolbar */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4039 | # ifdef USE_GTK3 |
Bram Moolenaar | 3f2a5d8 | 2016-02-27 22:08:16 +0100 | [diff] [blame] | 4040 | /* TODO: Add GTK+ 3 code here using GtkCssProvider if necessary. */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4041 | /* N.B. Since the default value of GtkToolbar::button-relief is |
| 4042 | * GTK_RELIEF_NONE, there's no need to specify that, probably. */ |
| 4043 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4044 | gtk_rc_parse_string( |
| 4045 | "style \"vim-toolbar-style\" {\n" |
| 4046 | " GtkToolbar::button_relief = GTK_RELIEF_NONE\n" |
| 4047 | "}\n" |
| 4048 | "widget \"*.vim-toolbar\" style \"vim-toolbar-style\"\n"); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4049 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4050 | gui.toolbar = gtk_toolbar_new(); |
| 4051 | gtk_widget_set_name(gui.toolbar, "vim-toolbar"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4052 | set_toolbar_style(GTK_TOOLBAR(gui.toolbar)); |
| 4053 | |
| 4054 | # ifdef FEAT_GUI_GNOME |
| 4055 | if (using_gnome) |
| 4056 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4057 | BonoboDockItem *dockitem; |
| 4058 | |
| 4059 | gnome_app_set_toolbar(GNOME_APP(gui.mainwin), GTK_TOOLBAR(gui.toolbar)); |
| 4060 | dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), |
| 4061 | GNOME_APP_TOOLBAR_NAME); |
| 4062 | gui.toolbar_h = GTK_WIDGET(dockitem); |
Bram Moolenaar | e580b0c | 2006-03-21 21:33:03 +0000 | [diff] [blame] | 4063 | /* When the toolbar is floating it gets stuck. So long as that isn't |
Bram Moolenaar | db552d60 | 2006-03-23 22:59:57 +0000 | [diff] [blame] | 4064 | * fixed let's disallow floating. */ |
Bram Moolenaar | e580b0c | 2006-03-21 21:33:03 +0000 | [diff] [blame] | 4065 | bonobo_dock_item_set_behavior(dockitem, |
Bram Moolenaar | db552d60 | 2006-03-23 22:59:57 +0000 | [diff] [blame] | 4066 | bonobo_dock_item_get_behavior(dockitem) |
| 4067 | | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4068 | gtk_container_set_border_width(GTK_CONTAINER(gui.toolbar), 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4069 | } |
| 4070 | else |
| 4071 | # endif /* FEAT_GUI_GNOME */ |
| 4072 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4073 | if (vim_strchr(p_go, GO_TOOLBAR) != NULL |
| 4074 | && (toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS))) |
| 4075 | gtk_widget_show(gui.toolbar); |
| 4076 | gtk_box_pack_start(GTK_BOX(vbox), gui.toolbar, FALSE, FALSE, 0); |
| 4077 | } |
| 4078 | #endif /* FEAT_TOOLBAR */ |
| 4079 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 4080 | #ifdef FEAT_GUI_TABLINE |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 4081 | /* |
| 4082 | * Use a Notebook for the tab pages labels. The labels are hidden by |
| 4083 | * default. |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 4084 | */ |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4085 | gui.tabline = gtk_notebook_new(); |
| 4086 | gtk_widget_show(gui.tabline); |
| 4087 | gtk_box_pack_start(GTK_BOX(vbox), gui.tabline, FALSE, FALSE, 0); |
| 4088 | gtk_notebook_set_show_border(GTK_NOTEBOOK(gui.tabline), FALSE); |
| 4089 | gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gui.tabline), FALSE); |
Bram Moolenaar | 4a85b41 | 2006-04-23 22:40:29 +0000 | [diff] [blame] | 4090 | gtk_notebook_set_scrollable(GTK_NOTEBOOK(gui.tabline), TRUE); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4091 | # if !GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 9635157 | 2006-05-05 21:16:59 +0000 | [diff] [blame] | 4092 | gtk_notebook_set_tab_border(GTK_NOTEBOOK(gui.tabline), FALSE); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4093 | # endif |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4094 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4095 | # if !GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 4096 | tabline_tooltip = gtk_tooltips_new(); |
| 4097 | gtk_tooltips_enable(GTK_TOOLTIPS(tabline_tooltip)); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4098 | # endif |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 4099 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 4100 | { |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 4101 | GtkWidget *page, *label, *event_box; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 4102 | |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4103 | /* Add the first tab. */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4104 | # if GTK_CHECK_VERSION(3,2,0) |
| 4105 | page = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); |
| 4106 | gtk_box_set_homogeneous(GTK_BOX(page), FALSE); |
| 4107 | # else |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 4108 | page = gtk_vbox_new(FALSE, 0); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4109 | # endif |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 4110 | gtk_widget_show(page); |
| 4111 | gtk_container_add(GTK_CONTAINER(gui.tabline), page); |
| 4112 | label = gtk_label_new("-Empty-"); |
| 4113 | gtk_widget_show(label); |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 4114 | event_box = gtk_event_box_new(); |
| 4115 | gtk_widget_show(event_box); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4116 | # if GTK_CHECK_VERSION(3,0,0) |
| 4117 | g_object_set_data(G_OBJECT(event_box), "tab_num", GINT_TO_POINTER(1L)); |
| 4118 | # else |
Bram Moolenaar | 47b46d7 | 2008-07-02 19:05:48 +0000 | [diff] [blame] | 4119 | gtk_object_set_user_data(GTK_OBJECT(event_box), (gpointer)1L); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4120 | # endif |
| 4121 | # if !GTK_CHECK_VERSION(3,14,0) |
Bram Moolenaar | 8ea9123 | 2006-04-28 22:41:43 +0000 | [diff] [blame] | 4122 | gtk_misc_set_padding(GTK_MISC(label), 2, 2); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4123 | # endif |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 4124 | gtk_container_add(GTK_CONTAINER(event_box), label); |
Bram Moolenaar | 437df8f | 2006-04-27 21:47:44 +0000 | [diff] [blame] | 4125 | gtk_notebook_set_tab_label(GTK_NOTEBOOK(gui.tabline), page, event_box); |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 4126 | } |
Bram Moolenaar | 54a709e | 2006-05-04 21:57:11 +0000 | [diff] [blame] | 4127 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4128 | # if GTK_CHECK_VERSION(3,0,0) |
| 4129 | g_signal_connect(G_OBJECT(gui.tabline), "switch-page", |
| 4130 | G_CALLBACK(on_select_tab), NULL); |
| 4131 | # else |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4132 | gtk_signal_connect(GTK_OBJECT(gui.tabline), "switch_page", |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4133 | GTK_SIGNAL_FUNC(on_select_tab), NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4134 | # endif |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4135 | |
| 4136 | /* Create a popup menu for the tab line and connect it. */ |
| 4137 | tabline_menu = create_tabline_menu(); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4138 | # if GTK_CHECK_VERSION(3,0,0) |
| 4139 | g_signal_connect_swapped(G_OBJECT(gui.tabline), "button-press-event", |
| 4140 | G_CALLBACK(on_tabline_menu), G_OBJECT(tabline_menu)); |
| 4141 | # else |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4142 | gtk_signal_connect_object(GTK_OBJECT(gui.tabline), "button_press_event", |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4143 | GTK_SIGNAL_FUNC(on_tabline_menu), GTK_OBJECT(tabline_menu)); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4144 | # endif |
| 4145 | #endif /* FEAT_GUI_TABLINE */ |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 4146 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4147 | gui.formwin = gtk_form_new(); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4148 | #if GTK_CHECK_VERSION(3,0,0) |
| 4149 | gtk_container_set_border_width(GTK_CONTAINER(gui.formwin), 0); |
| 4150 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4151 | gtk_container_border_width(GTK_CONTAINER(gui.formwin), 0); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4152 | #endif |
| 4153 | #if !GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4154 | gtk_widget_set_events(gui.formwin, GDK_EXPOSURE_MASK); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4155 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4156 | |
| 4157 | gui.drawarea = gtk_drawing_area_new(); |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 4158 | #if GTK_CHECK_VERSION(3,22,2) |
| 4159 | gtk_widget_set_name(gui.drawarea, "vim-gui-drawarea"); |
| 4160 | #endif |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4161 | #if GTK_CHECK_VERSION(3,0,0) |
| 4162 | gui.surface = NULL; |
| 4163 | gui.by_signal = FALSE; |
| 4164 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4165 | |
| 4166 | /* Determine which events we will filter. */ |
| 4167 | gtk_widget_set_events(gui.drawarea, |
| 4168 | GDK_EXPOSURE_MASK | |
| 4169 | GDK_ENTER_NOTIFY_MASK | |
| 4170 | GDK_LEAVE_NOTIFY_MASK | |
| 4171 | GDK_BUTTON_PRESS_MASK | |
| 4172 | GDK_BUTTON_RELEASE_MASK | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4173 | GDK_SCROLL_MASK | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4174 | GDK_KEY_PRESS_MASK | |
| 4175 | GDK_KEY_RELEASE_MASK | |
| 4176 | GDK_POINTER_MOTION_MASK | |
| 4177 | GDK_POINTER_MOTION_HINT_MASK); |
| 4178 | |
| 4179 | gtk_widget_show(gui.drawarea); |
| 4180 | gtk_form_put(GTK_FORM(gui.formwin), gui.drawarea, 0, 0); |
| 4181 | gtk_widget_show(gui.formwin); |
| 4182 | gtk_box_pack_start(GTK_BOX(vbox), gui.formwin, TRUE, TRUE, 0); |
| 4183 | |
| 4184 | /* For GtkSockets, key-presses must go to the focus widget (drawarea) |
| 4185 | * and not the window. */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4186 | #if GTK_CHECK_VERSION(3,0,0) |
| 4187 | g_signal_connect((gtk_socket_id == 0) ? G_OBJECT(gui.mainwin) |
| 4188 | : G_OBJECT(gui.drawarea), |
| 4189 | "key-press-event", |
| 4190 | G_CALLBACK(key_press_event), NULL); |
| 4191 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4192 | gtk_signal_connect((gtk_socket_id == 0) ? GTK_OBJECT(gui.mainwin) |
| 4193 | : GTK_OBJECT(gui.drawarea), |
| 4194 | "key_press_event", |
| 4195 | GTK_SIGNAL_FUNC(key_press_event), NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4196 | #endif |
| 4197 | #if defined(FEAT_XIM) || GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4198 | /* Also forward key release events for the benefit of GTK+ 2 input |
| 4199 | * modules. Try CTRL-SHIFT-xdigits to enter a Unicode code point. */ |
| 4200 | g_signal_connect((gtk_socket_id == 0) ? G_OBJECT(gui.mainwin) |
| 4201 | : G_OBJECT(gui.drawarea), |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4202 | "key-release-event", |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4203 | G_CALLBACK(&key_release_event), NULL); |
| 4204 | #endif |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4205 | #if GTK_CHECK_VERSION(3,0,0) |
| 4206 | g_signal_connect(G_OBJECT(gui.drawarea), "realize", |
| 4207 | G_CALLBACK(drawarea_realize_cb), NULL); |
| 4208 | g_signal_connect(G_OBJECT(gui.drawarea), "unrealize", |
| 4209 | G_CALLBACK(drawarea_unrealize_cb), NULL); |
| 4210 | g_signal_connect(G_OBJECT(gui.drawarea), "configure-event", |
| 4211 | G_CALLBACK(drawarea_configure_event_cb), NULL); |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 4212 | # if GTK_CHECK_VERSION(3,22,2) |
| 4213 | g_signal_connect_after(G_OBJECT(gui.drawarea), "style-updated", |
| 4214 | G_CALLBACK(&drawarea_style_updated_cb), NULL); |
| 4215 | # else |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4216 | g_signal_connect_after(G_OBJECT(gui.drawarea), "style-set", |
| 4217 | G_CALLBACK(&drawarea_style_set_cb), NULL); |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 4218 | # endif |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4219 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4220 | gtk_signal_connect(GTK_OBJECT(gui.drawarea), "realize", |
| 4221 | GTK_SIGNAL_FUNC(drawarea_realize_cb), NULL); |
| 4222 | gtk_signal_connect(GTK_OBJECT(gui.drawarea), "unrealize", |
| 4223 | GTK_SIGNAL_FUNC(drawarea_unrealize_cb), NULL); |
| 4224 | |
| 4225 | gtk_signal_connect_after(GTK_OBJECT(gui.drawarea), "style_set", |
| 4226 | GTK_SIGNAL_FUNC(&drawarea_style_set_cb), NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4227 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4228 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4229 | #if !GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4230 | gui.visibility = GDK_VISIBILITY_UNOBSCURED; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4231 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4232 | |
| 4233 | #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) |
| 4234 | wm_protocols_atom = gdk_atom_intern("WM_PROTOCOLS", FALSE); |
| 4235 | save_yourself_atom = gdk_atom_intern("WM_SAVE_YOURSELF", FALSE); |
| 4236 | #endif |
| 4237 | |
| 4238 | if (gtk_socket_id != 0) |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 4239 | /* make sure keyboard input can go to the drawarea */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4240 | #if GTK_CHECK_VERSION(3,0,0) |
| 4241 | gtk_widget_set_can_focus(gui.drawarea, TRUE); |
| 4242 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4243 | GTK_WIDGET_SET_FLAGS(gui.drawarea, GTK_CAN_FOCUS); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4244 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4245 | |
| 4246 | /* |
| 4247 | * Set clipboard specific atoms |
| 4248 | */ |
| 4249 | vim_atom = gdk_atom_intern(VIM_ATOM_NAME, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4250 | vimenc_atom = gdk_atom_intern(VIMENC_ATOM_NAME, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4251 | clip_star.gtk_sel_atom = GDK_SELECTION_PRIMARY; |
| 4252 | clip_plus.gtk_sel_atom = gdk_atom_intern("CLIPBOARD", FALSE); |
| 4253 | |
| 4254 | /* |
| 4255 | * Start out by adding the configured border width into the border offset. |
| 4256 | */ |
| 4257 | gui.border_offset = gui.border_width; |
| 4258 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4259 | #if GTK_CHECK_VERSION(3,0,0) |
| 4260 | g_signal_connect(G_OBJECT(gui.drawarea), "draw", |
| 4261 | G_CALLBACK(draw_event), NULL); |
| 4262 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4263 | gtk_signal_connect(GTK_OBJECT(gui.mainwin), "visibility_notify_event", |
| 4264 | GTK_SIGNAL_FUNC(visibility_event), NULL); |
| 4265 | gtk_signal_connect(GTK_OBJECT(gui.drawarea), "expose_event", |
| 4266 | GTK_SIGNAL_FUNC(expose_event), NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4267 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4268 | |
| 4269 | /* |
| 4270 | * Only install these enter/leave callbacks when 'p' in 'guioptions'. |
| 4271 | * Only needed for some window managers. |
| 4272 | */ |
| 4273 | if (vim_strchr(p_go, GO_POINTER) != NULL) |
| 4274 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4275 | #if GTK_CHECK_VERSION(3,0,0) |
| 4276 | g_signal_connect(G_OBJECT(gui.drawarea), "leave-notify-event", |
| 4277 | G_CALLBACK(leave_notify_event), NULL); |
| 4278 | g_signal_connect(G_OBJECT(gui.drawarea), "enter-notify-event", |
| 4279 | G_CALLBACK(enter_notify_event), NULL); |
| 4280 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4281 | gtk_signal_connect(GTK_OBJECT(gui.drawarea), "leave_notify_event", |
| 4282 | GTK_SIGNAL_FUNC(leave_notify_event), NULL); |
| 4283 | gtk_signal_connect(GTK_OBJECT(gui.drawarea), "enter_notify_event", |
| 4284 | GTK_SIGNAL_FUNC(enter_notify_event), NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4285 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4286 | } |
| 4287 | |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4288 | /* Real windows can get focus ... GtkPlug, being a mere container can't, |
| 4289 | * only its widgets. Arguably, this could be common code and we not use |
| 4290 | * the window focus at all, but let's be safe. |
| 4291 | */ |
| 4292 | if (gtk_socket_id == 0) |
| 4293 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4294 | #if GTK_CHECK_VERSION(3,0,0) |
| 4295 | g_signal_connect(G_OBJECT(gui.mainwin), "focus-out-event", |
| 4296 | G_CALLBACK(focus_out_event), NULL); |
| 4297 | g_signal_connect(G_OBJECT(gui.mainwin), "focus-in-event", |
| 4298 | G_CALLBACK(focus_in_event), NULL); |
| 4299 | #else |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4300 | gtk_signal_connect(GTK_OBJECT(gui.mainwin), "focus_out_event", |
| 4301 | GTK_SIGNAL_FUNC(focus_out_event), NULL); |
| 4302 | gtk_signal_connect(GTK_OBJECT(gui.mainwin), "focus_in_event", |
| 4303 | GTK_SIGNAL_FUNC(focus_in_event), NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4304 | #endif |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4305 | } |
| 4306 | else |
| 4307 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4308 | #if GTK_CHECK_VERSION(3,0,0) |
| 4309 | g_signal_connect(G_OBJECT(gui.drawarea), "focus-out-event", |
| 4310 | G_CALLBACK(focus_out_event), NULL); |
| 4311 | g_signal_connect(G_OBJECT(gui.drawarea), "focus-in-event", |
| 4312 | G_CALLBACK(focus_in_event), NULL); |
| 4313 | #else |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4314 | gtk_signal_connect(GTK_OBJECT(gui.drawarea), "focus_out_event", |
| 4315 | GTK_SIGNAL_FUNC(focus_out_event), NULL); |
| 4316 | gtk_signal_connect(GTK_OBJECT(gui.drawarea), "focus_in_event", |
| 4317 | GTK_SIGNAL_FUNC(focus_in_event), NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4318 | #endif |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4319 | #ifdef FEAT_GUI_TABLINE |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4320 | # if GTK_CHECK_VERSION(3,0,0) |
| 4321 | g_signal_connect(G_OBJECT(gui.tabline), "focus-out-event", |
| 4322 | G_CALLBACK(focus_out_event), NULL); |
| 4323 | g_signal_connect(G_OBJECT(gui.tabline), "focus-in-event", |
| 4324 | G_CALLBACK(focus_in_event), NULL); |
| 4325 | # else |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4326 | gtk_signal_connect(GTK_OBJECT(gui.tabline), "focus_out_event", |
| 4327 | GTK_SIGNAL_FUNC(focus_out_event), NULL); |
| 4328 | gtk_signal_connect(GTK_OBJECT(gui.tabline), "focus_in_event", |
| 4329 | GTK_SIGNAL_FUNC(focus_in_event), NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4330 | # endif |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4331 | #endif /* FEAT_GUI_TABLINE */ |
| 4332 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4333 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4334 | #if GTK_CHECK_VERSION(3,0,0) |
| 4335 | g_signal_connect(G_OBJECT(gui.drawarea), "motion-notify-event", |
| 4336 | G_CALLBACK(motion_notify_event), NULL); |
| 4337 | g_signal_connect(G_OBJECT(gui.drawarea), "button-press-event", |
| 4338 | G_CALLBACK(button_press_event), NULL); |
| 4339 | g_signal_connect(G_OBJECT(gui.drawarea), "button-release-event", |
| 4340 | G_CALLBACK(button_release_event), NULL); |
| 4341 | g_signal_connect(G_OBJECT(gui.drawarea), "scroll-event", |
| 4342 | G_CALLBACK(&scroll_event), NULL); |
| 4343 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4344 | gtk_signal_connect(GTK_OBJECT(gui.drawarea), "motion_notify_event", |
| 4345 | GTK_SIGNAL_FUNC(motion_notify_event), NULL); |
| 4346 | gtk_signal_connect(GTK_OBJECT(gui.drawarea), "button_press_event", |
| 4347 | GTK_SIGNAL_FUNC(button_press_event), NULL); |
| 4348 | gtk_signal_connect(GTK_OBJECT(gui.drawarea), "button_release_event", |
| 4349 | GTK_SIGNAL_FUNC(button_release_event), NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4350 | g_signal_connect(G_OBJECT(gui.drawarea), "scroll_event", |
| 4351 | G_CALLBACK(&scroll_event), NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4352 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4353 | |
| 4354 | /* |
| 4355 | * Add selection handler functions. |
| 4356 | */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4357 | #if GTK_CHECK_VERSION(3,0,0) |
| 4358 | g_signal_connect(G_OBJECT(gui.drawarea), "selection-clear-event", |
| 4359 | G_CALLBACK(selection_clear_event), NULL); |
| 4360 | g_signal_connect(G_OBJECT(gui.drawarea), "selection-received", |
| 4361 | G_CALLBACK(selection_received_cb), NULL); |
| 4362 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4363 | gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_clear_event", |
| 4364 | GTK_SIGNAL_FUNC(selection_clear_event), NULL); |
| 4365 | gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_received", |
| 4366 | GTK_SIGNAL_FUNC(selection_received_cb), NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4367 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4368 | |
Bram Moolenaar | a76638f | 2010-06-05 12:49:46 +0200 | [diff] [blame] | 4369 | gui_gtk_set_selection_targets(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4370 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4371 | #if GTK_CHECK_VERSION(3,0,0) |
| 4372 | g_signal_connect(G_OBJECT(gui.drawarea), "selection-get", |
| 4373 | G_CALLBACK(selection_get_cb), NULL); |
| 4374 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4375 | gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_get", |
| 4376 | GTK_SIGNAL_FUNC(selection_get_cb), NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4377 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4378 | |
| 4379 | /* Pretend we don't have input focus, we will get an event if we do. */ |
| 4380 | gui.in_focus = FALSE; |
| 4381 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4382 | return OK; |
| 4383 | } |
| 4384 | |
| 4385 | #if (defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) || defined(PROTO) |
| 4386 | /* |
| 4387 | * This is called from gui_start() after a fork() has been done. |
| 4388 | * We have to tell the session manager our new PID. |
| 4389 | */ |
| 4390 | void |
| 4391 | gui_mch_forked(void) |
| 4392 | { |
| 4393 | if (using_gnome) |
| 4394 | { |
| 4395 | GnomeClient *client; |
| 4396 | |
| 4397 | client = gnome_master_client(); |
| 4398 | |
| 4399 | if (client != NULL) |
| 4400 | gnome_client_set_process_id(client, getpid()); |
| 4401 | } |
| 4402 | } |
| 4403 | #endif /* FEAT_GUI_GNOME && FEAT_SESSION */ |
| 4404 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4405 | #if GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 4406 | static GdkRGBA |
| 4407 | color_to_rgba(guicolor_T color) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4408 | { |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 4409 | GdkRGBA rgba; |
| 4410 | rgba.red = ((color & 0xff0000) >> 16) / 255.0; |
| 4411 | rgba.green = ((color & 0xff00) >> 8) / 255.0; |
| 4412 | rgba.blue = ((color & 0xff)) / 255.0; |
| 4413 | rgba.alpha = 1.0; |
| 4414 | return rgba; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4415 | } |
| 4416 | |
| 4417 | static void |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 4418 | set_cairo_source_rgba_from_color(cairo_t *cr, guicolor_T color) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4419 | { |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 4420 | const GdkRGBA rgba = color_to_rgba(color); |
| 4421 | cairo_set_source_rgba(cr, rgba.red, rgba.green, rgba.blue, rgba.alpha); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4422 | } |
| 4423 | #endif /* GTK_CHECK_VERSION(3,0,0) */ |
| 4424 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4425 | /* |
| 4426 | * Called when the foreground or background color has been changed. |
| 4427 | * This used to change the graphics contexts directly but we are |
| 4428 | * currently manipulating them where desired. |
| 4429 | */ |
| 4430 | void |
| 4431 | gui_mch_new_colors(void) |
| 4432 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4433 | #if GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 4434 | # if !GTK_CHECK_VERSION(3,22,2) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4435 | GdkWindow * const da_win = gtk_widget_get_window(gui.drawarea); |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 4436 | # endif |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4437 | |
| 4438 | if (gui.drawarea != NULL && gtk_widget_get_window(gui.drawarea) != NULL) |
| 4439 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4440 | if (gui.drawarea != NULL && gui.drawarea->window != NULL) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4441 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4442 | { |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 4443 | #if GTK_CHECK_VERSION(3,22,2) |
| 4444 | GtkStyleContext * const context |
| 4445 | = gtk_widget_get_style_context(gui.drawarea); |
| 4446 | GtkCssProvider * const provider = gtk_css_provider_new(); |
| 4447 | gchar * const css = g_strdup_printf( |
| 4448 | "widget#vim-gui-drawarea {\n" |
| 4449 | " background-color: #%.2lx%.2lx%.2lx;\n" |
| 4450 | "}\n", |
| 4451 | (gui.back_pixel >> 16) & 0xff, |
| 4452 | (gui.back_pixel >> 8) & 0xff, |
| 4453 | gui.back_pixel & 0xff); |
| 4454 | |
| 4455 | gtk_css_provider_load_from_data(provider, css, -1, NULL); |
| 4456 | gtk_style_context_add_provider(context, |
| 4457 | GTK_STYLE_PROVIDER(provider), G_MAXUINT); |
| 4458 | |
| 4459 | g_free(css); |
| 4460 | g_object_unref(provider); |
| 4461 | #elif GTK_CHECK_VERSION(3,4,0) /* !GTK_CHECK_VERSION(3,22,2) */ |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 4462 | GdkRGBA rgba; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4463 | |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 4464 | rgba = color_to_rgba(gui.back_pixel); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4465 | { |
| 4466 | cairo_pattern_t * const pat = cairo_pattern_create_rgba( |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 4467 | rgba.red, rgba.green, rgba.blue, rgba.alpha); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4468 | if (pat != NULL) |
| 4469 | { |
| 4470 | gdk_window_set_background_pattern(da_win, pat); |
| 4471 | cairo_pattern_destroy(pat); |
| 4472 | } |
| 4473 | else |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 4474 | gdk_window_set_background_rgba(da_win, &rgba); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4475 | } |
| 4476 | #else /* !GTK_CHECK_VERSION(3,4,0) */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4477 | GdkColor color = { 0, 0, 0, 0 }; |
| 4478 | |
| 4479 | color.pixel = gui.back_pixel; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4480 | # if GTK_CHECK_VERSION(3,0,0) |
| 4481 | gdk_window_set_background(da_win, &color); |
| 4482 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4483 | gdk_window_set_background(gui.drawarea->window, &color); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4484 | # endif |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 4485 | #endif /* !GTK_CHECK_VERSION(3,22,2) */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4486 | } |
| 4487 | } |
| 4488 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4489 | /* |
| 4490 | * This signal informs us about the need to rearrange our sub-widgets. |
| 4491 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4492 | static gint |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 4493 | form_configure_event(GtkWidget *widget UNUSED, |
| 4494 | GdkEventConfigure *event, |
| 4495 | gpointer data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4496 | { |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4497 | int usable_height = event->height; |
| 4498 | |
Bram Moolenaar | 182707a | 2016-11-21 20:55:58 +0100 | [diff] [blame] | 4499 | #if GTK_CHECK_VERSION(3,22,2) && !GTK_CHECK_VERSION(3,22,4) |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 4500 | /* As of 3.22.2, GdkWindows have started distributing configure events to |
| 4501 | * their "native" children (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=12579fe71b3b8f79eb9c1b80e429443bcc437dd0). |
| 4502 | * |
| 4503 | * As can be seen from the implementation of move_native_children() and |
| 4504 | * configure_native_child() in gdkwindow.c, those functions actually |
| 4505 | * propagate configure events to every child, failing to distinguish |
| 4506 | * "native" one from non-native one. |
| 4507 | * |
| 4508 | * Naturally, configure events propagated to here like that are fallacious |
| 4509 | * and, as a matter of fact, they trigger a geometric collapse of |
| 4510 | * gui.formwin. |
| 4511 | * |
| 4512 | * To filter out such fallacious events, check if the given event is the |
| 4513 | * one that was sent out to the right place. Ignore it if not. |
| 4514 | */ |
Bram Moolenaar | 182707a | 2016-11-21 20:55:58 +0100 | [diff] [blame] | 4515 | /* Follow-up |
| 4516 | * After a few weeks later, the GdkWindow change mentioned above was |
| 4517 | * reverted (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=f70039cb9603a02d2369fec4038abf40a1711155). |
| 4518 | * The corresponding official release is 3.22.4. */ |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 4519 | if (event->window != gtk_widget_get_window(gui.formwin)) |
| 4520 | return TRUE; |
| 4521 | #endif |
| 4522 | |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4523 | /* When in a GtkPlug, we can't guarantee valid heights (as a round |
| 4524 | * no. of char-heights), so we have to manually sanitise them. |
| 4525 | * Widths seem to sort themselves out, don't ask me why. |
| 4526 | */ |
| 4527 | if (gtk_socket_id != 0) |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4528 | usable_height -= (gui.char_height - (gui.char_height/2)); /* sic. */ |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4529 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4530 | gtk_form_freeze(GTK_FORM(gui.formwin)); |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4531 | gui_resize_shell(event->width, usable_height); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4532 | gtk_form_thaw(GTK_FORM(gui.formwin)); |
| 4533 | |
| 4534 | return TRUE; |
| 4535 | } |
| 4536 | |
| 4537 | /* |
| 4538 | * Function called when window already closed. |
| 4539 | * We can't do much more here than to trying to preserve what had been done, |
| 4540 | * since the window is already inevitably going away. |
| 4541 | */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4542 | #if GTK_CHECK_VERSION(3,0,0) |
| 4543 | static void |
| 4544 | mainwin_destroy_cb(GObject *object UNUSED, gpointer data UNUSED) |
| 4545 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4546 | static void |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 4547 | mainwin_destroy_cb(GtkObject *object UNUSED, gpointer data UNUSED) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4548 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4549 | { |
| 4550 | /* Don't write messages to the GUI anymore */ |
| 4551 | full_screen = FALSE; |
| 4552 | |
| 4553 | gui.mainwin = NULL; |
| 4554 | gui.drawarea = NULL; |
| 4555 | |
| 4556 | if (!exiting) /* only do anything if the destroy was unexpected */ |
| 4557 | { |
Bram Moolenaar | ce0842a | 2005-07-18 21:58:11 +0000 | [diff] [blame] | 4558 | vim_strncpy(IObuff, |
| 4559 | (char_u *)_("Vim: Main window unexpectedly destroyed\n"), |
| 4560 | IOSIZE - 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4561 | preserve_exit(); |
| 4562 | } |
Bram Moolenaar | 36e294c | 2015-12-29 18:55:46 +0100 | [diff] [blame] | 4563 | #ifdef USE_GRESOURCE |
| 4564 | gui_gtk_unregister_resource(); |
| 4565 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4566 | } |
| 4567 | |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4568 | |
| 4569 | /* |
| 4570 | * Bit of a hack to ensure we start GtkPlug windows with the correct window |
| 4571 | * hints (and thus the required size from -geom), but that after that we |
| 4572 | * put the hints back to normal (the actual minimum size) so we may |
| 4573 | * subsequently be resized smaller. GtkSocket (the parent end) uses the |
Bram Moolenaar | 4932594 | 2007-05-10 19:19:59 +0000 | [diff] [blame] | 4574 | * plug's window 'min hints to set *it's* minimum size, but that's also the |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4575 | * only way we have of making ourselves bigger (by set lines/columns). |
| 4576 | * Thus set hints at start-up to ensure correct init. size, then a |
Bram Moolenaar | 3f2a5d8 | 2016-02-27 22:08:16 +0100 | [diff] [blame] | 4577 | * second after the final attempt to reset the real minimum hints (done by |
| 4578 | * scrollbar init.), actually do the standard hints and stop the timer. |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4579 | * We'll not let the default hints be set while this timer's active. |
| 4580 | */ |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4581 | static gboolean |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 4582 | check_startup_plug_hints(gpointer data UNUSED) |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4583 | { |
| 4584 | if (init_window_hints_state == 1) |
| 4585 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4586 | /* Safe to use normal hints now */ |
| 4587 | init_window_hints_state = 0; |
| 4588 | update_window_manager_hints(0, 0); |
| 4589 | return FALSE; /* stop timer */ |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4590 | } |
| 4591 | |
| 4592 | /* Keep on trying */ |
| 4593 | init_window_hints_state = 1; |
| 4594 | return TRUE; |
| 4595 | } |
| 4596 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4597 | /* |
| 4598 | * Open the GUI window which was created by a call to gui_mch_init(). |
| 4599 | */ |
| 4600 | int |
| 4601 | gui_mch_open(void) |
| 4602 | { |
| 4603 | guicolor_T fg_pixel = INVALCOLOR; |
| 4604 | guicolor_T bg_pixel = INVALCOLOR; |
Bram Moolenaar | 79ef6d6 | 2009-09-23 15:35:48 +0000 | [diff] [blame] | 4605 | guint pixel_width; |
| 4606 | guint pixel_height; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4607 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4608 | /* |
| 4609 | * Allow setting a window role on the command line, or invent one |
| 4610 | * if none was specified. This is mainly useful for GNOME session |
| 4611 | * support; allowing the WM to restore window placement. |
| 4612 | */ |
| 4613 | if (role_argument != NULL) |
| 4614 | { |
| 4615 | gtk_window_set_role(GTK_WINDOW(gui.mainwin), role_argument); |
| 4616 | } |
| 4617 | else |
| 4618 | { |
| 4619 | char *role; |
| 4620 | |
| 4621 | /* Invent a unique-enough ID string for the role */ |
| 4622 | role = g_strdup_printf("vim-%u-%u-%u", |
| 4623 | (unsigned)mch_get_pid(), |
| 4624 | (unsigned)g_random_int(), |
| 4625 | (unsigned)time(NULL)); |
| 4626 | |
| 4627 | gtk_window_set_role(GTK_WINDOW(gui.mainwin), role); |
| 4628 | g_free(role); |
| 4629 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4630 | |
| 4631 | if (gui_win_x != -1 && gui_win_y != -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4632 | gtk_window_move(GTK_WINDOW(gui.mainwin), gui_win_x, gui_win_y); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4633 | |
| 4634 | /* Determine user specified geometry, if present. */ |
| 4635 | if (gui.geom != NULL) |
| 4636 | { |
| 4637 | int mask; |
| 4638 | unsigned int w, h; |
| 4639 | int x = 0; |
| 4640 | int y = 0; |
| 4641 | |
| 4642 | mask = XParseGeometry((char *)gui.geom, &x, &y, &w, &h); |
| 4643 | |
| 4644 | if (mask & WidthValue) |
| 4645 | Columns = w; |
| 4646 | if (mask & HeightValue) |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 4647 | { |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 4648 | if (p_window > (long)h - 1 || !option_was_set((char_u *)"window")) |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 4649 | p_window = h - 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4650 | Rows = h; |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 4651 | } |
Bram Moolenaar | e057d40 | 2013-06-30 17:51:51 +0200 | [diff] [blame] | 4652 | limit_screen_size(); |
Bram Moolenaar | 2dd8b52 | 2007-10-19 12:33:44 +0000 | [diff] [blame] | 4653 | |
| 4654 | pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width); |
| 4655 | pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height); |
| 4656 | |
Bram Moolenaar | 2dd8b52 | 2007-10-19 12:33:44 +0000 | [diff] [blame] | 4657 | pixel_width += get_menu_tool_width(); |
| 4658 | pixel_height += get_menu_tool_height(); |
Bram Moolenaar | 2dd8b52 | 2007-10-19 12:33:44 +0000 | [diff] [blame] | 4659 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4660 | if (mask & (XValue | YValue)) |
Bram Moolenaar | 2dd8b52 | 2007-10-19 12:33:44 +0000 | [diff] [blame] | 4661 | { |
Bram Moolenaar | fe86f2d | 2008-11-28 20:29:07 +0000 | [diff] [blame] | 4662 | int ww, hh; |
| 4663 | gui_mch_get_screen_dimensions(&ww, &hh); |
| 4664 | hh += p_ghr + get_menu_tool_height(); |
| 4665 | ww += get_menu_tool_width(); |
Bram Moolenaar | 2dd8b52 | 2007-10-19 12:33:44 +0000 | [diff] [blame] | 4666 | if (mask & XNegative) |
Bram Moolenaar | fe86f2d | 2008-11-28 20:29:07 +0000 | [diff] [blame] | 4667 | x += ww - pixel_width; |
Bram Moolenaar | 2dd8b52 | 2007-10-19 12:33:44 +0000 | [diff] [blame] | 4668 | if (mask & YNegative) |
Bram Moolenaar | fe86f2d | 2008-11-28 20:29:07 +0000 | [diff] [blame] | 4669 | y += hh - pixel_height; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4670 | gtk_window_move(GTK_WINDOW(gui.mainwin), x, y); |
Bram Moolenaar | 2dd8b52 | 2007-10-19 12:33:44 +0000 | [diff] [blame] | 4671 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4672 | vim_free(gui.geom); |
| 4673 | gui.geom = NULL; |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4674 | |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4675 | /* From now until everyone's stopped trying to set the window hints |
| 4676 | * to their correct minimum values, stop them being set as we need |
| 4677 | * them to remain at our required size for the parent GtkSocket to |
| 4678 | * give us the right initial size. |
| 4679 | */ |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4680 | if (gtk_socket_id != 0 && (mask & WidthValue || mask & HeightValue)) |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4681 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4682 | update_window_manager_hints(pixel_width, pixel_height); |
| 4683 | init_window_hints_state = 1; |
| 4684 | g_timeout_add(1000, check_startup_plug_hints, NULL); |
| 4685 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4686 | } |
| 4687 | |
Bram Moolenaar | 79ef6d6 | 2009-09-23 15:35:48 +0000 | [diff] [blame] | 4688 | pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width); |
| 4689 | pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height); |
Bram Moolenaar | 79ef6d6 | 2009-09-23 15:35:48 +0000 | [diff] [blame] | 4690 | /* For GTK2 changing the size of the form widget doesn't cause window |
| 4691 | * resizing. */ |
Bram Moolenaar | debe25a | 2010-06-06 17:41:24 +0200 | [diff] [blame] | 4692 | if (gtk_socket_id == 0) |
Bram Moolenaar | 79ef6d6 | 2009-09-23 15:35:48 +0000 | [diff] [blame] | 4693 | gtk_window_resize(GTK_WINDOW(gui.mainwin), pixel_width, pixel_height); |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4694 | update_window_manager_hints(0, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4695 | |
| 4696 | if (foreground_argument != NULL) |
| 4697 | fg_pixel = gui_get_color((char_u *)foreground_argument); |
| 4698 | if (fg_pixel == INVALCOLOR) |
| 4699 | fg_pixel = gui_get_color((char_u *)"Black"); |
| 4700 | |
| 4701 | if (background_argument != NULL) |
| 4702 | bg_pixel = gui_get_color((char_u *)background_argument); |
| 4703 | if (bg_pixel == INVALCOLOR) |
| 4704 | bg_pixel = gui_get_color((char_u *)"White"); |
| 4705 | |
| 4706 | if (found_reverse_arg) |
| 4707 | { |
| 4708 | gui.def_norm_pixel = bg_pixel; |
| 4709 | gui.def_back_pixel = fg_pixel; |
| 4710 | } |
| 4711 | else |
| 4712 | { |
| 4713 | gui.def_norm_pixel = fg_pixel; |
| 4714 | gui.def_back_pixel = bg_pixel; |
| 4715 | } |
| 4716 | |
| 4717 | /* Get the colors from the "Normal" and "Menu" group (set in syntax.c or |
| 4718 | * in a vimrc file) */ |
| 4719 | set_normal_colors(); |
| 4720 | |
| 4721 | /* Check that none of the colors are the same as the background color */ |
| 4722 | gui_check_colors(); |
| 4723 | |
| 4724 | /* Get the colors for the highlight groups (gui_check_colors() might have |
| 4725 | * changed them). */ |
| 4726 | highlight_gui_started(); /* re-init colors and fonts */ |
| 4727 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4728 | #if GTK_CHECK_VERSION(3,0,0) |
| 4729 | g_signal_connect(G_OBJECT(gui.mainwin), "destroy", |
| 4730 | G_CALLBACK(mainwin_destroy_cb), NULL); |
| 4731 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4732 | gtk_signal_connect(GTK_OBJECT(gui.mainwin), "destroy", |
| 4733 | GTK_SIGNAL_FUNC(mainwin_destroy_cb), NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4734 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4735 | |
| 4736 | #ifdef FEAT_HANGULIN |
| 4737 | hangul_keyboard_set(); |
| 4738 | #endif |
| 4739 | |
| 4740 | /* |
| 4741 | * Notify the fixed area about the need to resize the contents of the |
| 4742 | * gui.formwin, which we use for random positioning of the included |
| 4743 | * components. |
| 4744 | * |
| 4745 | * We connect this signal deferred finally after anything is in place, |
| 4746 | * since this is intended to handle resizements coming from the window |
| 4747 | * manager upon us and should not interfere with what VIM is requesting |
| 4748 | * upon startup. |
| 4749 | */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4750 | #if GTK_CHECK_VERSION(3,0,0) |
| 4751 | g_signal_connect(G_OBJECT(gui.formwin), "configure-event", |
| 4752 | G_CALLBACK(form_configure_event), NULL); |
| 4753 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4754 | gtk_signal_connect(GTK_OBJECT(gui.formwin), "configure_event", |
| 4755 | GTK_SIGNAL_FUNC(form_configure_event), NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4756 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4757 | |
| 4758 | #ifdef FEAT_DND |
Bram Moolenaar | a76638f | 2010-06-05 12:49:46 +0200 | [diff] [blame] | 4759 | /* Set up for receiving DND items. */ |
| 4760 | gui_gtk_set_dnd_targets(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4761 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4762 | # if GTK_CHECK_VERSION(3,0,0) |
| 4763 | g_signal_connect(G_OBJECT(gui.drawarea), "drag-data-received", |
| 4764 | G_CALLBACK(drag_data_received_cb), NULL); |
| 4765 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4766 | gtk_signal_connect(GTK_OBJECT(gui.drawarea), "drag_data_received", |
| 4767 | GTK_SIGNAL_FUNC(drag_data_received_cb), NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4768 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4769 | #endif |
| 4770 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4771 | /* With GTK+ 2, we need to iconify the window before calling show() |
Bram Moolenaar | 182c5be | 2010-06-25 05:37:59 +0200 | [diff] [blame] | 4772 | * to avoid mapping the window for a short time. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4773 | if (found_iconic_arg && gtk_socket_id == 0) |
| 4774 | gui_mch_iconify(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4775 | |
| 4776 | { |
Bram Moolenaar | 182c5be | 2010-06-25 05:37:59 +0200 | [diff] [blame] | 4777 | #if defined(FEAT_GUI_GNOME) && defined(FEAT_MENU) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4778 | unsigned long menu_handler = 0; |
| 4779 | # ifdef FEAT_TOOLBAR |
| 4780 | unsigned long tool_handler = 0; |
| 4781 | # endif |
| 4782 | /* |
| 4783 | * Urgh hackish :/ For some reason BonoboDockLayout always forces a |
| 4784 | * show when restoring the saved layout configuration. We can't just |
| 4785 | * hide the widgets again after gtk_widget_show(gui.mainwin) since it's |
| 4786 | * a toplevel window and thus will be realized immediately. Instead, |
| 4787 | * connect signal handlers to hide the widgets just after they've been |
| 4788 | * marked visible, but before the main window is realized. |
| 4789 | */ |
| 4790 | if (using_gnome && vim_strchr(p_go, GO_MENUS) == NULL) |
| 4791 | menu_handler = g_signal_connect_after(gui.menubar_h, "show", |
| 4792 | G_CALLBACK(>k_widget_hide), |
| 4793 | NULL); |
| 4794 | # ifdef FEAT_TOOLBAR |
| 4795 | if (using_gnome && vim_strchr(p_go, GO_TOOLBAR) == NULL |
| 4796 | && (toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS))) |
| 4797 | tool_handler = g_signal_connect_after(gui.toolbar_h, "show", |
| 4798 | G_CALLBACK(>k_widget_hide), |
| 4799 | NULL); |
| 4800 | # endif |
| 4801 | #endif |
| 4802 | gtk_widget_show(gui.mainwin); |
| 4803 | |
Bram Moolenaar | 182c5be | 2010-06-25 05:37:59 +0200 | [diff] [blame] | 4804 | #if defined(FEAT_GUI_GNOME) && defined(FEAT_MENU) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4805 | if (menu_handler != 0) |
| 4806 | g_signal_handler_disconnect(gui.menubar_h, menu_handler); |
| 4807 | # ifdef FEAT_TOOLBAR |
| 4808 | if (tool_handler != 0) |
| 4809 | g_signal_handler_disconnect(gui.toolbar_h, tool_handler); |
| 4810 | # endif |
| 4811 | #endif |
| 4812 | } |
| 4813 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4814 | return OK; |
| 4815 | } |
| 4816 | |
| 4817 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4818 | void |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 4819 | gui_mch_exit(int rc UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4820 | { |
| 4821 | if (gui.mainwin != NULL) |
| 4822 | gtk_widget_destroy(gui.mainwin); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4823 | } |
| 4824 | |
| 4825 | /* |
| 4826 | * Get the position of the top left corner of the window. |
| 4827 | */ |
| 4828 | int |
| 4829 | gui_mch_get_winpos(int *x, int *y) |
| 4830 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4831 | gtk_window_get_position(GTK_WINDOW(gui.mainwin), x, y); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4832 | return OK; |
| 4833 | } |
| 4834 | |
| 4835 | /* |
| 4836 | * Set the position of the top left corner of the window to the given |
| 4837 | * coordinates. |
| 4838 | */ |
| 4839 | void |
| 4840 | gui_mch_set_winpos(int x, int y) |
| 4841 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4842 | gtk_window_move(GTK_WINDOW(gui.mainwin), x, y); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4843 | } |
| 4844 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4845 | #if !GTK_CHECK_VERSION(3,0,0) |
| 4846 | # if 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4847 | static int resize_idle_installed = FALSE; |
| 4848 | /* |
| 4849 | * Idle handler to force resize. Used by gui_mch_set_shellsize() to ensure |
| 4850 | * the shell size doesn't exceed the window size, i.e. if the window manager |
| 4851 | * ignored our size request. Usually this happens if the window is maximized. |
| 4852 | * |
| 4853 | * FIXME: It'd be nice if we could find a little more orthodox solution. |
| 4854 | * See also the remark below in gui_mch_set_shellsize(). |
| 4855 | * |
| 4856 | * DISABLED: When doing ":set lines+=1" this function would first invoke |
| 4857 | * gui_resize_shell() with the old size, then the normal callback would |
| 4858 | * report the new size through form_configure_event(). That caused the window |
| 4859 | * layout to be messed up. |
| 4860 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4861 | static gboolean |
| 4862 | force_shell_resize_idle(gpointer data) |
| 4863 | { |
| 4864 | if (gui.mainwin != NULL |
| 4865 | && GTK_WIDGET_REALIZED(gui.mainwin) |
| 4866 | && GTK_WIDGET_VISIBLE(gui.mainwin)) |
| 4867 | { |
| 4868 | int width; |
| 4869 | int height; |
| 4870 | |
| 4871 | gtk_window_get_size(GTK_WINDOW(gui.mainwin), &width, &height); |
| 4872 | |
| 4873 | width -= get_menu_tool_width(); |
| 4874 | height -= get_menu_tool_height(); |
| 4875 | |
| 4876 | gui_resize_shell(width, height); |
| 4877 | } |
| 4878 | |
| 4879 | resize_idle_installed = FALSE; |
| 4880 | return FALSE; /* don't call me again */ |
| 4881 | } |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4882 | # endif |
| 4883 | #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4884 | |
Bram Moolenaar | 0973623 | 2009-09-23 16:14:49 +0000 | [diff] [blame] | 4885 | /* |
| 4886 | * Return TRUE if the main window is maximized. |
| 4887 | */ |
| 4888 | int |
Bram Moolenaar | 66f948e | 2016-01-30 16:39:25 +0100 | [diff] [blame] | 4889 | gui_mch_maximized(void) |
Bram Moolenaar | 0973623 | 2009-09-23 16:14:49 +0000 | [diff] [blame] | 4890 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4891 | #if GTK_CHECK_VERSION(3,0,0) |
| 4892 | return (gui.mainwin != NULL && gtk_widget_get_window(gui.mainwin) != NULL |
| 4893 | && (gdk_window_get_state(gtk_widget_get_window(gui.mainwin)) |
| 4894 | & GDK_WINDOW_STATE_MAXIMIZED)); |
| 4895 | #else |
Bram Moolenaar | 0973623 | 2009-09-23 16:14:49 +0000 | [diff] [blame] | 4896 | return (gui.mainwin != NULL && gui.mainwin->window != NULL |
| 4897 | && (gdk_window_get_state(gui.mainwin->window) |
| 4898 | & GDK_WINDOW_STATE_MAXIMIZED)); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4899 | #endif |
Bram Moolenaar | 0973623 | 2009-09-23 16:14:49 +0000 | [diff] [blame] | 4900 | } |
| 4901 | |
| 4902 | /* |
| 4903 | * Unmaximize the main window |
| 4904 | */ |
| 4905 | void |
Bram Moolenaar | 66f948e | 2016-01-30 16:39:25 +0100 | [diff] [blame] | 4906 | gui_mch_unmaximize(void) |
Bram Moolenaar | 0973623 | 2009-09-23 16:14:49 +0000 | [diff] [blame] | 4907 | { |
| 4908 | if (gui.mainwin != NULL) |
| 4909 | gtk_window_unmaximize(GTK_WINDOW(gui.mainwin)); |
| 4910 | } |
Bram Moolenaar | 0973623 | 2009-09-23 16:14:49 +0000 | [diff] [blame] | 4911 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4912 | /* |
Bram Moolenaar | 12bc1b5 | 2011-08-10 17:44:45 +0200 | [diff] [blame] | 4913 | * Called when the font changed while the window is maximized. Compute the |
| 4914 | * new Rows and Columns. This is like resizing the window. |
| 4915 | */ |
| 4916 | void |
Bram Moolenaar | 66f948e | 2016-01-30 16:39:25 +0100 | [diff] [blame] | 4917 | gui_mch_newfont(void) |
Bram Moolenaar | 12bc1b5 | 2011-08-10 17:44:45 +0200 | [diff] [blame] | 4918 | { |
| 4919 | int w, h; |
| 4920 | |
| 4921 | gtk_window_get_size(GTK_WINDOW(gui.mainwin), &w, &h); |
| 4922 | w -= get_menu_tool_width(); |
| 4923 | h -= get_menu_tool_height(); |
| 4924 | gui_resize_shell(w, h); |
| 4925 | } |
| 4926 | |
| 4927 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4928 | * Set the windows size. |
| 4929 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4930 | void |
| 4931 | gui_mch_set_shellsize(int width, int height, |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 4932 | int min_width UNUSED, int min_height UNUSED, |
| 4933 | int base_width UNUSED, int base_height UNUSED, |
| 4934 | int direction UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4935 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4936 | /* give GTK+ a chance to put all widget's into place */ |
| 4937 | gui_mch_update(); |
| 4938 | |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4939 | /* this will cause the proper resizement to happen too */ |
| 4940 | if (gtk_socket_id == 0) |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4941 | update_window_manager_hints(0, 0); |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4942 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4943 | /* With GTK+ 2, changing the size of the form widget doesn't resize |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4944 | * the window. So let's do it the other way around and resize the |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4945 | * main window instead. */ |
| 4946 | width += get_menu_tool_width(); |
| 4947 | height += get_menu_tool_height(); |
| 4948 | |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4949 | if (gtk_socket_id == 0) |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4950 | gtk_window_resize(GTK_WINDOW(gui.mainwin), width, height); |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 4951 | else |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4952 | update_window_manager_hints(width, height); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4953 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4954 | # if !GTK_CHECK_VERSION(3,0,0) |
| 4955 | # if 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4956 | if (!resize_idle_installed) |
| 4957 | { |
| 4958 | g_idle_add_full(GDK_PRIORITY_EVENTS + 10, |
| 4959 | &force_shell_resize_idle, NULL, NULL); |
| 4960 | resize_idle_installed = TRUE; |
| 4961 | } |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 4962 | # endif |
| 4963 | # endif /* !GTK_CHECK_VERSION(3,0,0) */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4964 | /* |
| 4965 | * Wait until all events are processed to prevent a crash because the |
| 4966 | * real size of the drawing area doesn't reflect Vim's internal ideas. |
| 4967 | * |
| 4968 | * This is a bit of a hack, since Vim is a terminal application with a GUI |
| 4969 | * on top, while the GUI expects to be the boss. |
| 4970 | */ |
| 4971 | gui_mch_update(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4972 | } |
| 4973 | |
| 4974 | |
| 4975 | /* |
| 4976 | * The screen size is used to make sure the initial window doesn't get bigger |
| 4977 | * than the screen. This subtracts some room for menubar, toolbar and window |
| 4978 | * decorations. |
| 4979 | */ |
| 4980 | void |
| 4981 | gui_mch_get_screen_dimensions(int *screen_w, int *screen_h) |
| 4982 | { |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 4983 | #if GTK_CHECK_VERSION(3,22,2) |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 4984 | GdkRectangle rect; |
| 4985 | GdkMonitor * const mon = gdk_display_get_monitor_at_window( |
| 4986 | gtk_widget_get_display(gui.mainwin), |
| 4987 | gtk_widget_get_window(gui.mainwin)); |
| 4988 | gdk_monitor_get_geometry(mon, &rect); |
| 4989 | |
| 4990 | *screen_w = rect.width; |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 4991 | /* Subtract 'guiheadroom' from the height to allow some room for the |
| 4992 | * window manager (task list and window title bar). */ |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 4993 | *screen_h = rect.height - p_ghr; |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 4994 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4995 | GdkScreen* screen; |
| 4996 | |
| 4997 | if (gui.mainwin != NULL && gtk_widget_has_screen(gui.mainwin)) |
| 4998 | screen = gtk_widget_get_screen(gui.mainwin); |
| 4999 | else |
| 5000 | screen = gdk_screen_get_default(); |
| 5001 | |
| 5002 | *screen_w = gdk_screen_get_width(screen); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5003 | /* Subtract 'guiheadroom' from the height to allow some room for the |
| 5004 | * window manager (task list and window title bar). */ |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 5005 | *screen_h = gdk_screen_get_height(screen) - p_ghr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5006 | #endif |
| 5007 | |
| 5008 | /* |
| 5009 | * FIXME: dirty trick: Because the gui_get_base_height() doesn't include |
| 5010 | * the toolbar and menubar for GTK, we subtract them from the screen |
Bram Moolenaar | 6440447 | 2010-06-26 06:24:45 +0200 | [diff] [blame] | 5011 | * height, so that the window size can be made to fit on the screen. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5012 | * This should be completely changed later. |
| 5013 | */ |
| 5014 | *screen_w -= get_menu_tool_width(); |
| 5015 | *screen_h -= get_menu_tool_height(); |
| 5016 | } |
| 5017 | |
| 5018 | #if defined(FEAT_TITLE) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5019 | void |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 5020 | gui_mch_settitle(char_u *title, char_u *icon UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5021 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5022 | if (title != NULL && output_conv.vc_type != CONV_NONE) |
| 5023 | title = string_convert(&output_conv, title, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5024 | |
| 5025 | gtk_window_set_title(GTK_WINDOW(gui.mainwin), (const char *)title); |
| 5026 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5027 | if (output_conv.vc_type != CONV_NONE) |
| 5028 | vim_free(title); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5029 | } |
| 5030 | #endif /* FEAT_TITLE */ |
| 5031 | |
| 5032 | #if defined(FEAT_MENU) || defined(PROTO) |
| 5033 | void |
| 5034 | gui_mch_enable_menu(int showit) |
| 5035 | { |
| 5036 | GtkWidget *widget; |
| 5037 | |
| 5038 | # ifdef FEAT_GUI_GNOME |
| 5039 | if (using_gnome) |
| 5040 | widget = gui.menubar_h; |
| 5041 | else |
| 5042 | # endif |
| 5043 | widget = gui.menubar; |
| 5044 | |
Bram Moolenaar | 18144c8 | 2006-04-12 21:52:12 +0000 | [diff] [blame] | 5045 | /* Do not disable the menu while starting up, otherwise F10 doesn't work. */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5046 | # if GTK_CHECK_VERSION(3,0,0) |
| 5047 | if (!showit != !gtk_widget_get_visible(widget) && !gui.starting) |
| 5048 | # else |
Bram Moolenaar | 18144c8 | 2006-04-12 21:52:12 +0000 | [diff] [blame] | 5049 | if (!showit != !GTK_WIDGET_VISIBLE(widget) && !gui.starting) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5050 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5051 | { |
| 5052 | if (showit) |
| 5053 | gtk_widget_show(widget); |
| 5054 | else |
| 5055 | gtk_widget_hide(widget); |
| 5056 | |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 5057 | update_window_manager_hints(0, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5058 | } |
| 5059 | } |
| 5060 | #endif /* FEAT_MENU */ |
| 5061 | |
| 5062 | #if defined(FEAT_TOOLBAR) || defined(PROTO) |
| 5063 | void |
| 5064 | gui_mch_show_toolbar(int showit) |
| 5065 | { |
| 5066 | GtkWidget *widget; |
| 5067 | |
| 5068 | if (gui.toolbar == NULL) |
| 5069 | return; |
| 5070 | |
| 5071 | # ifdef FEAT_GUI_GNOME |
| 5072 | if (using_gnome) |
| 5073 | widget = gui.toolbar_h; |
| 5074 | else |
| 5075 | # endif |
| 5076 | widget = gui.toolbar; |
| 5077 | |
| 5078 | if (showit) |
| 5079 | set_toolbar_style(GTK_TOOLBAR(gui.toolbar)); |
| 5080 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5081 | # if GTK_CHECK_VERSION(3,0,0) |
| 5082 | if (!showit != !gtk_widget_get_visible(widget)) |
| 5083 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5084 | if (!showit != !GTK_WIDGET_VISIBLE(widget)) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5085 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5086 | { |
| 5087 | if (showit) |
| 5088 | gtk_widget_show(widget); |
| 5089 | else |
| 5090 | gtk_widget_hide(widget); |
| 5091 | |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 5092 | update_window_manager_hints(0, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5093 | } |
| 5094 | } |
| 5095 | #endif /* FEAT_TOOLBAR */ |
| 5096 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5097 | /* |
| 5098 | * Check if a given font is a CJK font. This is done in a very crude manner. It |
| 5099 | * just see if U+04E00 for zh and ja and U+AC00 for ko are covered in a given |
| 5100 | * font. Consequently, this function cannot be used as a general purpose check |
| 5101 | * for CJK-ness for which fontconfig APIs should be used. This is only used by |
| 5102 | * gui_mch_init_font() to deal with 'CJK fixed width fonts'. |
| 5103 | */ |
| 5104 | static int |
| 5105 | is_cjk_font(PangoFontDescription *font_desc) |
| 5106 | { |
| 5107 | static const char * const cjk_langs[] = |
| 5108 | {"zh_CN", "zh_TW", "zh_HK", "ja", "ko"}; |
| 5109 | |
| 5110 | PangoFont *font; |
| 5111 | unsigned i; |
| 5112 | int is_cjk = FALSE; |
| 5113 | |
| 5114 | font = pango_context_load_font(gui.text_context, font_desc); |
| 5115 | |
| 5116 | if (font == NULL) |
| 5117 | return FALSE; |
| 5118 | |
| 5119 | for (i = 0; !is_cjk && i < G_N_ELEMENTS(cjk_langs); ++i) |
| 5120 | { |
| 5121 | PangoCoverage *coverage; |
| 5122 | gunichar uc; |
| 5123 | |
| 5124 | coverage = pango_font_get_coverage( |
| 5125 | font, pango_language_from_string(cjk_langs[i])); |
| 5126 | |
| 5127 | if (coverage != NULL) |
| 5128 | { |
| 5129 | uc = (cjk_langs[i][0] == 'k') ? 0xAC00 : 0x4E00; |
| 5130 | is_cjk = (pango_coverage_get(coverage, uc) == PANGO_COVERAGE_EXACT); |
| 5131 | pango_coverage_unref(coverage); |
| 5132 | } |
| 5133 | } |
| 5134 | |
| 5135 | g_object_unref(font); |
| 5136 | |
| 5137 | return is_cjk; |
| 5138 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5139 | |
Bram Moolenaar | 231334e | 2005-07-25 20:46:57 +0000 | [diff] [blame] | 5140 | /* |
| 5141 | * Adjust gui.char_height (after 'linespace' was changed). |
| 5142 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5143 | int |
Bram Moolenaar | 231334e | 2005-07-25 20:46:57 +0000 | [diff] [blame] | 5144 | gui_mch_adjust_charheight(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5145 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5146 | PangoFontMetrics *metrics; |
| 5147 | int ascent; |
| 5148 | int descent; |
| 5149 | |
| 5150 | metrics = pango_context_get_metrics(gui.text_context, gui.norm_font, |
| 5151 | pango_context_get_language(gui.text_context)); |
| 5152 | ascent = pango_font_metrics_get_ascent(metrics); |
| 5153 | descent = pango_font_metrics_get_descent(metrics); |
| 5154 | |
| 5155 | pango_font_metrics_unref(metrics); |
| 5156 | |
| 5157 | gui.char_height = (ascent + descent + PANGO_SCALE - 1) / PANGO_SCALE |
Bram Moolenaar | 231334e | 2005-07-25 20:46:57 +0000 | [diff] [blame] | 5158 | + p_linespace; |
Bram Moolenaar | b71ec9f | 2005-01-25 22:22:02 +0000 | [diff] [blame] | 5159 | /* LINTED: avoid warning: bitwise operation on signed value */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5160 | gui.char_ascent = PANGO_PIXELS(ascent + p_linespace * PANGO_SCALE / 2); |
| 5161 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5162 | /* A not-positive value of char_height may crash Vim. Only happens |
| 5163 | * if 'linespace' is negative (which does make sense sometimes). */ |
| 5164 | gui.char_ascent = MAX(gui.char_ascent, 0); |
| 5165 | gui.char_height = MAX(gui.char_height, gui.char_ascent + 1); |
| 5166 | |
| 5167 | return OK; |
| 5168 | } |
| 5169 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5170 | #if GTK_CHECK_VERSION(3,0,0) |
| 5171 | /* Callback function used in gui_mch_font_dialog() */ |
| 5172 | static gboolean |
| 5173 | font_filter(const PangoFontFamily *family, |
| 5174 | const PangoFontFace *face UNUSED, |
| 5175 | gpointer data UNUSED) |
| 5176 | { |
| 5177 | return pango_font_family_is_monospace((PangoFontFamily *)family); |
| 5178 | } |
| 5179 | #endif |
| 5180 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5181 | /* |
| 5182 | * Put up a font dialog and return the selected font name in allocated memory. |
| 5183 | * "oldval" is the previous value. Return NULL when cancelled. |
| 5184 | * This should probably go into gui_gtk.c. Hmm. |
| 5185 | * FIXME: |
| 5186 | * The GTK2 font selection dialog has no filtering API. So we could either |
| 5187 | * a) implement our own (possibly copying the code from somewhere else) or |
| 5188 | * b) just live with it. |
| 5189 | */ |
| 5190 | char_u * |
| 5191 | gui_mch_font_dialog(char_u *oldval) |
| 5192 | { |
| 5193 | GtkWidget *dialog; |
| 5194 | int response; |
| 5195 | char_u *fontname = NULL; |
| 5196 | char_u *oldname; |
| 5197 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5198 | #if GTK_CHECK_VERSION(3,2,0) |
| 5199 | dialog = gtk_font_chooser_dialog_new(NULL, NULL); |
| 5200 | gtk_font_chooser_set_filter_func(GTK_FONT_CHOOSER(dialog), font_filter, |
| 5201 | NULL, NULL); |
| 5202 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5203 | dialog = gtk_font_selection_dialog_new(NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5204 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5205 | |
| 5206 | gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gui.mainwin)); |
| 5207 | gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); |
| 5208 | |
| 5209 | if (oldval != NULL && oldval[0] != NUL) |
| 5210 | { |
| 5211 | if (output_conv.vc_type != CONV_NONE) |
| 5212 | oldname = string_convert(&output_conv, oldval, NULL); |
| 5213 | else |
| 5214 | oldname = oldval; |
| 5215 | |
| 5216 | /* Annoying bug in GTK (or Pango): if the font name does not include a |
| 5217 | * size, zero is used. Use default point size ten. */ |
| 5218 | if (!vim_isdigit(oldname[STRLEN(oldname) - 1])) |
| 5219 | { |
| 5220 | char_u *p = vim_strnsave(oldname, STRLEN(oldname) + 3); |
| 5221 | |
| 5222 | if (p != NULL) |
| 5223 | { |
| 5224 | STRCPY(p + STRLEN(p), " 10"); |
| 5225 | if (oldname != oldval) |
| 5226 | vim_free(oldname); |
| 5227 | oldname = p; |
| 5228 | } |
| 5229 | } |
| 5230 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5231 | #if GTK_CHECK_VERSION(3,2,0) |
| 5232 | gtk_font_chooser_set_font( |
| 5233 | GTK_FONT_CHOOSER(dialog), (const gchar *)oldname); |
| 5234 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5235 | gtk_font_selection_dialog_set_font_name( |
| 5236 | GTK_FONT_SELECTION_DIALOG(dialog), (const char *)oldname); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5237 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5238 | |
| 5239 | if (oldname != oldval) |
Bram Moolenaar | 8c71145 | 2005-01-14 21:53:12 +0000 | [diff] [blame] | 5240 | vim_free(oldname); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5241 | } |
Bram Moolenaar | bef9d83 | 2009-09-11 13:46:41 +0000 | [diff] [blame] | 5242 | else |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5243 | #if GTK_CHECK_VERSION(3,2,0) |
| 5244 | gtk_font_chooser_set_font( |
| 5245 | GTK_FONT_CHOOSER(dialog), DEFAULT_FONT); |
| 5246 | #else |
Bram Moolenaar | bef9d83 | 2009-09-11 13:46:41 +0000 | [diff] [blame] | 5247 | gtk_font_selection_dialog_set_font_name( |
| 5248 | GTK_FONT_SELECTION_DIALOG(dialog), DEFAULT_FONT); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5249 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5250 | |
| 5251 | response = gtk_dialog_run(GTK_DIALOG(dialog)); |
| 5252 | |
| 5253 | if (response == GTK_RESPONSE_OK) |
| 5254 | { |
| 5255 | char *name; |
| 5256 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5257 | #if GTK_CHECK_VERSION(3,2,0) |
| 5258 | name = gtk_font_chooser_get_font(GTK_FONT_CHOOSER(dialog)); |
| 5259 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5260 | name = gtk_font_selection_dialog_get_font_name( |
| 5261 | GTK_FONT_SELECTION_DIALOG(dialog)); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5262 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5263 | if (name != NULL) |
| 5264 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5265 | char_u *p; |
| 5266 | |
| 5267 | /* Apparently some font names include a comma, need to escape |
| 5268 | * that, because in 'guifont' it separates names. */ |
| 5269 | p = vim_strsave_escaped((char_u *)name, (char_u *)","); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5270 | g_free(name); |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 5271 | if (p != NULL && input_conv.vc_type != CONV_NONE) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5272 | { |
| 5273 | fontname = string_convert(&input_conv, p, NULL); |
| 5274 | vim_free(p); |
| 5275 | } |
| 5276 | else |
| 5277 | fontname = p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5278 | } |
| 5279 | } |
| 5280 | |
| 5281 | if (response != GTK_RESPONSE_NONE) |
| 5282 | gtk_widget_destroy(dialog); |
| 5283 | |
| 5284 | return fontname; |
| 5285 | } |
| 5286 | |
| 5287 | /* |
| 5288 | * Some monospace fonts don't support a bold weight, and fall back |
| 5289 | * silently to the regular weight. But this is no good since our text |
| 5290 | * drawing function can emulate bold by overstriking. So let's try |
| 5291 | * to detect whether bold weight is actually available and emulate it |
| 5292 | * otherwise. |
| 5293 | * |
| 5294 | * Note that we don't need to check for italic style since Xft can |
| 5295 | * emulate italic on its own, provided you have a proper fontconfig |
| 5296 | * setup. We wouldn't be able to emulate it in Vim anyway. |
| 5297 | */ |
| 5298 | static void |
| 5299 | get_styled_font_variants(void) |
| 5300 | { |
| 5301 | PangoFontDescription *bold_font_desc; |
| 5302 | PangoFont *plain_font; |
| 5303 | PangoFont *bold_font; |
| 5304 | |
| 5305 | gui.font_can_bold = FALSE; |
| 5306 | |
| 5307 | plain_font = pango_context_load_font(gui.text_context, gui.norm_font); |
| 5308 | |
| 5309 | if (plain_font == NULL) |
| 5310 | return; |
| 5311 | |
| 5312 | bold_font_desc = pango_font_description_copy_static(gui.norm_font); |
| 5313 | pango_font_description_set_weight(bold_font_desc, PANGO_WEIGHT_BOLD); |
| 5314 | |
| 5315 | bold_font = pango_context_load_font(gui.text_context, bold_font_desc); |
| 5316 | /* |
| 5317 | * The comparison relies on the unique handle nature of a PangoFont*, |
| 5318 | * i.e. it's assumed that a different PangoFont* won't refer to the |
| 5319 | * same font. Seems to work, and failing here isn't critical anyway. |
| 5320 | */ |
| 5321 | if (bold_font != NULL) |
| 5322 | { |
| 5323 | gui.font_can_bold = (bold_font != plain_font); |
| 5324 | g_object_unref(bold_font); |
| 5325 | } |
| 5326 | |
| 5327 | pango_font_description_free(bold_font_desc); |
| 5328 | g_object_unref(plain_font); |
| 5329 | } |
| 5330 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5331 | static PangoEngineShape *default_shape_engine = NULL; |
| 5332 | |
| 5333 | /* |
| 5334 | * Create a map from ASCII characters in the range [32,126] to glyphs |
| 5335 | * of the current font. This is used by gui_gtk2_draw_string() to skip |
| 5336 | * the itemize and shaping process for the most common case. |
| 5337 | */ |
| 5338 | static void |
| 5339 | ascii_glyph_table_init(void) |
| 5340 | { |
Bram Moolenaar | 16350cb | 2016-08-14 20:27:34 +0200 | [diff] [blame] | 5341 | char_u ascii_chars[2 * 128]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5342 | PangoAttrList *attr_list; |
| 5343 | GList *item_list; |
| 5344 | int i; |
| 5345 | |
| 5346 | if (gui.ascii_glyphs != NULL) |
| 5347 | pango_glyph_string_free(gui.ascii_glyphs); |
| 5348 | if (gui.ascii_font != NULL) |
| 5349 | g_object_unref(gui.ascii_font); |
| 5350 | |
| 5351 | gui.ascii_glyphs = NULL; |
| 5352 | gui.ascii_font = NULL; |
| 5353 | |
Bram Moolenaar | 16350cb | 2016-08-14 20:27:34 +0200 | [diff] [blame] | 5354 | /* For safety, fill in question marks for the control characters. |
| 5355 | * Put a space between characters to avoid shaping. */ |
| 5356 | for (i = 0; i < 128; ++i) |
| 5357 | { |
| 5358 | if (i >= 32 && i < 127) |
| 5359 | ascii_chars[2 * i] = i; |
| 5360 | else |
| 5361 | ascii_chars[2 * i] = '?'; |
| 5362 | ascii_chars[2 * i + 1] = ' '; |
| 5363 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5364 | |
| 5365 | attr_list = pango_attr_list_new(); |
| 5366 | item_list = pango_itemize(gui.text_context, (const char *)ascii_chars, |
| 5367 | 0, sizeof(ascii_chars), attr_list, NULL); |
| 5368 | |
| 5369 | if (item_list != NULL && item_list->next == NULL) /* play safe */ |
| 5370 | { |
| 5371 | PangoItem *item; |
| 5372 | int width; |
| 5373 | |
| 5374 | item = (PangoItem *)item_list->data; |
| 5375 | width = gui.char_width * PANGO_SCALE; |
| 5376 | |
| 5377 | /* Remember the shape engine used for ASCII. */ |
| 5378 | default_shape_engine = item->analysis.shape_engine; |
| 5379 | |
| 5380 | gui.ascii_font = item->analysis.font; |
| 5381 | g_object_ref(gui.ascii_font); |
| 5382 | |
| 5383 | gui.ascii_glyphs = pango_glyph_string_new(); |
| 5384 | |
| 5385 | pango_shape((const char *)ascii_chars, sizeof(ascii_chars), |
| 5386 | &item->analysis, gui.ascii_glyphs); |
| 5387 | |
| 5388 | g_return_if_fail(gui.ascii_glyphs->num_glyphs == sizeof(ascii_chars)); |
| 5389 | |
| 5390 | for (i = 0; i < gui.ascii_glyphs->num_glyphs; ++i) |
| 5391 | { |
| 5392 | PangoGlyphGeometry *geom; |
| 5393 | |
| 5394 | geom = &gui.ascii_glyphs->glyphs[i].geometry; |
| 5395 | geom->x_offset += MAX(0, width - geom->width) / 2; |
| 5396 | geom->width = width; |
| 5397 | } |
| 5398 | } |
| 5399 | |
| 5400 | g_list_foreach(item_list, (GFunc)&pango_item_free, NULL); |
| 5401 | g_list_free(item_list); |
| 5402 | pango_attr_list_unref(attr_list); |
| 5403 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5404 | |
| 5405 | /* |
| 5406 | * Initialize Vim to use the font or fontset with the given name. |
| 5407 | * Return FAIL if the font could not be loaded, OK otherwise. |
| 5408 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5409 | int |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 5410 | gui_mch_init_font(char_u *font_name, int fontset UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5411 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5412 | PangoFontDescription *font_desc; |
| 5413 | PangoLayout *layout; |
| 5414 | int width; |
| 5415 | |
| 5416 | /* If font_name is NULL, this means to use the default, which should |
| 5417 | * be present on all proper Pango/fontconfig installations. */ |
| 5418 | if (font_name == NULL) |
| 5419 | font_name = (char_u *)DEFAULT_FONT; |
| 5420 | |
| 5421 | font_desc = gui_mch_get_font(font_name, FALSE); |
| 5422 | |
| 5423 | if (font_desc == NULL) |
| 5424 | return FAIL; |
| 5425 | |
| 5426 | gui_mch_free_font(gui.norm_font); |
| 5427 | gui.norm_font = font_desc; |
| 5428 | |
| 5429 | pango_context_set_font_description(gui.text_context, font_desc); |
| 5430 | |
| 5431 | layout = pango_layout_new(gui.text_context); |
| 5432 | pango_layout_set_text(layout, "MW", 2); |
| 5433 | pango_layout_get_size(layout, &width, NULL); |
| 5434 | /* |
| 5435 | * Set char_width to half the width obtained from pango_layout_get_size() |
| 5436 | * for CJK fixed_width/bi-width fonts. An unpatched version of Xft leads |
| 5437 | * Pango to use the same width for both non-CJK characters (e.g. Latin |
| 5438 | * letters and numbers) and CJK characters. This results in 's p a c e d |
| 5439 | * o u t' rendering when a CJK 'fixed width' font is used. To work around |
| 5440 | * that, divide the width returned by Pango by 2 if cjk_width is equal to |
| 5441 | * width for CJK fonts. |
| 5442 | * |
| 5443 | * For related bugs, see: |
| 5444 | * http://bugzilla.gnome.org/show_bug.cgi?id=106618 |
| 5445 | * http://bugzilla.gnome.org/show_bug.cgi?id=106624 |
| 5446 | * |
| 5447 | * With this, for all four of the following cases, Vim works fine: |
| 5448 | * guifont=CJK_fixed_width_font |
| 5449 | * guifont=Non_CJK_fixed_font |
| 5450 | * guifont=Non_CJK_fixed_font,CJK_Fixed_font |
| 5451 | * guifont=Non_CJK_fixed_font guifontwide=CJK_fixed_font |
| 5452 | */ |
| 5453 | if (is_cjk_font(gui.norm_font)) |
| 5454 | { |
| 5455 | int cjk_width; |
| 5456 | |
| 5457 | /* Measure the text extent of U+4E00 and U+4E8C */ |
| 5458 | pango_layout_set_text(layout, "\344\270\200\344\272\214", -1); |
| 5459 | pango_layout_get_size(layout, &cjk_width, NULL); |
| 5460 | |
| 5461 | if (width == cjk_width) /* Xft not patched */ |
| 5462 | width /= 2; |
| 5463 | } |
| 5464 | g_object_unref(layout); |
| 5465 | |
| 5466 | gui.char_width = (width / 2 + PANGO_SCALE - 1) / PANGO_SCALE; |
| 5467 | |
| 5468 | /* A zero width may cause a crash. Happens for semi-invalid fontsets. */ |
| 5469 | if (gui.char_width <= 0) |
| 5470 | gui.char_width = 8; |
| 5471 | |
Bram Moolenaar | 231334e | 2005-07-25 20:46:57 +0000 | [diff] [blame] | 5472 | gui_mch_adjust_charheight(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5473 | |
| 5474 | /* Set the fontname, which will be used for information purposes */ |
| 5475 | hl_set_font_name(font_name); |
| 5476 | |
| 5477 | get_styled_font_variants(); |
| 5478 | ascii_glyph_table_init(); |
| 5479 | |
| 5480 | /* Avoid unnecessary overhead if 'guifontwide' is equal to 'guifont'. */ |
| 5481 | if (gui.wide_font != NULL |
| 5482 | && pango_font_description_equal(gui.norm_font, gui.wide_font)) |
| 5483 | { |
| 5484 | pango_font_description_free(gui.wide_font); |
| 5485 | gui.wide_font = NULL; |
| 5486 | } |
| 5487 | |
Bram Moolenaar | e161c79 | 2009-11-03 17:13:59 +0000 | [diff] [blame] | 5488 | if (gui_mch_maximized()) |
| 5489 | { |
Bram Moolenaar | e161c79 | 2009-11-03 17:13:59 +0000 | [diff] [blame] | 5490 | /* Update lines and columns in accordance with the new font, keep the |
| 5491 | * window maximized. */ |
Bram Moolenaar | 12bc1b5 | 2011-08-10 17:44:45 +0200 | [diff] [blame] | 5492 | gui_mch_newfont(); |
Bram Moolenaar | e161c79 | 2009-11-03 17:13:59 +0000 | [diff] [blame] | 5493 | } |
| 5494 | else |
Bram Moolenaar | e161c79 | 2009-11-03 17:13:59 +0000 | [diff] [blame] | 5495 | { |
| 5496 | /* Preserve the logical dimensions of the screen. */ |
| 5497 | update_window_manager_hints(0, 0); |
| 5498 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5499 | |
| 5500 | return OK; |
| 5501 | } |
| 5502 | |
| 5503 | /* |
| 5504 | * Get a reference to the font "name". |
| 5505 | * Return zero for failure. |
| 5506 | */ |
| 5507 | GuiFont |
| 5508 | gui_mch_get_font(char_u *name, int report_error) |
| 5509 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5510 | PangoFontDescription *font; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5511 | |
| 5512 | /* can't do this when GUI is not running */ |
| 5513 | if (!gui.in_use || name == NULL) |
| 5514 | return NULL; |
| 5515 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5516 | if (output_conv.vc_type != CONV_NONE) |
| 5517 | { |
| 5518 | char_u *buf; |
| 5519 | |
| 5520 | buf = string_convert(&output_conv, name, NULL); |
| 5521 | if (buf != NULL) |
| 5522 | { |
| 5523 | font = pango_font_description_from_string((const char *)buf); |
| 5524 | vim_free(buf); |
| 5525 | } |
| 5526 | else |
| 5527 | font = NULL; |
| 5528 | } |
| 5529 | else |
| 5530 | font = pango_font_description_from_string((const char *)name); |
| 5531 | |
| 5532 | if (font != NULL) |
| 5533 | { |
| 5534 | PangoFont *real_font; |
| 5535 | |
| 5536 | /* pango_context_load_font() bails out if no font size is set */ |
| 5537 | if (pango_font_description_get_size(font) <= 0) |
| 5538 | pango_font_description_set_size(font, 10 * PANGO_SCALE); |
| 5539 | |
| 5540 | real_font = pango_context_load_font(gui.text_context, font); |
| 5541 | |
| 5542 | if (real_font == NULL) |
| 5543 | { |
| 5544 | pango_font_description_free(font); |
| 5545 | font = NULL; |
| 5546 | } |
| 5547 | else |
| 5548 | g_object_unref(real_font); |
| 5549 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5550 | |
| 5551 | if (font == NULL) |
| 5552 | { |
| 5553 | if (report_error) |
Bram Moolenaar | c93e791 | 2008-07-08 10:46:08 +0000 | [diff] [blame] | 5554 | EMSG2(_((char *)e_font), name); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5555 | return NULL; |
| 5556 | } |
| 5557 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5558 | return font; |
| 5559 | } |
| 5560 | |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5561 | #if defined(FEAT_EVAL) || defined(PROTO) |
Bram Moolenaar | 46c9c73 | 2004-12-12 11:37:09 +0000 | [diff] [blame] | 5562 | /* |
| 5563 | * Return the name of font "font" in allocated memory. |
| 5564 | */ |
Bram Moolenaar | 46c9c73 | 2004-12-12 11:37:09 +0000 | [diff] [blame] | 5565 | char_u * |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 5566 | gui_mch_get_fontname(GuiFont font, char_u *name UNUSED) |
Bram Moolenaar | 46c9c73 | 2004-12-12 11:37:09 +0000 | [diff] [blame] | 5567 | { |
Bram Moolenaar | 46c9c73 | 2004-12-12 11:37:09 +0000 | [diff] [blame] | 5568 | if (font != NOFONT) |
| 5569 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 5570 | char *pangoname = pango_font_description_to_string(font); |
Bram Moolenaar | 46c9c73 | 2004-12-12 11:37:09 +0000 | [diff] [blame] | 5571 | |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 5572 | if (pangoname != NULL) |
Bram Moolenaar | 46c9c73 | 2004-12-12 11:37:09 +0000 | [diff] [blame] | 5573 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 5574 | char_u *s = vim_strsave((char_u *)pangoname); |
Bram Moolenaar | 46c9c73 | 2004-12-12 11:37:09 +0000 | [diff] [blame] | 5575 | |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 5576 | g_free(pangoname); |
Bram Moolenaar | 46c9c73 | 2004-12-12 11:37:09 +0000 | [diff] [blame] | 5577 | return s; |
| 5578 | } |
| 5579 | } |
Bram Moolenaar | 46c9c73 | 2004-12-12 11:37:09 +0000 | [diff] [blame] | 5580 | return NULL; |
| 5581 | } |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5582 | #endif |
Bram Moolenaar | 46c9c73 | 2004-12-12 11:37:09 +0000 | [diff] [blame] | 5583 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5584 | /* |
| 5585 | * If a font is not going to be used, free its structure. |
| 5586 | */ |
| 5587 | void |
| 5588 | gui_mch_free_font(GuiFont font) |
| 5589 | { |
| 5590 | if (font != NOFONT) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5591 | pango_font_description_free(font); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5592 | } |
| 5593 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5594 | /* |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 5595 | * Return the Pixel value (color) for the given color name. |
| 5596 | * |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5597 | * Return INVALCOLOR for error. |
| 5598 | */ |
| 5599 | guicolor_T |
| 5600 | gui_mch_get_color(char_u *name) |
| 5601 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5602 | if (!gui.in_use) /* can't do this when GUI not running */ |
| 5603 | return INVALCOLOR; |
| 5604 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5605 | #if GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 5606 | return name != NULL ? gui_get_color_cmn(name) : INVALCOLOR; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5607 | #else |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 5608 | guicolor_T color; |
| 5609 | GdkColor gcolor; |
| 5610 | int ret; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5611 | |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 5612 | color = (name != NULL) ? gui_get_color_cmn(name) : INVALCOLOR; |
| 5613 | if (color == INVALCOLOR) |
| 5614 | return INVALCOLOR; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5615 | |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 5616 | gcolor.red = (guint16)(((color & 0xff0000) >> 16) / 255.0 * 65535 + 0.5); |
| 5617 | gcolor.green = (guint16)(((color & 0xff00) >> 8) / 255.0 * 65535 + 0.5); |
| 5618 | gcolor.blue = (guint16)((color & 0xff) / 255.0 * 65535 + 0.5); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5619 | |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 5620 | ret = gdk_colormap_alloc_color(gtk_widget_get_colormap(gui.drawarea), |
| 5621 | &gcolor, FALSE, TRUE); |
| 5622 | |
| 5623 | return ret != 0 ? (guicolor_T)gcolor.pixel : INVALCOLOR; |
| 5624 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5625 | } |
| 5626 | |
| 5627 | /* |
| 5628 | * Set the current text foreground color. |
| 5629 | */ |
| 5630 | void |
| 5631 | gui_mch_set_fg_color(guicolor_T color) |
| 5632 | { |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 5633 | #if GTK_CHECK_VERSION(3,0,0) |
| 5634 | *gui.fgcolor = color_to_rgba(color); |
| 5635 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5636 | gui.fgcolor->pixel = (unsigned long)color; |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 5637 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5638 | } |
| 5639 | |
| 5640 | /* |
| 5641 | * Set the current text background color. |
| 5642 | */ |
| 5643 | void |
| 5644 | gui_mch_set_bg_color(guicolor_T color) |
| 5645 | { |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 5646 | #if GTK_CHECK_VERSION(3,0,0) |
| 5647 | *gui.bgcolor = color_to_rgba(color); |
| 5648 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5649 | gui.bgcolor->pixel = (unsigned long)color; |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 5650 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5651 | } |
| 5652 | |
Bram Moolenaar | f36d369 | 2005-03-15 22:48:14 +0000 | [diff] [blame] | 5653 | /* |
| 5654 | * Set the current text special color. |
| 5655 | */ |
| 5656 | void |
| 5657 | gui_mch_set_sp_color(guicolor_T color) |
| 5658 | { |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 5659 | #if GTK_CHECK_VERSION(3,0,0) |
| 5660 | *gui.spcolor = color_to_rgba(color); |
| 5661 | #else |
Bram Moolenaar | f36d369 | 2005-03-15 22:48:14 +0000 | [diff] [blame] | 5662 | gui.spcolor->pixel = (unsigned long)color; |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 5663 | #endif |
Bram Moolenaar | f36d369 | 2005-03-15 22:48:14 +0000 | [diff] [blame] | 5664 | } |
| 5665 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5666 | /* |
| 5667 | * Function-like convenience macro for the sake of efficiency. |
| 5668 | */ |
| 5669 | #define INSERT_PANGO_ATTR(Attribute, AttrList, Start, End) \ |
| 5670 | G_STMT_START{ \ |
| 5671 | PangoAttribute *tmp_attr_; \ |
| 5672 | tmp_attr_ = (Attribute); \ |
| 5673 | tmp_attr_->start_index = (Start); \ |
| 5674 | tmp_attr_->end_index = (End); \ |
| 5675 | pango_attr_list_insert((AttrList), tmp_attr_); \ |
| 5676 | }G_STMT_END |
| 5677 | |
| 5678 | static void |
| 5679 | apply_wide_font_attr(char_u *s, int len, PangoAttrList *attr_list) |
| 5680 | { |
| 5681 | char_u *start = NULL; |
| 5682 | char_u *p; |
| 5683 | int uc; |
| 5684 | |
| 5685 | for (p = s; p < s + len; p += utf_byte2len(*p)) |
| 5686 | { |
| 5687 | uc = utf_ptr2char(p); |
| 5688 | |
| 5689 | if (start == NULL) |
| 5690 | { |
| 5691 | if (uc >= 0x80 && utf_char2cells(uc) == 2) |
| 5692 | start = p; |
| 5693 | } |
| 5694 | else if (uc < 0x80 /* optimization shortcut */ |
| 5695 | || (utf_char2cells(uc) != 2 && !utf_iscomposing(uc))) |
| 5696 | { |
| 5697 | INSERT_PANGO_ATTR(pango_attr_font_desc_new(gui.wide_font), |
| 5698 | attr_list, start - s, p - s); |
| 5699 | start = NULL; |
| 5700 | } |
| 5701 | } |
| 5702 | |
| 5703 | if (start != NULL) |
| 5704 | INSERT_PANGO_ATTR(pango_attr_font_desc_new(gui.wide_font), |
| 5705 | attr_list, start - s, len); |
| 5706 | } |
| 5707 | |
| 5708 | static int |
| 5709 | count_cluster_cells(char_u *s, PangoItem *item, |
| 5710 | PangoGlyphString* glyphs, int i, |
| 5711 | int *cluster_width, |
| 5712 | int *last_glyph_rbearing) |
| 5713 | { |
| 5714 | char_u *p; |
| 5715 | int next; /* glyph start index of next cluster */ |
| 5716 | int start, end; /* string segment of current cluster */ |
| 5717 | int width; /* real cluster width in Pango units */ |
| 5718 | int uc; |
| 5719 | int cellcount = 0; |
| 5720 | |
| 5721 | width = glyphs->glyphs[i].geometry.width; |
| 5722 | |
| 5723 | for (next = i + 1; next < glyphs->num_glyphs; ++next) |
| 5724 | { |
| 5725 | if (glyphs->glyphs[next].attr.is_cluster_start) |
| 5726 | break; |
| 5727 | else if (glyphs->glyphs[next].geometry.width > width) |
| 5728 | width = glyphs->glyphs[next].geometry.width; |
| 5729 | } |
| 5730 | |
| 5731 | start = item->offset + glyphs->log_clusters[i]; |
| 5732 | end = item->offset + ((next < glyphs->num_glyphs) ? |
| 5733 | glyphs->log_clusters[next] : item->length); |
| 5734 | |
| 5735 | for (p = s + start; p < s + end; p += utf_byte2len(*p)) |
| 5736 | { |
| 5737 | uc = utf_ptr2char(p); |
| 5738 | if (uc < 0x80) |
| 5739 | ++cellcount; |
| 5740 | else if (!utf_iscomposing(uc)) |
| 5741 | cellcount += utf_char2cells(uc); |
| 5742 | } |
| 5743 | |
| 5744 | if (last_glyph_rbearing != NULL |
| 5745 | && cellcount > 0 && next == glyphs->num_glyphs) |
| 5746 | { |
| 5747 | PangoRectangle ink_rect; |
| 5748 | /* |
| 5749 | * If a certain combining mark had to be taken from a non-monospace |
| 5750 | * font, we have to compensate manually by adapting x_offset according |
| 5751 | * to the ink extents of the previous glyph. |
| 5752 | */ |
| 5753 | pango_font_get_glyph_extents(item->analysis.font, |
| 5754 | glyphs->glyphs[i].glyph, |
| 5755 | &ink_rect, NULL); |
| 5756 | |
| 5757 | if (PANGO_RBEARING(ink_rect) > 0) |
| 5758 | *last_glyph_rbearing = PANGO_RBEARING(ink_rect); |
| 5759 | } |
| 5760 | |
| 5761 | if (cellcount > 0) |
| 5762 | *cluster_width = width; |
| 5763 | |
| 5764 | return cellcount; |
| 5765 | } |
| 5766 | |
| 5767 | /* |
| 5768 | * If there are only combining characters in the cluster, we cannot just |
| 5769 | * change the width of the previous glyph since there is none. Therefore |
| 5770 | * some guesswork is needed. |
| 5771 | * |
| 5772 | * If ink_rect.x is negative Pango apparently has taken care of the composing |
| 5773 | * by itself. Actually setting x_offset = 0 should be sufficient then, but due |
| 5774 | * to problems with composing from different fonts we still need to fine-tune |
Bram Moolenaar | 6440447 | 2010-06-26 06:24:45 +0200 | [diff] [blame] | 5775 | * x_offset to avoid ugliness. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5776 | * |
| 5777 | * If ink_rect.x is not negative, force overstriking by pointing x_offset to |
| 5778 | * the position of the previous glyph. Apparently this happens only with old |
| 5779 | * X fonts which don't provide the special combining information needed by |
| 5780 | * Pango. |
| 5781 | */ |
| 5782 | static void |
| 5783 | setup_zero_width_cluster(PangoItem *item, PangoGlyphInfo *glyph, |
| 5784 | int last_cellcount, int last_cluster_width, |
| 5785 | int last_glyph_rbearing) |
| 5786 | { |
| 5787 | PangoRectangle ink_rect; |
| 5788 | PangoRectangle logical_rect; |
| 5789 | int width; |
| 5790 | |
| 5791 | width = last_cellcount * gui.char_width * PANGO_SCALE; |
| 5792 | glyph->geometry.x_offset = -width + MAX(0, width - last_cluster_width) / 2; |
| 5793 | glyph->geometry.width = 0; |
| 5794 | |
| 5795 | pango_font_get_glyph_extents(item->analysis.font, |
| 5796 | glyph->glyph, |
| 5797 | &ink_rect, &logical_rect); |
| 5798 | if (ink_rect.x < 0) |
| 5799 | { |
| 5800 | glyph->geometry.x_offset += last_glyph_rbearing; |
| 5801 | glyph->geometry.y_offset = logical_rect.height |
| 5802 | - (gui.char_height - p_linespace) * PANGO_SCALE; |
| 5803 | } |
Bram Moolenaar | 706e84b | 2010-08-07 15:46:45 +0200 | [diff] [blame] | 5804 | else |
| 5805 | /* If the accent width is smaller than the cluster width, position it |
| 5806 | * in the middle. */ |
| 5807 | glyph->geometry.x_offset = -width + MAX(0, width - ink_rect.width) / 2; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5808 | } |
| 5809 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5810 | #if GTK_CHECK_VERSION(3,0,0) |
| 5811 | static void |
| 5812 | draw_glyph_string(int row, int col, int num_cells, int flags, |
| 5813 | PangoFont *font, PangoGlyphString *glyphs, |
| 5814 | cairo_t *cr) |
| 5815 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5816 | static void |
| 5817 | draw_glyph_string(int row, int col, int num_cells, int flags, |
| 5818 | PangoFont *font, PangoGlyphString *glyphs) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5819 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5820 | { |
| 5821 | if (!(flags & DRAW_TRANSP)) |
| 5822 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5823 | #if GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 5824 | cairo_set_source_rgba(cr, |
| 5825 | gui.bgcolor->red, gui.bgcolor->green, gui.bgcolor->blue, |
| 5826 | gui.bgcolor->alpha); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5827 | cairo_rectangle(cr, |
| 5828 | FILL_X(col), FILL_Y(row), |
| 5829 | num_cells * gui.char_width, gui.char_height); |
| 5830 | cairo_fill(cr); |
| 5831 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5832 | gdk_gc_set_foreground(gui.text_gc, gui.bgcolor); |
| 5833 | |
| 5834 | gdk_draw_rectangle(gui.drawarea->window, |
| 5835 | gui.text_gc, |
| 5836 | TRUE, |
| 5837 | FILL_X(col), |
| 5838 | FILL_Y(row), |
| 5839 | num_cells * gui.char_width, |
| 5840 | gui.char_height); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5841 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5842 | } |
| 5843 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5844 | #if GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 5845 | cairo_set_source_rgba(cr, |
| 5846 | gui.fgcolor->red, gui.fgcolor->green, gui.fgcolor->blue, |
| 5847 | gui.fgcolor->alpha); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5848 | cairo_move_to(cr, TEXT_X(col), TEXT_Y(row)); |
| 5849 | pango_cairo_show_glyph_string(cr, font, glyphs); |
| 5850 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5851 | gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
| 5852 | |
| 5853 | gdk_draw_glyphs(gui.drawarea->window, |
| 5854 | gui.text_gc, |
| 5855 | font, |
| 5856 | TEXT_X(col), |
| 5857 | TEXT_Y(row), |
| 5858 | glyphs); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5859 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5860 | |
| 5861 | /* redraw the contents with an offset of 1 to emulate bold */ |
| 5862 | if ((flags & DRAW_BOLD) && !gui.font_can_bold) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5863 | #if GTK_CHECK_VERSION(3,0,0) |
| 5864 | { |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 5865 | cairo_set_source_rgba(cr, |
| 5866 | gui.fgcolor->red, gui.fgcolor->green, gui.fgcolor->blue, |
| 5867 | gui.fgcolor->alpha); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5868 | cairo_move_to(cr, TEXT_X(col) + 1, TEXT_Y(row)); |
| 5869 | pango_cairo_show_glyph_string(cr, font, glyphs); |
| 5870 | } |
| 5871 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5872 | gdk_draw_glyphs(gui.drawarea->window, |
| 5873 | gui.text_gc, |
| 5874 | font, |
| 5875 | TEXT_X(col) + 1, |
| 5876 | TEXT_Y(row), |
| 5877 | glyphs); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5878 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5879 | } |
| 5880 | |
Bram Moolenaar | f36d369 | 2005-03-15 22:48:14 +0000 | [diff] [blame] | 5881 | /* |
| 5882 | * Draw underline and undercurl at the bottom of the character cell. |
| 5883 | */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5884 | #if GTK_CHECK_VERSION(3,0,0) |
| 5885 | static void |
| 5886 | draw_under(int flags, int row, int col, int cells, cairo_t *cr) |
| 5887 | #else |
Bram Moolenaar | f36d369 | 2005-03-15 22:48:14 +0000 | [diff] [blame] | 5888 | static void |
| 5889 | draw_under(int flags, int row, int col, int cells) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5890 | #endif |
Bram Moolenaar | f36d369 | 2005-03-15 22:48:14 +0000 | [diff] [blame] | 5891 | { |
| 5892 | int i; |
| 5893 | int offset; |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 5894 | static const int val[8] = {1, 0, 0, 0, 1, 2, 2, 2 }; |
Bram Moolenaar | f36d369 | 2005-03-15 22:48:14 +0000 | [diff] [blame] | 5895 | int y = FILL_Y(row + 1) - 1; |
| 5896 | |
| 5897 | /* Undercurl: draw curl at the bottom of the character cell. */ |
| 5898 | if (flags & DRAW_UNDERC) |
| 5899 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5900 | #if GTK_CHECK_VERSION(3,0,0) |
| 5901 | cairo_set_line_width(cr, 1.0); |
| 5902 | cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 5903 | cairo_set_source_rgba(cr, |
| 5904 | gui.spcolor->red, gui.spcolor->green, gui.spcolor->blue, |
| 5905 | gui.spcolor->alpha); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5906 | for (i = FILL_X(col); i < FILL_X(col + cells); ++i) |
| 5907 | { |
| 5908 | offset = val[i % 8]; |
| 5909 | cairo_line_to(cr, i, y - offset + 0.5); |
| 5910 | } |
| 5911 | cairo_stroke(cr); |
| 5912 | #else |
Bram Moolenaar | f36d369 | 2005-03-15 22:48:14 +0000 | [diff] [blame] | 5913 | gdk_gc_set_foreground(gui.text_gc, gui.spcolor); |
| 5914 | for (i = FILL_X(col); i < FILL_X(col + cells); ++i) |
| 5915 | { |
| 5916 | offset = val[i % 8]; |
| 5917 | gdk_draw_point(gui.drawarea->window, gui.text_gc, i, y - offset); |
| 5918 | } |
| 5919 | gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5920 | #endif |
Bram Moolenaar | f36d369 | 2005-03-15 22:48:14 +0000 | [diff] [blame] | 5921 | } |
| 5922 | |
| 5923 | /* Underline: draw a line at the bottom of the character cell. */ |
| 5924 | if (flags & DRAW_UNDERL) |
| 5925 | { |
| 5926 | /* When p_linespace is 0, overwrite the bottom row of pixels. |
| 5927 | * Otherwise put the line just below the character. */ |
| 5928 | if (p_linespace > 1) |
| 5929 | y -= p_linespace - 1; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5930 | #if GTK_CHECK_VERSION(3,0,0) |
| 5931 | { |
| 5932 | cairo_set_line_width(cr, 1.0); |
| 5933 | cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 5934 | cairo_set_source_rgba(cr, |
| 5935 | gui.fgcolor->red, gui.fgcolor->green, gui.fgcolor->blue, |
| 5936 | gui.fgcolor->alpha); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5937 | cairo_move_to(cr, FILL_X(col), y + 0.5); |
| 5938 | cairo_line_to(cr, FILL_X(col + cells), y + 0.5); |
| 5939 | cairo_stroke(cr); |
| 5940 | } |
| 5941 | #else |
Bram Moolenaar | f36d369 | 2005-03-15 22:48:14 +0000 | [diff] [blame] | 5942 | gdk_draw_line(gui.drawarea->window, gui.text_gc, |
| 5943 | FILL_X(col), y, |
| 5944 | FILL_X(col + cells) - 1, y); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5945 | #endif |
Bram Moolenaar | f36d369 | 2005-03-15 22:48:14 +0000 | [diff] [blame] | 5946 | } |
| 5947 | } |
| 5948 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5949 | int |
| 5950 | gui_gtk2_draw_string(int row, int col, char_u *s, int len, int flags) |
| 5951 | { |
| 5952 | GdkRectangle area; /* area for clip mask */ |
| 5953 | PangoGlyphString *glyphs; /* glyphs of current item */ |
| 5954 | int column_offset = 0; /* column offset in cells */ |
| 5955 | int i; |
| 5956 | char_u *conv_buf = NULL; /* result of UTF-8 conversion */ |
| 5957 | char_u *new_conv_buf; |
| 5958 | int convlen; |
| 5959 | char_u *sp, *bp; |
| 5960 | int plen; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5961 | #if GTK_CHECK_VERSION(3,0,0) |
| 5962 | cairo_t *cr; |
| 5963 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5964 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5965 | #if GTK_CHECK_VERSION(3,0,0) |
| 5966 | if (gui.text_context == NULL || gtk_widget_get_window(gui.drawarea) == NULL) |
| 5967 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5968 | if (gui.text_context == NULL || gui.drawarea->window == NULL) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 5969 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5970 | return len; |
| 5971 | |
| 5972 | if (output_conv.vc_type != CONV_NONE) |
| 5973 | { |
| 5974 | /* |
| 5975 | * Convert characters from 'encoding' to 'termencoding', which is set |
| 5976 | * to UTF-8 by gui_mch_init(). did_set_string_option() in option.c |
| 5977 | * prohibits changing this to something else than UTF-8 if the GUI is |
| 5978 | * in use. |
| 5979 | */ |
| 5980 | convlen = len; |
| 5981 | conv_buf = string_convert(&output_conv, s, &convlen); |
| 5982 | g_return_val_if_fail(conv_buf != NULL, len); |
| 5983 | |
| 5984 | /* Correct for differences in char width: some chars are |
| 5985 | * double-wide in 'encoding' but single-wide in utf-8. Add a space to |
| 5986 | * compensate for that. */ |
| 5987 | for (sp = s, bp = conv_buf; sp < s + len && bp < conv_buf + convlen; ) |
| 5988 | { |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5989 | plen = utf_ptr2len(bp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5990 | if ((*mb_ptr2cells)(sp) == 2 && utf_ptr2cells(bp) == 1) |
| 5991 | { |
| 5992 | new_conv_buf = alloc(convlen + 2); |
| 5993 | if (new_conv_buf == NULL) |
| 5994 | return len; |
| 5995 | plen += bp - conv_buf; |
| 5996 | mch_memmove(new_conv_buf, conv_buf, plen); |
| 5997 | new_conv_buf[plen] = ' '; |
| 5998 | mch_memmove(new_conv_buf + plen + 1, conv_buf + plen, |
| 5999 | convlen - plen + 1); |
| 6000 | vim_free(conv_buf); |
| 6001 | conv_buf = new_conv_buf; |
| 6002 | ++convlen; |
| 6003 | bp = conv_buf + plen; |
| 6004 | plen = 1; |
| 6005 | } |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6006 | sp += (*mb_ptr2len)(sp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6007 | bp += plen; |
| 6008 | } |
| 6009 | s = conv_buf; |
| 6010 | len = convlen; |
| 6011 | } |
| 6012 | |
| 6013 | /* |
| 6014 | * Restrict all drawing to the current screen line in order to prevent |
| 6015 | * fuzzy font lookups from messing up the screen. |
| 6016 | */ |
| 6017 | area.x = gui.border_offset; |
| 6018 | area.y = FILL_Y(row); |
| 6019 | area.width = gui.num_cols * gui.char_width; |
| 6020 | area.height = gui.char_height; |
| 6021 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6022 | #if GTK_CHECK_VERSION(3,0,0) |
| 6023 | cr = cairo_create(gui.surface); |
| 6024 | cairo_rectangle(cr, area.x, area.y, area.width, area.height); |
| 6025 | cairo_clip(cr); |
| 6026 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6027 | gdk_gc_set_clip_origin(gui.text_gc, 0, 0); |
| 6028 | gdk_gc_set_clip_rectangle(gui.text_gc, &area); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6029 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6030 | |
| 6031 | glyphs = pango_glyph_string_new(); |
| 6032 | |
| 6033 | /* |
| 6034 | * Optimization hack: If possible, skip the itemize and shaping process |
| 6035 | * for pure ASCII strings. This optimization is particularly effective |
| 6036 | * because Vim draws space characters to clear parts of the screen. |
| 6037 | */ |
| 6038 | if (!(flags & DRAW_ITALIC) |
| 6039 | && !((flags & DRAW_BOLD) && gui.font_can_bold) |
| 6040 | && gui.ascii_glyphs != NULL) |
| 6041 | { |
| 6042 | char_u *p; |
| 6043 | |
| 6044 | for (p = s; p < s + len; ++p) |
| 6045 | if (*p & 0x80) |
| 6046 | goto not_ascii; |
| 6047 | |
| 6048 | pango_glyph_string_set_size(glyphs, len); |
| 6049 | |
| 6050 | for (i = 0; i < len; ++i) |
| 6051 | { |
Bram Moolenaar | 16350cb | 2016-08-14 20:27:34 +0200 | [diff] [blame] | 6052 | glyphs->glyphs[i] = gui.ascii_glyphs->glyphs[2 * s[i]]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6053 | glyphs->log_clusters[i] = i; |
| 6054 | } |
| 6055 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6056 | #if GTK_CHECK_VERSION(3,0,0) |
| 6057 | draw_glyph_string(row, col, len, flags, gui.ascii_font, glyphs, cr); |
| 6058 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6059 | draw_glyph_string(row, col, len, flags, gui.ascii_font, glyphs); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6060 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6061 | |
| 6062 | column_offset = len; |
| 6063 | } |
| 6064 | else |
| 6065 | not_ascii: |
| 6066 | { |
| 6067 | PangoAttrList *attr_list; |
| 6068 | GList *item_list; |
| 6069 | int cluster_width; |
| 6070 | int last_glyph_rbearing; |
| 6071 | int cells = 0; /* cells occupied by current cluster */ |
| 6072 | |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 6073 | /* Safety check: pango crashes when invoked with invalid utf-8 |
| 6074 | * characters. */ |
| 6075 | if (!utf_valid_string(s, s + len)) |
| 6076 | { |
| 6077 | column_offset = len; |
| 6078 | goto skipitall; |
| 6079 | } |
| 6080 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6081 | /* original width of the current cluster */ |
| 6082 | cluster_width = PANGO_SCALE * gui.char_width; |
| 6083 | |
| 6084 | /* right bearing of the last non-composing glyph */ |
| 6085 | last_glyph_rbearing = PANGO_SCALE * gui.char_width; |
| 6086 | |
| 6087 | attr_list = pango_attr_list_new(); |
| 6088 | |
| 6089 | /* If 'guifontwide' is set then use that for double-width characters. |
| 6090 | * Otherwise just go with 'guifont' and let Pango do its thing. */ |
| 6091 | if (gui.wide_font != NULL) |
| 6092 | apply_wide_font_attr(s, len, attr_list); |
| 6093 | |
| 6094 | if ((flags & DRAW_BOLD) && gui.font_can_bold) |
| 6095 | INSERT_PANGO_ATTR(pango_attr_weight_new(PANGO_WEIGHT_BOLD), |
| 6096 | attr_list, 0, len); |
| 6097 | if (flags & DRAW_ITALIC) |
| 6098 | INSERT_PANGO_ATTR(pango_attr_style_new(PANGO_STYLE_ITALIC), |
| 6099 | attr_list, 0, len); |
| 6100 | /* |
| 6101 | * Break the text into segments with consistent directional level |
| 6102 | * and shaping engine. Pure Latin text needs only a single segment, |
| 6103 | * so there's no need to worry about the loop's efficiency. Better |
| 6104 | * try to optimize elsewhere, e.g. reducing exposes and stuff :) |
| 6105 | */ |
| 6106 | item_list = pango_itemize(gui.text_context, |
| 6107 | (const char *)s, 0, len, attr_list, NULL); |
| 6108 | |
| 6109 | while (item_list != NULL) |
| 6110 | { |
| 6111 | PangoItem *item; |
| 6112 | int item_cells = 0; /* item length in cells */ |
| 6113 | |
| 6114 | item = (PangoItem *)item_list->data; |
| 6115 | item_list = g_list_delete_link(item_list, item_list); |
| 6116 | /* |
| 6117 | * Increment the bidirectional embedding level by 1 if it is not |
| 6118 | * even. An odd number means the output will be RTL, but we don't |
| 6119 | * want that since Vim handles right-to-left text on its own. It |
| 6120 | * would probably be sufficient to just set level = 0, but you can |
| 6121 | * never know :) |
| 6122 | * |
| 6123 | * Unfortunately we can't take advantage of Pango's ability to |
| 6124 | * render both LTR and RTL at the same time. In order to support |
| 6125 | * that, Vim's main screen engine would have to make use of Pango |
| 6126 | * functionality. |
| 6127 | */ |
| 6128 | item->analysis.level = (item->analysis.level + 1) & (~1U); |
| 6129 | |
| 6130 | /* HACK: Overrule the shape engine, we don't want shaping to be |
| 6131 | * done, because drawing the cursor would change the display. */ |
| 6132 | item->analysis.shape_engine = default_shape_engine; |
| 6133 | |
Bram Moolenaar | 3cbe0c0 | 2015-09-08 20:00:22 +0200 | [diff] [blame] | 6134 | #ifdef HAVE_PANGO_SHAPE_FULL |
Bram Moolenaar | 7e2ec00 | 2015-09-08 16:31:06 +0200 | [diff] [blame] | 6135 | pango_shape_full((const char *)s + item->offset, item->length, |
| 6136 | (const char *)s, len, &item->analysis, glyphs); |
Bram Moolenaar | 3cbe0c0 | 2015-09-08 20:00:22 +0200 | [diff] [blame] | 6137 | #else |
| 6138 | pango_shape((const char *)s + item->offset, item->length, |
| 6139 | &item->analysis, glyphs); |
| 6140 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6141 | /* |
| 6142 | * Fixed-width hack: iterate over the array and assign a fixed |
| 6143 | * width to each glyph, thus overriding the choice made by the |
| 6144 | * shaping engine. We use utf_char2cells() to determine the |
| 6145 | * number of cells needed. |
| 6146 | * |
| 6147 | * Also perform all kind of dark magic to get composing |
| 6148 | * characters right (and pretty too of course). |
| 6149 | */ |
| 6150 | for (i = 0; i < glyphs->num_glyphs; ++i) |
| 6151 | { |
| 6152 | PangoGlyphInfo *glyph; |
| 6153 | |
| 6154 | glyph = &glyphs->glyphs[i]; |
| 6155 | |
| 6156 | if (glyph->attr.is_cluster_start) |
| 6157 | { |
| 6158 | int cellcount; |
| 6159 | |
| 6160 | cellcount = count_cluster_cells( |
| 6161 | s, item, glyphs, i, &cluster_width, |
| 6162 | (item_list != NULL) ? &last_glyph_rbearing : NULL); |
| 6163 | |
| 6164 | if (cellcount > 0) |
| 6165 | { |
| 6166 | int width; |
| 6167 | |
| 6168 | width = cellcount * gui.char_width * PANGO_SCALE; |
| 6169 | glyph->geometry.x_offset += |
| 6170 | MAX(0, width - cluster_width) / 2; |
| 6171 | glyph->geometry.width = width; |
| 6172 | } |
| 6173 | else |
| 6174 | { |
| 6175 | /* If there are only combining characters in the |
| 6176 | * cluster, we cannot just change the width of the |
| 6177 | * previous glyph since there is none. Therefore |
| 6178 | * some guesswork is needed. */ |
| 6179 | setup_zero_width_cluster(item, glyph, cells, |
| 6180 | cluster_width, |
| 6181 | last_glyph_rbearing); |
| 6182 | } |
| 6183 | |
| 6184 | item_cells += cellcount; |
| 6185 | cells = cellcount; |
| 6186 | } |
| 6187 | else if (i > 0) |
| 6188 | { |
| 6189 | int width; |
| 6190 | |
| 6191 | /* There is a previous glyph, so we deal with combining |
Bram Moolenaar | 706e84b | 2010-08-07 15:46:45 +0200 | [diff] [blame] | 6192 | * characters the canonical way. |
Bram Moolenaar | 96118f3 | 2010-08-08 14:40:37 +0200 | [diff] [blame] | 6193 | * In some circumstances Pango uses a positive x_offset, |
| 6194 | * then use the width of the previous glyph for this one |
| 6195 | * and set the previous width to zero. |
| 6196 | * Otherwise we get a negative x_offset, Pango has already |
| 6197 | * positioned the combining char, keep the widths as they |
| 6198 | * are. |
Bram Moolenaar | 706e84b | 2010-08-07 15:46:45 +0200 | [diff] [blame] | 6199 | * For both adjust the x_offset to position the glyph in |
Bram Moolenaar | 96118f3 | 2010-08-08 14:40:37 +0200 | [diff] [blame] | 6200 | * the middle. */ |
Bram Moolenaar | 706e84b | 2010-08-07 15:46:45 +0200 | [diff] [blame] | 6201 | if (glyph->geometry.x_offset >= 0) |
Bram Moolenaar | 96118f3 | 2010-08-08 14:40:37 +0200 | [diff] [blame] | 6202 | { |
| 6203 | glyphs->glyphs[i].geometry.width = |
| 6204 | glyphs->glyphs[i - 1].geometry.width; |
Bram Moolenaar | 706e84b | 2010-08-07 15:46:45 +0200 | [diff] [blame] | 6205 | glyphs->glyphs[i - 1].geometry.width = 0; |
Bram Moolenaar | 96118f3 | 2010-08-08 14:40:37 +0200 | [diff] [blame] | 6206 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6207 | width = cells * gui.char_width * PANGO_SCALE; |
| 6208 | glyph->geometry.x_offset += |
| 6209 | MAX(0, width - cluster_width) / 2; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6210 | } |
| 6211 | else /* i == 0 "cannot happen" */ |
| 6212 | { |
| 6213 | glyph->geometry.width = 0; |
| 6214 | } |
| 6215 | } |
| 6216 | |
| 6217 | /*** Aaaaand action! ***/ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6218 | #if GTK_CHECK_VERSION(3,0,0) |
| 6219 | draw_glyph_string(row, col + column_offset, item_cells, |
| 6220 | flags, item->analysis.font, glyphs, |
| 6221 | cr); |
| 6222 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6223 | draw_glyph_string(row, col + column_offset, item_cells, |
| 6224 | flags, item->analysis.font, glyphs); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6225 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6226 | |
| 6227 | pango_item_free(item); |
| 6228 | |
| 6229 | column_offset += item_cells; |
| 6230 | } |
| 6231 | |
| 6232 | pango_attr_list_unref(attr_list); |
| 6233 | } |
| 6234 | |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 6235 | skipitall: |
Bram Moolenaar | f36d369 | 2005-03-15 22:48:14 +0000 | [diff] [blame] | 6236 | /* Draw underline and undercurl. */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6237 | #if GTK_CHECK_VERSION(3,0,0) |
| 6238 | draw_under(flags, row, col, column_offset, cr); |
| 6239 | #else |
Bram Moolenaar | f36d369 | 2005-03-15 22:48:14 +0000 | [diff] [blame] | 6240 | draw_under(flags, row, col, column_offset); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6241 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6242 | |
| 6243 | pango_glyph_string_free(glyphs); |
| 6244 | vim_free(conv_buf); |
| 6245 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6246 | #if GTK_CHECK_VERSION(3,0,0) |
| 6247 | cairo_destroy(cr); |
| 6248 | if (!gui.by_signal) |
| 6249 | gdk_window_invalidate_rect(gtk_widget_get_window(gui.drawarea), |
| 6250 | &area, FALSE); |
| 6251 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6252 | gdk_gc_set_clip_rectangle(gui.text_gc, NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6253 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6254 | |
| 6255 | return column_offset; |
| 6256 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6257 | |
| 6258 | /* |
| 6259 | * Return OK if the key with the termcap name "name" is supported. |
| 6260 | */ |
| 6261 | int |
| 6262 | gui_mch_haskey(char_u *name) |
| 6263 | { |
| 6264 | int i; |
| 6265 | |
| 6266 | for (i = 0; special_keys[i].key_sym != 0; i++) |
| 6267 | if (name[0] == special_keys[i].code0 |
| 6268 | && name[1] == special_keys[i].code1) |
| 6269 | return OK; |
| 6270 | return FAIL; |
| 6271 | } |
| 6272 | |
Bram Moolenaar | b2c5a5a | 2013-02-14 22:11:39 +0100 | [diff] [blame] | 6273 | #if defined(FEAT_TITLE) || defined(FEAT_EVAL) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6274 | /* |
| 6275 | * Return the text window-id and display. Only required for X-based GUI's |
| 6276 | */ |
| 6277 | int |
| 6278 | gui_get_x11_windis(Window *win, Display **dis) |
| 6279 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6280 | #if GTK_CHECK_VERSION(3,0,0) |
| 6281 | if (gui.mainwin != NULL && gtk_widget_get_window(gui.mainwin) != NULL) |
| 6282 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6283 | if (gui.mainwin != NULL && gui.mainwin->window != NULL) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6284 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6285 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6286 | #if GTK_CHECK_VERSION(3,0,0) |
| 6287 | *dis = GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.mainwin)); |
| 6288 | *win = GDK_WINDOW_XID(gtk_widget_get_window(gui.mainwin)); |
| 6289 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6290 | *dis = GDK_WINDOW_XDISPLAY(gui.mainwin->window); |
| 6291 | *win = GDK_WINDOW_XWINDOW(gui.mainwin->window); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6292 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6293 | return OK; |
| 6294 | } |
| 6295 | |
| 6296 | *dis = NULL; |
| 6297 | *win = 0; |
| 6298 | return FAIL; |
| 6299 | } |
| 6300 | #endif |
| 6301 | |
| 6302 | #if defined(FEAT_CLIENTSERVER) \ |
| 6303 | || (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO) |
| 6304 | |
| 6305 | Display * |
| 6306 | gui_mch_get_display(void) |
| 6307 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6308 | #if GTK_CHECK_VERSION(3,0,0) |
| 6309 | if (gui.mainwin != NULL && gtk_widget_get_window(gui.mainwin) != NULL) |
| 6310 | return GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.mainwin)); |
| 6311 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6312 | if (gui.mainwin != NULL && gui.mainwin->window != NULL) |
| 6313 | return GDK_WINDOW_XDISPLAY(gui.mainwin->window); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6314 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6315 | else |
| 6316 | return NULL; |
| 6317 | } |
| 6318 | #endif |
| 6319 | |
| 6320 | void |
| 6321 | gui_mch_beep(void) |
| 6322 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6323 | GdkDisplay *display; |
| 6324 | |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 6325 | #if GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6326 | if (gui.mainwin != NULL && gtk_widget_get_realized(gui.mainwin)) |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 6327 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6328 | if (gui.mainwin != NULL && GTK_WIDGET_REALIZED(gui.mainwin)) |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 6329 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6330 | display = gtk_widget_get_display(gui.mainwin); |
| 6331 | else |
| 6332 | display = gdk_display_get_default(); |
| 6333 | |
| 6334 | if (display != NULL) |
| 6335 | gdk_display_beep(display); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6336 | } |
| 6337 | |
| 6338 | void |
| 6339 | gui_mch_flash(int msec) |
| 6340 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6341 | #if GTK_CHECK_VERSION(3,0,0) |
| 6342 | /* TODO Replace GdkGC with Cairo */ |
| 6343 | (void)msec; |
| 6344 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6345 | GdkGCValues values; |
| 6346 | GdkGC *invert_gc; |
| 6347 | |
| 6348 | if (gui.drawarea->window == NULL) |
| 6349 | return; |
| 6350 | |
| 6351 | values.foreground.pixel = gui.norm_pixel ^ gui.back_pixel; |
| 6352 | values.background.pixel = gui.norm_pixel ^ gui.back_pixel; |
| 6353 | values.function = GDK_XOR; |
| 6354 | invert_gc = gdk_gc_new_with_values(gui.drawarea->window, |
| 6355 | &values, |
| 6356 | GDK_GC_FOREGROUND | |
| 6357 | GDK_GC_BACKGROUND | |
| 6358 | GDK_GC_FUNCTION); |
| 6359 | gdk_gc_set_exposures(invert_gc, |
| 6360 | gui.visibility != GDK_VISIBILITY_UNOBSCURED); |
| 6361 | /* |
| 6362 | * Do a visual beep by changing back and forth in some undetermined way, |
| 6363 | * the foreground and background colors. This is due to the fact that |
| 6364 | * there can't be really any prediction about the effects of XOR on |
| 6365 | * arbitrary X11 servers. However this seems to be enough for what we |
| 6366 | * intend it to do. |
| 6367 | */ |
| 6368 | gdk_draw_rectangle(gui.drawarea->window, invert_gc, |
| 6369 | TRUE, |
| 6370 | 0, 0, |
| 6371 | FILL_X((int)Columns) + gui.border_offset, |
| 6372 | FILL_Y((int)Rows) + gui.border_offset); |
| 6373 | |
| 6374 | gui_mch_flush(); |
| 6375 | ui_delay((long)msec, TRUE); /* wait so many msec */ |
| 6376 | |
| 6377 | gdk_draw_rectangle(gui.drawarea->window, invert_gc, |
| 6378 | TRUE, |
| 6379 | 0, 0, |
| 6380 | FILL_X((int)Columns) + gui.border_offset, |
| 6381 | FILL_Y((int)Rows) + gui.border_offset); |
| 6382 | |
| 6383 | gdk_gc_destroy(invert_gc); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6384 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6385 | } |
| 6386 | |
| 6387 | /* |
| 6388 | * Invert a rectangle from row r, column c, for nr rows and nc columns. |
| 6389 | */ |
| 6390 | void |
| 6391 | gui_mch_invert_rectangle(int r, int c, int nr, int nc) |
| 6392 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6393 | #if GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 4fc563b | 2016-03-12 12:40:58 +0100 | [diff] [blame] | 6394 | const GdkRectangle rect = { |
| 6395 | FILL_X(c), FILL_Y(r), nc * gui.char_width, nr * gui.char_height |
| 6396 | }; |
| 6397 | cairo_t * const cr = cairo_create(gui.surface); |
| 6398 | |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 6399 | set_cairo_source_rgba_from_color(cr, gui.norm_pixel ^ gui.back_pixel); |
Bram Moolenaar | 4fc563b | 2016-03-12 12:40:58 +0100 | [diff] [blame] | 6400 | # if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,9,2) |
| 6401 | cairo_set_operator(cr, CAIRO_OPERATOR_DIFFERENCE); |
| 6402 | # else |
| 6403 | /* Give an implementation for older cairo versions if necessary. */ |
| 6404 | # endif |
| 6405 | gdk_cairo_rectangle(cr, &rect); |
| 6406 | cairo_fill(cr); |
| 6407 | |
| 6408 | cairo_destroy(cr); |
| 6409 | |
| 6410 | if (!gui.by_signal) |
| 6411 | gtk_widget_queue_draw_area(gui.drawarea, rect.x, rect.y, |
| 6412 | rect.width, rect.height); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6413 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6414 | GdkGCValues values; |
| 6415 | GdkGC *invert_gc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6416 | |
| 6417 | if (gui.drawarea->window == NULL) |
| 6418 | return; |
| 6419 | |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 6420 | values.foreground.pixel = gui.norm_pixel ^ gui.back_pixel; |
| 6421 | values.background.pixel = gui.norm_pixel ^ gui.back_pixel; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6422 | values.function = GDK_XOR; |
| 6423 | invert_gc = gdk_gc_new_with_values(gui.drawarea->window, |
| 6424 | &values, |
| 6425 | GDK_GC_FOREGROUND | |
| 6426 | GDK_GC_BACKGROUND | |
| 6427 | GDK_GC_FUNCTION); |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 6428 | gdk_gc_set_exposures(invert_gc, gui.visibility != |
| 6429 | GDK_VISIBILITY_UNOBSCURED); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6430 | gdk_draw_rectangle(gui.drawarea->window, invert_gc, |
| 6431 | TRUE, |
| 6432 | FILL_X(c), FILL_Y(r), |
| 6433 | (nc) * gui.char_width, (nr) * gui.char_height); |
| 6434 | gdk_gc_destroy(invert_gc); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6435 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6436 | } |
| 6437 | |
| 6438 | /* |
| 6439 | * Iconify the GUI window. |
| 6440 | */ |
| 6441 | void |
| 6442 | gui_mch_iconify(void) |
| 6443 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6444 | gtk_window_iconify(GTK_WINDOW(gui.mainwin)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6445 | } |
| 6446 | |
| 6447 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 6448 | /* |
| 6449 | * Bring the Vim window to the foreground. |
| 6450 | */ |
| 6451 | void |
| 6452 | gui_mch_set_foreground(void) |
| 6453 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6454 | gtk_window_present(GTK_WINDOW(gui.mainwin)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6455 | } |
| 6456 | #endif |
| 6457 | |
| 6458 | /* |
| 6459 | * Draw a cursor without focus. |
| 6460 | */ |
| 6461 | void |
| 6462 | gui_mch_draw_hollow_cursor(guicolor_T color) |
| 6463 | { |
| 6464 | int i = 1; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6465 | #if GTK_CHECK_VERSION(3,0,0) |
| 6466 | cairo_t *cr; |
| 6467 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6468 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6469 | #if GTK_CHECK_VERSION(3,0,0) |
| 6470 | if (gtk_widget_get_window(gui.drawarea) == NULL) |
| 6471 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6472 | if (gui.drawarea->window == NULL) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6473 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6474 | return; |
| 6475 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6476 | #if GTK_CHECK_VERSION(3,0,0) |
| 6477 | cr = cairo_create(gui.surface); |
| 6478 | #endif |
| 6479 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6480 | gui_mch_set_fg_color(color); |
| 6481 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6482 | #if GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 6483 | cairo_set_source_rgba(cr, |
| 6484 | gui.fgcolor->red, gui.fgcolor->green, gui.fgcolor->blue, |
| 6485 | gui.fgcolor->alpha); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6486 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6487 | gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6488 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6489 | if (mb_lefthalve(gui.row, gui.col)) |
| 6490 | i = 2; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6491 | #if GTK_CHECK_VERSION(3,0,0) |
| 6492 | cairo_set_line_width(cr, 1.0); |
| 6493 | cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); |
| 6494 | cairo_rectangle(cr, |
| 6495 | FILL_X(gui.col) + 0.5, FILL_Y(gui.row) + 0.5, |
| 6496 | i * gui.char_width - 1, gui.char_height - 1); |
| 6497 | cairo_stroke(cr); |
| 6498 | cairo_destroy(cr); |
| 6499 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6500 | gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, |
| 6501 | FALSE, |
| 6502 | FILL_X(gui.col), FILL_Y(gui.row), |
| 6503 | i * gui.char_width - 1, gui.char_height - 1); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6504 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6505 | } |
| 6506 | |
| 6507 | /* |
| 6508 | * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using |
| 6509 | * color "color". |
| 6510 | */ |
| 6511 | void |
| 6512 | gui_mch_draw_part_cursor(int w, int h, guicolor_T color) |
| 6513 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6514 | #if GTK_CHECK_VERSION(3,0,0) |
| 6515 | if (gtk_widget_get_window(gui.drawarea) == NULL) |
| 6516 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6517 | if (gui.drawarea->window == NULL) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6518 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6519 | return; |
| 6520 | |
| 6521 | gui_mch_set_fg_color(color); |
| 6522 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6523 | #if GTK_CHECK_VERSION(3,0,0) |
| 6524 | { |
| 6525 | cairo_t *cr; |
| 6526 | |
| 6527 | cr = cairo_create(gui.surface); |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 6528 | cairo_set_source_rgba(cr, |
| 6529 | gui.fgcolor->red, gui.fgcolor->green, gui.fgcolor->blue, |
| 6530 | gui.fgcolor->alpha); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6531 | cairo_rectangle(cr, |
| 6532 | # ifdef FEAT_RIGHTLEFT |
| 6533 | /* vertical line should be on the right of current point */ |
| 6534 | CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w : |
| 6535 | # endif |
| 6536 | FILL_X(gui.col), FILL_Y(gui.row) + gui.char_height - h, |
| 6537 | w, h); |
| 6538 | cairo_fill(cr); |
| 6539 | cairo_destroy(cr); |
| 6540 | } |
| 6541 | #else /* !GTK_CHECK_VERSION(3,0,0) */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6542 | gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
| 6543 | gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, |
| 6544 | TRUE, |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6545 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6546 | /* vertical line should be on the right of current point */ |
| 6547 | CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w : |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6548 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6549 | FILL_X(gui.col), |
| 6550 | FILL_Y(gui.row) + gui.char_height - h, |
| 6551 | w, h); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6552 | #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6553 | } |
| 6554 | |
| 6555 | |
| 6556 | /* |
| 6557 | * Catch up with any queued X11 events. This may put keyboard input into the |
| 6558 | * input buffer, call resize call-backs, trigger timers etc. If there is |
| 6559 | * nothing in the X11 event queue (& no timers pending), then we return |
| 6560 | * immediately. |
| 6561 | */ |
| 6562 | void |
| 6563 | gui_mch_update(void) |
| 6564 | { |
Bram Moolenaar | a3f4166 | 2010-07-11 19:01:06 +0200 | [diff] [blame] | 6565 | while (g_main_context_pending(NULL) && !vim_is_input_buf_full()) |
| 6566 | g_main_context_iteration(NULL, TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6567 | } |
| 6568 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6569 | #if GTK_CHECK_VERSION(3,0,0) |
| 6570 | static gboolean |
| 6571 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6572 | static gint |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6573 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6574 | input_timer_cb(gpointer data) |
| 6575 | { |
| 6576 | int *timed_out = (int *) data; |
| 6577 | |
Bram Moolenaar | 4932594 | 2007-05-10 19:19:59 +0000 | [diff] [blame] | 6578 | /* Just inform the caller about the occurrence of it */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6579 | *timed_out = TRUE; |
| 6580 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6581 | return FALSE; /* don't happen again */ |
| 6582 | } |
| 6583 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6584 | /* |
| 6585 | * GUI input routine called by gui_wait_for_chars(). Waits for a character |
| 6586 | * from the keyboard. |
| 6587 | * wtime == -1 Wait forever. |
| 6588 | * wtime == 0 This should never happen. |
| 6589 | * wtime > 0 Wait wtime milliseconds for a character. |
| 6590 | * Returns OK if a character was found to be available within the given time, |
| 6591 | * or FAIL otherwise. |
| 6592 | */ |
| 6593 | int |
| 6594 | gui_mch_wait_for_chars(long wtime) |
| 6595 | { |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 6596 | int focus; |
| 6597 | guint timer; |
| 6598 | static int timed_out; |
| 6599 | int retval = FAIL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6600 | |
| 6601 | timed_out = FALSE; |
| 6602 | |
| 6603 | /* this timeout makes sure that we will return if no characters arrived in |
| 6604 | * time */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6605 | if (wtime > 0) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6606 | #if GTK_CHECK_VERSION(3,0,0) |
| 6607 | timer = g_timeout_add((guint)wtime, input_timer_cb, &timed_out); |
| 6608 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6609 | timer = gtk_timeout_add((guint32)wtime, input_timer_cb, &timed_out); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6610 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6611 | else |
| 6612 | timer = 0; |
| 6613 | |
| 6614 | focus = gui.in_focus; |
| 6615 | |
| 6616 | do |
| 6617 | { |
| 6618 | /* Stop or start blinking when focus changes */ |
| 6619 | if (gui.in_focus != focus) |
| 6620 | { |
| 6621 | if (gui.in_focus) |
| 6622 | gui_mch_start_blink(); |
| 6623 | else |
| 6624 | gui_mch_stop_blink(); |
| 6625 | focus = gui.in_focus; |
| 6626 | } |
| 6627 | |
Bram Moolenaar | 93c88e0 | 2015-09-15 14:12:05 +0200 | [diff] [blame] | 6628 | #ifdef MESSAGE_QUEUE |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 6629 | # ifdef FEAT_TIMERS |
| 6630 | did_add_timer = FALSE; |
| 6631 | # endif |
Bram Moolenaar | 93c88e0 | 2015-09-15 14:12:05 +0200 | [diff] [blame] | 6632 | parse_queued_messages(); |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 6633 | # ifdef FEAT_TIMERS |
| 6634 | if (did_add_timer) |
| 6635 | /* Need to recompute the waiting time. */ |
| 6636 | goto theend; |
| 6637 | # endif |
Bram Moolenaar | 8c8de83 | 2008-06-24 22:58:06 +0000 | [diff] [blame] | 6638 | #endif |
| 6639 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6640 | /* |
| 6641 | * Loop in GTK+ processing until a timeout or input occurs. |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 6642 | * Skip this if input is available anyway (can happen in rare |
| 6643 | * situations, sort of race condition). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6644 | */ |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 6645 | if (!input_available()) |
Bram Moolenaar | a3f4166 | 2010-07-11 19:01:06 +0200 | [diff] [blame] | 6646 | g_main_context_iteration(NULL, TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6647 | |
| 6648 | /* Got char, return immediately */ |
| 6649 | if (input_available()) |
| 6650 | { |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 6651 | retval = OK; |
| 6652 | goto theend; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6653 | } |
| 6654 | } while (wtime < 0 || !timed_out); |
| 6655 | |
| 6656 | /* |
| 6657 | * Flush all eventually pending (drawing) events. |
| 6658 | */ |
| 6659 | gui_mch_update(); |
| 6660 | |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 6661 | theend: |
| 6662 | if (timer != 0 && !timed_out) |
| 6663 | #if GTK_CHECK_VERSION(3,0,0) |
| 6664 | g_source_remove(timer); |
| 6665 | #else |
| 6666 | gtk_timeout_remove(timer); |
| 6667 | #endif |
| 6668 | |
| 6669 | return retval; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6670 | } |
| 6671 | |
| 6672 | |
| 6673 | /**************************************************************************** |
| 6674 | * Output drawing routines. |
| 6675 | ****************************************************************************/ |
| 6676 | |
| 6677 | |
| 6678 | /* Flush any output to the screen */ |
| 6679 | void |
| 6680 | gui_mch_flush(void) |
| 6681 | { |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 6682 | #if GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6683 | if (gui.mainwin != NULL && gtk_widget_get_realized(gui.mainwin)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6684 | #else |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 6685 | if (gui.mainwin != NULL && GTK_WIDGET_REALIZED(gui.mainwin)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6686 | #endif |
Bram Moolenaar | b463e8d | 2017-06-05 15:07:09 +0200 | [diff] [blame] | 6687 | gdk_display_flush(gtk_widget_get_display(gui.mainwin)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6688 | } |
| 6689 | |
| 6690 | /* |
| 6691 | * Clear a rectangular region of the screen from text pos (row1, col1) to |
| 6692 | * (row2, col2) inclusive. |
| 6693 | */ |
| 6694 | void |
Bram Moolenaar | fe344a9 | 2017-02-23 12:20:35 +0100 | [diff] [blame] | 6695 | gui_mch_clear_block(int row1arg, int col1arg, int row2arg, int col2arg) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6696 | { |
Bram Moolenaar | fe344a9 | 2017-02-23 12:20:35 +0100 | [diff] [blame] | 6697 | |
| 6698 | int col1 = check_col(col1arg); |
| 6699 | int col2 = check_col(col2arg); |
| 6700 | int row1 = check_row(row1arg); |
| 6701 | int row2 = check_row(row2arg); |
| 6702 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6703 | #if GTK_CHECK_VERSION(3,0,0) |
| 6704 | if (gtk_widget_get_window(gui.drawarea) == NULL) |
| 6705 | return; |
| 6706 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6707 | GdkColor color; |
| 6708 | |
| 6709 | if (gui.drawarea->window == NULL) |
| 6710 | return; |
| 6711 | |
| 6712 | color.pixel = gui.back_pixel; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6713 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6714 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6715 | #if GTK_CHECK_VERSION(3,0,0) |
| 6716 | { |
| 6717 | /* Add one pixel to the far right column in case a double-stroked |
| 6718 | * bold glyph may sit there. */ |
| 6719 | const GdkRectangle rect = { |
| 6720 | FILL_X(col1), FILL_Y(row1), |
| 6721 | (col2 - col1 + 1) * gui.char_width + (col2 == Columns - 1), |
| 6722 | (row2 - row1 + 1) * gui.char_height |
| 6723 | }; |
| 6724 | GdkWindow * const win = gtk_widget_get_window(gui.drawarea); |
| 6725 | cairo_t * const cr = cairo_create(gui.surface); |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 6726 | # if GTK_CHECK_VERSION(3,22,2) |
| 6727 | set_cairo_source_rgba_from_color(cr, gui.back_pixel); |
| 6728 | # else |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6729 | cairo_pattern_t * const pat = gdk_window_get_background_pattern(win); |
| 6730 | if (pat != NULL) |
| 6731 | cairo_set_source(cr, pat); |
| 6732 | else |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 6733 | set_cairo_source_rgba_from_color(cr, gui.back_pixel); |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 6734 | # endif |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6735 | gdk_cairo_rectangle(cr, &rect); |
| 6736 | cairo_fill(cr); |
| 6737 | cairo_destroy(cr); |
| 6738 | |
| 6739 | if (!gui.by_signal) |
| 6740 | gdk_window_invalidate_rect(win, &rect, FALSE); |
| 6741 | } |
| 6742 | #else /* !GTK_CHECK_VERSION(3,0,0) */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6743 | gdk_gc_set_foreground(gui.text_gc, &color); |
| 6744 | |
| 6745 | /* Clear one extra pixel at the far right, for when bold characters have |
| 6746 | * spilled over to the window border. */ |
| 6747 | gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, TRUE, |
| 6748 | FILL_X(col1), FILL_Y(row1), |
| 6749 | (col2 - col1 + 1) * gui.char_width |
| 6750 | + (col2 == Columns - 1), |
| 6751 | (row2 - row1 + 1) * gui.char_height); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6752 | #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6753 | } |
| 6754 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6755 | #if GTK_CHECK_VERSION(3,0,0) |
| 6756 | static void |
| 6757 | gui_gtk_window_clear(GdkWindow *win) |
| 6758 | { |
| 6759 | const GdkRectangle rect = { |
| 6760 | 0, 0, gdk_window_get_width(win), gdk_window_get_height(win) |
| 6761 | }; |
| 6762 | cairo_t * const cr = cairo_create(gui.surface); |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 6763 | # if GTK_CHECK_VERSION(3,22,2) |
| 6764 | set_cairo_source_rgba_from_color(cr, gui.back_pixel); |
| 6765 | # else |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6766 | cairo_pattern_t * const pat = gdk_window_get_background_pattern(win); |
| 6767 | if (pat != NULL) |
| 6768 | cairo_set_source(cr, pat); |
| 6769 | else |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 6770 | set_cairo_source_rgba_from_color(cr, gui.back_pixel); |
Bram Moolenaar | a859f04 | 2016-11-17 19:11:55 +0100 | [diff] [blame] | 6771 | # endif |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6772 | gdk_cairo_rectangle(cr, &rect); |
| 6773 | cairo_fill(cr); |
| 6774 | cairo_destroy(cr); |
| 6775 | |
| 6776 | if (!gui.by_signal) |
| 6777 | gdk_window_invalidate_rect(win, &rect, FALSE); |
| 6778 | } |
| 6779 | #endif |
| 6780 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6781 | void |
| 6782 | gui_mch_clear_all(void) |
| 6783 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6784 | #if GTK_CHECK_VERSION(3,0,0) |
| 6785 | if (gtk_widget_get_window(gui.drawarea) != NULL) |
| 6786 | gui_gtk_window_clear(gtk_widget_get_window(gui.drawarea)); |
| 6787 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6788 | if (gui.drawarea->window != NULL) |
| 6789 | gdk_window_clear(gui.drawarea->window); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6790 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6791 | } |
| 6792 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6793 | #if !GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6794 | /* |
| 6795 | * Redraw any text revealed by scrolling up/down. |
| 6796 | */ |
| 6797 | static void |
| 6798 | check_copy_area(void) |
| 6799 | { |
| 6800 | GdkEvent *event; |
| 6801 | int expose_count; |
| 6802 | |
| 6803 | if (gui.visibility != GDK_VISIBILITY_PARTIAL) |
| 6804 | return; |
| 6805 | |
| 6806 | /* Avoid redrawing the cursor while scrolling or it'll end up where |
| 6807 | * we don't want it to be. I'm not sure if it's correct to call |
| 6808 | * gui_dont_update_cursor() at this point but it works as a quick |
| 6809 | * fix for now. */ |
Bram Moolenaar | 107abd2 | 2016-08-12 14:08:25 +0200 | [diff] [blame] | 6810 | gui_dont_update_cursor(TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6811 | |
| 6812 | do |
| 6813 | { |
| 6814 | /* Wait to check whether the scroll worked or not. */ |
| 6815 | event = gdk_event_get_graphics_expose(gui.drawarea->window); |
| 6816 | |
| 6817 | if (event == NULL) |
| 6818 | break; /* received NoExpose event */ |
| 6819 | |
| 6820 | gui_redraw(event->expose.area.x, event->expose.area.y, |
| 6821 | event->expose.area.width, event->expose.area.height); |
| 6822 | |
| 6823 | expose_count = event->expose.count; |
| 6824 | gdk_event_free(event); |
| 6825 | } |
| 6826 | while (expose_count > 0); /* more events follow */ |
| 6827 | |
| 6828 | gui_can_update_cursor(); |
| 6829 | } |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6830 | #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
| 6831 | |
| 6832 | #if GTK_CHECK_VERSION(3,0,0) |
| 6833 | static void |
| 6834 | gui_gtk_surface_copy_rect(int dest_x, int dest_y, |
| 6835 | int src_x, int src_y, |
| 6836 | int width, int height) |
| 6837 | { |
| 6838 | cairo_t * const cr = cairo_create(gui.surface); |
| 6839 | |
| 6840 | cairo_rectangle(cr, dest_x, dest_y, width, height); |
| 6841 | cairo_clip(cr); |
| 6842 | cairo_push_group(cr); |
| 6843 | cairo_set_source_surface(cr, gui.surface, dest_x - src_x, dest_y - src_y); |
| 6844 | cairo_paint(cr); |
| 6845 | cairo_pop_group_to_source(cr); |
| 6846 | cairo_paint(cr); |
| 6847 | |
| 6848 | cairo_destroy(cr); |
| 6849 | } |
| 6850 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6851 | |
| 6852 | /* |
| 6853 | * Delete the given number of lines from the given row, scrolling up any |
| 6854 | * text further down within the scroll region. |
| 6855 | */ |
| 6856 | void |
| 6857 | gui_mch_delete_lines(int row, int num_lines) |
| 6858 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6859 | #if GTK_CHECK_VERSION(3,0,0) |
| 6860 | const int ncols = gui.scroll_region_right - gui.scroll_region_left + 1; |
| 6861 | const int nrows = gui.scroll_region_bot - row + 1; |
| 6862 | const int src_nrows = nrows - num_lines; |
| 6863 | |
| 6864 | gui_gtk_surface_copy_rect( |
| 6865 | FILL_X(gui.scroll_region_left), FILL_Y(row), |
| 6866 | FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), |
| 6867 | gui.char_width * ncols + 1, gui.char_height * src_nrows); |
| 6868 | gui_clear_block( |
| 6869 | gui.scroll_region_bot - num_lines + 1, gui.scroll_region_left, |
| 6870 | gui.scroll_region_bot, gui.scroll_region_right); |
| 6871 | gui_gtk3_redraw( |
| 6872 | FILL_X(gui.scroll_region_left), FILL_Y(row), |
| 6873 | gui.char_width * ncols + 1, gui.char_height * nrows); |
| 6874 | if (!gui.by_signal) |
| 6875 | gtk_widget_queue_draw_area(gui.drawarea, |
| 6876 | FILL_X(gui.scroll_region_left), FILL_Y(row), |
| 6877 | gui.char_width * ncols + 1, gui.char_height * nrows); |
| 6878 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6879 | if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) |
| 6880 | return; /* Can't see the window */ |
| 6881 | |
| 6882 | gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
| 6883 | gdk_gc_set_background(gui.text_gc, gui.bgcolor); |
| 6884 | |
| 6885 | /* copy one extra pixel, for when bold has spilled over */ |
| 6886 | gdk_window_copy_area(gui.drawarea->window, gui.text_gc, |
| 6887 | FILL_X(gui.scroll_region_left), FILL_Y(row), |
| 6888 | gui.drawarea->window, |
| 6889 | FILL_X(gui.scroll_region_left), |
| 6890 | FILL_Y(row + num_lines), |
| 6891 | gui.char_width * (gui.scroll_region_right |
| 6892 | - gui.scroll_region_left + 1) + 1, |
| 6893 | gui.char_height * (gui.scroll_region_bot - row - num_lines + 1)); |
| 6894 | |
| 6895 | gui_clear_block(gui.scroll_region_bot - num_lines + 1, |
| 6896 | gui.scroll_region_left, |
| 6897 | gui.scroll_region_bot, gui.scroll_region_right); |
| 6898 | check_copy_area(); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6899 | #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6900 | } |
| 6901 | |
| 6902 | /* |
| 6903 | * Insert the given number of lines before the given row, scrolling down any |
| 6904 | * following text within the scroll region. |
| 6905 | */ |
| 6906 | void |
| 6907 | gui_mch_insert_lines(int row, int num_lines) |
| 6908 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6909 | #if GTK_CHECK_VERSION(3,0,0) |
| 6910 | const int ncols = gui.scroll_region_right - gui.scroll_region_left + 1; |
| 6911 | const int nrows = gui.scroll_region_bot - row + 1; |
| 6912 | const int src_nrows = nrows - num_lines; |
| 6913 | |
| 6914 | gui_gtk_surface_copy_rect( |
| 6915 | FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), |
| 6916 | FILL_X(gui.scroll_region_left), FILL_Y(row), |
| 6917 | gui.char_width * ncols + 1, gui.char_height * src_nrows); |
| 6918 | gui_mch_clear_block( |
| 6919 | row, gui.scroll_region_left, |
| 6920 | row + num_lines - 1, gui.scroll_region_right); |
| 6921 | gui_gtk3_redraw( |
| 6922 | FILL_X(gui.scroll_region_left), FILL_Y(row), |
| 6923 | gui.char_width * ncols + 1, gui.char_height * nrows); |
| 6924 | if (!gui.by_signal) |
| 6925 | gtk_widget_queue_draw_area(gui.drawarea, |
| 6926 | FILL_X(gui.scroll_region_left), FILL_Y(row), |
| 6927 | gui.char_width * ncols + 1, gui.char_height * nrows); |
| 6928 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6929 | if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) |
| 6930 | return; /* Can't see the window */ |
| 6931 | |
| 6932 | gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
| 6933 | gdk_gc_set_background(gui.text_gc, gui.bgcolor); |
| 6934 | |
| 6935 | /* copy one extra pixel, for when bold has spilled over */ |
| 6936 | gdk_window_copy_area(gui.drawarea->window, gui.text_gc, |
| 6937 | FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), |
| 6938 | gui.drawarea->window, |
| 6939 | FILL_X(gui.scroll_region_left), FILL_Y(row), |
| 6940 | gui.char_width * (gui.scroll_region_right |
| 6941 | - gui.scroll_region_left + 1) + 1, |
| 6942 | gui.char_height * (gui.scroll_region_bot - row - num_lines + 1)); |
| 6943 | |
| 6944 | gui_clear_block(row, gui.scroll_region_left, |
| 6945 | row + num_lines - 1, gui.scroll_region_right); |
| 6946 | check_copy_area(); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6947 | #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6948 | } |
| 6949 | |
| 6950 | /* |
| 6951 | * X Selection stuff, for cutting and pasting text to other windows. |
| 6952 | */ |
| 6953 | void |
| 6954 | clip_mch_request_selection(VimClipboard *cbd) |
| 6955 | { |
| 6956 | GdkAtom target; |
| 6957 | unsigned i; |
Bram Moolenaar | 51b5ab9 | 2008-01-06 14:17:07 +0000 | [diff] [blame] | 6958 | time_t start; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6959 | |
| 6960 | for (i = 0; i < N_SELECTION_TARGETS; ++i) |
| 6961 | { |
Bram Moolenaar | 3a6eaa5 | 2009-06-16 13:23:06 +0000 | [diff] [blame] | 6962 | if (!clip_html && selection_targets[i].info == TARGET_HTML) |
| 6963 | continue; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6964 | received_selection = RS_NONE; |
| 6965 | target = gdk_atom_intern(selection_targets[i].target, FALSE); |
| 6966 | |
| 6967 | gtk_selection_convert(gui.drawarea, |
| 6968 | cbd->gtk_sel_atom, target, |
| 6969 | (guint32)GDK_CURRENT_TIME); |
| 6970 | |
Bram Moolenaar | 51b5ab9 | 2008-01-06 14:17:07 +0000 | [diff] [blame] | 6971 | /* Hack: Wait up to three seconds for the selection. A hang was |
| 6972 | * noticed here when using the netrw plugin combined with ":gui" |
| 6973 | * during the FocusGained event. */ |
| 6974 | start = time(NULL); |
| 6975 | while (received_selection == RS_NONE && time(NULL) < start + 3) |
Bram Moolenaar | a3f4166 | 2010-07-11 19:01:06 +0200 | [diff] [blame] | 6976 | g_main_context_iteration(NULL, TRUE); /* wait for selection_received_cb */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6977 | |
| 6978 | if (received_selection != RS_FAIL) |
| 6979 | return; |
| 6980 | } |
| 6981 | |
| 6982 | /* Final fallback position - use the X CUT_BUFFER0 store */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6983 | #if GTK_CHECK_VERSION(3,0,0) |
| 6984 | yank_cut_buffer0(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.mainwin)), |
| 6985 | cbd); |
| 6986 | #else |
Bram Moolenaar | bbc936b | 2009-07-01 16:04:58 +0000 | [diff] [blame] | 6987 | yank_cut_buffer0(GDK_WINDOW_XDISPLAY(gui.mainwin->window), cbd); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 6988 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6989 | } |
| 6990 | |
| 6991 | /* |
| 6992 | * Disown the selection. |
| 6993 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6994 | void |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 6995 | clip_mch_lose_selection(VimClipboard *cbd UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6996 | { |
Bram Moolenaar | 1a0316c | 2013-03-13 17:50:25 +0100 | [diff] [blame] | 6997 | gtk_selection_owner_set(NULL, cbd->gtk_sel_atom, gui.event_time); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6998 | gui_mch_update(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6999 | } |
| 7000 | |
| 7001 | /* |
| 7002 | * Own the selection and return OK if it worked. |
| 7003 | */ |
| 7004 | int |
| 7005 | clip_mch_own_selection(VimClipboard *cbd) |
| 7006 | { |
| 7007 | int success; |
| 7008 | |
| 7009 | success = gtk_selection_owner_set(gui.drawarea, cbd->gtk_sel_atom, |
Bram Moolenaar | 20892c1 | 2011-06-26 04:49:00 +0200 | [diff] [blame] | 7010 | gui.event_time); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7011 | gui_mch_update(); |
| 7012 | return (success) ? OK : FAIL; |
| 7013 | } |
| 7014 | |
| 7015 | /* |
| 7016 | * Send the current selection to the clipboard. Do nothing for X because we |
| 7017 | * will fill in the selection only when requested by another app. |
| 7018 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7019 | void |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 7020 | clip_mch_set_selection(VimClipboard *cbd UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7021 | { |
| 7022 | } |
| 7023 | |
Bram Moolenaar | 1a0316c | 2013-03-13 17:50:25 +0100 | [diff] [blame] | 7024 | int |
| 7025 | clip_gtk_owner_exists(VimClipboard *cbd) |
| 7026 | { |
| 7027 | return gdk_selection_owner_get(cbd->gtk_sel_atom) != NULL; |
| 7028 | } |
| 7029 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7030 | |
| 7031 | #if defined(FEAT_MENU) || defined(PROTO) |
| 7032 | /* |
| 7033 | * Make a menu item appear either active or not active (grey or not grey). |
| 7034 | */ |
| 7035 | void |
| 7036 | gui_mch_menu_grey(vimmenu_T *menu, int grey) |
| 7037 | { |
| 7038 | if (menu->id == NULL) |
| 7039 | return; |
| 7040 | |
| 7041 | if (menu_is_separator(menu->name)) |
| 7042 | grey = TRUE; |
| 7043 | |
| 7044 | gui_mch_menu_hidden(menu, FALSE); |
| 7045 | /* Be clever about bitfields versus true booleans here! */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7046 | # if GTK_CHECK_VERSION(3,0,0) |
| 7047 | if (!gtk_widget_get_sensitive(menu->id) == !grey) |
| 7048 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7049 | if (!GTK_WIDGET_SENSITIVE(menu->id) == !grey) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7050 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7051 | { |
| 7052 | gtk_widget_set_sensitive(menu->id, !grey); |
| 7053 | gui_mch_update(); |
| 7054 | } |
| 7055 | } |
| 7056 | |
| 7057 | /* |
| 7058 | * Make menu item hidden or not hidden. |
| 7059 | */ |
| 7060 | void |
| 7061 | gui_mch_menu_hidden(vimmenu_T *menu, int hidden) |
| 7062 | { |
| 7063 | if (menu->id == 0) |
| 7064 | return; |
| 7065 | |
| 7066 | if (hidden) |
| 7067 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7068 | # if GTK_CHECK_VERSION(3,0,0) |
| 7069 | if (gtk_widget_get_visible(menu->id)) |
| 7070 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7071 | if (GTK_WIDGET_VISIBLE(menu->id)) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7072 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7073 | { |
| 7074 | gtk_widget_hide(menu->id); |
| 7075 | gui_mch_update(); |
| 7076 | } |
| 7077 | } |
| 7078 | else |
| 7079 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7080 | # if GTK_CHECK_VERSION(3,0,0) |
| 7081 | if (!gtk_widget_get_visible(menu->id)) |
| 7082 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7083 | if (!GTK_WIDGET_VISIBLE(menu->id)) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7084 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7085 | { |
| 7086 | gtk_widget_show(menu->id); |
| 7087 | gui_mch_update(); |
| 7088 | } |
| 7089 | } |
| 7090 | } |
| 7091 | |
| 7092 | /* |
| 7093 | * This is called after setting all the menus to grey/hidden or not. |
| 7094 | */ |
| 7095 | void |
| 7096 | gui_mch_draw_menubar(void) |
| 7097 | { |
| 7098 | /* just make sure that the visual changes get effect immediately */ |
| 7099 | gui_mch_update(); |
| 7100 | } |
| 7101 | #endif /* FEAT_MENU */ |
| 7102 | |
| 7103 | /* |
| 7104 | * Scrollbar stuff. |
| 7105 | */ |
| 7106 | void |
| 7107 | gui_mch_enable_scrollbar(scrollbar_T *sb, int flag) |
| 7108 | { |
| 7109 | if (sb->id == NULL) |
| 7110 | return; |
| 7111 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7112 | #if GTK_CHECK_VERSION(3,0,0) |
| 7113 | gtk_widget_set_visible(sb->id, flag); |
| 7114 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7115 | if (flag) |
| 7116 | gtk_widget_show(sb->id); |
| 7117 | else |
| 7118 | gtk_widget_hide(sb->id); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7119 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7120 | |
Bram Moolenaar | b3656ed | 2006-03-20 21:59:49 +0000 | [diff] [blame] | 7121 | update_window_manager_hints(0, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7122 | } |
| 7123 | |
| 7124 | |
| 7125 | /* |
| 7126 | * Return the RGB value of a pixel as long. |
| 7127 | */ |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 7128 | guicolor_T |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7129 | gui_mch_get_rgb(guicolor_T pixel) |
| 7130 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7131 | #if GTK_CHECK_VERSION(3,0,0) |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 7132 | return (long_u)pixel; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7133 | #else |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 7134 | GdkColor color; |
| 7135 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7136 | gdk_colormap_query_color(gtk_widget_get_colormap(gui.drawarea), |
| 7137 | (unsigned long)pixel, &color); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7138 | |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 7139 | return (guicolor_T)( |
| 7140 | (((unsigned)color.red & 0xff00) << 8) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7141 | | ((unsigned)color.green & 0xff00) |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 7142 | | (((unsigned)color.blue & 0xff00) >> 8)); |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 7143 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7144 | } |
| 7145 | |
| 7146 | /* |
Bram Moolenaar | 6cc1619 | 2005-01-08 21:49:45 +0000 | [diff] [blame] | 7147 | * Get current mouse coordinates in text window. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7148 | */ |
Bram Moolenaar | 6cc1619 | 2005-01-08 21:49:45 +0000 | [diff] [blame] | 7149 | void |
| 7150 | gui_mch_getmouse(int *x, int *y) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7151 | { |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7152 | #if GTK_CHECK_VERSION(3,0,0) |
| 7153 | gui_gtk_get_pointer(gui.drawarea, x, y, NULL); |
| 7154 | #else |
Bram Moolenaar | 6cc1619 | 2005-01-08 21:49:45 +0000 | [diff] [blame] | 7155 | gdk_window_get_pointer(gui.drawarea->window, x, y, NULL); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7156 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7157 | } |
| 7158 | |
| 7159 | void |
| 7160 | gui_mch_setmouse(int x, int y) |
| 7161 | { |
| 7162 | /* Sorry for the Xlib call, but we can't avoid it, since there is no |
| 7163 | * internal GDK mechanism present to accomplish this. (and for good |
| 7164 | * reason...) */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7165 | #if GTK_CHECK_VERSION(3,0,0) |
| 7166 | XWarpPointer(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.drawarea)), |
| 7167 | (Window)0, GDK_WINDOW_XID(gtk_widget_get_window(gui.drawarea)), |
| 7168 | 0, 0, 0U, 0U, x, y); |
| 7169 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7170 | XWarpPointer(GDK_WINDOW_XDISPLAY(gui.drawarea->window), |
| 7171 | (Window)0, GDK_WINDOW_XWINDOW(gui.drawarea->window), |
| 7172 | 0, 0, 0U, 0U, x, y); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7173 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7174 | } |
| 7175 | |
| 7176 | |
| 7177 | #ifdef FEAT_MOUSESHAPE |
| 7178 | /* The last set mouse pointer shape is remembered, to be used when it goes |
| 7179 | * from hidden to not hidden. */ |
| 7180 | static int last_shape = 0; |
| 7181 | #endif |
| 7182 | |
| 7183 | /* |
| 7184 | * Use the blank mouse pointer or not. |
| 7185 | * |
| 7186 | * hide: TRUE = use blank ptr, FALSE = use parent ptr |
| 7187 | */ |
| 7188 | void |
| 7189 | gui_mch_mousehide(int hide) |
| 7190 | { |
| 7191 | if (gui.pointer_hidden != hide) |
| 7192 | { |
| 7193 | gui.pointer_hidden = hide; |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7194 | #if GTK_CHECK_VERSION(3,0,0) |
| 7195 | if (gtk_widget_get_window(gui.drawarea) && gui.blank_pointer != NULL) |
| 7196 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7197 | if (gui.drawarea->window && gui.blank_pointer != NULL) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7198 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7199 | { |
| 7200 | if (hide) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7201 | #if GTK_CHECK_VERSION(3,0,0) |
| 7202 | gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), |
| 7203 | gui.blank_pointer); |
| 7204 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7205 | gdk_window_set_cursor(gui.drawarea->window, gui.blank_pointer); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7206 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7207 | else |
| 7208 | #ifdef FEAT_MOUSESHAPE |
| 7209 | mch_set_mouse_shape(last_shape); |
Bram Moolenaar | 3f2a5d8 | 2016-02-27 22:08:16 +0100 | [diff] [blame] | 7210 | #elif GTK_CHECK_VERSION(3,0,0) |
| 7211 | gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7212 | #else |
| 7213 | gdk_window_set_cursor(gui.drawarea->window, NULL); |
| 7214 | #endif |
| 7215 | } |
| 7216 | } |
| 7217 | } |
| 7218 | |
| 7219 | #if defined(FEAT_MOUSESHAPE) || defined(PROTO) |
| 7220 | |
| 7221 | /* Table for shape IDs. Keep in sync with the mshape_names[] table in |
| 7222 | * misc2.c! */ |
| 7223 | static const int mshape_ids[] = |
| 7224 | { |
| 7225 | GDK_LEFT_PTR, /* arrow */ |
| 7226 | GDK_CURSOR_IS_PIXMAP, /* blank */ |
| 7227 | GDK_XTERM, /* beam */ |
| 7228 | GDK_SB_V_DOUBLE_ARROW, /* updown */ |
| 7229 | GDK_SIZING, /* udsizing */ |
| 7230 | GDK_SB_H_DOUBLE_ARROW, /* leftright */ |
| 7231 | GDK_SIZING, /* lrsizing */ |
| 7232 | GDK_WATCH, /* busy */ |
| 7233 | GDK_X_CURSOR, /* no */ |
| 7234 | GDK_CROSSHAIR, /* crosshair */ |
| 7235 | GDK_HAND1, /* hand1 */ |
| 7236 | GDK_HAND2, /* hand2 */ |
| 7237 | GDK_PENCIL, /* pencil */ |
| 7238 | GDK_QUESTION_ARROW, /* question */ |
| 7239 | GDK_RIGHT_PTR, /* right-arrow */ |
| 7240 | GDK_CENTER_PTR, /* up-arrow */ |
| 7241 | GDK_LEFT_PTR /* last one */ |
| 7242 | }; |
| 7243 | |
| 7244 | void |
| 7245 | mch_set_mouse_shape(int shape) |
| 7246 | { |
| 7247 | int id; |
| 7248 | GdkCursor *c; |
| 7249 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7250 | # if GTK_CHECK_VERSION(3,0,0) |
| 7251 | if (gtk_widget_get_window(gui.drawarea) == NULL) |
| 7252 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7253 | if (gui.drawarea->window == NULL) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7254 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7255 | return; |
| 7256 | |
| 7257 | if (shape == MSHAPE_HIDE || gui.pointer_hidden) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7258 | # if GTK_CHECK_VERSION(3,0,0) |
| 7259 | gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), |
| 7260 | gui.blank_pointer); |
| 7261 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7262 | gdk_window_set_cursor(gui.drawarea->window, gui.blank_pointer); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7263 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7264 | else |
| 7265 | { |
| 7266 | if (shape >= MSHAPE_NUMBERED) |
| 7267 | { |
| 7268 | id = shape - MSHAPE_NUMBERED; |
| 7269 | if (id >= GDK_LAST_CURSOR) |
| 7270 | id = GDK_LEFT_PTR; |
| 7271 | else |
| 7272 | id &= ~1; /* they are always even (why?) */ |
| 7273 | } |
Bram Moolenaar | b85cb21 | 2009-05-17 14:24:23 +0000 | [diff] [blame] | 7274 | else if (shape < (int)(sizeof(mshape_ids) / sizeof(int))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7275 | id = mshape_ids[shape]; |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 7276 | else |
| 7277 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7278 | c = gdk_cursor_new_for_display( |
Bram Moolenaar | b71ec9f | 2005-01-25 22:22:02 +0000 | [diff] [blame] | 7279 | gtk_widget_get_display(gui.drawarea), (GdkCursorType)id); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7280 | # if GTK_CHECK_VERSION(3,0,0) |
| 7281 | gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), c); |
| 7282 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7283 | gdk_window_set_cursor(gui.drawarea->window, c); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7284 | # endif |
| 7285 | # if GTK_CHECK_VERSION(3,0,0) |
| 7286 | g_object_unref(G_OBJECT(c)); |
| 7287 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7288 | gdk_cursor_destroy(c); /* Unref, actually. Bloody GTK+ 1. */ |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7289 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7290 | } |
| 7291 | if (shape != MSHAPE_HIDE) |
| 7292 | last_shape = shape; |
| 7293 | } |
| 7294 | #endif /* FEAT_MOUSESHAPE */ |
| 7295 | |
| 7296 | |
| 7297 | #if defined(FEAT_SIGN_ICONS) || defined(PROTO) |
| 7298 | /* |
| 7299 | * Signs are currently always 2 chars wide. With GTK+ 2, the image will be |
| 7300 | * scaled down if the current font is not big enough, or scaled up if the image |
| 7301 | * size is less than 3/4 of the maximum sign size. With GTK+ 1, the pixmap |
| 7302 | * will be cut off if the current font is not big enough, or centered if it's |
| 7303 | * too small. |
| 7304 | */ |
| 7305 | # define SIGN_WIDTH (2 * gui.char_width) |
| 7306 | # define SIGN_HEIGHT (gui.char_height) |
| 7307 | # define SIGN_ASPECT ((double)SIGN_HEIGHT / (double)SIGN_WIDTH) |
| 7308 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7309 | void |
| 7310 | gui_mch_drawsign(int row, int col, int typenr) |
| 7311 | { |
| 7312 | GdkPixbuf *sign; |
| 7313 | |
| 7314 | sign = (GdkPixbuf *)sign_get_image(typenr); |
| 7315 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7316 | # if GTK_CHECK_VERSION(3,0,0) |
| 7317 | if (sign != NULL && gui.drawarea != NULL |
| 7318 | && gtk_widget_get_window(gui.drawarea) != NULL) |
| 7319 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7320 | if (sign != NULL && gui.drawarea != NULL && gui.drawarea->window != NULL) |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7321 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7322 | { |
| 7323 | int width; |
| 7324 | int height; |
| 7325 | int xoffset; |
| 7326 | int yoffset; |
| 7327 | int need_scale; |
| 7328 | |
| 7329 | width = gdk_pixbuf_get_width(sign); |
| 7330 | height = gdk_pixbuf_get_height(sign); |
| 7331 | /* |
| 7332 | * Decide whether we need to scale. Allow one pixel of border |
| 7333 | * width to be cut off, in order to avoid excessive scaling for |
| 7334 | * tiny differences in font size. |
Bram Moolenaar | 58cbc91 | 2014-06-17 18:47:02 +0200 | [diff] [blame] | 7335 | * Do scale to fit the height to avoid gaps because of linespacing. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7336 | */ |
| 7337 | need_scale = (width > SIGN_WIDTH + 2 |
Bram Moolenaar | 58cbc91 | 2014-06-17 18:47:02 +0200 | [diff] [blame] | 7338 | || height != SIGN_HEIGHT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7339 | || (width < 3 * SIGN_WIDTH / 4 |
| 7340 | && height < 3 * SIGN_HEIGHT / 4)); |
| 7341 | if (need_scale) |
| 7342 | { |
Bram Moolenaar | 58cbc91 | 2014-06-17 18:47:02 +0200 | [diff] [blame] | 7343 | double aspect; |
| 7344 | int w = width; |
| 7345 | int h = height; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7346 | |
| 7347 | /* Keep the original aspect ratio */ |
| 7348 | aspect = (double)height / (double)width; |
| 7349 | width = (double)SIGN_WIDTH * SIGN_ASPECT / aspect; |
| 7350 | width = MIN(width, SIGN_WIDTH); |
Bram Moolenaar | 58cbc91 | 2014-06-17 18:47:02 +0200 | [diff] [blame] | 7351 | if (((double)(MAX(height, SIGN_HEIGHT)) / |
| 7352 | (double)(MIN(height, SIGN_HEIGHT))) < 1.15) |
| 7353 | { |
| 7354 | /* Change the aspect ratio by at most 15% to fill the |
| 7355 | * available space completly. */ |
| 7356 | height = (double)SIGN_HEIGHT * SIGN_ASPECT / aspect; |
| 7357 | height = MIN(height, SIGN_HEIGHT); |
| 7358 | } |
| 7359 | else |
| 7360 | height = (double)width * aspect; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7361 | |
Bram Moolenaar | 58cbc91 | 2014-06-17 18:47:02 +0200 | [diff] [blame] | 7362 | if (w == width && h == height) |
| 7363 | { |
| 7364 | /* no change in dimensions; don't decrease reference counter |
| 7365 | * (below) */ |
| 7366 | need_scale = FALSE; |
| 7367 | } |
| 7368 | else |
| 7369 | { |
| 7370 | /* This doesn't seem to be worth caching, and doing so would |
| 7371 | * complicate the code quite a bit. */ |
| 7372 | sign = gdk_pixbuf_scale_simple(sign, width, height, |
| 7373 | GDK_INTERP_BILINEAR); |
| 7374 | if (sign == NULL) |
| 7375 | return; /* out of memory */ |
| 7376 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7377 | } |
| 7378 | |
| 7379 | /* The origin is the upper-left corner of the pixmap. Therefore |
| 7380 | * these offset may become negative if the pixmap is smaller than |
| 7381 | * the 2x1 cells reserved for the sign icon. */ |
| 7382 | xoffset = (width - SIGN_WIDTH) / 2; |
| 7383 | yoffset = (height - SIGN_HEIGHT) / 2; |
| 7384 | |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7385 | # if GTK_CHECK_VERSION(3,0,0) |
| 7386 | { |
| 7387 | cairo_t *cr; |
| 7388 | cairo_surface_t *bg_surf; |
| 7389 | cairo_t *bg_cr; |
| 7390 | cairo_surface_t *sign_surf; |
| 7391 | cairo_t *sign_cr; |
| 7392 | |
| 7393 | cr = cairo_create(gui.surface); |
| 7394 | |
| 7395 | bg_surf = cairo_surface_create_similar(gui.surface, |
| 7396 | cairo_surface_get_content(gui.surface), |
| 7397 | SIGN_WIDTH, SIGN_HEIGHT); |
| 7398 | bg_cr = cairo_create(bg_surf); |
Bram Moolenaar | 36edf06 | 2016-07-21 22:10:12 +0200 | [diff] [blame] | 7399 | cairo_set_source_rgba(bg_cr, |
| 7400 | gui.bgcolor->red, gui.bgcolor->green, gui.bgcolor->blue, |
| 7401 | gui.bgcolor->alpha); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7402 | cairo_paint(bg_cr); |
| 7403 | |
| 7404 | sign_surf = cairo_surface_create_similar(gui.surface, |
| 7405 | cairo_surface_get_content(gui.surface), |
| 7406 | SIGN_WIDTH, SIGN_HEIGHT); |
| 7407 | sign_cr = cairo_create(sign_surf); |
| 7408 | gdk_cairo_set_source_pixbuf(sign_cr, sign, -xoffset, -yoffset); |
| 7409 | cairo_paint(sign_cr); |
| 7410 | |
| 7411 | cairo_set_operator(sign_cr, CAIRO_OPERATOR_DEST_OVER); |
| 7412 | cairo_set_source_surface(sign_cr, bg_surf, 0, 0); |
| 7413 | cairo_paint(sign_cr); |
| 7414 | |
| 7415 | cairo_set_source_surface(cr, sign_surf, FILL_X(col), FILL_Y(row)); |
| 7416 | cairo_paint(cr); |
| 7417 | |
| 7418 | cairo_destroy(sign_cr); |
| 7419 | cairo_surface_destroy(sign_surf); |
| 7420 | cairo_destroy(bg_cr); |
| 7421 | cairo_surface_destroy(bg_surf); |
| 7422 | cairo_destroy(cr); |
| 7423 | |
| 7424 | if (!gui.by_signal) |
| 7425 | gtk_widget_queue_draw_area(gui.drawarea, |
| 7426 | FILL_X(col), FILL_Y(col), width, height); |
| 7427 | |
| 7428 | } |
| 7429 | # else /* !GTK_CHECK_VERSION(3,0,0) */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7430 | gdk_gc_set_foreground(gui.text_gc, gui.bgcolor); |
| 7431 | |
| 7432 | gdk_draw_rectangle(gui.drawarea->window, |
| 7433 | gui.text_gc, |
| 7434 | TRUE, |
| 7435 | FILL_X(col), |
| 7436 | FILL_Y(row), |
| 7437 | SIGN_WIDTH, |
| 7438 | SIGN_HEIGHT); |
| 7439 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7440 | gdk_pixbuf_render_to_drawable_alpha(sign, |
| 7441 | gui.drawarea->window, |
| 7442 | MAX(0, xoffset), |
| 7443 | MAX(0, yoffset), |
| 7444 | FILL_X(col) - MIN(0, xoffset), |
| 7445 | FILL_Y(row) - MIN(0, yoffset), |
| 7446 | MIN(width, SIGN_WIDTH), |
| 7447 | MIN(height, SIGN_HEIGHT), |
| 7448 | GDK_PIXBUF_ALPHA_BILEVEL, |
| 7449 | 127, |
| 7450 | GDK_RGB_DITHER_NORMAL, |
| 7451 | 0, 0); |
Bram Moolenaar | 9892189 | 2016-02-23 17:14:37 +0100 | [diff] [blame] | 7452 | # endif /* !GTK_CHECK_VERSION(3,0,0) */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7453 | if (need_scale) |
| 7454 | g_object_unref(sign); |
| 7455 | } |
| 7456 | } |
| 7457 | |
| 7458 | void * |
| 7459 | gui_mch_register_sign(char_u *signfile) |
| 7460 | { |
| 7461 | if (signfile[0] != NUL && signfile[0] != '-' && gui.in_use) |
| 7462 | { |
| 7463 | GdkPixbuf *sign; |
| 7464 | GError *error = NULL; |
| 7465 | char_u *message; |
| 7466 | |
| 7467 | sign = gdk_pixbuf_new_from_file((const char *)signfile, &error); |
| 7468 | |
| 7469 | if (error == NULL) |
| 7470 | return sign; |
| 7471 | |
| 7472 | message = (char_u *)error->message; |
| 7473 | |
| 7474 | if (message != NULL && input_conv.vc_type != CONV_NONE) |
| 7475 | message = string_convert(&input_conv, message, NULL); |
| 7476 | |
| 7477 | if (message != NULL) |
| 7478 | { |
| 7479 | /* The error message is already translated and will be more |
| 7480 | * descriptive than anything we could possibly do ourselves. */ |
| 7481 | EMSG2("E255: %s", message); |
| 7482 | |
| 7483 | if (input_conv.vc_type != CONV_NONE) |
| 7484 | vim_free(message); |
| 7485 | } |
| 7486 | g_error_free(error); |
| 7487 | } |
| 7488 | |
| 7489 | return NULL; |
| 7490 | } |
| 7491 | |
| 7492 | void |
| 7493 | gui_mch_destroy_sign(void *sign) |
| 7494 | { |
| 7495 | if (sign != NULL) |
| 7496 | g_object_unref(sign); |
| 7497 | } |
| 7498 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7499 | #endif /* FEAT_SIGN_ICONS */ |