home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / unreleased / patches / old / 5.4o.4 < prev    next >
Encoding:
Internet Message Format  |  1999-07-12  |  6.5 KB

  1. To: vim-dev@vim.org
  2. Subject: patch 5.4o.4
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. ------------
  6.  
  7. Patch 5.4o.4
  8. Problem:    When running in an xterm and $WINDOWID is set to an illegal value,
  9.         Vim would exit with "Vim: Got X error".
  10. Solution:   When using the display which was opened for the xterm clipboard,
  11.         check if x11_window is valid by trying to obtain the window title.
  12.         Also add a check in setup_xterm_clip(), for when using X calls to
  13.         get the pointer position in an xterm.
  14. Files:        src/os_unix.c
  15.  
  16.  
  17. *** ../vim-5.4o/src/os_unix.c    Sun Jul 11 20:10:59 1999
  18. --- src/os_unix.c    Tue Jul 13 16:35:59 1999
  19. ***************
  20. *** 121,126 ****
  21. --- 121,127 ----
  22.   
  23.   # ifdef WANT_TITLE
  24.   static int  get_x11_windis __ARGS((void));
  25. + static int  test_x11_window __ARGS((Display *dpy));
  26.   static void set_x11_title __ARGS((char_u *));
  27.   static void set_x11_icon __ARGS((char_u *));
  28.   # endif
  29. ***************
  30. *** 725,736 ****
  31.       XGetErrorText(dpy, error_event->error_code, (char *)IObuff, IOSIZE);
  32.       STRCAT(IObuff, "\nVim: Got X error\n");
  33.   
  34. ! #if 1
  35.       preserve_exit();            /* preserve files and exit */
  36. - #else
  37. -     printf(IObuff);            /* print error message and continue */
  38. -                     /* Makes my system hang */
  39. - #endif
  40.   
  41.       return 0;        /* NOTREACHED */
  42.   }
  43. --- 726,735 ----
  44.       XGetErrorText(dpy, error_event->error_code, (char *)IObuff, IOSIZE);
  45.       STRCAT(IObuff, "\nVim: Got X error\n");
  46.   
  47. !     /* We cannot print a message and continue, because no X calls are allowed
  48. !      * here (causes my system to hang).  Silently continuing might be an
  49. !      * alternative... */
  50.       preserve_exit();            /* preserve files and exit */
  51.   
  52.       return 0;        /* NOTREACHED */
  53.   }
  54. ***************
  55. *** 762,769 ****
  56.   get_x11_windis()
  57.   {
  58.       char        *winid;
  59. -     XTextProperty   text_prop;
  60. -     int            (*old_handler)();
  61.       static int        result = -1;
  62.   #define XD_NONE     0    /* x11_display not set here */
  63.   #define XD_HERE     1    /* x11_display opened here */
  64. --- 761,766 ----
  65. ***************
  66. *** 786,794 ****
  67.           XCloseDisplay(x11_display);
  68.           x11_display = NULL;
  69.       }
  70. !     gui_get_x11_windis(&x11_window, &x11_display);
  71. !     x11_display_from = XD_GUI;
  72. !     return OK;
  73.       }
  74.       else if (x11_display_from == XD_GUI)
  75.       {
  76. --- 783,794 ----
  77.           XCloseDisplay(x11_display);
  78.           x11_display = NULL;
  79.       }
  80. !     if (gui_get_x11_windis(&x11_window, &x11_display) == OK)
  81. !     {
  82. !         x11_display_from = XD_GUI;
  83. !         return OK;
  84. !     }
  85. !     return FAIL;
  86.       }
  87.       else if (x11_display_from == XD_GUI)
  88.       {
  89. ***************
  90. *** 819,824 ****
  91. --- 819,832 ----
  92.           XCloseDisplay(x11_display);
  93.       x11_display = xterm_dpy;
  94.       x11_display_from = XD_XTERM;
  95. +     if (test_x11_window(x11_display) == FAIL)
  96. +     {
  97. +         /* probably bad $WINDOWID */
  98. +         x11_window = 0;
  99. +         x11_display = NULL;
  100. +         x11_display_from = XD_NONE;
  101. +         return FAIL;
  102. +     }
  103.       return OK;
  104.       }
  105.   #endif
  106. ***************
  107. *** 854,872 ****
  108.   #endif
  109.       if (x11_display != NULL)
  110.       {
  111. !         /*
  112. !          * Try to get the window title.  I don't actually want it yet, so
  113. !          * there may be a simpler call to use, but this will cause the
  114. !          * error handler x_error_check() to be called if anything is wrong,
  115. !          * such as the window pointer being invalid (as can happen when the
  116. !          * user changes his DISPLAY, but not his WINDOWID) -- webb
  117. !          */
  118. !         old_handler = XSetErrorHandler(x_error_check);
  119. !         got_x_error = FALSE;
  120. !         if (XGetWMName(x11_display, x11_window, &text_prop))
  121. !         XFree((void *)text_prop.value);
  122. !         XSync(x11_display, False);
  123. !         if (got_x_error)
  124.           {
  125.           /* Maybe window id is bad */
  126.           x11_window = 0;
  127. --- 862,868 ----
  128.   #endif
  129.       if (x11_display != NULL)
  130.       {
  131. !         if (test_x11_window(x11_display) == FAIL)
  132.           {
  133.           /* Maybe window id is bad */
  134.           x11_window = 0;
  135. ***************
  136. *** 875,881 ****
  137.           }
  138.           else
  139.           x11_display_from = XD_HERE;
  140. -         XSetErrorHandler(old_handler);
  141.       }
  142.       }
  143.       if (x11_window == 0 || x11_display == NULL)
  144. --- 871,876 ----
  145. ***************
  146. *** 884,889 ****
  147. --- 879,908 ----
  148.   }
  149.   
  150.   /*
  151. +  * Test if "dpy" and x11_window are valid by getting the window title.
  152. +  * I don't actually want it yet, so there may be a simpler call to use, but
  153. +  * this will cause the error handler x_error_check() to be called if anything
  154. +  * is wrong, such as the window pointer being invalid (as can happen when the
  155. +  * user changes his DISPLAY, but not his WINDOWID) -- webb
  156. +  */
  157. +     static int
  158. + test_x11_window(dpy)
  159. +     Display    *dpy;
  160. + {
  161. +     int            (*old_handler)();
  162. +     XTextProperty    text_prop;
  163. +     old_handler = XSetErrorHandler(x_error_check);
  164. +     got_x_error = FALSE;
  165. +     if (XGetWMName(dpy, x11_window, &text_prop))
  166. +     XFree((void *)text_prop.value);
  167. +     XSync(dpy, False);
  168. +     (void)XSetErrorHandler(old_handler);
  169. +     return (got_x_error ? FAIL : OK);
  170. + }
  171. + /*
  172.    * Determine original x11 Window Title
  173.    */
  174.       static int
  175. ***************
  176. *** 3825,3837 ****
  177.       open_app_context();
  178.       if (app_context != NULL && xterm_Shell == (Widget)0)
  179.       {
  180.       xterm_dpy = XtOpenDisplay(app_context, xterm_display,
  181.           "vim_xterm", "Vim_xterm", NULL, 0, &z, &strp);
  182.       if (xterm_dpy == NULL)
  183.           return;
  184. !     /*
  185. !      * So converters work.
  186. !      */
  187.       AppShell = XtVaAppCreateShell("vim_xterm", "Vim_xterm",
  188.           applicationShellWidgetClass, xterm_dpy,
  189.           NULL);
  190. --- 3844,3862 ----
  191.       open_app_context();
  192.       if (app_context != NULL && xterm_Shell == (Widget)0)
  193.       {
  194. +     /* Ignore X errors while opening the display */
  195. +     XSetErrorHandler(x_error_check);
  196.       xterm_dpy = XtOpenDisplay(app_context, xterm_display,
  197.           "vim_xterm", "Vim_xterm", NULL, 0, &z, &strp);
  198. +     /* Now handle X errors normally. */
  199. +     XSetErrorHandler(x_error_handler);
  200.       if (xterm_dpy == NULL)
  201.           return;
  202. !     /* Create a Shell to make converters work. */
  203.       AppShell = XtVaAppCreateShell("vim_xterm", "Vim_xterm",
  204.           applicationShellWidgetClass, xterm_dpy,
  205.           NULL);
  206. ***************
  207. *** 3859,3864 ****
  208. --- 3884,3892 ----
  209.       clip_init(TRUE);
  210.       if (x11_window == 0 && (strp = getenv("WINDOWID")) != NULL)
  211.           x11_window = (Window)atol(strp);
  212. +     /* Check if $WINDOWID is valid. */
  213. +     if (test_x11_window(xterm_dpy) == FAIL)
  214. +         x11_window = 0;
  215.       if (x11_window != 0)
  216.           xterm_trace = 0;
  217.       }
  218.  
  219. --
  220. hundred-and-one symptoms of being an internet addict:
  221. 80. At parties, you introduce your spouse as your "service provider."
  222.  
  223. --/-/---- Bram Moolenaar ---- Bram@moolenaar.net ---- Bram@vim.org ---\-\--
  224.   \ \    www.vim.org/iccf      www.moolenaar.net       www.vim.org    / /
  225.