I noticed in gnome-terminal that window title redrawing behaved in
unpredictable ways. I determined that the functions did_set_title() and
maketitle() were unstable and needed some minor refactoring.
To reproduce:
vim --clean
:set title
:set notitle title
:redraw
Notice that 'titleold' is displayed rather than the normal window title. This
is not expected. The above is a corner case. An example from normal Vim use
is as follows:
vim --clean
:set title
:set titlestring=My\ Title
:options
:redraw
Notice 'titleold' is now seen instead of "My Title". This is because the
"optwin.vim" script toggles the 'title' setting internally.
Note also that even :redraw fails work in both cases!
There are two problems here:
1. maketitle() uses a static var, "lasttitle", to keep track of the most
recently set title string. When ":set notitle" is run, "lasttitle" is not
updated. This means that the next call to maketitle() will see no change
in the title string and will possibly not update the titlestring. This is
why ":set notitle title" breaks.
2. did_set_title() doesn't respect 'lazyredraw'. Whenever notitle or noicon
is set, the title is updated immediately.
Both of the above problems are fixed in this patch by moving title setting
checks into maketitle() where they belong. This lets us update the "lasttitle"
variable, and it lets us obey the 'lazyredraw' setting by using the logic
already in maketitle().
I would include a test, but I don't see a good way to grab the current title
being displayed.
Thanks,
Jason Franklin
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
>From 34edfb3893dbc7f499af3328952370106e751223 Mon Sep 17 00:00:00 2001
From: Jason Franklin <[email protected]>
Date: Sat, 16 Jun 2018 12:34:25 -0400
Subject: [PATCH] Improve the logic for redrawing the window title
---
src/buffer.c | 20 +++++++++++++++++++-
src/option.c | 44 +++++++++++---------------------------------
2 files changed, 30 insertions(+), 34 deletions(-)
diff --git a/src/buffer.c b/src/buffer.c
index 68b4a04..dfa299a 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -3565,17 +3565,35 @@ maketitle(void)
char_u buf[IOSIZE];
int off;
+ /* Postpone this operation when 'lazyredraw' is set. */
if (!redrawing())
{
- /* Postpone updating the title when 'lazyredraw' is set. */
need_maketitle = TRUE;
return;
}
need_maketitle = FALSE;
+
+ /* This is for efficiency. Return if no work needs to be done. */
if (!p_title && !p_icon && lasttitle == NULL && lasticon == NULL)
return;
+ /* Restore defaults whenever 'notitle' or 'noicon' has been set. */
+ if (!p_title)
+ {
+ lasttitle = NULL;
+ mch_restore_title(1);
+ }
+ if (!p_icon)
+ {
+ lasticon = NULL;
+ mch_restore_title(2);
+ }
+
+ /* Defaults have been restored. Return immediately. */
+ if (!p_title && !p_icon)
+ return;
+
if (p_title)
{
if (p_titlelen > 0)
diff --git a/src/option.c b/src/option.c
index 0200b20..dd03da3 100644
--- a/src/option.c
+++ b/src/option.c
@@ -3257,7 +3257,7 @@ static char_u *illegal_char(char_u *, int);
static char_u *check_cedit(void);
#endif
#ifdef FEAT_TITLE
-static void did_set_title(int icon);
+static void did_set_title(void);
#endif
static char_u *option_expand(int opt_idx, char_u *val);
static void didset_options(void);
@@ -5368,33 +5368,17 @@ check_cedit(void)
#ifdef FEAT_TITLE
/*
- * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
- * maketitle() to create and display it.
- * When switching the title or icon off, call mch_restore_title() to get
- * the old value back.
+ * When setting 'title', 'titlestring', 'icon', or 'iconstring', call
+ * maketitle() to build and display the window title.
*/
static void
-did_set_title(
- int icon) /* Did set icon instead of title */
+did_set_title(void)
{
- if (starting != NO_SCREEN
+ if (starting != NO_SCREEN)
#ifdef FEAT_GUI
- && !gui.starting
+ if (!gui.starting)
#endif
- )
- {
- maketitle();
- if (icon)
- {
- if (!p_icon)
- mch_restore_title(2);
- }
- else
- {
- if (!p_title)
- mch_restore_title(1);
- }
- }
+ maketitle();
}
#endif
@@ -6949,8 +6933,7 @@ did_set_string_option(
else
stl_syntax &= ~flagval;
# endif
- did_set_title(varp == &p_iconstring);
-
+ did_set_title();
}
#endif
@@ -8400,15 +8383,10 @@ set_bool_option(
#endif
#ifdef FEAT_TITLE
- /* when 'title' changed, may need to change the title; same for 'icon' */
- else if ((int *)varp == &p_title)
- {
- did_set_title(FALSE);
- }
-
- else if ((int *)varp == &p_icon)
+ /* 'title' and 'icon' */
+ else if ((int *)varp == &p_title || (int *)varp == &p_icon)
{
- did_set_title(TRUE);
+ did_set_title();
}
#endif
--
2.7.4