Do not sanitize title when popping it from stack, also add a limit to

number of pushed titles.
This commit is contained in:
nicm
2026-05-05 13:18:46 +00:00
parent 1fbd00e1e8
commit 518fcf7e03
2 changed files with 16 additions and 3 deletions

View File

@@ -264,6 +264,16 @@ screen_push_title(struct screen *s)
{ {
struct screen_title_entry *title_entry; struct screen_title_entry *title_entry;
log_debug("%s: %u", __func__, s->ntitles);
while (s->ntitles >= 10) {
title_entry = TAILQ_LAST(s->titles, screen_titles);
free(title_entry->text);
TAILQ_REMOVE(s->titles, title_entry, entry);
free(title_entry);
s->ntitles--;
}
if (s->titles == NULL) { if (s->titles == NULL) {
s->titles = xmalloc(sizeof *s->titles); s->titles = xmalloc(sizeof *s->titles);
TAILQ_INIT(s->titles); TAILQ_INIT(s->titles);
@@ -271,6 +281,7 @@ screen_push_title(struct screen *s)
title_entry = xmalloc(sizeof *title_entry); title_entry = xmalloc(sizeof *title_entry);
title_entry->text = xstrdup(s->title); title_entry->text = xstrdup(s->title);
TAILQ_INSERT_HEAD(s->titles, title_entry, entry); TAILQ_INSERT_HEAD(s->titles, title_entry, entry);
s->ntitles++;
} }
/* /*
@@ -284,14 +295,15 @@ screen_pop_title(struct screen *s)
if (s->titles == NULL) if (s->titles == NULL)
return; return;
log_debug("%s: %u", __func__, s->ntitles);
title_entry = TAILQ_FIRST(s->titles); title_entry = TAILQ_FIRST(s->titles);
if (title_entry != NULL) { if (title_entry != NULL) {
screen_set_title(s, title_entry->text); free(s->title);
s->title = title_entry->text;
TAILQ_REMOVE(s->titles, title_entry, entry); TAILQ_REMOVE(s->titles, title_entry, entry);
free(title_entry->text);
free(title_entry); free(title_entry);
s->ntitles--;
} }
} }

1
tmux.h
View File

@@ -979,6 +979,7 @@ struct screen {
char *title; char *title;
char *path; char *path;
struct screen_titles *titles; struct screen_titles *titles;
u_int ntitles;
struct grid *grid; /* grid data */ struct grid *grid; /* grid data */