changeset 3518:7bafe52b6245 v7.3.520

updated for version 7.3.520 Problem: Gvim starts up slow on Unbuntu 12.04. Solution: Move the call to gui_mch_init_check() to after fork(). (Yasuhiro Matsumoto) Do check $DISPLAY being set.
author Bram Moolenaar <bram@vim.org>
date Fri, 18 May 2012 17:03:18 +0200
parents 20507e1e60e8
children 290fb0dbe181
files src/gui.c src/gui_gtk_x11.c src/proto/gui_gtk_x11.pro src/version.c
diffstat 4 files changed, 43 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/gui.c
+++ b/src/gui.c
@@ -270,6 +270,12 @@ gui_do_fork()
     }
     /* Child */
 
+#ifdef FEAT_GUI_GTK
+    /* Call gtk_init_check() here after fork(). See gui_init_check(). */
+    if (gui_mch_init_check() != OK)
+	exit(1);
+#endif
+
 # if defined(HAVE_SETSID) || defined(HAVE_SETPGID)
     /*
      * Change our process group.  On some systems/shells a CTRL-C in the
@@ -430,7 +436,17 @@ gui_init_check()
 #ifdef ALWAYS_USE_GUI
     result = OK;
 #else
+# ifdef FEAT_GUI_GTK
+    /*
+     * Note: Don't call gtk_init_check() before fork, it will be called after
+     * the fork. When calling it before fork, it make vim hang for a while.
+     * See gui_do_fork().
+     * Use a simpler check if the GUI window can probably be opened.
+     */
+    result = gui.dofork ? gui_mch_early_init_check() : gui_mch_init_check();
+# else
     result = gui_mch_init_check();
+# endif
 #endif
     return result;
 }
--- a/src/gui_gtk_x11.c
+++ b/src/gui_gtk_x11.c
@@ -1414,7 +1414,29 @@ selection_get_cb(GtkWidget	    *widget U
 }
 
 /*
- * Check if the GUI can be started.  Called before gvimrc is sourced.
+ * Check if the GUI can be started.  Called before gvimrc is sourced and
+ * before fork().
+ * Return OK or FAIL.
+ */
+    int
+gui_mch_early_init_check(void)
+{
+    char_u *p;
+
+    /* Guess that when $DISPLAY isn't set the GUI can't start. */
+    p = mch_getenv((char_u *)"DISPLAY");
+    if (p == NULL || *p == NUL)
+    {
+	gui.dying = TRUE;
+	EMSG(_((char *)e_opendisp));
+	return FAIL;
+    }
+    return OK;
+}
+
+/*
+ * Check if the GUI can be started.  Called before gvimrc is sourced but after
+ * fork().
  * Return OK or FAIL.
  */
     int
@@ -3050,7 +3072,7 @@ gui_gtk_set_selection_targets(void)
 
     for (i = 0; i < (int)N_SELECTION_TARGETS; ++i)
     {
-	/* OpenOffice tries to use TARGET_HTML and fails when it doesn't
+	/* OpenOffice tries to use TARGET_HTML and fails when we don't
 	 * return something, instead of trying another target. Therefore only
 	 * offer TARGET_HTML when it works. */
 	if (!clip_html && selection_targets[i].info == TARGET_HTML)
--- a/src/proto/gui_gtk_x11.pro
+++ b/src/proto/gui_gtk_x11.pro
@@ -4,6 +4,7 @@ void gui_mch_free_all __ARGS((void));
 void gui_mch_set_blinking __ARGS((long waittime, long on, long off));
 void gui_mch_stop_blink __ARGS((void));
 void gui_mch_start_blink __ARGS((void));
+int gui_mch_early_init_check __ARGS((void));
 int gui_mch_init_check __ARGS((void));
 void gui_mch_show_tabline __ARGS((int showit));
 int gui_mch_showing_tabline __ARGS((void));
--- a/src/version.c
+++ b/src/version.c
@@ -715,6 +715,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    520,
+/**/
     519,
 /**/
     518,