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 | * GUI/Motif support by Robert Webb |
| 5 | * |
| 6 | * Do ":help uganda" in Vim to read copying and usage conditions. |
| 7 | * Do ":help credits" in Vim to see a list of people who contributed. |
| 8 | * See README.txt for an overview of the Vim source code. |
| 9 | */ |
| 10 | /* |
| 11 | * Common code for the Motif and Athena GUI. |
| 12 | * Not used for GTK. |
| 13 | */ |
| 14 | |
Bram Moolenaar | f7506ca | 2017-02-25 16:01:49 +0100 | [diff] [blame] | 15 | #include "vim.h" |
| 16 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 17 | #include <X11/keysym.h> |
| 18 | #include <X11/Xatom.h> |
| 19 | #include <X11/StringDefs.h> |
| 20 | #include <X11/Intrinsic.h> |
| 21 | #include <X11/Shell.h> |
| 22 | #include <X11/cursorfont.h> |
| 23 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 24 | /* |
| 25 | * For Workshop XpmP.h is preferred, because it makes the signs drawn with a |
| 26 | * transparent background instead of black. |
| 27 | */ |
| 28 | #if defined(HAVE_XM_XPMP_H) && defined(FEAT_GUI_MOTIF) \ |
| 29 | && (!defined(HAVE_X11_XPM_H) || defined(FEAT_SUN_WORKSHOP)) |
| 30 | # include <Xm/XpmP.h> |
| 31 | #else |
| 32 | # ifdef HAVE_X11_XPM_H |
| 33 | # include <X11/xpm.h> |
| 34 | # endif |
| 35 | #endif |
| 36 | |
| 37 | #ifdef FEAT_XFONTSET |
| 38 | # ifdef X_LOCALE |
| 39 | # include <X11/Xlocale.h> |
| 40 | # else |
| 41 | # include <locale.h> |
| 42 | # endif |
| 43 | #endif |
| 44 | |
| 45 | #ifdef HAVE_X11_SUNKEYSYM_H |
| 46 | # include <X11/Sunkeysym.h> |
| 47 | #endif |
| 48 | |
| 49 | #ifdef HAVE_X11_XMU_EDITRES_H |
| 50 | # include <X11/Xmu/Editres.h> |
| 51 | #endif |
| 52 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 53 | #define VIM_NAME "vim" |
| 54 | #define VIM_CLASS "Vim" |
| 55 | |
| 56 | /* Default resource values */ |
| 57 | #define DFLT_FONT "7x13" |
| 58 | #ifdef FONTSET_ALWAYS |
| 59 | # define DFLT_MENU_FONT XtDefaultFontSet |
| 60 | #else |
| 61 | # define DFLT_MENU_FONT XtDefaultFont |
| 62 | #endif |
| 63 | #define DFLT_TOOLTIP_FONT XtDefaultFontSet |
| 64 | |
| 65 | #ifdef FEAT_GUI_ATHENA |
| 66 | # define DFLT_MENU_BG_COLOR "gray77" |
| 67 | # define DFLT_MENU_FG_COLOR "black" |
| 68 | # define DFLT_SCROLL_BG_COLOR "gray60" |
| 69 | # define DFLT_SCROLL_FG_COLOR "gray77" |
Bram Moolenaar | 4658228 | 2016-07-23 14:35:12 +0200 | [diff] [blame] | 70 | # define DFLT_TOOLTIP_BG_COLOR "#ffff91" |
| 71 | # define DFLT_TOOLTIP_FG_COLOR "#000000" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 72 | #else |
| 73 | /* use the default (CDE) colors */ |
| 74 | # define DFLT_MENU_BG_COLOR "" |
| 75 | # define DFLT_MENU_FG_COLOR "" |
| 76 | # define DFLT_SCROLL_BG_COLOR "" |
| 77 | # define DFLT_SCROLL_FG_COLOR "" |
Bram Moolenaar | 4658228 | 2016-07-23 14:35:12 +0200 | [diff] [blame] | 78 | # define DFLT_TOOLTIP_BG_COLOR "#ffff91" |
| 79 | # define DFLT_TOOLTIP_FG_COLOR "#000000" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 80 | #endif |
| 81 | |
| 82 | Widget vimShell = (Widget)0; |
| 83 | |
| 84 | static Atom wm_atoms[2]; /* Window Manager Atoms */ |
| 85 | #define DELETE_WINDOW_IDX 0 /* index in wm_atoms[] for WM_DELETE_WINDOW */ |
| 86 | #define SAVE_YOURSELF_IDX 1 /* index in wm_atoms[] for WM_SAVE_YOURSELF */ |
| 87 | |
| 88 | #ifdef FEAT_XFONTSET |
| 89 | /* |
| 90 | * We either draw with a fontset (when current_fontset != NULL) or with a |
| 91 | * normal font (current_fontset == NULL, use gui.text_gc and gui.back_gc). |
| 92 | */ |
| 93 | static XFontSet current_fontset = NULL; |
| 94 | |
| 95 | #define XDrawString(dpy, win, gc, x, y, str, n) \ |
| 96 | do \ |
| 97 | { \ |
| 98 | if (current_fontset != NULL) \ |
| 99 | XmbDrawString(dpy, win, current_fontset, gc, x, y, str, n); \ |
| 100 | else \ |
| 101 | XDrawString(dpy, win, gc, x, y, str, n); \ |
| 102 | } while (0) |
| 103 | |
| 104 | #define XDrawString16(dpy, win, gc, x, y, str, n) \ |
| 105 | do \ |
| 106 | { \ |
| 107 | if (current_fontset != NULL) \ |
| 108 | XwcDrawString(dpy, win, current_fontset, gc, x, y, (wchar_t *)str, n); \ |
| 109 | else \ |
Bram Moolenaar | a3227e2 | 2006-03-08 21:32:40 +0000 | [diff] [blame] | 110 | XDrawString16(dpy, win, gc, x, y, (XChar2b *)str, n); \ |
| 111 | } while (0) |
| 112 | |
| 113 | #define XDrawImageString16(dpy, win, gc, x, y, str, n) \ |
| 114 | do \ |
| 115 | { \ |
| 116 | if (current_fontset != NULL) \ |
| 117 | XwcDrawImageString(dpy, win, current_fontset, gc, x, y, (wchar_t *)str, n); \ |
| 118 | else \ |
| 119 | XDrawImageString16(dpy, win, gc, x, y, (XChar2b *)str, n); \ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 120 | } while (0) |
| 121 | |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 122 | static int check_fontset_sanity(XFontSet fs); |
| 123 | static int fontset_width(XFontSet fs); |
| 124 | static int fontset_ascent(XFontSet fs); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 125 | #endif |
| 126 | |
| 127 | static guicolor_T prev_fg_color = INVALCOLOR; |
| 128 | static guicolor_T prev_bg_color = INVALCOLOR; |
Bram Moolenaar | fb26980 | 2005-03-15 22:46:30 +0000 | [diff] [blame] | 129 | static guicolor_T prev_sp_color = INVALCOLOR; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 130 | |
| 131 | #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) |
| 132 | static XButtonPressedEvent last_mouse_event; |
| 133 | #endif |
| 134 | |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 135 | static void gui_x11_check_copy_area(void); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 136 | #ifdef FEAT_CLIENTSERVER |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 137 | static void gui_x11_send_event_handler(Widget, XtPointer, XEvent *, Boolean *); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 138 | #endif |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 139 | static void gui_x11_wm_protocol_handler(Widget, XtPointer, XEvent *, Boolean *); |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 140 | static Cursor gui_x11_create_blank_mouse(void); |
| 141 | static void draw_curl(int row, int col, int cells); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 142 | |
| 143 | |
| 144 | /* |
| 145 | * Keycodes recognized by vim. |
| 146 | * NOTE: when changing this, the table in gui_gtk_x11.c probably needs the |
| 147 | * same change! |
| 148 | */ |
| 149 | static struct specialkey |
| 150 | { |
| 151 | KeySym key_sym; |
| 152 | char_u vim_code0; |
| 153 | char_u vim_code1; |
| 154 | } special_keys[] = |
| 155 | { |
| 156 | {XK_Up, 'k', 'u'}, |
| 157 | {XK_Down, 'k', 'd'}, |
| 158 | {XK_Left, 'k', 'l'}, |
| 159 | {XK_Right, 'k', 'r'}, |
| 160 | |
| 161 | {XK_F1, 'k', '1'}, |
| 162 | {XK_F2, 'k', '2'}, |
| 163 | {XK_F3, 'k', '3'}, |
| 164 | {XK_F4, 'k', '4'}, |
| 165 | {XK_F5, 'k', '5'}, |
| 166 | {XK_F6, 'k', '6'}, |
| 167 | {XK_F7, 'k', '7'}, |
| 168 | {XK_F8, 'k', '8'}, |
| 169 | {XK_F9, 'k', '9'}, |
| 170 | {XK_F10, 'k', ';'}, |
| 171 | |
| 172 | {XK_F11, 'F', '1'}, |
| 173 | {XK_F12, 'F', '2'}, |
| 174 | {XK_F13, 'F', '3'}, |
| 175 | {XK_F14, 'F', '4'}, |
| 176 | {XK_F15, 'F', '5'}, |
| 177 | {XK_F16, 'F', '6'}, |
| 178 | {XK_F17, 'F', '7'}, |
| 179 | {XK_F18, 'F', '8'}, |
| 180 | {XK_F19, 'F', '9'}, |
| 181 | {XK_F20, 'F', 'A'}, |
| 182 | |
| 183 | {XK_F21, 'F', 'B'}, |
| 184 | {XK_F22, 'F', 'C'}, |
| 185 | {XK_F23, 'F', 'D'}, |
| 186 | {XK_F24, 'F', 'E'}, |
| 187 | {XK_F25, 'F', 'F'}, |
| 188 | {XK_F26, 'F', 'G'}, |
| 189 | {XK_F27, 'F', 'H'}, |
| 190 | {XK_F28, 'F', 'I'}, |
| 191 | {XK_F29, 'F', 'J'}, |
| 192 | {XK_F30, 'F', 'K'}, |
| 193 | |
| 194 | {XK_F31, 'F', 'L'}, |
| 195 | {XK_F32, 'F', 'M'}, |
| 196 | {XK_F33, 'F', 'N'}, |
| 197 | {XK_F34, 'F', 'O'}, |
| 198 | {XK_F35, 'F', 'P'}, /* keysymdef.h defines up to F35 */ |
| 199 | #ifdef SunXK_F36 |
| 200 | {SunXK_F36, 'F', 'Q'}, |
| 201 | {SunXK_F37, 'F', 'R'}, |
| 202 | #endif |
| 203 | |
| 204 | {XK_Help, '%', '1'}, |
| 205 | {XK_Undo, '&', '8'}, |
| 206 | {XK_BackSpace, 'k', 'b'}, |
| 207 | {XK_Insert, 'k', 'I'}, |
| 208 | {XK_Delete, 'k', 'D'}, |
| 209 | {XK_Home, 'k', 'h'}, |
| 210 | {XK_End, '@', '7'}, |
| 211 | {XK_Prior, 'k', 'P'}, |
| 212 | {XK_Next, 'k', 'N'}, |
| 213 | {XK_Print, '%', '9'}, |
| 214 | |
| 215 | /* Keypad keys: */ |
| 216 | #ifdef XK_KP_Left |
| 217 | {XK_KP_Left, 'k', 'l'}, |
| 218 | {XK_KP_Right, 'k', 'r'}, |
| 219 | {XK_KP_Up, 'k', 'u'}, |
| 220 | {XK_KP_Down, 'k', 'd'}, |
| 221 | {XK_KP_Insert, KS_EXTRA, (char_u)KE_KINS}, |
| 222 | {XK_KP_Delete, KS_EXTRA, (char_u)KE_KDEL}, |
| 223 | {XK_KP_Home, 'K', '1'}, |
| 224 | {XK_KP_End, 'K', '4'}, |
| 225 | {XK_KP_Prior, 'K', '3'}, |
| 226 | {XK_KP_Next, 'K', '5'}, |
| 227 | |
| 228 | {XK_KP_Add, 'K', '6'}, |
| 229 | {XK_KP_Subtract, 'K', '7'}, |
| 230 | {XK_KP_Divide, 'K', '8'}, |
| 231 | {XK_KP_Multiply, 'K', '9'}, |
| 232 | {XK_KP_Enter, 'K', 'A'}, |
| 233 | {XK_KP_Decimal, 'K', 'B'}, |
| 234 | |
| 235 | {XK_KP_0, 'K', 'C'}, |
| 236 | {XK_KP_1, 'K', 'D'}, |
| 237 | {XK_KP_2, 'K', 'E'}, |
| 238 | {XK_KP_3, 'K', 'F'}, |
| 239 | {XK_KP_4, 'K', 'G'}, |
| 240 | {XK_KP_5, 'K', 'H'}, |
| 241 | {XK_KP_6, 'K', 'I'}, |
| 242 | {XK_KP_7, 'K', 'J'}, |
| 243 | {XK_KP_8, 'K', 'K'}, |
| 244 | {XK_KP_9, 'K', 'L'}, |
| 245 | #endif |
| 246 | |
| 247 | /* End of list marker: */ |
| 248 | {(KeySym)0, 0, 0} |
| 249 | }; |
| 250 | |
| 251 | #define XtNboldFont "boldFont" |
| 252 | #define XtCBoldFont "BoldFont" |
| 253 | #define XtNitalicFont "italicFont" |
| 254 | #define XtCItalicFont "ItalicFont" |
| 255 | #define XtNboldItalicFont "boldItalicFont" |
| 256 | #define XtCBoldItalicFont "BoldItalicFont" |
| 257 | #define XtNscrollbarWidth "scrollbarWidth" |
| 258 | #define XtCScrollbarWidth "ScrollbarWidth" |
| 259 | #define XtNmenuHeight "menuHeight" |
| 260 | #define XtCMenuHeight "MenuHeight" |
| 261 | #define XtNmenuFont "menuFont" |
| 262 | #define XtCMenuFont "MenuFont" |
| 263 | #define XtNmenuFontSet "menuFontSet" |
| 264 | #define XtCMenuFontSet "MenuFontSet" |
| 265 | |
| 266 | |
| 267 | /* Resources for setting the foreground and background colors of menus */ |
| 268 | #define XtNmenuBackground "menuBackground" |
| 269 | #define XtCMenuBackground "MenuBackground" |
| 270 | #define XtNmenuForeground "menuForeground" |
| 271 | #define XtCMenuForeground "MenuForeground" |
| 272 | |
| 273 | /* Resources for setting the foreground and background colors of scrollbars */ |
| 274 | #define XtNscrollBackground "scrollBackground" |
| 275 | #define XtCScrollBackground "ScrollBackground" |
| 276 | #define XtNscrollForeground "scrollForeground" |
| 277 | #define XtCScrollForeground "ScrollForeground" |
| 278 | |
| 279 | /* Resources for setting the foreground and background colors of tooltip */ |
| 280 | #define XtNtooltipBackground "tooltipBackground" |
| 281 | #define XtCTooltipBackground "TooltipBackground" |
| 282 | #define XtNtooltipForeground "tooltipForeground" |
| 283 | #define XtCTooltipForeground "TooltipForeground" |
| 284 | #define XtNtooltipFont "tooltipFont" |
| 285 | #define XtCTooltipFont "TooltipFont" |
| 286 | |
| 287 | /* |
| 288 | * X Resources: |
| 289 | */ |
| 290 | static XtResource vim_resources[] = |
| 291 | { |
| 292 | { |
| 293 | XtNforeground, |
| 294 | XtCForeground, |
| 295 | XtRPixel, |
| 296 | sizeof(Pixel), |
| 297 | XtOffsetOf(gui_T, def_norm_pixel), |
| 298 | XtRString, |
| 299 | XtDefaultForeground |
| 300 | }, |
| 301 | { |
| 302 | XtNbackground, |
| 303 | XtCBackground, |
| 304 | XtRPixel, |
| 305 | sizeof(Pixel), |
| 306 | XtOffsetOf(gui_T, def_back_pixel), |
| 307 | XtRString, |
| 308 | XtDefaultBackground |
| 309 | }, |
| 310 | { |
| 311 | XtNfont, |
| 312 | XtCFont, |
| 313 | XtRString, |
| 314 | sizeof(String *), |
| 315 | XtOffsetOf(gui_T, rsrc_font_name), |
| 316 | XtRImmediate, |
| 317 | XtDefaultFont |
| 318 | }, |
| 319 | { |
| 320 | XtNboldFont, |
| 321 | XtCBoldFont, |
| 322 | XtRString, |
| 323 | sizeof(String *), |
| 324 | XtOffsetOf(gui_T, rsrc_bold_font_name), |
| 325 | XtRImmediate, |
| 326 | "" |
| 327 | }, |
| 328 | { |
| 329 | XtNitalicFont, |
| 330 | XtCItalicFont, |
| 331 | XtRString, |
| 332 | sizeof(String *), |
| 333 | XtOffsetOf(gui_T, rsrc_ital_font_name), |
| 334 | XtRImmediate, |
| 335 | "" |
| 336 | }, |
| 337 | { |
| 338 | XtNboldItalicFont, |
| 339 | XtCBoldItalicFont, |
| 340 | XtRString, |
| 341 | sizeof(String *), |
| 342 | XtOffsetOf(gui_T, rsrc_boldital_font_name), |
| 343 | XtRImmediate, |
| 344 | "" |
| 345 | }, |
| 346 | { |
| 347 | XtNgeometry, |
| 348 | XtCGeometry, |
| 349 | XtRString, |
| 350 | sizeof(String *), |
| 351 | XtOffsetOf(gui_T, geom), |
| 352 | XtRImmediate, |
| 353 | "" |
| 354 | }, |
| 355 | { |
| 356 | XtNreverseVideo, |
| 357 | XtCReverseVideo, |
| 358 | XtRBool, |
| 359 | sizeof(Bool), |
| 360 | XtOffsetOf(gui_T, rsrc_rev_video), |
| 361 | XtRImmediate, |
| 362 | (XtPointer)False |
| 363 | }, |
| 364 | { |
| 365 | XtNborderWidth, |
| 366 | XtCBorderWidth, |
| 367 | XtRInt, |
| 368 | sizeof(int), |
| 369 | XtOffsetOf(gui_T, border_width), |
| 370 | XtRImmediate, |
| 371 | (XtPointer)2 |
| 372 | }, |
| 373 | { |
| 374 | XtNscrollbarWidth, |
| 375 | XtCScrollbarWidth, |
| 376 | XtRInt, |
| 377 | sizeof(int), |
| 378 | XtOffsetOf(gui_T, scrollbar_width), |
| 379 | XtRImmediate, |
| 380 | (XtPointer)SB_DEFAULT_WIDTH |
| 381 | }, |
| 382 | #ifdef FEAT_MENU |
| 383 | # ifdef FEAT_GUI_ATHENA /* with Motif the height is always computed */ |
| 384 | { |
| 385 | XtNmenuHeight, |
| 386 | XtCMenuHeight, |
| 387 | XtRInt, |
| 388 | sizeof(int), |
| 389 | XtOffsetOf(gui_T, menu_height), |
| 390 | XtRImmediate, |
| 391 | (XtPointer)MENU_DEFAULT_HEIGHT /* Should figure out at run time */ |
| 392 | }, |
| 393 | # endif |
| 394 | { |
| 395 | # ifdef FONTSET_ALWAYS |
| 396 | XtNmenuFontSet, |
| 397 | XtCMenuFontSet, |
| 398 | #else |
| 399 | XtNmenuFont, |
| 400 | XtCMenuFont, |
| 401 | #endif |
| 402 | XtRString, |
| 403 | sizeof(char *), |
| 404 | XtOffsetOf(gui_T, rsrc_menu_font_name), |
| 405 | XtRString, |
| 406 | DFLT_MENU_FONT |
| 407 | }, |
| 408 | #endif |
| 409 | { |
| 410 | XtNmenuForeground, |
| 411 | XtCMenuForeground, |
| 412 | XtRString, |
| 413 | sizeof(char *), |
| 414 | XtOffsetOf(gui_T, rsrc_menu_fg_name), |
| 415 | XtRString, |
| 416 | DFLT_MENU_FG_COLOR |
| 417 | }, |
| 418 | { |
| 419 | XtNmenuBackground, |
| 420 | XtCMenuBackground, |
| 421 | XtRString, |
| 422 | sizeof(char *), |
| 423 | XtOffsetOf(gui_T, rsrc_menu_bg_name), |
| 424 | XtRString, |
| 425 | DFLT_MENU_BG_COLOR |
| 426 | }, |
| 427 | { |
| 428 | XtNscrollForeground, |
| 429 | XtCScrollForeground, |
| 430 | XtRString, |
| 431 | sizeof(char *), |
| 432 | XtOffsetOf(gui_T, rsrc_scroll_fg_name), |
| 433 | XtRString, |
| 434 | DFLT_SCROLL_FG_COLOR |
| 435 | }, |
| 436 | { |
| 437 | XtNscrollBackground, |
| 438 | XtCScrollBackground, |
| 439 | XtRString, |
| 440 | sizeof(char *), |
| 441 | XtOffsetOf(gui_T, rsrc_scroll_bg_name), |
| 442 | XtRString, |
| 443 | DFLT_SCROLL_BG_COLOR |
| 444 | }, |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 445 | #ifdef FEAT_BEVAL_GUI |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 446 | { |
| 447 | XtNtooltipForeground, |
| 448 | XtCTooltipForeground, |
| 449 | XtRString, |
| 450 | sizeof(char *), |
| 451 | XtOffsetOf(gui_T, rsrc_tooltip_fg_name), |
| 452 | XtRString, |
| 453 | DFLT_TOOLTIP_FG_COLOR |
| 454 | }, |
| 455 | { |
| 456 | XtNtooltipBackground, |
| 457 | XtCTooltipBackground, |
| 458 | XtRString, |
| 459 | sizeof(char *), |
| 460 | XtOffsetOf(gui_T, rsrc_tooltip_bg_name), |
| 461 | XtRString, |
| 462 | DFLT_TOOLTIP_BG_COLOR |
| 463 | }, |
| 464 | { |
| 465 | XtNtooltipFont, |
| 466 | XtCTooltipFont, |
| 467 | XtRString, |
| 468 | sizeof(char *), |
| 469 | XtOffsetOf(gui_T, rsrc_tooltip_font_name), |
| 470 | XtRString, |
| 471 | DFLT_TOOLTIP_FONT |
| 472 | }, |
| 473 | /* This one isn't really needed, keep for Sun Workshop? */ |
| 474 | { |
| 475 | "balloonEvalFontSet", |
| 476 | XtCFontSet, |
| 477 | XtRFontSet, |
| 478 | sizeof(XFontSet), |
| 479 | XtOffsetOf(gui_T, tooltip_fontset), |
| 480 | XtRImmediate, |
| 481 | (XtPointer)NOFONTSET |
| 482 | }, |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 483 | #endif /* FEAT_BEVAL_GUI */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 484 | #ifdef FEAT_XIM |
| 485 | { |
| 486 | "preeditType", |
| 487 | "PreeditType", |
| 488 | XtRString, |
| 489 | sizeof(char*), |
| 490 | XtOffsetOf(gui_T, rsrc_preedit_type_name), |
| 491 | XtRString, |
| 492 | (XtPointer)"OverTheSpot,OffTheSpot,Root" |
| 493 | }, |
| 494 | { |
| 495 | "inputMethod", |
| 496 | "InputMethod", |
| 497 | XtRString, |
| 498 | sizeof(char*), |
| 499 | XtOffsetOf(gui_T, rsrc_input_method), |
| 500 | XtRString, |
| 501 | NULL |
| 502 | }, |
| 503 | #endif /* FEAT_XIM */ |
| 504 | }; |
| 505 | |
| 506 | /* |
| 507 | * This table holds all the X GUI command line options allowed. This includes |
| 508 | * the standard ones so that we can skip them when vim is started without the |
| 509 | * GUI (but the GUI might start up later). |
| 510 | * When changing this, also update doc/vim_gui.txt and the usage message!!! |
| 511 | */ |
| 512 | static XrmOptionDescRec cmdline_options[] = |
| 513 | { |
| 514 | /* We handle these options ourselves */ |
| 515 | {"-bg", ".background", XrmoptionSepArg, NULL}, |
| 516 | {"-background", ".background", XrmoptionSepArg, NULL}, |
| 517 | {"-fg", ".foreground", XrmoptionSepArg, NULL}, |
| 518 | {"-foreground", ".foreground", XrmoptionSepArg, NULL}, |
| 519 | {"-fn", ".font", XrmoptionSepArg, NULL}, |
| 520 | {"-font", ".font", XrmoptionSepArg, NULL}, |
| 521 | {"-boldfont", ".boldFont", XrmoptionSepArg, NULL}, |
| 522 | {"-italicfont", ".italicFont", XrmoptionSepArg, NULL}, |
| 523 | {"-geom", ".geometry", XrmoptionSepArg, NULL}, |
| 524 | {"-geometry", ".geometry", XrmoptionSepArg, NULL}, |
| 525 | {"-reverse", "*reverseVideo", XrmoptionNoArg, "True"}, |
| 526 | {"-rv", "*reverseVideo", XrmoptionNoArg, "True"}, |
| 527 | {"+reverse", "*reverseVideo", XrmoptionNoArg, "False"}, |
| 528 | {"+rv", "*reverseVideo", XrmoptionNoArg, "False"}, |
| 529 | {"-display", ".display", XrmoptionSepArg, NULL}, |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 530 | {"-iconic", ".iconic", XrmoptionNoArg, "True"}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 531 | {"-name", ".name", XrmoptionSepArg, NULL}, |
| 532 | {"-bw", ".borderWidth", XrmoptionSepArg, NULL}, |
| 533 | {"-borderwidth", ".borderWidth", XrmoptionSepArg, NULL}, |
| 534 | {"-sw", ".scrollbarWidth", XrmoptionSepArg, NULL}, |
| 535 | {"-scrollbarwidth", ".scrollbarWidth", XrmoptionSepArg, NULL}, |
| 536 | {"-mh", ".menuHeight", XrmoptionSepArg, NULL}, |
| 537 | {"-menuheight", ".menuHeight", XrmoptionSepArg, NULL}, |
| 538 | #ifdef FONTSET_ALWAYS |
| 539 | {"-mf", ".menuFontSet", XrmoptionSepArg, NULL}, |
| 540 | {"-menufont", ".menuFontSet", XrmoptionSepArg, NULL}, |
| 541 | {"-menufontset", ".menuFontSet", XrmoptionSepArg, NULL}, |
| 542 | #else |
| 543 | {"-mf", ".menuFont", XrmoptionSepArg, NULL}, |
| 544 | {"-menufont", ".menuFont", XrmoptionSepArg, NULL}, |
| 545 | #endif |
| 546 | {"-xrm", NULL, XrmoptionResArg, NULL} |
| 547 | }; |
| 548 | |
| 549 | static int gui_argc = 0; |
| 550 | static char **gui_argv = NULL; |
| 551 | |
| 552 | /* |
| 553 | * Call-back routines. |
| 554 | */ |
| 555 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 556 | static void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 557 | gui_x11_timer_cb( |
| 558 | XtPointer timed_out, |
| 559 | XtIntervalId *interval_id UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 560 | { |
| 561 | *((int *)timed_out) = TRUE; |
| 562 | } |
| 563 | |
Bram Moolenaar | 1dccf63 | 2017-08-27 17:38:27 +0200 | [diff] [blame] | 564 | #ifdef FEAT_JOB_CHANNEL |
| 565 | static void |
| 566 | channel_poll_cb( |
| 567 | XtPointer client_data, |
| 568 | XtIntervalId *interval_id UNUSED) |
| 569 | { |
| 570 | XtIntervalId *channel_timer = (XtIntervalId *)client_data; |
| 571 | |
| 572 | /* Using an event handler for a channel that may be disconnected does |
| 573 | * not work, it hangs. Instead poll for messages. */ |
| 574 | channel_handle_events(TRUE); |
| 575 | parse_queued_messages(); |
| 576 | |
| 577 | /* repeat */ |
| 578 | *channel_timer = XtAppAddTimeOut(app_context, (long_u)20, |
| 579 | channel_poll_cb, client_data); |
| 580 | } |
| 581 | #endif |
| 582 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 583 | static void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 584 | gui_x11_visibility_cb( |
| 585 | Widget w UNUSED, |
| 586 | XtPointer dud UNUSED, |
| 587 | XEvent *event, |
| 588 | Boolean *dum UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 589 | { |
| 590 | if (event->type != VisibilityNotify) |
| 591 | return; |
| 592 | |
| 593 | gui.visibility = event->xvisibility.state; |
| 594 | |
| 595 | /* |
| 596 | * When we do an XCopyArea(), and the window is partially obscured, we want |
| 597 | * to receive an event to tell us whether it worked or not. |
| 598 | */ |
| 599 | XSetGraphicsExposures(gui.dpy, gui.text_gc, |
| 600 | gui.visibility != VisibilityUnobscured); |
| 601 | |
| 602 | /* This is needed for when redrawing is slow. */ |
| 603 | gui_mch_update(); |
| 604 | } |
| 605 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 606 | static void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 607 | gui_x11_expose_cb( |
| 608 | Widget w UNUSED, |
| 609 | XtPointer dud UNUSED, |
| 610 | XEvent *event, |
| 611 | Boolean *dum UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 612 | { |
| 613 | XExposeEvent *gevent; |
| 614 | int new_x; |
| 615 | |
| 616 | if (event->type != Expose) |
| 617 | return; |
| 618 | |
| 619 | out_flush(); /* make sure all output has been processed */ |
| 620 | |
| 621 | gevent = (XExposeEvent *)event; |
| 622 | gui_redraw(gevent->x, gevent->y, gevent->width, gevent->height); |
| 623 | |
| 624 | new_x = FILL_X(0); |
| 625 | |
| 626 | /* Clear the border areas if needed */ |
| 627 | if (gevent->x < new_x) |
| 628 | XClearArea(gui.dpy, gui.wid, 0, 0, new_x, 0, False); |
| 629 | if (gevent->y < FILL_Y(0)) |
| 630 | XClearArea(gui.dpy, gui.wid, 0, 0, 0, FILL_Y(0), False); |
| 631 | if (gevent->x > FILL_X(Columns)) |
| 632 | XClearArea(gui.dpy, gui.wid, FILL_X((int)Columns), 0, 0, 0, False); |
| 633 | if (gevent->y > FILL_Y(Rows)) |
| 634 | XClearArea(gui.dpy, gui.wid, 0, FILL_Y((int)Rows), 0, 0, False); |
| 635 | |
| 636 | /* This is needed for when redrawing is slow. */ |
| 637 | gui_mch_update(); |
| 638 | } |
| 639 | |
Bram Moolenaar | 67c5384 | 2010-05-22 18:28:27 +0200 | [diff] [blame] | 640 | #if ((defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)) \ |
| 641 | && defined(FEAT_GUI_MOTIF)) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 642 | /* |
Bram Moolenaar | 231334e | 2005-07-25 20:46:57 +0000 | [diff] [blame] | 643 | * This function fills in the XRectangle object with the current x,y |
| 644 | * coordinates and height, width so that an XtVaSetValues to the same shell of |
Bram Moolenaar | 4932594 | 2007-05-10 19:19:59 +0000 | [diff] [blame] | 645 | * those resources will restore the window to its former position and |
Bram Moolenaar | 231334e | 2005-07-25 20:46:57 +0000 | [diff] [blame] | 646 | * dimensions. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 647 | * |
Bram Moolenaar | 231334e | 2005-07-25 20:46:57 +0000 | [diff] [blame] | 648 | * Note: This function may fail, in which case the XRectangle will be |
| 649 | * unchanged. Be sure to have the XRectangle set with the proper values for a |
| 650 | * failed condition prior to calling this function. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 651 | */ |
| 652 | static void |
| 653 | shellRectangle(Widget shell, XRectangle *r) |
| 654 | { |
| 655 | Window rootw, shellw, child, parentw; |
| 656 | int absx, absy; |
| 657 | XWindowAttributes a; |
| 658 | Window *children; |
| 659 | unsigned int childrenCount; |
| 660 | |
| 661 | shellw = XtWindow(shell); |
| 662 | if (shellw == 0) |
| 663 | return; |
| 664 | for (;;) |
| 665 | { |
| 666 | XQueryTree(XtDisplay(shell), shellw, &rootw, &parentw, |
| 667 | &children, &childrenCount); |
| 668 | XFree(children); |
| 669 | if (parentw == rootw) |
| 670 | break; |
| 671 | shellw = parentw; |
| 672 | } |
| 673 | XGetWindowAttributes(XtDisplay(shell), shellw, &a); |
| 674 | XTranslateCoordinates(XtDisplay(shell), shellw, a.root, 0, 0, |
| 675 | &absx, &absy, &child); |
| 676 | r->x = absx; |
| 677 | r->y = absy; |
| 678 | XtVaGetValues(shell, XmNheight, &r->height, XmNwidth, &r->width, NULL); |
| 679 | } |
| 680 | #endif |
| 681 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 682 | static void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 683 | gui_x11_resize_window_cb( |
| 684 | Widget w UNUSED, |
| 685 | XtPointer dud UNUSED, |
| 686 | XEvent *event, |
| 687 | Boolean *dum UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 688 | { |
| 689 | static int lastWidth, lastHeight; |
| 690 | |
| 691 | if (event->type != ConfigureNotify) |
| 692 | return; |
| 693 | |
| 694 | if (event->xconfigure.width != lastWidth |
| 695 | || event->xconfigure.height != lastHeight) |
| 696 | { |
| 697 | lastWidth = event->xconfigure.width; |
| 698 | lastHeight = event->xconfigure.height; |
| 699 | gui_resize_shell(event->xconfigure.width, event->xconfigure.height |
| 700 | #ifdef FEAT_XIM |
| 701 | - xim_get_status_area_height() |
| 702 | #endif |
| 703 | ); |
| 704 | } |
| 705 | #ifdef FEAT_SUN_WORKSHOP |
| 706 | if (usingSunWorkShop) |
| 707 | { |
| 708 | XRectangle rec; |
| 709 | |
| 710 | shellRectangle(w, &rec); |
| 711 | workshop_frame_moved(rec.x, rec.y, rec.width, rec.height); |
| 712 | } |
| 713 | #endif |
Bram Moolenaar | 67c5384 | 2010-05-22 18:28:27 +0200 | [diff] [blame] | 714 | #if defined(FEAT_NETBEANS_INTG) && defined(FEAT_GUI_MOTIF) |
Bram Moolenaar | b26e632 | 2010-05-22 21:34:09 +0200 | [diff] [blame] | 715 | if (netbeans_active()) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 716 | { |
| 717 | XRectangle rec; |
| 718 | |
| 719 | shellRectangle(w, &rec); |
| 720 | netbeans_frame_moved(rec.x, rec.y); |
| 721 | } |
| 722 | #endif |
| 723 | #ifdef FEAT_XIM |
| 724 | xim_set_preedit(); |
| 725 | #endif |
| 726 | } |
| 727 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 728 | static void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 729 | gui_x11_focus_change_cb( |
| 730 | Widget w UNUSED, |
| 731 | XtPointer data UNUSED, |
| 732 | XEvent *event, |
| 733 | Boolean *dum UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 734 | { |
| 735 | gui_focus_change(event->type == FocusIn); |
| 736 | } |
| 737 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 738 | static void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 739 | gui_x11_enter_cb( |
| 740 | Widget w UNUSED, |
| 741 | XtPointer data UNUSED, |
| 742 | XEvent *event UNUSED, |
| 743 | Boolean *dum UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 744 | { |
| 745 | gui_focus_change(TRUE); |
| 746 | } |
| 747 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 748 | static void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 749 | gui_x11_leave_cb( |
| 750 | Widget w UNUSED, |
| 751 | XtPointer data UNUSED, |
| 752 | XEvent *event UNUSED, |
| 753 | Boolean *dum UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 754 | { |
| 755 | gui_focus_change(FALSE); |
| 756 | } |
| 757 | |
| 758 | #if defined(X_HAVE_UTF8_STRING) && defined(FEAT_MBYTE) |
| 759 | # if X_HAVE_UTF8_STRING |
| 760 | # define USE_UTF8LOOKUP |
| 761 | # endif |
| 762 | #endif |
| 763 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 764 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 765 | gui_x11_key_hit_cb( |
| 766 | Widget w UNUSED, |
| 767 | XtPointer dud UNUSED, |
| 768 | XEvent *event, |
| 769 | Boolean *dum UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 770 | { |
| 771 | XKeyPressedEvent *ev_press; |
| 772 | #ifdef FEAT_XIM |
| 773 | char_u string2[256]; |
| 774 | char_u string_shortbuf[256]; |
| 775 | char_u *string = string_shortbuf; |
| 776 | Boolean string_alloced = False; |
| 777 | Status status; |
| 778 | #else |
| 779 | char_u string[4], string2[3]; |
| 780 | #endif |
| 781 | KeySym key_sym, key_sym2; |
| 782 | int len, len2; |
| 783 | int i; |
| 784 | int modifiers; |
| 785 | int key; |
| 786 | |
| 787 | ev_press = (XKeyPressedEvent *)event; |
| 788 | |
| 789 | #ifdef FEAT_XIM |
| 790 | if (xic) |
| 791 | { |
| 792 | # ifdef USE_UTF8LOOKUP |
| 793 | /* XFree86 4.0.2 or newer: Be able to get UTF-8 characters even when |
| 794 | * the locale isn't utf-8. */ |
| 795 | if (enc_utf8) |
| 796 | len = Xutf8LookupString(xic, ev_press, (char *)string, |
| 797 | sizeof(string_shortbuf), &key_sym, &status); |
| 798 | else |
| 799 | # endif |
| 800 | len = XmbLookupString(xic, ev_press, (char *)string, |
| 801 | sizeof(string_shortbuf), &key_sym, &status); |
| 802 | if (status == XBufferOverflow) |
| 803 | { |
| 804 | string = (char_u *)XtMalloc(len + 1); |
| 805 | string_alloced = True; |
| 806 | # ifdef USE_UTF8LOOKUP |
| 807 | /* XFree86 4.0.2 or newer: Be able to get UTF-8 characters even |
| 808 | * when the locale isn't utf-8. */ |
| 809 | if (enc_utf8) |
| 810 | len = Xutf8LookupString(xic, ev_press, (char *)string, |
| 811 | len, &key_sym, &status); |
| 812 | else |
| 813 | # endif |
| 814 | len = XmbLookupString(xic, ev_press, (char *)string, |
| 815 | len, &key_sym, &status); |
| 816 | } |
| 817 | if (status == XLookupNone || status == XLookupChars) |
| 818 | key_sym = XK_VoidSymbol; |
| 819 | |
| 820 | # ifdef FEAT_MBYTE |
| 821 | /* Do conversion from 'termencoding' to 'encoding'. When using |
| 822 | * Xutf8LookupString() it has already been done. */ |
| 823 | if (len > 0 && input_conv.vc_type != CONV_NONE |
| 824 | # ifdef USE_UTF8LOOKUP |
| 825 | && !enc_utf8 |
| 826 | # endif |
| 827 | ) |
| 828 | { |
Bram Moolenaar | d23a823 | 2018-02-10 18:45:26 +0100 | [diff] [blame] | 829 | int maxlen = len * 4 + 40; /* guessed */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 830 | char_u *p = (char_u *)XtMalloc(maxlen); |
| 831 | |
| 832 | mch_memmove(p, string, len); |
| 833 | if (string_alloced) |
| 834 | XtFree((char *)string); |
| 835 | string = p; |
| 836 | string_alloced = True; |
| 837 | len = convert_input(p, len, maxlen); |
| 838 | } |
| 839 | # endif |
| 840 | |
| 841 | /* Translate CSI to K_CSI, otherwise it could be recognized as the |
| 842 | * start of a special key. */ |
| 843 | for (i = 0; i < len; ++i) |
| 844 | if (string[i] == CSI) |
| 845 | { |
| 846 | char_u *p = (char_u *)XtMalloc(len + 3); |
| 847 | |
| 848 | mch_memmove(p, string, i + 1); |
| 849 | p[i + 1] = KS_EXTRA; |
| 850 | p[i + 2] = (int)KE_CSI; |
| 851 | mch_memmove(p + i + 3, string + i + 1, len - i); |
| 852 | if (string_alloced) |
| 853 | XtFree((char *)string); |
| 854 | string = p; |
| 855 | string_alloced = True; |
| 856 | i += 2; |
| 857 | len += 2; |
| 858 | } |
| 859 | } |
| 860 | else |
| 861 | #endif |
| 862 | len = XLookupString(ev_press, (char *)string, sizeof(string), |
| 863 | &key_sym, NULL); |
| 864 | |
| 865 | #ifdef SunXK_F36 |
| 866 | /* |
| 867 | * These keys have bogus lookup strings, and trapping them here is |
| 868 | * easier than trying to XRebindKeysym() on them with every possible |
| 869 | * combination of modifiers. |
| 870 | */ |
| 871 | if (key_sym == SunXK_F36 || key_sym == SunXK_F37) |
| 872 | len = 0; |
| 873 | #endif |
| 874 | |
| 875 | #ifdef FEAT_HANGULIN |
| 876 | if ((key_sym == XK_space) && (ev_press->state & ShiftMask)) |
| 877 | { |
| 878 | hangul_input_state_toggle(); |
| 879 | goto theend; |
| 880 | } |
| 881 | #endif |
| 882 | |
| 883 | if (key_sym == XK_space) |
| 884 | string[0] = ' '; /* Otherwise Ctrl-Space doesn't work */ |
| 885 | |
| 886 | /* |
| 887 | * Only on some machines ^_ requires Ctrl+Shift+minus. For consistency, |
| 888 | * allow just Ctrl+minus too. |
| 889 | */ |
| 890 | if (key_sym == XK_minus && (ev_press->state & ControlMask)) |
| 891 | string[0] = Ctrl__; |
| 892 | |
| 893 | #ifdef XK_ISO_Left_Tab |
| 894 | /* why do we get XK_ISO_Left_Tab instead of XK_Tab for shift-tab? */ |
| 895 | if (key_sym == XK_ISO_Left_Tab) |
| 896 | { |
| 897 | key_sym = XK_Tab; |
| 898 | string[0] = TAB; |
| 899 | len = 1; |
| 900 | } |
| 901 | #endif |
| 902 | |
| 903 | /* Check for Alt/Meta key (Mod1Mask), but not for a BS, DEL or character |
| 904 | * that already has the 8th bit set. And not when using a double-byte |
| 905 | * encoding, setting the 8th bit may make it the lead byte of a |
| 906 | * double-byte character. */ |
| 907 | if (len == 1 |
| 908 | && (ev_press->state & Mod1Mask) |
| 909 | && !(key_sym == XK_BackSpace || key_sym == XK_Delete) |
| 910 | && (string[0] & 0x80) == 0 |
| 911 | #ifdef FEAT_MBYTE |
| 912 | && !enc_dbcs |
| 913 | #endif |
| 914 | ) |
| 915 | { |
| 916 | #if defined(FEAT_MENU) && defined(FEAT_GUI_MOTIF) |
| 917 | /* Ignore ALT keys when they are used for the menu only */ |
| 918 | if (gui.menu_is_active |
| 919 | && (p_wak[0] == 'y' |
| 920 | || (p_wak[0] == 'm' && gui_is_menu_shortcut(string[0])))) |
| 921 | goto theend; |
| 922 | #endif |
| 923 | /* |
| 924 | * Before we set the 8th bit, check to make sure the user doesn't |
| 925 | * already have a mapping defined for this sequence. We determine this |
| 926 | * by checking to see if the input would be the same without the |
| 927 | * Alt/Meta key. |
| 928 | * Don't do this for <S-M-Tab>, that should become K_S_TAB with ALT. |
| 929 | */ |
| 930 | ev_press->state &= ~Mod1Mask; |
| 931 | len2 = XLookupString(ev_press, (char *)string2, sizeof(string2), |
| 932 | &key_sym2, NULL); |
| 933 | if (key_sym2 == XK_space) |
| 934 | string2[0] = ' '; /* Otherwise Meta-Ctrl-Space doesn't work */ |
| 935 | if ( len2 == 1 |
| 936 | && string[0] == string2[0] |
| 937 | && !(key_sym == XK_Tab && (ev_press->state & ShiftMask))) |
| 938 | { |
| 939 | string[0] |= 0x80; |
| 940 | #ifdef FEAT_MBYTE |
| 941 | if (enc_utf8) /* convert to utf-8 */ |
| 942 | { |
| 943 | string[1] = string[0] & 0xbf; |
| 944 | string[0] = ((unsigned)string[0] >> 6) + 0xc0; |
| 945 | if (string[1] == CSI) |
| 946 | { |
| 947 | string[2] = KS_EXTRA; |
| 948 | string[3] = (int)KE_CSI; |
| 949 | len = 4; |
| 950 | } |
| 951 | else |
| 952 | len = 2; |
| 953 | } |
| 954 | #endif |
| 955 | } |
| 956 | else |
| 957 | ev_press->state |= Mod1Mask; |
| 958 | } |
| 959 | |
| 960 | if (len == 1 && string[0] == CSI) |
| 961 | { |
| 962 | string[1] = KS_EXTRA; |
| 963 | string[2] = (int)KE_CSI; |
| 964 | len = -3; |
| 965 | } |
| 966 | |
| 967 | /* Check for special keys. Also do this when len == 1 (key has an ASCII |
| 968 | * value) to detect backspace, delete and keypad keys. */ |
| 969 | if (len == 0 || len == 1) |
| 970 | { |
| 971 | for (i = 0; special_keys[i].key_sym != (KeySym)0; i++) |
| 972 | { |
| 973 | if (special_keys[i].key_sym == key_sym) |
| 974 | { |
| 975 | string[0] = CSI; |
| 976 | string[1] = special_keys[i].vim_code0; |
| 977 | string[2] = special_keys[i].vim_code1; |
| 978 | len = -3; |
| 979 | break; |
| 980 | } |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | /* Unrecognised key is ignored. */ |
| 985 | if (len == 0) |
| 986 | goto theend; |
| 987 | |
| 988 | /* Special keys (and a few others) may have modifiers. Also when using a |
| 989 | * double-byte encoding (can't set the 8th bit). */ |
| 990 | if (len == -3 || key_sym == XK_space || key_sym == XK_Tab |
| 991 | || key_sym == XK_Return || key_sym == XK_Linefeed |
| 992 | || key_sym == XK_Escape |
| 993 | #ifdef FEAT_MBYTE |
| 994 | || (enc_dbcs && len == 1 && (ev_press->state & Mod1Mask)) |
| 995 | #endif |
| 996 | ) |
| 997 | { |
| 998 | modifiers = 0; |
| 999 | if (ev_press->state & ShiftMask) |
| 1000 | modifiers |= MOD_MASK_SHIFT; |
| 1001 | if (ev_press->state & ControlMask) |
| 1002 | modifiers |= MOD_MASK_CTRL; |
| 1003 | if (ev_press->state & Mod1Mask) |
| 1004 | modifiers |= MOD_MASK_ALT; |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 1005 | if (ev_press->state & Mod4Mask) |
| 1006 | modifiers |= MOD_MASK_META; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1007 | |
| 1008 | /* |
| 1009 | * For some keys a shift modifier is translated into another key |
| 1010 | * code. |
| 1011 | */ |
| 1012 | if (len == -3) |
| 1013 | key = TO_SPECIAL(string[1], string[2]); |
| 1014 | else |
| 1015 | key = string[0]; |
| 1016 | key = simplify_key(key, &modifiers); |
| 1017 | if (key == CSI) |
| 1018 | key = K_CSI; |
| 1019 | if (IS_SPECIAL(key)) |
| 1020 | { |
| 1021 | string[0] = CSI; |
| 1022 | string[1] = K_SECOND(key); |
| 1023 | string[2] = K_THIRD(key); |
| 1024 | len = 3; |
| 1025 | } |
| 1026 | else |
| 1027 | { |
| 1028 | string[0] = key; |
| 1029 | len = 1; |
| 1030 | } |
| 1031 | |
| 1032 | if (modifiers != 0) |
| 1033 | { |
| 1034 | string2[0] = CSI; |
| 1035 | string2[1] = KS_MODIFIER; |
| 1036 | string2[2] = modifiers; |
| 1037 | add_to_input_buf(string2, 3); |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | if (len == 1 && ((string[0] == Ctrl_C && ctrl_c_interrupts) |
| 1042 | #ifdef UNIX |
| 1043 | || (intr_char != 0 && string[0] == intr_char) |
| 1044 | #endif |
| 1045 | )) |
| 1046 | { |
| 1047 | trash_input_buf(); |
| 1048 | got_int = TRUE; |
| 1049 | } |
| 1050 | |
| 1051 | add_to_input_buf(string, len); |
| 1052 | |
| 1053 | /* |
| 1054 | * blank out the pointer if necessary |
| 1055 | */ |
| 1056 | if (p_mh) |
| 1057 | gui_mch_mousehide(TRUE); |
| 1058 | |
| 1059 | #if defined(FEAT_BEVAL_TIP) |
| 1060 | { |
| 1061 | BalloonEval *be; |
| 1062 | |
| 1063 | if ((be = gui_mch_currently_showing_beval()) != NULL) |
| 1064 | gui_mch_unpost_balloon(be); |
| 1065 | } |
| 1066 | #endif |
| 1067 | theend: |
| 1068 | {} /* some compilers need a statement here */ |
| 1069 | #ifdef FEAT_XIM |
| 1070 | if (string_alloced) |
| 1071 | XtFree((char *)string); |
| 1072 | #endif |
| 1073 | } |
| 1074 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1075 | static void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 1076 | gui_x11_mouse_cb( |
| 1077 | Widget w UNUSED, |
| 1078 | XtPointer dud UNUSED, |
| 1079 | XEvent *event, |
| 1080 | Boolean *dum UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1081 | { |
| 1082 | static XtIntervalId timer = (XtIntervalId)0; |
| 1083 | static int timed_out = TRUE; |
| 1084 | |
| 1085 | int button; |
| 1086 | int repeated_click = FALSE; |
| 1087 | int x, y; |
| 1088 | int_u x_modifiers; |
| 1089 | int_u vim_modifiers; |
| 1090 | |
| 1091 | if (event->type == MotionNotify) |
| 1092 | { |
| 1093 | /* Get the latest position, avoids lagging behind on a drag. */ |
| 1094 | x = event->xmotion.x; |
| 1095 | y = event->xmotion.y; |
| 1096 | x_modifiers = event->xmotion.state; |
| 1097 | button = (x_modifiers & (Button1Mask | Button2Mask | Button3Mask)) |
| 1098 | ? MOUSE_DRAG : ' '; |
| 1099 | |
| 1100 | /* |
| 1101 | * if our pointer is currently hidden, then we should show it. |
| 1102 | */ |
| 1103 | gui_mch_mousehide(FALSE); |
| 1104 | |
| 1105 | if (button != MOUSE_DRAG) /* just moving the rodent */ |
| 1106 | { |
| 1107 | #ifdef FEAT_MENU |
| 1108 | if (dud) /* moved in vimForm */ |
| 1109 | y -= gui.menu_height; |
| 1110 | #endif |
| 1111 | gui_mouse_moved(x, y); |
| 1112 | return; |
| 1113 | } |
| 1114 | } |
| 1115 | else |
| 1116 | { |
| 1117 | x = event->xbutton.x; |
| 1118 | y = event->xbutton.y; |
| 1119 | if (event->type == ButtonPress) |
| 1120 | { |
| 1121 | /* Handle multiple clicks */ |
| 1122 | if (!timed_out) |
| 1123 | { |
| 1124 | XtRemoveTimeOut(timer); |
| 1125 | repeated_click = TRUE; |
| 1126 | } |
| 1127 | timed_out = FALSE; |
| 1128 | timer = XtAppAddTimeOut(app_context, (long_u)p_mouset, |
| 1129 | gui_x11_timer_cb, &timed_out); |
| 1130 | switch (event->xbutton.button) |
| 1131 | { |
Bram Moolenaar | 88e484b | 2015-11-24 15:38:44 +0100 | [diff] [blame] | 1132 | /* keep in sync with gui_gtk_x11.c */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1133 | case Button1: button = MOUSE_LEFT; break; |
| 1134 | case Button2: button = MOUSE_MIDDLE; break; |
| 1135 | case Button3: button = MOUSE_RIGHT; break; |
| 1136 | case Button4: button = MOUSE_4; break; |
| 1137 | case Button5: button = MOUSE_5; break; |
Bram Moolenaar | 88e484b | 2015-11-24 15:38:44 +0100 | [diff] [blame] | 1138 | case 6: button = MOUSE_7; break; |
| 1139 | case 7: button = MOUSE_6; break; |
| 1140 | case 8: button = MOUSE_X1; break; |
| 1141 | case 9: button = MOUSE_X2; break; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1142 | default: |
| 1143 | return; /* Unknown button */ |
| 1144 | } |
| 1145 | } |
| 1146 | else if (event->type == ButtonRelease) |
| 1147 | button = MOUSE_RELEASE; |
| 1148 | else |
| 1149 | return; /* Unknown mouse event type */ |
| 1150 | |
| 1151 | x_modifiers = event->xbutton.state; |
| 1152 | #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) |
| 1153 | last_mouse_event = event->xbutton; |
| 1154 | #endif |
| 1155 | } |
| 1156 | |
| 1157 | vim_modifiers = 0x0; |
| 1158 | if (x_modifiers & ShiftMask) |
| 1159 | vim_modifiers |= MOUSE_SHIFT; |
| 1160 | if (x_modifiers & ControlMask) |
| 1161 | vim_modifiers |= MOUSE_CTRL; |
| 1162 | if (x_modifiers & Mod1Mask) /* Alt or Meta key */ |
| 1163 | vim_modifiers |= MOUSE_ALT; |
| 1164 | |
| 1165 | gui_send_mouse_event(button, x, y, repeated_click, vim_modifiers); |
| 1166 | } |
| 1167 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1168 | /* |
| 1169 | * End of call-back routines |
| 1170 | */ |
| 1171 | |
| 1172 | /* |
| 1173 | * Parse the GUI related command-line arguments. Any arguments used are |
| 1174 | * deleted from argv, and *argc is decremented accordingly. This is called |
| 1175 | * when vim is started, whether or not the GUI has been started. |
| 1176 | */ |
| 1177 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 1178 | gui_mch_prepare(int *argc, char **argv) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1179 | { |
| 1180 | int arg; |
| 1181 | int i; |
| 1182 | |
| 1183 | /* |
| 1184 | * Move all the entries in argv which are relevant to X into gui_argv. |
| 1185 | */ |
| 1186 | gui_argc = 0; |
| 1187 | gui_argv = (char **)lalloc((long_u)(*argc * sizeof(char *)), FALSE); |
| 1188 | if (gui_argv == NULL) |
| 1189 | return; |
| 1190 | gui_argv[gui_argc++] = argv[0]; |
| 1191 | arg = 1; |
| 1192 | while (arg < *argc) |
| 1193 | { |
| 1194 | /* Look for argv[arg] in cmdline_options[] table */ |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 1195 | for (i = 0; i < (int)XtNumber(cmdline_options); i++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1196 | if (strcmp(argv[arg], cmdline_options[i].option) == 0) |
| 1197 | break; |
| 1198 | |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 1199 | if (i < (int)XtNumber(cmdline_options)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1200 | { |
| 1201 | /* Remember finding "-rv" or "-reverse" */ |
| 1202 | if (strcmp("-rv", argv[arg]) == 0 |
| 1203 | || strcmp("-reverse", argv[arg]) == 0) |
| 1204 | found_reverse_arg = TRUE; |
| 1205 | else if ((strcmp("-fn", argv[arg]) == 0 |
| 1206 | || strcmp("-font", argv[arg]) == 0) |
| 1207 | && arg + 1 < *argc) |
| 1208 | font_argument = argv[arg + 1]; |
| 1209 | |
| 1210 | /* Found match in table, so move it into gui_argv */ |
| 1211 | gui_argv[gui_argc++] = argv[arg]; |
| 1212 | if (--*argc > arg) |
| 1213 | { |
| 1214 | mch_memmove(&argv[arg], &argv[arg + 1], (*argc - arg) |
| 1215 | * sizeof(char *)); |
| 1216 | if (cmdline_options[i].argKind != XrmoptionNoArg) |
| 1217 | { |
| 1218 | /* Move the options argument as well */ |
| 1219 | gui_argv[gui_argc++] = argv[arg]; |
| 1220 | if (--*argc > arg) |
| 1221 | mch_memmove(&argv[arg], &argv[arg + 1], (*argc - arg) |
| 1222 | * sizeof(char *)); |
| 1223 | } |
| 1224 | } |
| 1225 | argv[*argc] = NULL; |
| 1226 | } |
| 1227 | else |
| 1228 | #ifdef FEAT_SUN_WORKSHOP |
| 1229 | if (strcmp("-ws", argv[arg]) == 0) |
| 1230 | { |
| 1231 | usingSunWorkShop++; |
| 1232 | p_acd = TRUE; |
| 1233 | gui.dofork = FALSE; /* don't fork() when starting GUI */ |
| 1234 | mch_memmove(&argv[arg], &argv[arg + 1], |
| 1235 | (--*argc - arg) * sizeof(char *)); |
| 1236 | argv[*argc] = NULL; |
| 1237 | # ifdef WSDEBUG |
| 1238 | wsdebug_wait(WT_ENV | WT_WAIT | WT_STOP, "SPRO_GVIM_WAIT", 20); |
| 1239 | wsdebug_log_init("SPRO_GVIM_DEBUG", "SPRO_GVIM_DLEVEL"); |
| 1240 | # endif |
| 1241 | } |
| 1242 | else |
| 1243 | #endif |
| 1244 | #ifdef FEAT_NETBEANS_INTG |
| 1245 | if (strncmp("-nb", argv[arg], 3) == 0) |
| 1246 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1247 | gui.dofork = FALSE; /* don't fork() when starting GUI */ |
| 1248 | netbeansArg = argv[arg]; |
| 1249 | mch_memmove(&argv[arg], &argv[arg + 1], |
| 1250 | (--*argc - arg) * sizeof(char *)); |
| 1251 | argv[*argc] = NULL; |
| 1252 | } |
| 1253 | else |
| 1254 | #endif |
| 1255 | arg++; |
| 1256 | } |
| 1257 | } |
| 1258 | |
| 1259 | #ifndef XtSpecificationRelease |
| 1260 | # define CARDINAL (Cardinal *) |
| 1261 | #else |
| 1262 | # if XtSpecificationRelease == 4 |
| 1263 | # define CARDINAL (Cardinal *) |
| 1264 | # else |
| 1265 | # define CARDINAL (int *) |
| 1266 | # endif |
| 1267 | #endif |
| 1268 | |
| 1269 | /* |
| 1270 | * Check if the GUI can be started. Called before gvimrc is sourced. |
| 1271 | * Return OK or FAIL. |
| 1272 | */ |
| 1273 | int |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 1274 | gui_mch_init_check(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1275 | { |
| 1276 | #ifdef FEAT_XIM |
| 1277 | XtSetLanguageProc(NULL, NULL, NULL); |
| 1278 | #endif |
| 1279 | open_app_context(); |
| 1280 | if (app_context != NULL) |
| 1281 | gui.dpy = XtOpenDisplay(app_context, 0, VIM_NAME, VIM_CLASS, |
Bram Moolenaar | 1c2fda2 | 2005-01-02 11:43:19 +0000 | [diff] [blame] | 1282 | cmdline_options, XtNumber(cmdline_options), |
| 1283 | CARDINAL &gui_argc, gui_argv); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1284 | |
| 1285 | if (app_context == NULL || gui.dpy == NULL) |
| 1286 | { |
| 1287 | gui.dying = TRUE; |
| 1288 | EMSG(_(e_opendisp)); |
| 1289 | return FAIL; |
| 1290 | } |
| 1291 | return OK; |
| 1292 | } |
| 1293 | |
| 1294 | |
| 1295 | #ifdef USE_XSMP |
| 1296 | /* |
| 1297 | * Handle XSMP processing, de-registering the attachment upon error |
| 1298 | */ |
| 1299 | static XtInputId _xsmp_xtinputid; |
| 1300 | |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 1301 | static void local_xsmp_handle_requests(XtPointer c, int *s, XtInputId *i); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1302 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1303 | static void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 1304 | local_xsmp_handle_requests( |
| 1305 | XtPointer c UNUSED, |
| 1306 | int *s UNUSED, |
| 1307 | XtInputId *i UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1308 | { |
| 1309 | if (xsmp_handle_requests() == FAIL) |
| 1310 | XtRemoveInput(_xsmp_xtinputid); |
| 1311 | } |
| 1312 | #endif |
| 1313 | |
| 1314 | |
| 1315 | /* |
| 1316 | * Initialise the X GUI. Create all the windows, set up all the call-backs etc. |
| 1317 | * Returns OK for success, FAIL when the GUI can't be started. |
| 1318 | */ |
| 1319 | int |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 1320 | gui_mch_init(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1321 | { |
| 1322 | XtGCMask gc_mask; |
| 1323 | XGCValues gc_vals; |
| 1324 | int x, y, mask; |
| 1325 | unsigned w, h; |
| 1326 | |
| 1327 | #if 0 |
| 1328 | /* Uncomment this to enable synchronous mode for debugging */ |
| 1329 | XSynchronize(gui.dpy, True); |
| 1330 | #endif |
| 1331 | |
| 1332 | vimShell = XtVaAppCreateShell(VIM_NAME, VIM_CLASS, |
| 1333 | applicationShellWidgetClass, gui.dpy, NULL); |
| 1334 | |
| 1335 | /* |
| 1336 | * Get the application resources |
| 1337 | */ |
| 1338 | XtVaGetApplicationResources(vimShell, (XtPointer)&gui, |
| 1339 | vim_resources, XtNumber(vim_resources), NULL); |
| 1340 | |
| 1341 | gui.scrollbar_height = gui.scrollbar_width; |
| 1342 | |
| 1343 | /* |
| 1344 | * Get the colors ourselves. Using the automatic conversion doesn't |
| 1345 | * handle looking for approximate colors. |
| 1346 | */ |
| 1347 | /* NOTE: These next few lines are an exact duplicate of gui_athena.c's |
| 1348 | * gui_mch_def_colors(). Why? |
| 1349 | */ |
| 1350 | gui.menu_fg_pixel = gui_get_color((char_u *)gui.rsrc_menu_fg_name); |
| 1351 | gui.menu_bg_pixel = gui_get_color((char_u *)gui.rsrc_menu_bg_name); |
| 1352 | gui.scroll_fg_pixel = gui_get_color((char_u *)gui.rsrc_scroll_fg_name); |
| 1353 | gui.scroll_bg_pixel = gui_get_color((char_u *)gui.rsrc_scroll_bg_name); |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 1354 | #ifdef FEAT_BEVAL_GUI |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1355 | gui.tooltip_fg_pixel = gui_get_color((char_u *)gui.rsrc_tooltip_fg_name); |
| 1356 | gui.tooltip_bg_pixel = gui_get_color((char_u *)gui.rsrc_tooltip_bg_name); |
| 1357 | #endif |
| 1358 | |
| 1359 | #if defined(FEAT_MENU) && defined(FEAT_GUI_ATHENA) |
| 1360 | /* If the menu height was set, don't change it at runtime */ |
| 1361 | if (gui.menu_height != MENU_DEFAULT_HEIGHT) |
| 1362 | gui.menu_height_fixed = TRUE; |
| 1363 | #endif |
| 1364 | |
| 1365 | /* Set default foreground and background colours */ |
| 1366 | gui.norm_pixel = gui.def_norm_pixel; |
| 1367 | gui.back_pixel = gui.def_back_pixel; |
| 1368 | |
| 1369 | /* Check if reverse video needs to be applied (on Sun it's done by X) */ |
| 1370 | if (gui.rsrc_rev_video && gui_get_lightness(gui.back_pixel) |
| 1371 | > gui_get_lightness(gui.norm_pixel)) |
| 1372 | { |
| 1373 | gui.norm_pixel = gui.def_back_pixel; |
| 1374 | gui.back_pixel = gui.def_norm_pixel; |
| 1375 | gui.def_norm_pixel = gui.norm_pixel; |
| 1376 | gui.def_back_pixel = gui.back_pixel; |
| 1377 | } |
| 1378 | |
| 1379 | /* Get the colors from the "Normal", "Tooltip", "Scrollbar" and "Menu" |
| 1380 | * group (set in syntax.c or in a vimrc file) */ |
| 1381 | set_normal_colors(); |
| 1382 | |
| 1383 | /* |
| 1384 | * Check that none of the colors are the same as the background color |
| 1385 | */ |
| 1386 | gui_check_colors(); |
| 1387 | |
| 1388 | /* |
| 1389 | * Set up the GCs. The font attributes will be set in gui_init_font(). |
| 1390 | */ |
| 1391 | gc_mask = GCForeground | GCBackground; |
| 1392 | gc_vals.foreground = gui.norm_pixel; |
| 1393 | gc_vals.background = gui.back_pixel; |
| 1394 | gui.text_gc = XtGetGC(vimShell, gc_mask, &gc_vals); |
| 1395 | |
| 1396 | gc_vals.foreground = gui.back_pixel; |
| 1397 | gc_vals.background = gui.norm_pixel; |
| 1398 | gui.back_gc = XtGetGC(vimShell, gc_mask, &gc_vals); |
| 1399 | |
| 1400 | gc_mask |= GCFunction; |
| 1401 | gc_vals.foreground = gui.norm_pixel ^ gui.back_pixel; |
| 1402 | gc_vals.background = gui.norm_pixel ^ gui.back_pixel; |
| 1403 | gc_vals.function = GXxor; |
| 1404 | gui.invert_gc = XtGetGC(vimShell, gc_mask, &gc_vals); |
| 1405 | |
| 1406 | gui.visibility = VisibilityUnobscured; |
| 1407 | x11_setup_atoms(gui.dpy); |
| 1408 | |
| 1409 | if (gui_win_x != -1 && gui_win_y != -1) |
| 1410 | gui_mch_set_winpos(gui_win_x, gui_win_y); |
| 1411 | |
| 1412 | /* Now adapt the supplied(?) geometry-settings */ |
| 1413 | /* Added by Kjetil Jacobsen <kjetilja@stud.cs.uit.no> */ |
| 1414 | if (gui.geom != NULL && *gui.geom != NUL) |
| 1415 | { |
| 1416 | mask = XParseGeometry((char *)gui.geom, &x, &y, &w, &h); |
| 1417 | if (mask & WidthValue) |
| 1418 | Columns = w; |
| 1419 | if (mask & HeightValue) |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 1420 | { |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 1421 | if (p_window > (long)h - 1 || !option_was_set((char_u *)"window")) |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 1422 | p_window = h - 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1423 | Rows = h; |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 1424 | } |
Bram Moolenaar | c33916a | 2013-07-01 21:43:08 +0200 | [diff] [blame] | 1425 | limit_screen_size(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1426 | /* |
| 1427 | * Set the (x,y) position of the main window only if specified in the |
| 1428 | * users geometry, so we get good defaults when they don't. This needs |
| 1429 | * to be done before the shell is popped up. |
| 1430 | */ |
| 1431 | if (mask & (XValue|YValue)) |
| 1432 | XtVaSetValues(vimShell, XtNgeometry, gui.geom, NULL); |
| 1433 | } |
| 1434 | |
| 1435 | gui_x11_create_widgets(); |
| 1436 | |
| 1437 | /* |
| 1438 | * Add an icon to Vim (Marcel Douben: 11 May 1998). |
| 1439 | */ |
| 1440 | if (vim_strchr(p_go, GO_ICON) != NULL) |
| 1441 | { |
| 1442 | #ifndef HAVE_XPM |
| 1443 | # include "vim_icon.xbm" |
| 1444 | # include "vim_mask.xbm" |
| 1445 | |
| 1446 | Arg arg[2]; |
| 1447 | |
| 1448 | XtSetArg(arg[0], XtNiconPixmap, |
| 1449 | XCreateBitmapFromData(gui.dpy, |
| 1450 | DefaultRootWindow(gui.dpy), |
| 1451 | (char *)vim_icon_bits, |
| 1452 | vim_icon_width, |
| 1453 | vim_icon_height)); |
| 1454 | XtSetArg(arg[1], XtNiconMask, |
| 1455 | XCreateBitmapFromData(gui.dpy, |
| 1456 | DefaultRootWindow(gui.dpy), |
| 1457 | (char *)vim_mask_icon_bits, |
| 1458 | vim_mask_icon_width, |
| 1459 | vim_mask_icon_height)); |
| 1460 | XtSetValues(vimShell, arg, (Cardinal)2); |
| 1461 | #else |
| 1462 | /* Use Pixmaps, looking much nicer. */ |
| 1463 | |
| 1464 | /* If you get an error message here, you still need to unpack the runtime |
| 1465 | * archive! */ |
| 1466 | # ifdef magick |
| 1467 | # undef magick |
| 1468 | # endif |
| 1469 | # define magick vim32x32 |
| 1470 | # include "../runtime/vim32x32.xpm" |
| 1471 | # undef magick |
| 1472 | # define magick vim16x16 |
| 1473 | # include "../runtime/vim16x16.xpm" |
| 1474 | # undef magick |
| 1475 | # define magick vim48x48 |
| 1476 | # include "../runtime/vim48x48.xpm" |
| 1477 | # undef magick |
| 1478 | |
| 1479 | static Pixmap icon = 0; |
| 1480 | static Pixmap icon_mask = 0; |
| 1481 | static char **magick = vim32x32; |
| 1482 | Window root_window; |
| 1483 | XIconSize *size; |
| 1484 | int number_sizes; |
| 1485 | Display *dsp; |
| 1486 | Screen *scr; |
| 1487 | XpmAttributes attr; |
| 1488 | Colormap cmap; |
| 1489 | |
| 1490 | /* |
| 1491 | * Adjust the icon to the preferences of the actual window manager. |
| 1492 | */ |
| 1493 | root_window = XRootWindowOfScreen(XtScreen(vimShell)); |
| 1494 | if (XGetIconSizes(XtDisplay(vimShell), root_window, |
| 1495 | &size, &number_sizes) != 0) |
| 1496 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1497 | if (number_sizes > 0) |
| 1498 | { |
Bram Moolenaar | 6f29266 | 2013-07-14 15:06:50 +0200 | [diff] [blame] | 1499 | if (size->max_height >= 48 && size->max_width >= 48) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1500 | magick = vim48x48; |
Bram Moolenaar | 6f29266 | 2013-07-14 15:06:50 +0200 | [diff] [blame] | 1501 | else if (size->max_height >= 32 && size->max_width >= 32) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1502 | magick = vim32x32; |
Bram Moolenaar | 6f29266 | 2013-07-14 15:06:50 +0200 | [diff] [blame] | 1503 | else if (size->max_height >= 16 && size->max_width >= 16) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1504 | magick = vim16x16; |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | dsp = XtDisplay(vimShell); |
| 1509 | scr = XtScreen(vimShell); |
| 1510 | |
| 1511 | cmap = DefaultColormap(dsp, DefaultScreen(dsp)); |
| 1512 | XtVaSetValues(vimShell, XtNcolormap, cmap, NULL); |
| 1513 | |
| 1514 | attr.valuemask = 0L; |
| 1515 | attr.valuemask = XpmCloseness | XpmReturnPixels | XpmColormap | XpmDepth; |
| 1516 | attr.closeness = 65535; /* accuracy isn't crucial */ |
| 1517 | attr.colormap = cmap; |
| 1518 | attr.depth = DefaultDepthOfScreen(scr); |
| 1519 | |
| 1520 | if (!icon) |
Bram Moolenaar | e820801 | 2008-06-20 09:59:25 +0000 | [diff] [blame] | 1521 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1522 | XpmCreatePixmapFromData(dsp, root_window, magick, &icon, |
| 1523 | &icon_mask, &attr); |
Bram Moolenaar | e820801 | 2008-06-20 09:59:25 +0000 | [diff] [blame] | 1524 | XpmFreeAttributes(&attr); |
| 1525 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1526 | |
| 1527 | # ifdef FEAT_GUI_ATHENA |
| 1528 | XtVaSetValues(vimShell, XtNiconPixmap, icon, XtNiconMask, icon_mask, NULL); |
| 1529 | # else |
| 1530 | XtVaSetValues(vimShell, XmNiconPixmap, icon, XmNiconMask, icon_mask, NULL); |
| 1531 | # endif |
| 1532 | #endif |
| 1533 | } |
| 1534 | |
| 1535 | if (gui.color_approx) |
| 1536 | EMSG(_("Vim E458: Cannot allocate colormap entry, some colors may be incorrect")); |
| 1537 | |
| 1538 | #ifdef FEAT_SUN_WORKSHOP |
| 1539 | if (usingSunWorkShop) |
| 1540 | workshop_connect(app_context); |
| 1541 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1542 | |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 1543 | #ifdef FEAT_BEVAL_GUI |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1544 | gui_init_tooltip_font(); |
| 1545 | #endif |
| 1546 | #ifdef FEAT_MENU |
| 1547 | gui_init_menu_font(); |
| 1548 | #endif |
| 1549 | |
| 1550 | #ifdef USE_XSMP |
| 1551 | /* Attach listener on ICE connection */ |
| 1552 | if (-1 != xsmp_icefd) |
| 1553 | _xsmp_xtinputid = XtAppAddInput(app_context, xsmp_icefd, |
| 1554 | (XtPointer)XtInputReadMask, local_xsmp_handle_requests, NULL); |
| 1555 | #endif |
| 1556 | |
| 1557 | return OK; |
| 1558 | } |
| 1559 | |
| 1560 | /* |
| 1561 | * Called when starting the GUI fails after calling gui_mch_init(). |
| 1562 | */ |
| 1563 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 1564 | gui_mch_uninit(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1565 | { |
| 1566 | gui_x11_destroy_widgets(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1567 | XtCloseDisplay(gui.dpy); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1568 | gui.dpy = NULL; |
| 1569 | vimShell = (Widget)0; |
Bram Moolenaar | d23a823 | 2018-02-10 18:45:26 +0100 | [diff] [blame] | 1570 | VIM_CLEAR(gui_argv); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | /* |
| 1574 | * Called when the foreground or background color has been changed. |
| 1575 | */ |
| 1576 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 1577 | gui_mch_new_colors(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1578 | { |
| 1579 | long_u gc_mask; |
| 1580 | XGCValues gc_vals; |
| 1581 | |
| 1582 | gc_mask = GCForeground | GCBackground; |
| 1583 | gc_vals.foreground = gui.norm_pixel; |
| 1584 | gc_vals.background = gui.back_pixel; |
| 1585 | if (gui.text_gc != NULL) |
| 1586 | XChangeGC(gui.dpy, gui.text_gc, gc_mask, &gc_vals); |
| 1587 | |
| 1588 | gc_vals.foreground = gui.back_pixel; |
| 1589 | gc_vals.background = gui.norm_pixel; |
| 1590 | if (gui.back_gc != NULL) |
| 1591 | XChangeGC(gui.dpy, gui.back_gc, gc_mask, &gc_vals); |
| 1592 | |
| 1593 | gc_mask |= GCFunction; |
| 1594 | gc_vals.foreground = gui.norm_pixel ^ gui.back_pixel; |
| 1595 | gc_vals.background = gui.norm_pixel ^ gui.back_pixel; |
| 1596 | gc_vals.function = GXxor; |
| 1597 | if (gui.invert_gc != NULL) |
| 1598 | XChangeGC(gui.dpy, gui.invert_gc, gc_mask, &gc_vals); |
| 1599 | |
| 1600 | gui_x11_set_back_color(); |
| 1601 | } |
| 1602 | |
| 1603 | /* |
| 1604 | * Open the GUI window which was created by a call to gui_mch_init(). |
| 1605 | */ |
| 1606 | int |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 1607 | gui_mch_open(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1608 | { |
| 1609 | /* Actually open the window */ |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 1610 | XtRealizeWidget(vimShell); |
| 1611 | XtManageChild(XtNameToWidget(vimShell, "*vimForm")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1612 | |
| 1613 | gui.wid = gui_x11_get_wid(); |
| 1614 | gui.blank_pointer = gui_x11_create_blank_mouse(); |
| 1615 | |
| 1616 | /* |
| 1617 | * Add a callback for the Close item on the window managers menu, and the |
| 1618 | * save-yourself event. |
| 1619 | */ |
| 1620 | wm_atoms[SAVE_YOURSELF_IDX] = |
| 1621 | XInternAtom(gui.dpy, "WM_SAVE_YOURSELF", False); |
| 1622 | wm_atoms[DELETE_WINDOW_IDX] = |
| 1623 | XInternAtom(gui.dpy, "WM_DELETE_WINDOW", False); |
| 1624 | XSetWMProtocols(gui.dpy, XtWindow(vimShell), wm_atoms, 2); |
| 1625 | XtAddEventHandler(vimShell, NoEventMask, True, gui_x11_wm_protocol_handler, |
| 1626 | NULL); |
| 1627 | #ifdef HAVE_X11_XMU_EDITRES_H |
| 1628 | /* |
| 1629 | * Enable editres protocol (see "man editres"). |
| 1630 | * Usually will need to add -lXmu to the linker line as well. |
| 1631 | */ |
| 1632 | XtAddEventHandler(vimShell, (EventMask)0, True, _XEditResCheckMessages, |
| 1633 | (XtPointer)NULL); |
| 1634 | #endif |
| 1635 | |
| 1636 | #ifdef FEAT_CLIENTSERVER |
| 1637 | if (serverName == NULL && serverDelayedStartName != NULL) |
| 1638 | { |
| 1639 | /* This is a :gui command in a plain vim with no previous server */ |
| 1640 | commWindow = XtWindow(vimShell); |
| 1641 | (void)serverRegisterName(gui.dpy, serverDelayedStartName); |
| 1642 | } |
| 1643 | else |
| 1644 | { |
| 1645 | /* |
| 1646 | * Cannot handle "widget-less" windows with XtProcessEvent() we'll |
| 1647 | * have to change the "server" registration to that of the main window |
| 1648 | * If we have not registered a name yet, remember the window |
| 1649 | */ |
| 1650 | serverChangeRegisteredWindow(gui.dpy, XtWindow(vimShell)); |
| 1651 | } |
| 1652 | XtAddEventHandler(vimShell, PropertyChangeMask, False, |
| 1653 | gui_x11_send_event_handler, NULL); |
| 1654 | #endif |
| 1655 | |
| 1656 | |
| 1657 | #if defined(FEAT_MENU) && defined(FEAT_GUI_ATHENA) |
| 1658 | /* The Athena GUI needs this again after opening the window */ |
| 1659 | gui_position_menu(); |
| 1660 | # ifdef FEAT_TOOLBAR |
| 1661 | gui_mch_set_toolbar_pos(0, gui.menu_height, gui.menu_width, |
| 1662 | gui.toolbar_height); |
| 1663 | # endif |
| 1664 | #endif |
| 1665 | |
| 1666 | /* Get the colors for the highlight groups (gui_check_colors() might have |
| 1667 | * changed them) */ |
| 1668 | highlight_gui_started(); /* re-init colors and fonts */ |
| 1669 | |
| 1670 | #ifdef FEAT_HANGULIN |
| 1671 | hangul_keyboard_set(); |
| 1672 | #endif |
| 1673 | #ifdef FEAT_XIM |
| 1674 | xim_init(); |
| 1675 | #endif |
| 1676 | #ifdef FEAT_SUN_WORKSHOP |
| 1677 | workshop_postinit(); |
| 1678 | #endif |
| 1679 | |
| 1680 | return OK; |
| 1681 | } |
| 1682 | |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 1683 | #if defined(FEAT_BEVAL_GUI) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1684 | /* |
| 1685 | * Convert the tooltip fontset name to an XFontSet. |
| 1686 | */ |
| 1687 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 1688 | gui_init_tooltip_font(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1689 | { |
| 1690 | XrmValue from, to; |
| 1691 | |
| 1692 | from.addr = (char *)gui.rsrc_tooltip_font_name; |
| 1693 | from.size = strlen(from.addr); |
| 1694 | to.addr = (XtPointer)&gui.tooltip_fontset; |
| 1695 | to.size = sizeof(XFontSet); |
| 1696 | |
| 1697 | if (XtConvertAndStore(vimShell, XtRString, &from, XtRFontSet, &to) == False) |
| 1698 | { |
| 1699 | /* Failed. What to do? */ |
| 1700 | } |
| 1701 | } |
| 1702 | #endif |
| 1703 | |
| 1704 | #if defined(FEAT_MENU) || defined(PROTO) |
| 1705 | /* Convert the menu font/fontset name to an XFontStruct/XFontset */ |
| 1706 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 1707 | gui_init_menu_font(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1708 | { |
| 1709 | XrmValue from, to; |
| 1710 | |
| 1711 | #ifdef FONTSET_ALWAYS |
| 1712 | from.addr = (char *)gui.rsrc_menu_font_name; |
| 1713 | from.size = strlen(from.addr); |
| 1714 | to.addr = (XtPointer)&gui.menu_fontset; |
| 1715 | to.size = sizeof(GuiFontset); |
| 1716 | |
| 1717 | if (XtConvertAndStore(vimShell, XtRString, &from, XtRFontSet, &to) == False) |
| 1718 | { |
| 1719 | /* Failed. What to do? */ |
| 1720 | } |
| 1721 | #else |
| 1722 | from.addr = (char *)gui.rsrc_menu_font_name; |
| 1723 | from.size = strlen(from.addr); |
| 1724 | to.addr = (XtPointer)&gui.menu_font; |
| 1725 | to.size = sizeof(GuiFont); |
| 1726 | |
| 1727 | if (XtConvertAndStore(vimShell, XtRString, &from, XtRFontStruct, &to) == False) |
| 1728 | { |
| 1729 | /* Failed. What to do? */ |
| 1730 | } |
| 1731 | #endif |
| 1732 | } |
| 1733 | #endif |
| 1734 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1735 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 1736 | gui_mch_exit(int rc UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1737 | { |
| 1738 | #if 0 |
| 1739 | /* Lesstif gives an error message here, and so does Solaris. The man page |
| 1740 | * says that this isn't needed when exiting, so just skip it. */ |
| 1741 | XtCloseDisplay(gui.dpy); |
| 1742 | #endif |
Bram Moolenaar | d23a823 | 2018-02-10 18:45:26 +0100 | [diff] [blame] | 1743 | VIM_CLEAR(gui_argv); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | /* |
| 1747 | * Get the position of the top left corner of the window. |
| 1748 | */ |
| 1749 | int |
Bram Moolenaar | 02fdaea | 2016-01-30 18:13:55 +0100 | [diff] [blame] | 1750 | gui_mch_get_winpos(int *x, int *y) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1751 | { |
| 1752 | Dimension xpos, ypos; |
| 1753 | |
| 1754 | XtVaGetValues(vimShell, |
| 1755 | XtNx, &xpos, |
| 1756 | XtNy, &ypos, |
| 1757 | NULL); |
| 1758 | *x = xpos; |
| 1759 | *y = ypos; |
| 1760 | return OK; |
| 1761 | } |
| 1762 | |
| 1763 | /* |
| 1764 | * Set the position of the top left corner of the window to the given |
| 1765 | * coordinates. |
| 1766 | */ |
| 1767 | void |
Bram Moolenaar | 02fdaea | 2016-01-30 18:13:55 +0100 | [diff] [blame] | 1768 | gui_mch_set_winpos(int x, int y) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1769 | { |
| 1770 | XtVaSetValues(vimShell, |
| 1771 | XtNx, x, |
| 1772 | XtNy, y, |
| 1773 | NULL); |
| 1774 | } |
| 1775 | |
| 1776 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 1777 | gui_mch_set_shellsize( |
| 1778 | int width, |
| 1779 | int height, |
| 1780 | int min_width, |
| 1781 | int min_height, |
| 1782 | int base_width, |
| 1783 | int base_height, |
| 1784 | int direction UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1785 | { |
Bram Moolenaar | 1c2fda2 | 2005-01-02 11:43:19 +0000 | [diff] [blame] | 1786 | #ifdef FEAT_XIM |
| 1787 | height += xim_get_status_area_height(), |
| 1788 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1789 | XtVaSetValues(vimShell, |
| 1790 | XtNwidthInc, gui.char_width, |
| 1791 | XtNheightInc, gui.char_height, |
| 1792 | #if defined(XtSpecificationRelease) && XtSpecificationRelease >= 4 |
| 1793 | XtNbaseWidth, base_width, |
| 1794 | XtNbaseHeight, base_height, |
| 1795 | #endif |
| 1796 | XtNminWidth, min_width, |
| 1797 | XtNminHeight, min_height, |
| 1798 | XtNwidth, width, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1799 | XtNheight, height, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1800 | NULL); |
| 1801 | } |
| 1802 | |
| 1803 | /* |
Bram Moolenaar | 231334e | 2005-07-25 20:46:57 +0000 | [diff] [blame] | 1804 | * Allow 10 pixels for horizontal borders, 'guiheadroom' for vertical borders. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1805 | * Is there no way in X to find out how wide the borders really are? |
| 1806 | */ |
| 1807 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 1808 | gui_mch_get_screen_dimensions( |
| 1809 | int *screen_w, |
| 1810 | int *screen_h) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1811 | { |
| 1812 | *screen_w = DisplayWidth(gui.dpy, DefaultScreen(gui.dpy)) - 10; |
| 1813 | *screen_h = DisplayHeight(gui.dpy, DefaultScreen(gui.dpy)) - p_ghr; |
| 1814 | } |
| 1815 | |
| 1816 | /* |
| 1817 | * Initialise vim to use the font "font_name". If it's NULL, pick a default |
| 1818 | * font. |
| 1819 | * If "fontset" is TRUE, load the "font_name" as a fontset. |
| 1820 | * Return FAIL if the font could not be loaded, OK otherwise. |
| 1821 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1822 | int |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 1823 | gui_mch_init_font( |
| 1824 | char_u *font_name, |
| 1825 | int do_fontset UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1826 | { |
| 1827 | XFontStruct *font = NULL; |
| 1828 | |
| 1829 | #ifdef FEAT_XFONTSET |
| 1830 | XFontSet fontset = NULL; |
Bram Moolenaar | 567e4de | 2004-12-31 21:01:02 +0000 | [diff] [blame] | 1831 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1832 | |
Bram Moolenaar | 567e4de | 2004-12-31 21:01:02 +0000 | [diff] [blame] | 1833 | #ifdef FEAT_GUI_MOTIF |
| 1834 | /* A font name equal "*" is indicating, that we should activate the font |
| 1835 | * selection dialogue to get a new font name. So let us do it here. */ |
| 1836 | if (font_name != NULL && STRCMP(font_name, "*") == 0) |
| 1837 | font_name = gui_xm_select_font(hl_get_font_name()); |
| 1838 | #endif |
| 1839 | |
| 1840 | #ifdef FEAT_XFONTSET |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1841 | if (do_fontset) |
| 1842 | { |
| 1843 | /* If 'guifontset' is set, VIM treats all font specifications as if |
| 1844 | * they were fontsets, and 'guifontset' becomes the default. */ |
| 1845 | if (font_name != NULL) |
| 1846 | { |
| 1847 | fontset = (XFontSet)gui_mch_get_fontset(font_name, FALSE, TRUE); |
| 1848 | if (fontset == NULL) |
| 1849 | return FAIL; |
| 1850 | } |
| 1851 | } |
| 1852 | else |
| 1853 | #endif |
| 1854 | { |
| 1855 | if (font_name == NULL) |
| 1856 | { |
| 1857 | /* |
| 1858 | * If none of the fonts in 'font' could be loaded, try the one set |
| 1859 | * in the X resource, and finally just try using DFLT_FONT, which |
| 1860 | * will hopefully always be there. |
| 1861 | */ |
| 1862 | font_name = gui.rsrc_font_name; |
| 1863 | font = (XFontStruct *)gui_mch_get_font(font_name, FALSE); |
| 1864 | if (font == NULL) |
| 1865 | font_name = (char_u *)DFLT_FONT; |
| 1866 | } |
| 1867 | if (font == NULL) |
| 1868 | font = (XFontStruct *)gui_mch_get_font(font_name, FALSE); |
| 1869 | if (font == NULL) |
| 1870 | return FAIL; |
| 1871 | } |
| 1872 | |
| 1873 | gui_mch_free_font(gui.norm_font); |
| 1874 | #ifdef FEAT_XFONTSET |
| 1875 | gui_mch_free_fontset(gui.fontset); |
| 1876 | |
| 1877 | if (fontset != NULL) |
| 1878 | { |
| 1879 | gui.norm_font = NOFONT; |
| 1880 | gui.fontset = (GuiFontset)fontset; |
| 1881 | gui.char_width = fontset_width(fontset); |
| 1882 | gui.char_height = fontset_height(fontset) + p_linespace; |
| 1883 | gui.char_ascent = fontset_ascent(fontset) + p_linespace / 2; |
| 1884 | } |
| 1885 | else |
| 1886 | #endif |
| 1887 | { |
| 1888 | gui.norm_font = (GuiFont)font; |
| 1889 | #ifdef FEAT_XFONTSET |
| 1890 | gui.fontset = NOFONTSET; |
| 1891 | #endif |
| 1892 | gui.char_width = font->max_bounds.width; |
| 1893 | gui.char_height = font->ascent + font->descent + p_linespace; |
| 1894 | gui.char_ascent = font->ascent + p_linespace / 2; |
| 1895 | } |
| 1896 | |
| 1897 | hl_set_font_name(font_name); |
| 1898 | |
| 1899 | /* |
| 1900 | * Try to load other fonts for bold, italic, and bold-italic. |
| 1901 | * We should also try to work out what font to use for these when they are |
| 1902 | * not specified by X resources, but we don't yet. |
| 1903 | */ |
| 1904 | if (font_name == gui.rsrc_font_name) |
| 1905 | { |
| 1906 | if (gui.bold_font == NOFONT |
| 1907 | && gui.rsrc_bold_font_name != NULL |
| 1908 | && *gui.rsrc_bold_font_name != NUL) |
| 1909 | gui.bold_font = gui_mch_get_font(gui.rsrc_bold_font_name, FALSE); |
| 1910 | if (gui.ital_font == NOFONT |
| 1911 | && gui.rsrc_ital_font_name != NULL |
| 1912 | && *gui.rsrc_ital_font_name != NUL) |
| 1913 | gui.ital_font = gui_mch_get_font(gui.rsrc_ital_font_name, FALSE); |
| 1914 | if (gui.boldital_font == NOFONT |
| 1915 | && gui.rsrc_boldital_font_name != NULL |
| 1916 | && *gui.rsrc_boldital_font_name != NUL) |
| 1917 | gui.boldital_font = gui_mch_get_font(gui.rsrc_boldital_font_name, |
| 1918 | FALSE); |
| 1919 | } |
| 1920 | else |
| 1921 | { |
| 1922 | /* When not using the font specified by the resources, also don't use |
| 1923 | * the bold/italic fonts, otherwise setting 'guifont' will look very |
| 1924 | * strange. */ |
| 1925 | if (gui.bold_font != NOFONT) |
| 1926 | { |
| 1927 | XFreeFont(gui.dpy, (XFontStruct *)gui.bold_font); |
| 1928 | gui.bold_font = NOFONT; |
| 1929 | } |
| 1930 | if (gui.ital_font != NOFONT) |
| 1931 | { |
| 1932 | XFreeFont(gui.dpy, (XFontStruct *)gui.ital_font); |
| 1933 | gui.ital_font = NOFONT; |
| 1934 | } |
| 1935 | if (gui.boldital_font != NOFONT) |
| 1936 | { |
| 1937 | XFreeFont(gui.dpy, (XFontStruct *)gui.boldital_font); |
| 1938 | gui.boldital_font = NOFONT; |
| 1939 | } |
| 1940 | } |
| 1941 | |
Bram Moolenaar | 567e4de | 2004-12-31 21:01:02 +0000 | [diff] [blame] | 1942 | #ifdef FEAT_GUI_MOTIF |
| 1943 | gui_motif_synch_fonts(); |
| 1944 | #endif |
| 1945 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1946 | return OK; |
| 1947 | } |
| 1948 | |
| 1949 | /* |
| 1950 | * Get a font structure for highlighting. |
| 1951 | */ |
| 1952 | GuiFont |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 1953 | gui_mch_get_font(char_u *name, int giveErrorIfMissing) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1954 | { |
| 1955 | XFontStruct *font; |
| 1956 | |
Bram Moolenaar | d23a823 | 2018-02-10 18:45:26 +0100 | [diff] [blame] | 1957 | if (!gui.in_use || name == NULL) /* can't do this when GUI not running */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1958 | return NOFONT; |
| 1959 | |
| 1960 | font = XLoadQueryFont(gui.dpy, (char *)name); |
| 1961 | |
| 1962 | if (font == NULL) |
| 1963 | { |
| 1964 | if (giveErrorIfMissing) |
| 1965 | EMSG2(_(e_font), name); |
| 1966 | return NOFONT; |
| 1967 | } |
| 1968 | |
| 1969 | #ifdef DEBUG |
| 1970 | printf("Font Information for '%s':\n", name); |
| 1971 | printf(" w = %d, h = %d, ascent = %d, descent = %d\n", |
| 1972 | font->max_bounds.width, font->ascent + font->descent, |
| 1973 | font->ascent, font->descent); |
| 1974 | printf(" max ascent = %d, max descent = %d, max h = %d\n", |
| 1975 | font->max_bounds.ascent, font->max_bounds.descent, |
| 1976 | font->max_bounds.ascent + font->max_bounds.descent); |
| 1977 | printf(" min lbearing = %d, min rbearing = %d\n", |
| 1978 | font->min_bounds.lbearing, font->min_bounds.rbearing); |
| 1979 | printf(" max lbearing = %d, max rbearing = %d\n", |
| 1980 | font->max_bounds.lbearing, font->max_bounds.rbearing); |
| 1981 | printf(" leftink = %d, rightink = %d\n", |
| 1982 | (font->min_bounds.lbearing < 0), |
| 1983 | (font->max_bounds.rbearing > font->max_bounds.width)); |
| 1984 | printf("\n"); |
| 1985 | #endif |
| 1986 | |
| 1987 | if (font->max_bounds.width != font->min_bounds.width) |
| 1988 | { |
| 1989 | EMSG2(_(e_fontwidth), name); |
| 1990 | XFreeFont(gui.dpy, font); |
| 1991 | return NOFONT; |
| 1992 | } |
| 1993 | return (GuiFont)font; |
| 1994 | } |
| 1995 | |
Bram Moolenaar | 567e4de | 2004-12-31 21:01:02 +0000 | [diff] [blame] | 1996 | #if defined(FEAT_EVAL) || defined(PROTO) |
Bram Moolenaar | 46c9c73 | 2004-12-12 11:37:09 +0000 | [diff] [blame] | 1997 | /* |
| 1998 | * Return the name of font "font" in allocated memory. |
Bram Moolenaar | 46c9c73 | 2004-12-12 11:37:09 +0000 | [diff] [blame] | 1999 | */ |
| 2000 | char_u * |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 2001 | gui_mch_get_fontname(GuiFont font, char_u *name) |
Bram Moolenaar | 46c9c73 | 2004-12-12 11:37:09 +0000 | [diff] [blame] | 2002 | { |
Bram Moolenaar | 8774845 | 2017-03-12 17:10:33 +0100 | [diff] [blame] | 2003 | char_u *ret = NULL; |
| 2004 | |
| 2005 | if (name != NULL && font == NULL) |
| 2006 | { |
| 2007 | /* In this case, there's no way other than doing this. */ |
| 2008 | ret = vim_strsave(name); |
| 2009 | } |
| 2010 | else if (font != NULL) |
| 2011 | { |
| 2012 | /* In this case, try to retrieve the XLFD corresponding to 'font'->fid; |
| 2013 | * if failed, use 'name' unless it's NULL. */ |
| 2014 | unsigned long value = 0L; |
| 2015 | |
| 2016 | if (XGetFontProperty(font, XA_FONT, &value)) |
| 2017 | { |
| 2018 | char *xa_font_name = NULL; |
| 2019 | |
| 2020 | xa_font_name = XGetAtomName(gui.dpy, value); |
| 2021 | if (xa_font_name != NULL) |
| 2022 | { |
| 2023 | ret = vim_strsave((char_u *)xa_font_name); |
| 2024 | XFree(xa_font_name); |
| 2025 | } |
| 2026 | else if (name != NULL) |
| 2027 | ret = vim_strsave(name); |
| 2028 | } |
| 2029 | else if (name != NULL) |
| 2030 | ret = vim_strsave(name); |
| 2031 | } |
| 2032 | return ret; |
Bram Moolenaar | 46c9c73 | 2004-12-12 11:37:09 +0000 | [diff] [blame] | 2033 | } |
Bram Moolenaar | 567e4de | 2004-12-31 21:01:02 +0000 | [diff] [blame] | 2034 | #endif |
Bram Moolenaar | 46c9c73 | 2004-12-12 11:37:09 +0000 | [diff] [blame] | 2035 | |
Bram Moolenaar | 231334e | 2005-07-25 20:46:57 +0000 | [diff] [blame] | 2036 | /* |
| 2037 | * Adjust gui.char_height (after 'linespace' was changed). |
| 2038 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2039 | int |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2040 | gui_mch_adjust_charheight(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2041 | { |
| 2042 | #ifdef FEAT_XFONTSET |
| 2043 | if (gui.fontset != NOFONTSET) |
| 2044 | { |
| 2045 | gui.char_height = fontset_height((XFontSet)gui.fontset) + p_linespace; |
| 2046 | gui.char_ascent = fontset_ascent((XFontSet)gui.fontset) |
| 2047 | + p_linespace / 2; |
| 2048 | } |
| 2049 | else |
| 2050 | #endif |
| 2051 | { |
| 2052 | XFontStruct *font = (XFontStruct *)gui.norm_font; |
| 2053 | |
| 2054 | gui.char_height = font->ascent + font->descent + p_linespace; |
| 2055 | gui.char_ascent = font->ascent + p_linespace / 2; |
| 2056 | } |
| 2057 | return OK; |
| 2058 | } |
| 2059 | |
| 2060 | /* |
| 2061 | * Set the current text font. |
| 2062 | */ |
| 2063 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2064 | gui_mch_set_font(GuiFont font) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2065 | { |
| 2066 | static Font prev_font = (Font)-1; |
| 2067 | Font fid = ((XFontStruct *)font)->fid; |
| 2068 | |
| 2069 | if (fid != prev_font) |
| 2070 | { |
| 2071 | XSetFont(gui.dpy, gui.text_gc, fid); |
| 2072 | XSetFont(gui.dpy, gui.back_gc, fid); |
| 2073 | prev_font = fid; |
| 2074 | gui.char_ascent = ((XFontStruct *)font)->ascent + p_linespace / 2; |
| 2075 | } |
| 2076 | #ifdef FEAT_XFONTSET |
| 2077 | current_fontset = (XFontSet)NULL; |
| 2078 | #endif |
| 2079 | } |
| 2080 | |
| 2081 | #if defined(FEAT_XFONTSET) || defined(PROTO) |
| 2082 | /* |
| 2083 | * Set the current text fontset. |
| 2084 | * Adjust the ascent, in case it's different. |
| 2085 | */ |
| 2086 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2087 | gui_mch_set_fontset(GuiFontset fontset) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2088 | { |
| 2089 | current_fontset = (XFontSet)fontset; |
| 2090 | gui.char_ascent = fontset_ascent(current_fontset) + p_linespace / 2; |
| 2091 | } |
| 2092 | #endif |
| 2093 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2094 | /* |
| 2095 | * If a font is not going to be used, free its structure. |
| 2096 | */ |
| 2097 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2098 | gui_mch_free_font(GuiFont font) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2099 | { |
| 2100 | if (font != NOFONT) |
| 2101 | XFreeFont(gui.dpy, (XFontStruct *)font); |
| 2102 | } |
| 2103 | |
| 2104 | #if defined(FEAT_XFONTSET) || defined(PROTO) |
| 2105 | /* |
| 2106 | * If a fontset is not going to be used, free its structure. |
| 2107 | */ |
| 2108 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2109 | gui_mch_free_fontset(GuiFontset fontset) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2110 | { |
| 2111 | if (fontset != NOFONTSET) |
| 2112 | XFreeFontSet(gui.dpy, (XFontSet)fontset); |
| 2113 | } |
| 2114 | |
| 2115 | /* |
| 2116 | * Load the fontset "name". |
| 2117 | * Return a reference to the fontset, or NOFONTSET when failing. |
| 2118 | */ |
| 2119 | GuiFontset |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2120 | gui_mch_get_fontset( |
| 2121 | char_u *name, |
| 2122 | int giveErrorIfMissing, |
| 2123 | int fixed_width) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2124 | { |
| 2125 | XFontSet fontset; |
| 2126 | char **missing, *def_str; |
| 2127 | int num_missing; |
| 2128 | |
| 2129 | if (!gui.in_use || name == NULL) |
| 2130 | return NOFONTSET; |
| 2131 | |
| 2132 | fontset = XCreateFontSet(gui.dpy, (char *)name, &missing, &num_missing, |
| 2133 | &def_str); |
| 2134 | if (num_missing > 0) |
| 2135 | { |
| 2136 | int i; |
| 2137 | |
| 2138 | if (giveErrorIfMissing) |
| 2139 | { |
| 2140 | EMSG2(_("E250: Fonts for the following charsets are missing in fontset %s:"), name); |
| 2141 | for (i = 0; i < num_missing; i++) |
| 2142 | EMSG2("%s", missing[i]); |
| 2143 | } |
| 2144 | XFreeStringList(missing); |
| 2145 | } |
| 2146 | |
| 2147 | if (fontset == NULL) |
| 2148 | { |
| 2149 | if (giveErrorIfMissing) |
| 2150 | EMSG2(_(e_fontset), name); |
| 2151 | return NOFONTSET; |
| 2152 | } |
| 2153 | |
| 2154 | if (fixed_width && check_fontset_sanity(fontset) == FAIL) |
| 2155 | { |
| 2156 | XFreeFontSet(gui.dpy, fontset); |
| 2157 | return NOFONTSET; |
| 2158 | } |
| 2159 | return (GuiFontset)fontset; |
| 2160 | } |
| 2161 | |
| 2162 | /* |
| 2163 | * Check if fontset "fs" is fixed width. |
| 2164 | */ |
| 2165 | static int |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2166 | check_fontset_sanity(XFontSet fs) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2167 | { |
| 2168 | XFontStruct **xfs; |
| 2169 | char **font_name; |
| 2170 | int fn; |
| 2171 | char *base_name; |
| 2172 | int i; |
| 2173 | int min_width; |
| 2174 | int min_font_idx = 0; |
| 2175 | |
| 2176 | base_name = XBaseFontNameListOfFontSet(fs); |
| 2177 | fn = XFontsOfFontSet(fs, &xfs, &font_name); |
| 2178 | for (i = 0; i < fn; i++) |
| 2179 | { |
| 2180 | if (xfs[i]->max_bounds.width != xfs[i]->min_bounds.width) |
| 2181 | { |
| 2182 | EMSG2(_("E252: Fontset name: %s"), base_name); |
| 2183 | EMSG2(_("Font '%s' is not fixed-width"), font_name[i]); |
| 2184 | return FAIL; |
| 2185 | } |
| 2186 | } |
| 2187 | /* scan base font width */ |
| 2188 | min_width = 32767; |
| 2189 | for (i = 0; i < fn; i++) |
| 2190 | { |
| 2191 | if (xfs[i]->max_bounds.width<min_width) |
| 2192 | { |
| 2193 | min_width = xfs[i]->max_bounds.width; |
| 2194 | min_font_idx = i; |
| 2195 | } |
| 2196 | } |
| 2197 | for (i = 0; i < fn; i++) |
| 2198 | { |
| 2199 | if ( xfs[i]->max_bounds.width != 2 * min_width |
| 2200 | && xfs[i]->max_bounds.width != min_width) |
| 2201 | { |
Bram Moolenaar | 9d438d3 | 2013-06-13 21:57:20 +0200 | [diff] [blame] | 2202 | EMSG2(_("E253: Fontset name: %s"), base_name); |
| 2203 | EMSG2(_("Font0: %s"), font_name[min_font_idx]); |
| 2204 | EMSG2(_("Font1: %s"), font_name[i]); |
| 2205 | EMSGN(_("Font%ld width is not twice that of font0"), i); |
| 2206 | EMSGN(_("Font0 width: %ld"), xfs[min_font_idx]->max_bounds.width); |
| 2207 | EMSGN(_("Font1 width: %ld"), xfs[i]->max_bounds.width); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2208 | return FAIL; |
| 2209 | } |
| 2210 | } |
| 2211 | /* it seems ok. Good Luck!! */ |
| 2212 | return OK; |
| 2213 | } |
| 2214 | |
| 2215 | static int |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2216 | fontset_width(XFontSet fs) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2217 | { |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2218 | return XmbTextEscapement(fs, "Vim", 3) / 3; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | int |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2222 | fontset_height( |
| 2223 | XFontSet fs) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2224 | { |
| 2225 | XFontSetExtents *extents; |
| 2226 | |
| 2227 | extents = XExtentsOfFontSet(fs); |
| 2228 | return extents->max_logical_extent.height; |
| 2229 | } |
| 2230 | |
| 2231 | #if (defined(FONTSET_ALWAYS) && defined(FEAT_GUI_ATHENA) \ |
| 2232 | && defined(FEAT_MENU)) || defined(PROTO) |
| 2233 | /* |
| 2234 | * Returns the bounding box height around the actual glyph image of all |
| 2235 | * characters in all fonts of the fontset. |
| 2236 | */ |
| 2237 | int |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2238 | fontset_height2(XFontSet fs) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2239 | { |
| 2240 | XFontSetExtents *extents; |
| 2241 | |
| 2242 | extents = XExtentsOfFontSet(fs); |
| 2243 | return extents->max_ink_extent.height; |
| 2244 | } |
| 2245 | #endif |
| 2246 | |
| 2247 | /* NOT USED YET |
| 2248 | static int |
Bram Moolenaar | d14e00e | 2016-01-31 17:30:51 +0100 | [diff] [blame] | 2249 | fontset_descent(XFontSet fs) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2250 | { |
| 2251 | XFontSetExtents *extents; |
| 2252 | |
| 2253 | extents = XExtentsOfFontSet (fs); |
| 2254 | return extents->max_logical_extent.height + extents->max_logical_extent.y; |
| 2255 | } |
| 2256 | */ |
| 2257 | |
| 2258 | static int |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2259 | fontset_ascent(XFontSet fs) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2260 | { |
| 2261 | XFontSetExtents *extents; |
| 2262 | |
| 2263 | extents = XExtentsOfFontSet(fs); |
| 2264 | return -extents->max_logical_extent.y; |
| 2265 | } |
| 2266 | |
| 2267 | #endif /* FEAT_XFONTSET */ |
| 2268 | |
| 2269 | /* |
| 2270 | * Return the Pixel value (color) for the given color name. |
| 2271 | * Return INVALCOLOR for error. |
| 2272 | */ |
| 2273 | guicolor_T |
Bram Moolenaar | 4658228 | 2016-07-23 14:35:12 +0200 | [diff] [blame] | 2274 | gui_mch_get_color(char_u *name) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2275 | { |
Bram Moolenaar | d23a823 | 2018-02-10 18:45:26 +0100 | [diff] [blame] | 2276 | guicolor_T requested; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2277 | |
| 2278 | /* can't do this when GUI not running */ |
Bram Moolenaar | 4658228 | 2016-07-23 14:35:12 +0200 | [diff] [blame] | 2279 | if (!gui.in_use || name == NULL || *name == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2280 | return INVALCOLOR; |
| 2281 | |
Bram Moolenaar | 4658228 | 2016-07-23 14:35:12 +0200 | [diff] [blame] | 2282 | requested = gui_get_color_cmn(name); |
| 2283 | if (requested == INVALCOLOR) |
| 2284 | return INVALCOLOR; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2285 | |
Bram Moolenaar | 26af85d | 2017-07-23 16:45:10 +0200 | [diff] [blame] | 2286 | return gui_mch_get_rgb_color( |
Bram Moolenaar | 4658228 | 2016-07-23 14:35:12 +0200 | [diff] [blame] | 2287 | (requested & 0xff0000) >> 16, |
| 2288 | (requested & 0xff00) >> 8, |
| 2289 | requested & 0xff); |
Bram Moolenaar | 26af85d | 2017-07-23 16:45:10 +0200 | [diff] [blame] | 2290 | } |
| 2291 | |
| 2292 | /* |
| 2293 | * Return the Pixel value (color) for the given RGB values. |
| 2294 | * Return INVALCOLOR for error. |
| 2295 | */ |
| 2296 | guicolor_T |
| 2297 | gui_mch_get_rgb_color(int r, int g, int b) |
| 2298 | { |
Bram Moolenaar | d23a823 | 2018-02-10 18:45:26 +0100 | [diff] [blame] | 2299 | char spec[8]; /* space enough to hold "#RRGGBB" */ |
| 2300 | XColor available; |
Bram Moolenaar | d60547b | 2017-07-24 20:15:30 +0200 | [diff] [blame] | 2301 | Colormap colormap; |
Bram Moolenaar | 26af85d | 2017-07-23 16:45:10 +0200 | [diff] [blame] | 2302 | |
| 2303 | vim_snprintf(spec, sizeof(spec), "#%.2x%.2x%.2x", r, g, b); |
Bram Moolenaar | 4658228 | 2016-07-23 14:35:12 +0200 | [diff] [blame] | 2304 | colormap = DefaultColormap(gui.dpy, DefaultScreen(gui.dpy)); |
| 2305 | if (XParseColor(gui.dpy, colormap, (char *)spec, &available) != 0 |
| 2306 | && XAllocColor(gui.dpy, colormap, &available) != 0) |
| 2307 | return (guicolor_T)available.pixel; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2308 | |
| 2309 | return INVALCOLOR; |
| 2310 | } |
| 2311 | |
| 2312 | /* |
Bram Moolenaar | fb26980 | 2005-03-15 22:46:30 +0000 | [diff] [blame] | 2313 | * Set the current text foreground color. |
| 2314 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2315 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2316 | gui_mch_set_fg_color(guicolor_T color) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2317 | { |
| 2318 | if (color != prev_fg_color) |
| 2319 | { |
| 2320 | XSetForeground(gui.dpy, gui.text_gc, (Pixel)color); |
| 2321 | prev_fg_color = color; |
| 2322 | } |
| 2323 | } |
| 2324 | |
| 2325 | /* |
| 2326 | * Set the current text background color. |
| 2327 | */ |
| 2328 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2329 | gui_mch_set_bg_color(guicolor_T color) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2330 | { |
| 2331 | if (color != prev_bg_color) |
| 2332 | { |
| 2333 | XSetBackground(gui.dpy, gui.text_gc, (Pixel)color); |
| 2334 | prev_bg_color = color; |
| 2335 | } |
| 2336 | } |
| 2337 | |
| 2338 | /* |
Bram Moolenaar | fb26980 | 2005-03-15 22:46:30 +0000 | [diff] [blame] | 2339 | * Set the current text special color. |
| 2340 | */ |
| 2341 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2342 | gui_mch_set_sp_color(guicolor_T color) |
Bram Moolenaar | fb26980 | 2005-03-15 22:46:30 +0000 | [diff] [blame] | 2343 | { |
| 2344 | prev_sp_color = color; |
| 2345 | } |
| 2346 | |
| 2347 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2348 | * create a mouse pointer that is blank |
| 2349 | */ |
| 2350 | static Cursor |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2351 | gui_x11_create_blank_mouse(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2352 | { |
| 2353 | Pixmap blank_pixmap = XCreatePixmap(gui.dpy, gui.wid, 1, 1, 1); |
| 2354 | GC gc = XCreateGC(gui.dpy, blank_pixmap, (unsigned long)0, (XGCValues*)0); |
| 2355 | XDrawPoint(gui.dpy, blank_pixmap, gc, 0, 0); |
| 2356 | XFreeGC(gui.dpy, gc); |
| 2357 | return XCreatePixmapCursor(gui.dpy, blank_pixmap, blank_pixmap, |
| 2358 | (XColor*)&gui.norm_pixel, (XColor*)&gui.norm_pixel, 0, 0); |
| 2359 | } |
| 2360 | |
Bram Moolenaar | fb26980 | 2005-03-15 22:46:30 +0000 | [diff] [blame] | 2361 | /* |
| 2362 | * Draw a curled line at the bottom of the character cell. |
| 2363 | */ |
| 2364 | static void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2365 | draw_curl(int row, int col, int cells) |
Bram Moolenaar | fb26980 | 2005-03-15 22:46:30 +0000 | [diff] [blame] | 2366 | { |
| 2367 | int i; |
| 2368 | int offset; |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 2369 | static const int val[8] = {1, 0, 0, 0, 1, 2, 2, 2 }; |
Bram Moolenaar | fb26980 | 2005-03-15 22:46:30 +0000 | [diff] [blame] | 2370 | |
| 2371 | XSetForeground(gui.dpy, gui.text_gc, prev_sp_color); |
| 2372 | for (i = FILL_X(col); i < FILL_X(col + cells); ++i) |
| 2373 | { |
| 2374 | offset = val[i % 8]; |
| 2375 | XDrawPoint(gui.dpy, gui.wid, gui.text_gc, i, |
| 2376 | FILL_Y(row + 1) - 1 - offset); |
| 2377 | } |
| 2378 | XSetForeground(gui.dpy, gui.text_gc, prev_fg_color); |
| 2379 | } |
| 2380 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2381 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2382 | gui_mch_draw_string( |
| 2383 | int row, |
| 2384 | int col, |
| 2385 | char_u *s, |
| 2386 | int len, |
| 2387 | int flags) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2388 | { |
| 2389 | int cells = len; |
| 2390 | #ifdef FEAT_MBYTE |
Bram Moolenaar | a3227e2 | 2006-03-08 21:32:40 +0000 | [diff] [blame] | 2391 | static void *buf = NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2392 | static int buflen = 0; |
| 2393 | char_u *p; |
| 2394 | int wlen = 0; |
| 2395 | int c; |
| 2396 | |
| 2397 | if (enc_utf8) |
| 2398 | { |
| 2399 | /* Convert UTF-8 byte sequence to 16 bit characters for the X |
| 2400 | * functions. Need a buffer for the 16 bit characters. Keep it |
| 2401 | * between calls, because allocating it each time is slow. */ |
| 2402 | if (buflen < len) |
| 2403 | { |
| 2404 | XtFree((char *)buf); |
Bram Moolenaar | a3227e2 | 2006-03-08 21:32:40 +0000 | [diff] [blame] | 2405 | buf = (void *)XtMalloc(len * (sizeof(XChar2b) < sizeof(wchar_t) |
| 2406 | ? sizeof(wchar_t) : sizeof(XChar2b))); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2407 | buflen = len; |
| 2408 | } |
| 2409 | p = s; |
| 2410 | cells = 0; |
| 2411 | while (p < s + len) |
| 2412 | { |
| 2413 | c = utf_ptr2char(p); |
Bram Moolenaar | a3227e2 | 2006-03-08 21:32:40 +0000 | [diff] [blame] | 2414 | # ifdef FEAT_XFONTSET |
| 2415 | if (current_fontset != NULL) |
| 2416 | { |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 2417 | # ifdef SMALL_WCHAR_T |
| 2418 | if (c >= 0x10000) |
Bram Moolenaar | a3227e2 | 2006-03-08 21:32:40 +0000 | [diff] [blame] | 2419 | c = 0xbf; /* show chars > 0xffff as ? */ |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 2420 | # endif |
Bram Moolenaar | a3227e2 | 2006-03-08 21:32:40 +0000 | [diff] [blame] | 2421 | ((wchar_t *)buf)[wlen] = c; |
| 2422 | } |
| 2423 | else |
| 2424 | # endif |
| 2425 | { |
| 2426 | if (c >= 0x10000) |
| 2427 | c = 0xbf; /* show chars > 0xffff as ? */ |
| 2428 | ((XChar2b *)buf)[wlen].byte1 = (unsigned)c >> 8; |
| 2429 | ((XChar2b *)buf)[wlen].byte2 = c; |
| 2430 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2431 | ++wlen; |
| 2432 | cells += utf_char2cells(c); |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 2433 | p += utf_ptr2len(p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2434 | } |
| 2435 | } |
| 2436 | else if (has_mbyte) |
| 2437 | { |
| 2438 | cells = 0; |
| 2439 | for (p = s; p < s + len; ) |
| 2440 | { |
| 2441 | cells += ptr2cells(p); |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 2442 | p += (*mb_ptr2len)(p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2443 | } |
| 2444 | } |
| 2445 | |
| 2446 | #endif |
| 2447 | |
| 2448 | #ifdef FEAT_XFONTSET |
| 2449 | if (current_fontset != NULL) |
| 2450 | { |
| 2451 | /* Setup a clip rectangle to avoid spilling over in the next or |
| 2452 | * previous line. This is apparently needed for some fonts which are |
| 2453 | * used in a fontset. */ |
| 2454 | XRectangle clip; |
| 2455 | |
| 2456 | clip.x = 0; |
| 2457 | clip.y = 0; |
| 2458 | clip.height = gui.char_height; |
| 2459 | clip.width = gui.char_width * cells + 1; |
| 2460 | XSetClipRectangles(gui.dpy, gui.text_gc, FILL_X(col), FILL_Y(row), |
| 2461 | &clip, 1, Unsorted); |
| 2462 | } |
| 2463 | #endif |
| 2464 | |
| 2465 | if (flags & DRAW_TRANSP) |
| 2466 | { |
| 2467 | #ifdef FEAT_MBYTE |
| 2468 | if (enc_utf8) |
| 2469 | XDrawString16(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col), |
| 2470 | TEXT_Y(row), buf, wlen); |
| 2471 | else |
| 2472 | #endif |
| 2473 | XDrawString(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col), |
| 2474 | TEXT_Y(row), (char *)s, len); |
| 2475 | } |
| 2476 | else if (p_linespace != 0 |
| 2477 | #ifdef FEAT_XFONTSET |
| 2478 | || current_fontset != NULL |
| 2479 | #endif |
| 2480 | ) |
| 2481 | { |
| 2482 | XSetForeground(gui.dpy, gui.text_gc, prev_bg_color); |
| 2483 | XFillRectangle(gui.dpy, gui.wid, gui.text_gc, FILL_X(col), |
| 2484 | FILL_Y(row), gui.char_width * cells, gui.char_height); |
| 2485 | XSetForeground(gui.dpy, gui.text_gc, prev_fg_color); |
Bram Moolenaar | fb26980 | 2005-03-15 22:46:30 +0000 | [diff] [blame] | 2486 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2487 | #ifdef FEAT_MBYTE |
| 2488 | if (enc_utf8) |
| 2489 | XDrawString16(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col), |
| 2490 | TEXT_Y(row), buf, wlen); |
| 2491 | else |
| 2492 | #endif |
| 2493 | XDrawString(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col), |
| 2494 | TEXT_Y(row), (char *)s, len); |
| 2495 | } |
| 2496 | else |
| 2497 | { |
| 2498 | /* XmbDrawImageString has bug, don't use it for fontset. */ |
| 2499 | #ifdef FEAT_MBYTE |
| 2500 | if (enc_utf8) |
| 2501 | XDrawImageString16(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col), |
| 2502 | TEXT_Y(row), buf, wlen); |
| 2503 | else |
| 2504 | #endif |
| 2505 | XDrawImageString(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col), |
| 2506 | TEXT_Y(row), (char *)s, len); |
| 2507 | } |
| 2508 | |
| 2509 | /* Bold trick: draw the text again with a one-pixel offset. */ |
| 2510 | if (flags & DRAW_BOLD) |
| 2511 | { |
| 2512 | #ifdef FEAT_MBYTE |
| 2513 | if (enc_utf8) |
| 2514 | XDrawString16(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col) + 1, |
| 2515 | TEXT_Y(row), buf, wlen); |
| 2516 | else |
| 2517 | #endif |
| 2518 | XDrawString(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col) + 1, |
| 2519 | TEXT_Y(row), (char *)s, len); |
| 2520 | } |
| 2521 | |
Bram Moolenaar | fb26980 | 2005-03-15 22:46:30 +0000 | [diff] [blame] | 2522 | /* Undercurl: draw curl at the bottom of the character cell. */ |
| 2523 | if (flags & DRAW_UNDERC) |
| 2524 | draw_curl(row, col, cells); |
| 2525 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2526 | /* Underline: draw a line at the bottom of the character cell. */ |
| 2527 | if (flags & DRAW_UNDERL) |
Bram Moolenaar | fb26980 | 2005-03-15 22:46:30 +0000 | [diff] [blame] | 2528 | { |
| 2529 | int y = FILL_Y(row + 1) - 1; |
| 2530 | |
| 2531 | /* When p_linespace is 0, overwrite the bottom row of pixels. |
| 2532 | * Otherwise put the line just below the character. */ |
| 2533 | if (p_linespace > 1) |
| 2534 | y -= p_linespace - 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2535 | XDrawLine(gui.dpy, gui.wid, gui.text_gc, FILL_X(col), |
Bram Moolenaar | fb26980 | 2005-03-15 22:46:30 +0000 | [diff] [blame] | 2536 | y, FILL_X(col + cells) - 1, y); |
| 2537 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2538 | |
Bram Moolenaar | cf4b00c | 2017-09-02 18:33:56 +0200 | [diff] [blame] | 2539 | if (flags & DRAW_STRIKE) |
| 2540 | { |
| 2541 | int y = FILL_Y(row + 1) - gui.char_height/2; |
| 2542 | |
| 2543 | XSetForeground(gui.dpy, gui.text_gc, prev_sp_color); |
| 2544 | XDrawLine(gui.dpy, gui.wid, gui.text_gc, FILL_X(col), |
| 2545 | y, FILL_X(col + cells) - 1, y); |
| 2546 | XSetForeground(gui.dpy, gui.text_gc, prev_fg_color); |
| 2547 | } |
| 2548 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2549 | #ifdef FEAT_XFONTSET |
| 2550 | if (current_fontset != NULL) |
| 2551 | XSetClipMask(gui.dpy, gui.text_gc, None); |
| 2552 | #endif |
| 2553 | } |
| 2554 | |
| 2555 | /* |
| 2556 | * Return OK if the key with the termcap name "name" is supported. |
| 2557 | */ |
| 2558 | int |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2559 | gui_mch_haskey(char_u *name) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2560 | { |
| 2561 | int i; |
| 2562 | |
| 2563 | for (i = 0; special_keys[i].key_sym != (KeySym)0; i++) |
| 2564 | if (name[0] == special_keys[i].vim_code0 && |
| 2565 | name[1] == special_keys[i].vim_code1) |
| 2566 | return OK; |
| 2567 | return FAIL; |
| 2568 | } |
| 2569 | |
| 2570 | /* |
| 2571 | * Return the text window-id and display. Only required for X-based GUI's |
| 2572 | */ |
| 2573 | int |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2574 | gui_get_x11_windis(Window *win, Display **dis) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2575 | { |
| 2576 | *win = XtWindow(vimShell); |
| 2577 | *dis = gui.dpy; |
| 2578 | return OK; |
| 2579 | } |
| 2580 | |
| 2581 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2582 | gui_mch_beep(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2583 | { |
| 2584 | XBell(gui.dpy, 0); |
| 2585 | } |
| 2586 | |
| 2587 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2588 | gui_mch_flash(int msec) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2589 | { |
| 2590 | /* Do a visual beep by reversing the foreground and background colors */ |
| 2591 | XFillRectangle(gui.dpy, gui.wid, gui.invert_gc, 0, 0, |
| 2592 | FILL_X((int)Columns) + gui.border_offset, |
| 2593 | FILL_Y((int)Rows) + gui.border_offset); |
| 2594 | XSync(gui.dpy, False); |
| 2595 | ui_delay((long)msec, TRUE); /* wait for a few msec */ |
| 2596 | XFillRectangle(gui.dpy, gui.wid, gui.invert_gc, 0, 0, |
| 2597 | FILL_X((int)Columns) + gui.border_offset, |
| 2598 | FILL_Y((int)Rows) + gui.border_offset); |
| 2599 | } |
| 2600 | |
| 2601 | /* |
| 2602 | * Invert a rectangle from row r, column c, for nr rows and nc columns. |
| 2603 | */ |
| 2604 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2605 | gui_mch_invert_rectangle( |
| 2606 | int r, |
| 2607 | int c, |
| 2608 | int nr, |
| 2609 | int nc) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2610 | { |
| 2611 | XFillRectangle(gui.dpy, gui.wid, gui.invert_gc, |
| 2612 | FILL_X(c), FILL_Y(r), (nc) * gui.char_width, (nr) * gui.char_height); |
| 2613 | } |
| 2614 | |
| 2615 | /* |
| 2616 | * Iconify the GUI window. |
| 2617 | */ |
| 2618 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2619 | gui_mch_iconify(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2620 | { |
| 2621 | XIconifyWindow(gui.dpy, XtWindow(vimShell), DefaultScreen(gui.dpy)); |
| 2622 | } |
| 2623 | |
| 2624 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 2625 | /* |
| 2626 | * Bring the Vim window to the foreground. |
| 2627 | */ |
| 2628 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2629 | gui_mch_set_foreground(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2630 | { |
| 2631 | XMapRaised(gui.dpy, XtWindow(vimShell)); |
| 2632 | } |
| 2633 | #endif |
| 2634 | |
| 2635 | /* |
| 2636 | * Draw a cursor without focus. |
| 2637 | */ |
| 2638 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2639 | gui_mch_draw_hollow_cursor(guicolor_T color) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2640 | { |
| 2641 | int w = 1; |
| 2642 | |
| 2643 | #ifdef FEAT_MBYTE |
| 2644 | if (mb_lefthalve(gui.row, gui.col)) |
| 2645 | w = 2; |
| 2646 | #endif |
| 2647 | gui_mch_set_fg_color(color); |
| 2648 | XDrawRectangle(gui.dpy, gui.wid, gui.text_gc, FILL_X(gui.col), |
| 2649 | FILL_Y(gui.row), w * gui.char_width - 1, gui.char_height - 1); |
| 2650 | } |
| 2651 | |
| 2652 | /* |
| 2653 | * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using |
| 2654 | * color "color". |
| 2655 | */ |
| 2656 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2657 | gui_mch_draw_part_cursor(int w, int h, guicolor_T color) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2658 | { |
| 2659 | gui_mch_set_fg_color(color); |
| 2660 | |
| 2661 | XFillRectangle(gui.dpy, gui.wid, gui.text_gc, |
| 2662 | #ifdef FEAT_RIGHTLEFT |
| 2663 | /* vertical line should be on the right of current point */ |
| 2664 | CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w : |
| 2665 | #endif |
| 2666 | FILL_X(gui.col), |
| 2667 | FILL_Y(gui.row) + gui.char_height - h, |
| 2668 | w, h); |
| 2669 | } |
| 2670 | |
| 2671 | /* |
| 2672 | * Catch up with any queued X events. This may put keyboard input into the |
| 2673 | * input buffer, call resize call-backs, trigger timers etc. If there is |
| 2674 | * nothing in the X event queue (& no timers pending), then we return |
| 2675 | * immediately. |
| 2676 | */ |
| 2677 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2678 | gui_mch_update(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2679 | { |
| 2680 | XtInputMask mask, desired; |
| 2681 | |
| 2682 | #ifdef ALT_X_INPUT |
| 2683 | if (suppress_alternate_input) |
| 2684 | desired = (XtIMXEvent | XtIMTimer); |
| 2685 | else |
| 2686 | #endif |
| 2687 | desired = (XtIMAll); |
| 2688 | while ((mask = XtAppPending(app_context)) && (mask & desired) |
| 2689 | && !vim_is_input_buf_full()) |
| 2690 | XtAppProcessEvent(app_context, desired); |
| 2691 | } |
| 2692 | |
| 2693 | /* |
| 2694 | * GUI input routine called by gui_wait_for_chars(). Waits for a character |
| 2695 | * from the keyboard. |
| 2696 | * wtime == -1 Wait forever. |
| 2697 | * wtime == 0 This should never happen. |
| 2698 | * wtime > 0 Wait wtime milliseconds for a character. |
| 2699 | * Returns OK if a character was found to be available within the given time, |
| 2700 | * or FAIL otherwise. |
| 2701 | */ |
| 2702 | int |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2703 | gui_mch_wait_for_chars(long wtime) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2704 | { |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 2705 | int focus; |
| 2706 | int retval = FAIL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2707 | |
| 2708 | /* |
| 2709 | * Make this static, in case gui_x11_timer_cb is called after leaving |
| 2710 | * this function (otherwise a random value on the stack may be changed). |
| 2711 | */ |
| 2712 | static int timed_out; |
| 2713 | XtIntervalId timer = (XtIntervalId)0; |
| 2714 | XtInputMask desired; |
Bram Moolenaar | 1dccf63 | 2017-08-27 17:38:27 +0200 | [diff] [blame] | 2715 | #ifdef FEAT_JOB_CHANNEL |
| 2716 | XtIntervalId channel_timer = (XtIntervalId)0; |
| 2717 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2718 | |
| 2719 | timed_out = FALSE; |
| 2720 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2721 | if (wtime > 0) |
| 2722 | timer = XtAppAddTimeOut(app_context, (long_u)wtime, gui_x11_timer_cb, |
| 2723 | &timed_out); |
Bram Moolenaar | 1dccf63 | 2017-08-27 17:38:27 +0200 | [diff] [blame] | 2724 | #ifdef FEAT_JOB_CHANNEL |
| 2725 | /* If there is a channel with the keep_open flag we need to poll for input |
| 2726 | * on them. */ |
| 2727 | if (channel_any_keep_open()) |
| 2728 | channel_timer = XtAppAddTimeOut(app_context, (long_u)20, |
| 2729 | channel_poll_cb, (XtPointer)&channel_timer); |
| 2730 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2731 | |
| 2732 | focus = gui.in_focus; |
| 2733 | #ifdef ALT_X_INPUT |
| 2734 | if (suppress_alternate_input) |
| 2735 | desired = (XtIMXEvent | XtIMTimer); |
| 2736 | else |
| 2737 | #endif |
| 2738 | desired = (XtIMAll); |
| 2739 | while (!timed_out) |
| 2740 | { |
| 2741 | /* Stop or start blinking when focus changes */ |
| 2742 | if (gui.in_focus != focus) |
| 2743 | { |
| 2744 | if (gui.in_focus) |
| 2745 | gui_mch_start_blink(); |
| 2746 | else |
Bram Moolenaar | 1dd45fb | 2018-01-31 21:10:01 +0100 | [diff] [blame] | 2747 | gui_mch_stop_blink(TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2748 | focus = gui.in_focus; |
| 2749 | } |
| 2750 | |
Bram Moolenaar | 93c88e0 | 2015-09-15 14:12:05 +0200 | [diff] [blame] | 2751 | #ifdef MESSAGE_QUEUE |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 2752 | # ifdef FEAT_TIMERS |
| 2753 | did_add_timer = FALSE; |
| 2754 | # endif |
Bram Moolenaar | 93c88e0 | 2015-09-15 14:12:05 +0200 | [diff] [blame] | 2755 | parse_queued_messages(); |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 2756 | # ifdef FEAT_TIMERS |
| 2757 | if (did_add_timer) |
| 2758 | /* Need to recompute the waiting time. */ |
| 2759 | break; |
| 2760 | # endif |
Bram Moolenaar | 03531f7 | 2010-11-16 15:04:57 +0100 | [diff] [blame] | 2761 | #endif |
| 2762 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2763 | /* |
| 2764 | * Don't use gui_mch_update() because then we will spin-lock until a |
| 2765 | * char arrives, instead we use XtAppProcessEvent() to hang until an |
| 2766 | * event arrives. No need to check for input_buf_full because we are |
| 2767 | * returning as soon as it contains a single char. Note that |
| 2768 | * XtAppNextEvent() may not be used because it will not return after a |
| 2769 | * timer event has arrived -- webb |
| 2770 | */ |
| 2771 | XtAppProcessEvent(app_context, desired); |
| 2772 | |
| 2773 | if (input_available()) |
| 2774 | { |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 2775 | retval = OK; |
| 2776 | break; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2777 | } |
| 2778 | } |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 2779 | |
| 2780 | if (timer != (XtIntervalId)0 && !timed_out) |
| 2781 | XtRemoveTimeOut(timer); |
Bram Moolenaar | 1dccf63 | 2017-08-27 17:38:27 +0200 | [diff] [blame] | 2782 | #ifdef FEAT_JOB_CHANNEL |
| 2783 | if (channel_timer != (XtIntervalId)0) |
| 2784 | XtRemoveTimeOut(channel_timer); |
| 2785 | #endif |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 2786 | |
| 2787 | return retval; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2788 | } |
| 2789 | |
| 2790 | /* |
| 2791 | * Output routines. |
| 2792 | */ |
| 2793 | |
| 2794 | /* Flush any output to the screen */ |
| 2795 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2796 | gui_mch_flush(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2797 | { |
| 2798 | XFlush(gui.dpy); |
| 2799 | } |
| 2800 | |
| 2801 | /* |
| 2802 | * Clear a rectangular region of the screen from text pos (row1, col1) to |
| 2803 | * (row2, col2) inclusive. |
| 2804 | */ |
| 2805 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2806 | gui_mch_clear_block( |
| 2807 | int row1, |
| 2808 | int col1, |
| 2809 | int row2, |
| 2810 | int col2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2811 | { |
| 2812 | int x; |
| 2813 | |
| 2814 | x = FILL_X(col1); |
| 2815 | |
| 2816 | /* Clear one extra pixel at the far right, for when bold characters have |
| 2817 | * spilled over to the next column. */ |
| 2818 | XFillRectangle(gui.dpy, gui.wid, gui.back_gc, x, FILL_Y(row1), |
| 2819 | (col2 - col1 + 1) * gui.char_width + (col2 == Columns - 1), |
| 2820 | (row2 - row1 + 1) * gui.char_height); |
| 2821 | } |
| 2822 | |
| 2823 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2824 | gui_mch_clear_all(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2825 | { |
| 2826 | XClearArea(gui.dpy, gui.wid, 0, 0, 0, 0, False); |
| 2827 | } |
| 2828 | |
| 2829 | /* |
| 2830 | * Delete the given number of lines from the given row, scrolling up any |
| 2831 | * text further down within the scroll region. |
| 2832 | */ |
| 2833 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2834 | gui_mch_delete_lines(int row, int num_lines) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2835 | { |
| 2836 | if (gui.visibility == VisibilityFullyObscured) |
| 2837 | return; /* Can't see the window */ |
| 2838 | |
| 2839 | /* copy one extra pixel at the far right, for when bold has spilled |
| 2840 | * over */ |
| 2841 | XCopyArea(gui.dpy, gui.wid, gui.wid, gui.text_gc, |
| 2842 | FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), |
| 2843 | gui.char_width * (gui.scroll_region_right - gui.scroll_region_left + 1) |
| 2844 | + (gui.scroll_region_right == Columns - 1), |
| 2845 | gui.char_height * (gui.scroll_region_bot - row - num_lines + 1), |
| 2846 | FILL_X(gui.scroll_region_left), FILL_Y(row)); |
| 2847 | |
| 2848 | gui_clear_block(gui.scroll_region_bot - num_lines + 1, |
| 2849 | gui.scroll_region_left, |
| 2850 | gui.scroll_region_bot, gui.scroll_region_right); |
| 2851 | gui_x11_check_copy_area(); |
| 2852 | } |
| 2853 | |
| 2854 | /* |
| 2855 | * Insert the given number of lines before the given row, scrolling down any |
| 2856 | * following text within the scroll region. |
| 2857 | */ |
| 2858 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2859 | gui_mch_insert_lines(int row, int num_lines) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2860 | { |
| 2861 | if (gui.visibility == VisibilityFullyObscured) |
| 2862 | return; /* Can't see the window */ |
| 2863 | |
| 2864 | /* copy one extra pixel at the far right, for when bold has spilled |
| 2865 | * over */ |
| 2866 | XCopyArea(gui.dpy, gui.wid, gui.wid, gui.text_gc, |
| 2867 | FILL_X(gui.scroll_region_left), FILL_Y(row), |
| 2868 | gui.char_width * (gui.scroll_region_right - gui.scroll_region_left + 1) |
| 2869 | + (gui.scroll_region_right == Columns - 1), |
| 2870 | gui.char_height * (gui.scroll_region_bot - row - num_lines + 1), |
| 2871 | FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines)); |
| 2872 | |
| 2873 | gui_clear_block(row, gui.scroll_region_left, |
| 2874 | row + num_lines - 1, gui.scroll_region_right); |
| 2875 | gui_x11_check_copy_area(); |
| 2876 | } |
| 2877 | |
| 2878 | /* |
| 2879 | * Update the region revealed by scrolling up/down. |
| 2880 | */ |
| 2881 | static void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2882 | gui_x11_check_copy_area(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2883 | { |
| 2884 | XEvent event; |
| 2885 | XGraphicsExposeEvent *gevent; |
| 2886 | |
| 2887 | if (gui.visibility != VisibilityPartiallyObscured) |
| 2888 | return; |
| 2889 | |
| 2890 | XFlush(gui.dpy); |
| 2891 | |
| 2892 | /* Wait to check whether the scroll worked or not */ |
| 2893 | for (;;) |
| 2894 | { |
| 2895 | if (XCheckTypedEvent(gui.dpy, NoExpose, &event)) |
| 2896 | return; /* The scroll worked. */ |
| 2897 | |
| 2898 | if (XCheckTypedEvent(gui.dpy, GraphicsExpose, &event)) |
| 2899 | { |
| 2900 | gevent = (XGraphicsExposeEvent *)&event; |
| 2901 | gui_redraw(gevent->x, gevent->y, gevent->width, gevent->height); |
| 2902 | if (gevent->count == 0) |
| 2903 | return; /* This was the last expose event */ |
| 2904 | } |
| 2905 | XSync(gui.dpy, False); |
| 2906 | } |
| 2907 | } |
| 2908 | |
| 2909 | /* |
| 2910 | * X Selection stuff, for cutting and pasting text to other windows. |
| 2911 | */ |
| 2912 | |
| 2913 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2914 | clip_mch_lose_selection(VimClipboard *cbd) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2915 | { |
| 2916 | clip_x11_lose_selection(vimShell, cbd); |
| 2917 | } |
| 2918 | |
| 2919 | int |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2920 | clip_mch_own_selection(VimClipboard *cbd) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2921 | { |
| 2922 | return clip_x11_own_selection(vimShell, cbd); |
| 2923 | } |
| 2924 | |
| 2925 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2926 | clip_mch_request_selection(VimClipboard *cbd) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2927 | { |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2928 | clip_x11_request_selection(vimShell, gui.dpy, cbd); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2932 | clip_mch_set_selection( |
| 2933 | VimClipboard *cbd) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2934 | { |
| 2935 | clip_x11_set_selection(cbd); |
| 2936 | } |
| 2937 | |
| 2938 | #if defined(FEAT_MENU) || defined(PROTO) |
| 2939 | /* |
| 2940 | * Menu stuff. |
| 2941 | */ |
| 2942 | |
| 2943 | /* |
| 2944 | * Make a menu either grey or not grey. |
| 2945 | */ |
| 2946 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2947 | gui_mch_menu_grey(vimmenu_T *menu, int grey) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2948 | { |
| 2949 | if (menu->id != (Widget)0) |
| 2950 | { |
| 2951 | gui_mch_menu_hidden(menu, False); |
| 2952 | if (grey |
| 2953 | #ifdef FEAT_GUI_MOTIF |
| 2954 | || !menu->sensitive |
| 2955 | #endif |
| 2956 | ) |
| 2957 | XtSetSensitive(menu->id, False); |
| 2958 | else |
| 2959 | XtSetSensitive(menu->id, True); |
| 2960 | } |
| 2961 | } |
| 2962 | |
| 2963 | /* |
| 2964 | * Make menu item hidden or not hidden |
| 2965 | */ |
| 2966 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2967 | gui_mch_menu_hidden(vimmenu_T *menu, int hidden) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2968 | { |
| 2969 | if (menu->id != (Widget)0) |
| 2970 | { |
| 2971 | if (hidden) |
| 2972 | XtUnmanageChild(menu->id); |
| 2973 | else |
| 2974 | XtManageChild(menu->id); |
| 2975 | } |
| 2976 | } |
| 2977 | |
| 2978 | /* |
| 2979 | * This is called after setting all the menus to grey/hidden or not. |
| 2980 | */ |
| 2981 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2982 | gui_mch_draw_menubar(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2983 | { |
| 2984 | /* Nothing to do in X */ |
| 2985 | } |
| 2986 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2987 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 2988 | gui_x11_menu_cb( |
| 2989 | Widget w UNUSED, |
| 2990 | XtPointer client_data, |
| 2991 | XtPointer call_data UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2992 | { |
| 2993 | gui_menu_cb((vimmenu_T *)client_data); |
| 2994 | } |
| 2995 | |
| 2996 | #endif /* FEAT_MENU */ |
| 2997 | |
| 2998 | |
| 2999 | |
| 3000 | /* |
| 3001 | * Function called when window closed. Works like ":qa". |
| 3002 | * Should put up a requester! |
| 3003 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3004 | static void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 3005 | gui_x11_wm_protocol_handler( |
| 3006 | Widget w UNUSED, |
| 3007 | XtPointer client_data UNUSED, |
| 3008 | XEvent *event, |
| 3009 | Boolean *dum UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3010 | { |
| 3011 | /* |
| 3012 | * Only deal with Client messages. |
| 3013 | */ |
| 3014 | if (event->type != ClientMessage) |
| 3015 | return; |
| 3016 | |
| 3017 | /* |
| 3018 | * The WM_SAVE_YOURSELF event arrives when the window manager wants to |
| 3019 | * exit. That can be cancelled though, thus Vim shouldn't exit here. |
| 3020 | * Just sync our swap files. |
| 3021 | */ |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 3022 | if ((Atom)((XClientMessageEvent *)event)->data.l[0] == |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3023 | wm_atoms[SAVE_YOURSELF_IDX]) |
| 3024 | { |
| 3025 | out_flush(); |
| 3026 | ml_sync_all(FALSE, FALSE); /* preserve all swap files */ |
| 3027 | |
| 3028 | /* Set the window's WM_COMMAND property, to let the window manager |
| 3029 | * know we are done saving ourselves. We don't want to be restarted, |
| 3030 | * thus set argv to NULL. */ |
| 3031 | XSetCommand(gui.dpy, XtWindow(vimShell), NULL, 0); |
| 3032 | return; |
| 3033 | } |
| 3034 | |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 3035 | if ((Atom)((XClientMessageEvent *)event)->data.l[0] != |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3036 | wm_atoms[DELETE_WINDOW_IDX]) |
| 3037 | return; |
| 3038 | |
| 3039 | gui_shell_closed(); |
| 3040 | } |
| 3041 | |
| 3042 | #ifdef FEAT_CLIENTSERVER |
| 3043 | /* |
| 3044 | * Function called when property changed. Check for incoming commands |
| 3045 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3046 | static void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 3047 | gui_x11_send_event_handler( |
| 3048 | Widget w UNUSED, |
| 3049 | XtPointer client_data UNUSED, |
| 3050 | XEvent *event, |
| 3051 | Boolean *dum UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3052 | { |
| 3053 | XPropertyEvent *e = (XPropertyEvent *) event; |
| 3054 | |
| 3055 | if (e->type == PropertyNotify && e->window == commWindow |
| 3056 | && e->atom == commProperty && e->state == PropertyNewValue) |
| 3057 | { |
Bram Moolenaar | 93c88e0 | 2015-09-15 14:12:05 +0200 | [diff] [blame] | 3058 | serverEventProc(gui.dpy, event, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3059 | } |
| 3060 | } |
| 3061 | #endif |
| 3062 | |
| 3063 | /* |
| 3064 | * Cursor blink functions. |
| 3065 | * |
| 3066 | * This is a simple state machine: |
| 3067 | * BLINK_NONE not blinking at all |
| 3068 | * BLINK_OFF blinking, cursor is not shown |
| 3069 | * BLINK_ON blinking, cursor is shown |
| 3070 | */ |
| 3071 | |
| 3072 | #define BLINK_NONE 0 |
| 3073 | #define BLINK_OFF 1 |
| 3074 | #define BLINK_ON 2 |
| 3075 | |
| 3076 | static int blink_state = BLINK_NONE; |
| 3077 | static long_u blink_waittime = 700; |
| 3078 | static long_u blink_ontime = 400; |
| 3079 | static long_u blink_offtime = 250; |
| 3080 | static XtIntervalId blink_timer = (XtIntervalId)0; |
| 3081 | |
Bram Moolenaar | 703a804 | 2016-06-04 16:24:32 +0200 | [diff] [blame] | 3082 | int |
| 3083 | gui_mch_is_blinking(void) |
| 3084 | { |
| 3085 | return blink_state != BLINK_NONE; |
| 3086 | } |
| 3087 | |
Bram Moolenaar | 9d5d3c9 | 2016-07-07 16:43:02 +0200 | [diff] [blame] | 3088 | int |
| 3089 | gui_mch_is_blink_off(void) |
| 3090 | { |
| 3091 | return blink_state == BLINK_OFF; |
| 3092 | } |
| 3093 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3094 | void |
Bram Moolenaar | 02fdaea | 2016-01-30 18:13:55 +0100 | [diff] [blame] | 3095 | gui_mch_set_blinking(long waittime, long on, long off) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3096 | { |
| 3097 | blink_waittime = waittime; |
| 3098 | blink_ontime = on; |
| 3099 | blink_offtime = off; |
| 3100 | } |
| 3101 | |
| 3102 | /* |
| 3103 | * Stop the cursor blinking. Show the cursor if it wasn't shown. |
| 3104 | */ |
| 3105 | void |
Bram Moolenaar | 1dd45fb | 2018-01-31 21:10:01 +0100 | [diff] [blame] | 3106 | gui_mch_stop_blink(int may_call_gui_update_cursor) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3107 | { |
| 3108 | if (blink_timer != (XtIntervalId)0) |
| 3109 | { |
| 3110 | XtRemoveTimeOut(blink_timer); |
| 3111 | blink_timer = (XtIntervalId)0; |
| 3112 | } |
Bram Moolenaar | 1dd45fb | 2018-01-31 21:10:01 +0100 | [diff] [blame] | 3113 | if (blink_state == BLINK_OFF && may_call_gui_update_cursor) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3114 | gui_update_cursor(TRUE, FALSE); |
| 3115 | blink_state = BLINK_NONE; |
| 3116 | } |
| 3117 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3118 | static void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 3119 | gui_x11_blink_cb( |
| 3120 | XtPointer timed_out UNUSED, |
| 3121 | XtIntervalId *interval_id UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3122 | { |
| 3123 | if (blink_state == BLINK_ON) |
| 3124 | { |
| 3125 | gui_undraw_cursor(); |
| 3126 | blink_state = BLINK_OFF; |
| 3127 | blink_timer = XtAppAddTimeOut(app_context, blink_offtime, |
| 3128 | gui_x11_blink_cb, NULL); |
| 3129 | } |
| 3130 | else |
| 3131 | { |
| 3132 | gui_update_cursor(TRUE, FALSE); |
| 3133 | blink_state = BLINK_ON; |
| 3134 | blink_timer = XtAppAddTimeOut(app_context, blink_ontime, |
| 3135 | gui_x11_blink_cb, NULL); |
| 3136 | } |
| 3137 | } |
| 3138 | |
| 3139 | /* |
Bram Moolenaar | 1dccf63 | 2017-08-27 17:38:27 +0200 | [diff] [blame] | 3140 | * Start the cursor blinking. If it was already blinking, this restarts the |
| 3141 | * waiting time and shows the cursor. |
| 3142 | */ |
| 3143 | void |
| 3144 | gui_mch_start_blink(void) |
| 3145 | { |
| 3146 | if (blink_timer != (XtIntervalId)0) |
| 3147 | XtRemoveTimeOut(blink_timer); |
| 3148 | /* Only switch blinking on if none of the times is zero */ |
| 3149 | if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus) |
| 3150 | { |
| 3151 | blink_timer = XtAppAddTimeOut(app_context, blink_waittime, |
| 3152 | gui_x11_blink_cb, NULL); |
| 3153 | blink_state = BLINK_ON; |
| 3154 | gui_update_cursor(TRUE, FALSE); |
| 3155 | } |
| 3156 | } |
| 3157 | |
| 3158 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3159 | * Return the RGB value of a pixel as a long. |
| 3160 | */ |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 3161 | guicolor_T |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 3162 | gui_mch_get_rgb(guicolor_T pixel) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3163 | { |
| 3164 | XColor xc; |
| 3165 | Colormap colormap; |
| 3166 | |
| 3167 | colormap = DefaultColormap(gui.dpy, XDefaultScreen(gui.dpy)); |
| 3168 | xc.pixel = pixel; |
| 3169 | XQueryColor(gui.dpy, colormap, &xc); |
| 3170 | |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 3171 | return (guicolor_T)(((xc.red & 0xff00) << 8) + (xc.green & 0xff00) |
| 3172 | + ((unsigned)xc.blue >> 8)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3173 | } |
| 3174 | |
| 3175 | /* |
| 3176 | * Add the callback functions. |
| 3177 | */ |
| 3178 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 3179 | gui_x11_callbacks(Widget textArea, Widget vimForm) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3180 | { |
| 3181 | XtAddEventHandler(textArea, VisibilityChangeMask, FALSE, |
| 3182 | gui_x11_visibility_cb, (XtPointer)0); |
| 3183 | |
| 3184 | XtAddEventHandler(textArea, ExposureMask, FALSE, gui_x11_expose_cb, |
| 3185 | (XtPointer)0); |
| 3186 | |
| 3187 | XtAddEventHandler(vimShell, StructureNotifyMask, FALSE, |
| 3188 | gui_x11_resize_window_cb, (XtPointer)0); |
| 3189 | |
| 3190 | XtAddEventHandler(vimShell, FocusChangeMask, FALSE, gui_x11_focus_change_cb, |
| 3191 | (XtPointer)0); |
| 3192 | /* |
| 3193 | * Only install these enter/leave callbacks when 'p' in 'guioptions'. |
| 3194 | * Only needed for some window managers. |
| 3195 | */ |
| 3196 | if (vim_strchr(p_go, GO_POINTER) != NULL) |
| 3197 | { |
| 3198 | XtAddEventHandler(vimShell, LeaveWindowMask, FALSE, gui_x11_leave_cb, |
| 3199 | (XtPointer)0); |
| 3200 | XtAddEventHandler(textArea, LeaveWindowMask, FALSE, gui_x11_leave_cb, |
| 3201 | (XtPointer)0); |
| 3202 | XtAddEventHandler(textArea, EnterWindowMask, FALSE, gui_x11_enter_cb, |
| 3203 | (XtPointer)0); |
| 3204 | XtAddEventHandler(vimShell, EnterWindowMask, FALSE, gui_x11_enter_cb, |
| 3205 | (XtPointer)0); |
| 3206 | } |
| 3207 | |
| 3208 | XtAddEventHandler(vimForm, KeyPressMask, FALSE, gui_x11_key_hit_cb, |
| 3209 | (XtPointer)0); |
| 3210 | XtAddEventHandler(textArea, KeyPressMask, FALSE, gui_x11_key_hit_cb, |
| 3211 | (XtPointer)0); |
| 3212 | |
| 3213 | /* get pointer moved events from scrollbar, needed for 'mousefocus' */ |
| 3214 | XtAddEventHandler(vimForm, PointerMotionMask, |
| 3215 | FALSE, gui_x11_mouse_cb, (XtPointer)1); |
| 3216 | XtAddEventHandler(textArea, ButtonPressMask | ButtonReleaseMask | |
| 3217 | ButtonMotionMask | PointerMotionMask, |
| 3218 | FALSE, gui_x11_mouse_cb, (XtPointer)0); |
| 3219 | } |
| 3220 | |
| 3221 | /* |
Bram Moolenaar | 6cc1619 | 2005-01-08 21:49:45 +0000 | [diff] [blame] | 3222 | * Get current mouse coordinates in text window. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3223 | */ |
Bram Moolenaar | 6cc1619 | 2005-01-08 21:49:45 +0000 | [diff] [blame] | 3224 | void |
| 3225 | gui_mch_getmouse(int *x, int *y) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3226 | { |
| 3227 | int rootx, rooty, winx, winy; |
| 3228 | Window root, child; |
| 3229 | unsigned int mask; |
| 3230 | |
| 3231 | if (gui.wid && XQueryPointer(gui.dpy, gui.wid, &root, &child, |
Bram Moolenaar | 6cc1619 | 2005-01-08 21:49:45 +0000 | [diff] [blame] | 3232 | &rootx, &rooty, &winx, &winy, &mask)) { |
| 3233 | *x = winx; |
| 3234 | *y = winy; |
| 3235 | } else { |
| 3236 | *x = -1; |
| 3237 | *y = -1; |
| 3238 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3239 | } |
| 3240 | |
| 3241 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 3242 | gui_mch_setmouse(int x, int y) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3243 | { |
| 3244 | if (gui.wid) |
| 3245 | XWarpPointer(gui.dpy, (Window)0, gui.wid, 0, 0, 0, 0, x, y); |
| 3246 | } |
| 3247 | |
| 3248 | #if (defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU)) || defined(PROTO) |
| 3249 | XButtonPressedEvent * |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 3250 | gui_x11_get_last_mouse_event(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3251 | { |
| 3252 | return &last_mouse_event; |
| 3253 | } |
| 3254 | #endif |
| 3255 | |
| 3256 | #if defined(FEAT_SIGN_ICONS) || defined(PROTO) |
| 3257 | |
| 3258 | /* Signs are currently always 2 chars wide. Hopefully the font is big enough |
| 3259 | * to provide room for the bitmap! */ |
| 3260 | # define SIGN_WIDTH (gui.char_width * 2) |
| 3261 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3262 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 3263 | gui_mch_drawsign(int row, int col, int typenr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3264 | { |
| 3265 | XImage *sign; |
| 3266 | |
| 3267 | if (gui.in_use && (sign = (XImage *)sign_get_image(typenr)) != NULL) |
| 3268 | { |
| 3269 | XClearArea(gui.dpy, gui.wid, TEXT_X(col), TEXT_Y(row) - sign->height, |
| 3270 | SIGN_WIDTH, gui.char_height, FALSE); |
| 3271 | XPutImage(gui.dpy, gui.wid, gui.text_gc, sign, 0, 0, |
| 3272 | TEXT_X(col) + (SIGN_WIDTH - sign->width) / 2, |
| 3273 | TEXT_Y(row) - sign->height, |
| 3274 | sign->width, sign->height); |
| 3275 | } |
| 3276 | } |
| 3277 | |
| 3278 | void * |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 3279 | gui_mch_register_sign(char_u *signfile) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3280 | { |
| 3281 | XpmAttributes attrs; |
Bram Moolenaar | e4bfca8 | 2009-02-24 03:12:40 +0000 | [diff] [blame] | 3282 | XImage *sign = NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3283 | int status; |
| 3284 | |
| 3285 | /* |
| 3286 | * Setup the color substitution table. |
| 3287 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3288 | if (signfile[0] != NUL && signfile[0] != '-') |
| 3289 | { |
Bram Moolenaar | e4bfca8 | 2009-02-24 03:12:40 +0000 | [diff] [blame] | 3290 | XpmColorSymbol color[5] = |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3291 | { |
Bram Moolenaar | e4bfca8 | 2009-02-24 03:12:40 +0000 | [diff] [blame] | 3292 | {"none", NULL, 0}, |
| 3293 | {"iconColor1", NULL, 0}, |
| 3294 | {"bottomShadowColor", NULL, 0}, |
| 3295 | {"topShadowColor", NULL, 0}, |
| 3296 | {"selectColor", NULL, 0} |
| 3297 | }; |
| 3298 | attrs.valuemask = XpmColorSymbols; |
| 3299 | attrs.numsymbols = 2; |
| 3300 | attrs.colorsymbols = color; |
| 3301 | attrs.colorsymbols[0].pixel = gui.back_pixel; |
| 3302 | attrs.colorsymbols[1].pixel = gui.norm_pixel; |
| 3303 | status = XpmReadFileToImage(gui.dpy, (char *)signfile, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3304 | &sign, NULL, &attrs); |
Bram Moolenaar | e4bfca8 | 2009-02-24 03:12:40 +0000 | [diff] [blame] | 3305 | if (status == 0) |
| 3306 | { |
| 3307 | /* Sign width is fixed at two columns now. |
| 3308 | if (sign->width > gui.sign_width) |
Bram Moolenaar | cc448b3 | 2010-07-14 16:52:17 +0200 | [diff] [blame] | 3309 | gui.sign_width = sign->width + 8; */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3310 | } |
Bram Moolenaar | e4bfca8 | 2009-02-24 03:12:40 +0000 | [diff] [blame] | 3311 | else |
| 3312 | EMSG(_(e_signdata)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3313 | } |
| 3314 | |
| 3315 | return (void *)sign; |
| 3316 | } |
| 3317 | |
| 3318 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 3319 | gui_mch_destroy_sign(void *sign) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3320 | { |
Bram Moolenaar | e4bfca8 | 2009-02-24 03:12:40 +0000 | [diff] [blame] | 3321 | XDestroyImage((XImage*)sign); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3322 | } |
| 3323 | #endif |
| 3324 | |
| 3325 | |
| 3326 | #ifdef FEAT_MOUSESHAPE |
| 3327 | /* The last set mouse pointer shape is remembered, to be used when it goes |
| 3328 | * from hidden to not hidden. */ |
| 3329 | static int last_shape = 0; |
| 3330 | #endif |
| 3331 | |
| 3332 | /* |
| 3333 | * Use the blank mouse pointer or not. |
| 3334 | */ |
| 3335 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 3336 | gui_mch_mousehide( |
| 3337 | int hide) /* TRUE = use blank ptr, FALSE = use parent ptr */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3338 | { |
| 3339 | if (gui.pointer_hidden != hide) |
| 3340 | { |
| 3341 | gui.pointer_hidden = hide; |
| 3342 | if (hide) |
| 3343 | XDefineCursor(gui.dpy, gui.wid, gui.blank_pointer); |
| 3344 | else |
| 3345 | #ifdef FEAT_MOUSESHAPE |
| 3346 | mch_set_mouse_shape(last_shape); |
| 3347 | #else |
| 3348 | XUndefineCursor(gui.dpy, gui.wid); |
| 3349 | #endif |
| 3350 | } |
| 3351 | } |
| 3352 | |
| 3353 | #if defined(FEAT_MOUSESHAPE) || defined(PROTO) |
| 3354 | |
| 3355 | /* Table for shape IDs. Keep in sync with the mshape_names[] table in |
| 3356 | * misc2.c! */ |
| 3357 | static int mshape_ids[] = |
| 3358 | { |
| 3359 | XC_left_ptr, /* arrow */ |
| 3360 | 0, /* blank */ |
| 3361 | XC_xterm, /* beam */ |
| 3362 | XC_sb_v_double_arrow, /* updown */ |
| 3363 | XC_sizing, /* udsizing */ |
| 3364 | XC_sb_h_double_arrow, /* leftright */ |
| 3365 | XC_sizing, /* lrsizing */ |
| 3366 | XC_watch, /* busy */ |
| 3367 | XC_X_cursor, /* no */ |
| 3368 | XC_crosshair, /* crosshair */ |
| 3369 | XC_hand1, /* hand1 */ |
| 3370 | XC_hand2, /* hand2 */ |
| 3371 | XC_pencil, /* pencil */ |
| 3372 | XC_question_arrow, /* question */ |
| 3373 | XC_right_ptr, /* right-arrow */ |
| 3374 | XC_center_ptr, /* up-arrow */ |
| 3375 | XC_left_ptr /* last one */ |
| 3376 | }; |
| 3377 | |
| 3378 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 3379 | mch_set_mouse_shape(int shape) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3380 | { |
| 3381 | int id; |
| 3382 | |
| 3383 | if (!gui.in_use) |
| 3384 | return; |
| 3385 | |
| 3386 | if (shape == MSHAPE_HIDE || gui.pointer_hidden) |
| 3387 | XDefineCursor(gui.dpy, gui.wid, gui.blank_pointer); |
| 3388 | else |
| 3389 | { |
| 3390 | if (shape >= MSHAPE_NUMBERED) |
| 3391 | { |
| 3392 | id = shape - MSHAPE_NUMBERED; |
| 3393 | if (id >= XC_num_glyphs) |
| 3394 | id = XC_left_ptr; |
| 3395 | else |
| 3396 | id &= ~1; /* they are always even (why?) */ |
| 3397 | } |
| 3398 | else |
| 3399 | id = mshape_ids[shape]; |
| 3400 | |
| 3401 | XDefineCursor(gui.dpy, gui.wid, XCreateFontCursor(gui.dpy, id)); |
| 3402 | } |
| 3403 | if (shape != MSHAPE_HIDE) |
| 3404 | last_shape = shape; |
| 3405 | } |
| 3406 | #endif |
| 3407 | |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 3408 | #if (defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL_GUI)) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3409 | /* |
| 3410 | * Set the balloon-eval used for the tooltip of a toolbar menu item. |
| 3411 | * The check for a non-toolbar item was added, because there is a crash when |
| 3412 | * passing a normal menu item here. Can't explain that, but better avoid it. |
| 3413 | */ |
| 3414 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 3415 | gui_mch_menu_set_tip(vimmenu_T *menu) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3416 | { |
| 3417 | if (menu->id != NULL && menu->parent != NULL |
| 3418 | && menu_is_toolbar(menu->parent->name)) |
| 3419 | { |
| 3420 | /* Always destroy and create the balloon, in case the string was |
| 3421 | * changed. */ |
| 3422 | if (menu->tip != NULL) |
| 3423 | { |
| 3424 | gui_mch_destroy_beval_area(menu->tip); |
| 3425 | menu->tip = NULL; |
| 3426 | } |
| 3427 | if (menu->strings[MENU_INDEX_TIP] != NULL) |
| 3428 | menu->tip = gui_mch_create_beval_area( |
| 3429 | menu->id, |
| 3430 | menu->strings[MENU_INDEX_TIP], |
| 3431 | NULL, |
| 3432 | NULL); |
| 3433 | } |
| 3434 | } |
| 3435 | #endif |