]> granicus.if.org Git - vim/commitdiff
patch 8.1.0253: saving and restoring window title does not always work v8.1.0253
authorBram Moolenaar <Bram@vim.org>
Tue, 7 Aug 2018 20:31:44 +0000 (22:31 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 7 Aug 2018 20:31:44 +0000 (22:31 +0200)
Problem:    Saving and restoring window title does not always work.
Solution:   Use the stack push and pop commands. (Kouichi Iwamoto,
            closes #3059)

14 files changed:
runtime/doc/term.txt
src/buffer.c
src/ex_docmd.c
src/main.c
src/option.c
src/os_amiga.c
src/os_mswin.c
src/os_unix.c
src/os_win32.c
src/proto/term.pro
src/term.c
src/term.h
src/version.c
src/vim.h

index 77cd933b42566f607811a31cb16b64671f345120..4ade4a131cff7f3a9db6c3af03012a6ad2d3127a 100644 (file)
@@ -352,6 +352,10 @@ Added by Vim (there are no standard codes for these):
        t_SH    set cursor shape                                *t_SH* *'t_SH'*
        t_RC    request terminal cursor blinking                *t_RC* *'t_RC'*
        t_RS    request terminal cursor style                   *t_RS* *'t_RS'*
+       t_ST    save window title to stack                      *t_ST* *'t_ST'*
+       t_RT    restore window title from stack                 *t_RT* *'t_RT'*
+       t_Si    save icon text to stack                         *t_Si* *'t_Si'*
+       t_Ri    restore icon text from stack                    *t_Ri* *'t_Ri'*
 
 Some codes have a start, middle and end part.  The start and end are defined
 by the termcap option, the middle part is text.
index 64ba5ab0e6bbf8c02186860fab0b58e8b638d70b..32d1eb402054e5517a007d3e9ea76fa09668145c 100644 (file)
@@ -3798,7 +3798,8 @@ value_changed(char_u *str, char_u **last)
        if (str == NULL)
        {
            *last = NULL;
-           mch_restore_title(last == &lasttitle ? 1 : 2);
+           mch_restore_title(
+                 last == &lasttitle ? SAVE_RESTORE_TITLE : SAVE_RESTORE_ICON);
        }
        else
        {
index 0539a5114b98ec077ee606da4c2b1e341ef9e0ca..294fbdbccc7689b25f6d4bb6c309156c71fb9b08 100644 (file)
@@ -7750,7 +7750,7 @@ ex_stop(exarg_T *eap)
        stoptermcap();
        out_flush();            /* needed for SUN to restore xterm buffer */
 #ifdef FEAT_TITLE
-       mch_restore_title(3);   /* restore window titles */
+       mch_restore_title(SAVE_RESTORE_BOTH);   /* restore window titles */
 #endif
        ui_suspend();           /* call machine specific function */
 #ifdef FEAT_TITLE
index f67706699c64baaa677ccba2b01c9449fe5d7c77..b8390508d32d10990d2a30f5b7f738f7b495899e 100644 (file)
@@ -706,6 +706,10 @@ vim_main2(void)
        scroll_region_reset();          /* In case Rows changed */
     scroll_start();    /* may scroll the screen to the right position */
 
+#ifdef FEAT_TITLE
+    term_push_title(SAVE_RESTORE_BOTH);
+#endif
+
     /*
      * Don't clear the screen when starting in Ex mode, unless using the GUI.
      */
index f86b1b19c3362ce425e6140565b97eb79038dfe8..a7a6ebbd9234ce96b670ab9fcadf00088f72746d 100644 (file)
@@ -3192,7 +3192,9 @@ static struct vimoption options[] =
     p_term("t_RB", T_RBG)
     p_term("t_RC", T_CRC)
     p_term("t_RI", T_CRI)
+    p_term("t_Ri", T_SRI)
     p_term("t_RS", T_CRS)
+    p_term("t_RT", T_CRT)
     p_term("t_RV", T_CRV)
     p_term("t_Sb", T_CSB)
     p_term("t_SC", T_CSC)
@@ -3200,9 +3202,11 @@ static struct vimoption options[] =
     p_term("t_Sf", T_CSF)
     p_term("t_SH", T_CSH)
     p_term("t_SI", T_CSI)
+    p_term("t_Si", T_SSI)
     p_term("t_so", T_SO)
     p_term("t_SR", T_CSR)
     p_term("t_sr", T_SR)
+    p_term("t_ST", T_CST)
     p_term("t_Te", T_STE)
     p_term("t_te", T_TE)
     p_term("t_ti", T_TI)
@@ -10414,7 +10418,7 @@ clear_termoptions(void)
     mch_setmouse(FALSE);           /* switch mouse off */
 #endif
 #ifdef FEAT_TITLE
-    mch_restore_title(3);          /* restore window titles */
+    mch_restore_title(SAVE_RESTORE_BOTH);    /* restore window titles */
 #endif
 #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
     /* When starting the GUI close the display opened for the clipboard.
@@ -11219,8 +11223,8 @@ buf_copy_options(buf_T *buf, int flags)
                buf->b_p_isk = NULL;
            }
            /*
-            * Always free the allocated strings.
-            * If not already initialized, set 'readonly' and copy 'fileformat'.
+            * Always free the allocated strings.  If not already initialized,
+            * reset 'readonly' and copy 'fileformat'.
             */
            if (!buf->b_p_initialized)
            {
index 39fb222fdd8fd560d92e6d07e05392ab625bf6a0..767cbfaf31efdff8358058db3c54298fd2ccbfb3 100644 (file)
@@ -617,14 +617,14 @@ mch_settitle(char_u *title, char_u *icon)
 /*
  * Restore the window/icon title.
  * which is one of:
- *  1  Just restore title
- *  2  Just restore icon (which we don't have)
- *  3  Restore title and icon (which we don't have)
+ *  SAVE_RESTORE_TITLE  Just restore title
+ *  SAVE_RESTORE_ICON   Just restore icon (which we don't have)
+ *  SAVE_RESTORE_BOTH   Restore title and icon (which we don't have)
  */
     void
 mch_restore_title(int which)
 {
-    if (which & 1)
+    if (which & SAVE_RESTORE_TITLE)
        mch_settitle(oldwindowtitle, NULL);
 }
 
@@ -907,7 +907,7 @@ mch_exit(int r)
     }
 
 #ifdef FEAT_TITLE
-    mch_restore_title(3);          /* restore window title */
+    mch_restore_title(SAVE_RESTORE_BOTH);    /* restore window title */
 #endif
 
     ml_close_all(TRUE);                    /* remove all memfiles */
index 5dbfd0ef0cf79c6133c95e9f7c63980d3d5441a8..2112b0c2aa7ab19021ff80b0fdd44c25dc5b5404 100644 (file)
@@ -304,9 +304,9 @@ mch_settitle(
 /*
  * Restore the window/icon title.
  * which is one of:
- *  1: Just restore title
- *  2: Just restore icon (which we don't have)
- *  3: Restore title and icon (which we don't have)
+ *  SAVE_RESTORE_TITLE: Just restore title
+ *  SAVE_RESTORE_ICON:  Just restore icon (which we don't have)
+ *  SAVE_RESTORE_BOTH:  Restore title and icon (which we don't have)
  */
     void
 mch_restore_title(int which UNUSED)
index 94c3dc9a2ee2b6aac8047f29a28f39d336b6f35e..4b452b5ceb73ccbad99a4ca1b17e86275786999c 100644 (file)
@@ -2336,17 +2336,21 @@ mch_settitle(char_u *title, char_u *icon)
 /*
  * Restore the window/icon title.
  * "which" is one of:
- *   only restore title
- *  2  only restore icon
- *  3  restore title and icon
+ *  SAVE_RESTORE_TITLE only restore title
+ *  SAVE_RESTORE_ICON  only restore icon
+ *  SAVE_RESTORE_BOTH  restore title and icon
  */
     void
 mch_restore_title(int which)
 {
     /* only restore the title or icon when it has been set */
-    mch_settitle(((which & 1) && did_set_title) ?
+    mch_settitle(((which & SAVE_RESTORE_TITLE) && did_set_title) ?
                        (oldtitle ? oldtitle : p_titleold) : NULL,
-                             ((which & 2) && did_set_icon) ? oldicon : NULL);
+              ((which & SAVE_RESTORE_ICON) && did_set_icon) ? oldicon : NULL);
+
+    // pop and push from/to the stack
+    term_pop_title(which);
+    term_push_title(which);
 }
 
 #endif /* FEAT_TITLE */
@@ -3412,7 +3416,9 @@ mch_exit(int r)
     {
        settmode(TMODE_COOK);
 #ifdef FEAT_TITLE
-       mch_restore_title(3);   /* restore xterm title and icon name */
+       // restore xterm title and icon name
+       mch_restore_title(SAVE_RESTORE_BOTH);
+       term_pop_title(SAVE_RESTORE_BOTH);
 #endif
        /*
         * When t_ti is not empty but it doesn't cause swapping terminal
index 63572350b2877e65a822737433787bb819e582cb..85c8a57d11d1c8dd1ff2626742521c1c8b6bf8ea 100644 (file)
@@ -2695,7 +2695,7 @@ mch_exit(int r)
     if (g_fWindInitCalled)
     {
 #ifdef FEAT_TITLE
-       mch_restore_title(3);
+       mch_restore_title(SAVE_RESTORE_BOTH);
        /*
         * Restore both the small and big icons of the console window to
         * what they were at startup.  Don't do this when the window is
index 9a9606baf0b105d8b48ae9121dabf0f670cf1074..1b8ab5f0dd833f9a6852761224491cbacd1c0841 100644 (file)
@@ -31,6 +31,8 @@ void term_bg_color(int n);
 void term_fg_rgb_color(guicolor_T rgb);
 void term_bg_rgb_color(guicolor_T rgb);
 void term_settitle(char_u *title);
+void term_push_title(int which);
+void term_pop_title(int which);
 void ttest(int pairs);
 void add_long_to_buf(long_u val, char_u *dst);
 void check_shellsize(void);
index ace467f6df51f21c23f88615e557c29b3b6ea5b2..66f03ee1082a2fdd0c986a8ab90208f45cf7cdbd 100644 (file)
@@ -922,6 +922,10 @@ static struct builtin_term builtin_termcaps[] =
 #  endif
     {(int)KS_CBE,      IF_EB("\033[?2004h", ESC_STR "[?2004h")},
     {(int)KS_CBD,      IF_EB("\033[?2004l", ESC_STR "[?2004l")},
+    {(int)KS_CST,      IF_EB("\033[22;2t", ESC_STR "[22;2t")},
+    {(int)KS_CRT,      IF_EB("\033[23;2t", ESC_STR "[23;2t")},
+    {(int)KS_SSI,      IF_EB("\033[22;1t", ESC_STR "[22;1t")},
+    {(int)KS_SRI,      IF_EB("\033[23;1t", ESC_STR "[23;1t")},
 
     {K_UP,             IF_EB("\033O*A", ESC_STR "O*A")},
     {K_DOWN,           IF_EB("\033O*B", ESC_STR "O*B")},
@@ -1600,6 +1604,8 @@ get_term_entries(int *height, int *width)
                        {KS_8F, "8f"}, {KS_8B, "8b"},
                        {KS_CBE, "BE"}, {KS_CBD, "BD"},
                        {KS_CPS, "PS"}, {KS_CPE, "PE"},
+                       {KS_CST, "ST"}, {KS_CRT, "RT"},
+                       {KS_SSI, "Si"}, {KS_SRI, "Ri"},
                        {(enum SpecialKey)0, NULL}
                    };
     int                    i;
@@ -2974,6 +2980,45 @@ term_settitle(char_u *title)
     out_str(T_FS);                     /* set title end */
     out_flush();
 }
+
+/*
+ * Tell the terminal to push (save) the title and/or icon, so that it can be
+ * popped (restored) later.
+ */
+    void
+term_push_title(int which)
+{
+    if ((which & SAVE_RESTORE_TITLE) && *T_CST != NUL)
+    {
+       OUT_STR(T_CST);
+       out_flush();
+    }
+
+    if ((which & SAVE_RESTORE_ICON) && *T_SSI != NUL)
+    {
+       OUT_STR(T_SSI);
+       out_flush();
+    }
+}
+
+/*
+ * Tell the terminal to pop the title and/or icon.
+ */
+    void
+term_pop_title(int which)
+{
+    if ((which & SAVE_RESTORE_TITLE) && *T_CRT != NUL)
+    {
+       OUT_STR(T_CRT);
+       out_flush();
+    }
+
+    if ((which & SAVE_RESTORE_ICON) && *T_SRI != NUL)
+    {
+       OUT_STR(T_SRI);
+       out_flush();
+    }
+}
 #endif
 
 /*
index 8808f7db18e5ca907995b28894ada9624639d9a1..219a2083d2e0d643b767919d0e3e64234ff80ea4 100644 (file)
@@ -101,10 +101,14 @@ enum SpecialKey
     KS_CBE,    /* enable bracketed paste mode */
     KS_CBD,    /* disable bracketed paste mode */
     KS_CPS,    /* start of bracketed paste */
-    KS_CPE     /* end of bracketed paste */
+    KS_CPE,    /* end of bracketed paste */
+    KS_CST,    /* save window title */
+    KS_CRT,    /* restore window title */
+    KS_SSI,    /* save icon text */
+    KS_SRI     /* restore icon text */
 };
 
-#define KS_LAST            KS_CPE
+#define KS_LAST            KS_SRI
 
 /*
  * the terminal capabilities are stored in this array
@@ -196,6 +200,10 @@ extern char_u *(term_strings[]);    /* current terminal strings */
 #define T_BD   (TERM_STR(KS_CBD))      /* disable bracketed paste mode */
 #define T_PS   (TERM_STR(KS_CPS))      /* start of bracketed paste */
 #define T_PE   (TERM_STR(KS_CPE))      /* end of bracketed paste */
+#define T_CST  (TERM_STR(KS_CST))      /* save window title */
+#define T_CRT  (TERM_STR(KS_CRT))      /* restore window title */
+#define T_SSI  (TERM_STR(KS_SSI))      /* save icon text */
+#define T_SRI  (TERM_STR(KS_SRI))      /* restore icon text */
 
 #define TMODE_COOK  0  /* terminal mode for external cmds and Ex mode */
 #define TMODE_SLEEP 1  /* terminal mode for sleeping (cooked but no echo) */
index 4a4969c435155844b1bb6053c6578f547013e080..8b01248209ee9db80f13354813f0b3f5ca7f8830 100644 (file)
@@ -794,6 +794,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    253,
 /**/
     252,
 /**/
index a85d47f5eb380028664319c60c9af51e23d853e5..524ed921325e2fae83450de427b58e83a3aa6708 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -2548,4 +2548,16 @@ typedef enum {
 #define TERM_START_FORCEIT     2
 #define TERM_START_SYSTEM      4
 
+#if defined(HAVE_DROP_FILE) \
+       || (defined(FEAT_GUI_GTK) && defined(FEAT_DND)) \
+       || defined(FEAT_GUI_MSWIN) \
+       || defined(FEAT_GUI_MAC)
+# define HAVE_HANDLE_DROP
+#endif
+
+// Used for icon/title save and restore.
+#define SAVE_RESTORE_TITLE     1
+#define SAVE_RESTORE_ICON      2
+#define SAVE_RESTORE_BOTH      (SAVE_RESTORE_TITLE | SAVE_RESTORE_ICON)
+
 #endif /* VIM__H */