summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-08-07 22:31:44 +0200
committerBram Moolenaar <Bram@vim.org>2018-08-07 22:31:44 +0200
commit40385dbcdfb44885f2e9b83e1e0285aeb8a0c2a8 (patch)
tree35de952db98f597df68144ef4ab99a294177861d
parentde3b3677f7eace66be454196db0fbf710cfc8c5e (diff)
patch 8.1.0253: saving and restoring window title does not always workv8.1.0253
Problem: Saving and restoring window title does not always work. Solution: Use the stack push and pop commands. (Kouichi Iwamoto, closes #3059)
-rw-r--r--runtime/doc/term.txt4
-rw-r--r--src/buffer.c3
-rw-r--r--src/ex_docmd.c2
-rw-r--r--src/main.c4
-rw-r--r--src/option.c10
-rw-r--r--src/os_amiga.c10
-rw-r--r--src/os_mswin.c6
-rw-r--r--src/os_unix.c18
-rw-r--r--src/os_win32.c2
-rw-r--r--src/proto/term.pro2
-rw-r--r--src/term.c45
-rw-r--r--src/term.h12
-rw-r--r--src/version.c2
-rw-r--r--src/vim.h12
14 files changed, 110 insertions, 22 deletions
diff --git a/runtime/doc/term.txt b/runtime/doc/term.txt
index 77cd933b42..4ade4a131c 100644
--- a/runtime/doc/term.txt
+++ b/runtime/doc/term.txt
@@ -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.
diff --git a/src/buffer.c b/src/buffer.c
index 64ba5ab0e6..32d1eb4020 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -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
{
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 0539a5114b..294fbdbccc 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -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
diff --git a/src/main.c b/src/main.c
index f67706699c..b8390508d3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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.
*/
diff --git a/src/option.c b/src/option.c
index f86b1b19c3..a7a6ebbd92 100644
--- a/src/option.c
+++ b/src/option.c
@@ -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)
{
diff --git a/src/os_amiga.c b/src/os_amiga.c
index 39fb222fdd..767cbfaf31 100644
--- a/src/os_amiga.c
+++ b/src/os_amiga.c
@@ -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 */
diff --git a/src/os_mswin.c b/src/os_mswin.c
index 5dbfd0ef0c..2112b0c2aa 100644
--- a/src/os_mswin.c
+++ b/src/os_mswin.c
@@ -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)
diff --git a/src/os_unix.c b/src/os_unix.c
index 94c3dc9a2e..4b452b5ceb 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -2336,17 +2336,21 @@ mch_settitle(char_u *title, char_u *icon)
/*
* Restore the window/icon title.
* "which" is one of:
- * 1 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
diff --git a/src/os_win32.c b/src/os_win32.c
index 63572350b2..85c8a57d11 100644
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -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
diff --git a/src/proto/term.pro b/src/proto/term.pro
index 9a9606baf0..1b8ab5f0dd 100644
--- a/src/proto/term.pro
+++ b/src/proto/term.pro
@@ -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);
diff --git a/src/term.c b/src/term.c
index ace467f6df..66f03ee108 100644
--- a/src/term.c
+++ b/src/term.c
@@ -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
/*
diff --git a/src/term.h b/src/term.h
index 8808f7db18..219a2083d2 100644
--- a/src/term.h
+++ b/src/term.h
@@ -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) */
diff --git a/src/version.c b/src/version.c
index 4a4969c435..8b01248209 100644
--- a/src/version.c
+++ b/src/version.c
@@ -795,6 +795,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 253,
+/**/
252,
/**/
251,
diff --git a/src/vim.h b/src/vim.h
index a85d47f5eb..524ed92132 100644
--- 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 */