From 63d499f480e264f8251552fb6d16965a1065e0e6 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Fri, 18 Sep 2009 15:19:27 +0000 Subject: New option, set-titles-string, to allow the window title to be specified (as for status-left/right) if set-titles is on. Also only update the title when the status line is being redrawn. --- server.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'server.c') diff --git a/server.c b/server.c index 268a79dd..2262b4fe 100644 --- a/server.c +++ b/server.c @@ -66,6 +66,7 @@ void server_clean_dead(void); void server_lost_client(struct client *); void server_check_window(struct window *); void server_check_redraw(struct client *); +void server_set_title(struct client *); void server_redraw_locked(struct client *); void server_check_timers(struct client *); void server_second_timers(void); @@ -516,7 +517,6 @@ server_check_redraw(struct client *c) { struct session *s; struct window_pane *wp; - char title[512]; int flags, redraw; if (c == NULL || c->session == NULL) @@ -526,19 +526,10 @@ server_check_redraw(struct client *c) flags = c->tty.flags & TTY_FREEZE; c->tty.flags &= ~TTY_FREEZE; - if (options_get_number(&s->options, "set-titles")) { - xsnprintf(title, sizeof title, "%s:%u:%s - \"%s\"", - s->name, s->curw->idx, s->curw->window->name, - s->curw->window->active->screen->title); - if (c->title == NULL || strcmp(title, c->title) != 0) { - if (c->title != NULL) - xfree(c->title); - c->title = xstrdup(title); - tty_set_title(&c->tty, c->title); - } - } - if (c->flags & (CLIENT_REDRAW|CLIENT_STATUS)) { + if (options_get_number(&s->options, "set-titles")) + server_set_title(c); + if (c->message_string != NULL) redraw = status_message_redraw(c); else if (c->prompt_string != NULL) @@ -570,6 +561,26 @@ server_check_redraw(struct client *c) c->flags &= ~(CLIENT_REDRAW|CLIENT_STATUS); } +/* Set client title. */ +void +server_set_title(struct client *c) +{ + struct session *s = c->session; + const char *template; + char *title; + + template = options_get_string(&s->options, "set-titles-string"); + + title = status_replace(c->session, template, time(NULL)); + if (c->title == NULL || strcmp(title, c->title) != 0) { + if (c->title != NULL) + xfree(c->title); + c->title = xstrdup(title); + tty_set_title(&c->tty, c->title); + } + xfree(title); +} + /* Redraw client when locked. */ void server_redraw_locked(struct client *c) -- cgit