]> granicus.if.org Git - vim/commitdiff
patch 8.1.1307: cannot reconnect to the X server after it restarted v8.1.1307
authorBram Moolenaar <Bram@vim.org>
Thu, 9 May 2019 16:59:31 +0000 (18:59 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 9 May 2019 16:59:31 +0000 (18:59 +0200)
Problem:    Cannot reconnect to the X server after it restarted.
Solution:   Add the :xrestore command. (Adrian Kocis, closes #844)

runtime/doc/index.txt
runtime/doc/various.txt
src/ex_cmdidxs.h
src/ex_cmds.h
src/ex_docmd.c
src/globals.h
src/os_unix.c
src/proto/os_unix.pro
src/testdir/test_paste.vim
src/version.c

index 792a71569e6015c0719d8d41da121a8400e0edb6..8437f2410bfa82c5030c5d0869ed2ca5b43d909a 100644 (file)
@@ -1714,6 +1714,7 @@ tag               command         action ~
 |:xmapclear|   :xmapc[lear]    remove all mappings for Visual mode
 |:xmap|                :xm[ap]         like ":map" but for Visual mode
 |:xmenu|       :xme[nu]        add menu for Visual mode
+|:xrestore|    :xr[estore]     restores the X server connection
 |:xnoremap|    :xn[oremap]     like ":noremap" but for Visual mode
 |:xnoremenu|   :xnoreme[nu]    like ":noremenu" but for Visual mode
 |:xunmap|      :xu[nmap]       like ":unmap" but for Visual mode
index 79889276a5d6a31d23b9dcd800b5435c729d90fb..9b61e8b2c3d38aad4599799ee51d9070ed93f0a9 100644 (file)
@@ -704,6 +704,21 @@ K                  Run a program to lookup the keyword under the
                        available when compiled with the |+netbeans_intg|
                        feature}
 
+                                                       *:xrestore* *:xr*
+:xr[estore] [display]  Reinitializes the connection to the X11 server. Useful
+                       after the X server restarts, e.g. when running Vim for
+                       long time inside screen/tmux and connecting from
+                       different machines).
+                       [display] should be in the format of the $DISPLAY 
+                       environment variable (e.g. "localhost:10.0")
+                       If [display] is omitted, then it reinitializes the
+                       connection to the X11 server using the same value as
+                       was used for the previous execution of this command.
+                       If the value was never specified, then it uses the
+                       value of $DISPLAY environment variable as it was when
+                       Vim was started.
+                       {only available when compiled with the |+clipboard| 
+                       feature}
 
                                                        *g_CTRL-A*
 g CTRL-A               Only when Vim was compiled with MEM_PROFILING defined
index 6b96c6cfa1fe028dbabe870515dfc2214b9ba5a4..0103a1741ab1b01ceb053bf427347df57783e939 100644 (file)
@@ -29,8 +29,8 @@ static const unsigned short cmdidxs1[26] =
   /* v */ 503,
   /* w */ 521,
   /* x */ 535,
-  /* y */ 544,
-  /* z */ 545
+  /* y */ 545,
+  /* z */ 546
 };
 
 /*
@@ -64,9 +64,9 @@ static const unsigned char cmdidxs2[26][26] =
   /* u */ {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 10,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
   /* v */ {  0,  0,  0,  0,  1,  0,  0,  0,  4,  0,  0,  0,  9, 12,  0,  0,  0,  0, 15,  0, 16,  0,  0,  0,  0,  0 },
   /* w */ {  2,  0,  0,  0,  0,  0,  0,  3,  4,  0,  0,  0,  0,  8,  0,  9, 10,  0,  0,  0, 12, 13,  0,  0,  0,  0 },
-  /* x */ {  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  2,  5,  0,  0,  0,  0,  0,  0,  7,  0,  0,  0,  0,  0 },
+  /* x */ {  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  2,  5,  0,  0,  0,  7,  0,  0,  8,  0,  0,  0,  0,  0 },
   /* y */ {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
   /* z */ {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 }
 };
 
-static const int command_count = 558;
+static const int command_count = 559;
index 37577f7b30e7482fd56c9ee6e41cc4ccb1c9aafd..5ec69be3641e8d35df974f358538d4b2c8d66de8 100644 (file)
@@ -1739,6 +1739,9 @@ EX(CMD_xnoremap,  "xnoremap",     ex_map,
 EX(CMD_xnoremenu,      "xnoremenu",    ex_menu,
                        RANGE|ZEROR|EXTRA|TRLBAR|NOTRLCOM|USECTRLV|CMDWIN,
                        ADDR_OTHER),
+EX(CMD_xrestore,       "xrestore",     ex_xrestore,
+                       EXTRA|TRLBAR|CMDWIN,
+                       ADDR_NONE),
 EX(CMD_xunmap,         "xunmap",       ex_unmap,
                        EXTRA|TRLBAR|NOTRLCOM|USECTRLV|CMDWIN,
                        ADDR_NONE),
index a2b302d92250b7cf4c662ab3f5e60a503730f4c9..16f505967d1c3aae30da8b842b0e5d81d0500504 100644 (file)
@@ -394,6 +394,9 @@ static void ex_folddo(exarg_T *eap);
 #ifndef FEAT_TERMINAL
 # define ex_terminal           ex_ni
 #endif
+#if !defined(FEAT_X11) || !defined(FEAT_XCLIPBOARD)
+# define ex_xrestore           ex_ni
+#endif
 
 /*
  * Declare cmdnames[].
index 1a055d6085dcfbac4ad712b1f8cb8dabe1d4bb68..09ac6b5e80832ef6b7025c781fa86a3384c21a8f 100644 (file)
@@ -1279,9 +1279,14 @@ EXTERN linenr_T printer_page_num;
 #endif
 
 #ifdef FEAT_XCLIPBOARD
-EXTERN char    *xterm_display INIT(= NULL);    /* xterm display name; points
-                                                  into argv[] */
-EXTERN Display *xterm_dpy INIT(= NULL);        /* xterm display pointer */
+// xterm display name
+EXTERN char    *xterm_display INIT(= NULL);
+
+// whether xterm_display was allocated, when FALSE it points into argv[]
+EXTERN int     xterm_display_allocated INIT(= FALSE);
+
+// xterm display pointer
+EXTERN Display *xterm_dpy INIT(= NULL);
 #endif
 #if defined(FEAT_XCLIPBOARD) || defined(FEAT_GUI_X11)
 EXTERN XtAppContext app_context INIT(= (XtAppContext)NULL);
index b5627b162812c266b8b7f01494055c10815ea06b..a6d1a12d1069c2d7a2da402614d10c29d1ba9f75 100644 (file)
@@ -1659,6 +1659,25 @@ may_restore_clipboard(void)
        get_x11_title(FALSE);
     }
 }
+
+    void
+ex_xrestore(exarg_T *eap)
+{
+    if (eap->arg != NULL && STRLEN(eap->arg) > 0)
+    {
+        if (xterm_display_allocated)
+            vim_free(xterm_display);
+        xterm_display = (char *)vim_strsave(eap->arg);
+        xterm_display_allocated = TRUE;
+    }
+    smsg(_("restoring display %s"), xterm_display == NULL
+                             ? (char *)mch_getenv("DISPLAY") : xterm_display);
+
+    clear_xterm_clip();
+    x11_window = 0;
+    xterm_dpy_retry_count = 5;  // Try reconnecting five times
+    may_restore_clipboard();
+}
 #endif
 
 /*
@@ -1761,6 +1780,10 @@ get_x11_windis(void)
        x11_window = (Window)atol(winid);
 
 #ifdef FEAT_XCLIPBOARD
+    if (xterm_dpy == x11_display)
+       // x11_display may have been set to xterm_dpy elsewhere
+       x11_display_from = XD_XTERM;
+
     if (xterm_dpy != NULL && x11_window != 0)
     {
        /* We may have checked it already, but Gnome terminal can move us to
@@ -7661,7 +7684,7 @@ do_xterm_trace(void)
     return TRUE;
 }
 
-# if defined(FEAT_GUI) || defined(PROTO)
+# if defined(FEAT_GUI) || defined(FEAT_XCLIPBOARD) || defined(PROTO)
 /*
  * Destroy the display, window and app_context.  Required for GTK.
  */
index 0117b1ea1e71703f16ca1c7f3962fe76f7d65708..0e7c609f391f93535a148a0c74f19e45a1891141 100644 (file)
@@ -13,6 +13,7 @@ void reset_signals(void);
 int vim_handle_signal(int sig);
 int mch_check_win(int argc, char **argv);
 int mch_input_isatty(void);
+void ex_xrestore(exarg_T *eap);
 int mch_can_restore_title(void);
 int mch_can_restore_icon(void);
 void mch_settitle(char_u *title, char_u *icon);
index f3664f6a6207dd886f5df1f2e8a86487236da53b..29206b94bcd055923b1ccc3ba0eec5f8885a04df 100644 (file)
@@ -110,3 +110,29 @@ func Test_paste_visual_mode()
 
   bwipe!
 endfunc
+
+func CheckCopyPaste()
+  call setline(1, ['copy this', ''])
+  normal 1G0"*y$
+  normal j"*p
+  call assert_equal('copy this', getline(2))
+endfunc
+
+func Test_xrestore()
+  if !has('xterm_clipboard')
+    return
+  endif
+call ch_logfile('logfile', 'w')
+  let display = $DISPLAY
+  new
+  call CheckCopyPaste()
+
+  xrestore
+  call CheckCopyPaste()
+
+  exe "xrestore " .. display
+  call CheckCopyPaste()
+
+call ch_logfile('', '')
+  bwipe!
+endfunc
index 3b9ef3236d72801743dcf1ebcf15a36aabbedcc4..ea04ff99c1aaa44db6c6762d2dd5be8e766013ac 100644 (file)
@@ -767,6 +767,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1307,
 /**/
     1306,
 /**/