From 8873c79cbcaf799ca4b371faf24564664aedc850 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Wed, 18 Jun 2008 18:52:44 +0000 Subject: [PATCH] Set window title to current session. New options set-titles to disable. --- CHANGES | 11 ++++++++++- TODO | 6 +----- cmd-set-option.c | 10 +++++++++- screen-write.c | 5 +---- server.c | 24 ++++++++++++++++++++---- tmux.c | 3 ++- tmux.h | 10 ++++++---- tty.c | 12 +++++++++--- 8 files changed, 58 insertions(+), 23 deletions(-) diff --git a/CHANGES b/CHANGES index 371a6e52..eed8d746 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,14 @@ 18 June 2008 +* New option, set-titles. On by default, this attempts to set the window title + using the \e]2;...\007 xterm code. + + Note that elinks requires the STY environment variable (used by screen) to be + set before it will set the window title. So, if you want window titles set by + elinks, set STY before running it (any value will do). I can't do this for all + windows since setting it to an invalid value breaks screen. Why they couldn't + just look for TERM=screen (or send it regardless if the user turned it on) is + beyond me. * Show arrows at either end of status line when scrolled if more windows exist. Highlight the arrow if a hidden window has activity or bell. * Scroll the status line to show the current window if necessary. Also handle @@ -494,4 +503,4 @@ (including mutt, emacs). No status bar yet and no key remapping or other customisation. -$Id: CHANGES,v 1.124 2008-06-18 17:14:02 nicm Exp $ +$Id: CHANGES,v 1.125 2008-06-18 18:52:44 nicm Exp $ diff --git a/TODO b/TODO index 631f151c..55e52fd1 100644 --- a/TODO +++ b/TODO @@ -63,12 +63,9 @@ - cfg file improvements - proper per-window options (per-session list of window ranges?) - better mode features: search, back word, forward word, etc -- status bar customisation variables, show-activity, show-last-window - figure out Linux tcsetattr problem, remove header bodge if unnecessary - flags to centre screen in window - get rid of DEFDATA etc -- scroll status line to show current window. mark beginning end with "<-"/"->" - and highlight this if any off-screen are active --- support window title commands properly: @@ -87,6 +84,5 @@ option to pass through to xterm window when switching window should not emulate it doing so - activity/bell should be per-window not per-link? what if it is cur win in session not being watched? -- document status-left/status-right/status-interval +- document status-left/status-right/status-interval/set-titles - enhance paste buffers. per-session buffers, lots of command love - diff --git a/cmd-set-option.c b/cmd-set-option.c index 244f1476..f9242ae4 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $Id: cmd-set-option.c,v 1.28 2008-06-16 06:33:50 nicm Exp $ */ +/* $Id: cmd-set-option.c,v 1.29 2008-06-18 18:52:44 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -272,6 +272,14 @@ cmd_set_option_exec(struct cmd *self, unused struct cmd_ctx *ctx) return; } options_set_number(oo, "status-interval", number); + } else if (strcmp(data->option, "set-titles") == 0) { + if (bool == -1) { + ctx->error(ctx, "bad value: %s", data->value); + return; + } + if (bool == -2) + bool = !options_get_number(oo, "set-titles"); + options_set_number(oo, "set-titles", bool); } else { ctx->error(ctx, "unknown option: %s", data->option); return; diff --git a/screen-write.c b/screen-write.c index f0696e02..52d03622 100644 --- a/screen-write.c +++ b/screen-write.c @@ -1,4 +1,4 @@ -/* $Id: screen-write.c,v 1.7 2008-06-04 19:20:09 nicm Exp $ */ +/* $Id: screen-write.c,v 1.8 2008-06-18 18:52:44 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -92,9 +92,6 @@ screen_write_set_title(struct screen_write_ctx *ctx, char *title) xfree(s->title); s->title = title; - - if (ctx->write != NULL) - ctx->write(ctx->data, TTY_TITLE, s->title); } /* Put a character. */ diff --git a/server.c b/server.c index c96c2bf5..ebbe578f 100644 --- a/server.c +++ b/server.c @@ -1,4 +1,4 @@ -/* $Id: server.c,v 1.65 2008-06-17 19:26:19 nicm Exp $ */ +/* $Id: server.c,v 1.66 2008-06-18 18:52:44 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -300,18 +300,33 @@ server_handle_windows(struct pollfd **pfd) void server_check_redraw(struct client *c) { + struct session *s; struct screen_redraw_ctx ctx; struct screen screen; u_int xx, yy, sx, sy; + char title[BUFSIZ]; if (c == NULL || c->session == NULL) return; + s = c->session; + + 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->base.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); + } + } xx = c->sx; - yy = c->sy - options_get_number(&global_options, "status-lines"); + yy = c->sy - options_get_number(&s->options, "status-lines"); if (c->flags & CLIENT_REDRAW) { - sx = screen_size_x(c->session->curw->window->screen); - sy = screen_size_y(c->session->curw->window->screen); + sx = screen_size_x(s->curw->window->screen); + sy = screen_size_y(s->curw->window->screen); if (sx < xx || sy < yy) { /* * Fake up a blank(ish) screen and use it to draw the @@ -463,6 +478,7 @@ server_accept_client(int srv_fd) c->out = buffer_create(BUFSIZ); c->tty.fd = -1; + c->title = NULL; c->session = NULL; c->sx = 80; diff --git a/tmux.c b/tmux.c index 0621a020..9cf028f3 100644 --- a/tmux.c +++ b/tmux.c @@ -1,4 +1,4 @@ -/* $Id: tmux.c,v 1.57 2008-06-18 16:39:15 nicm Exp $ */ +/* $Id: tmux.c,v 1.58 2008-06-18 18:52:44 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -212,6 +212,7 @@ main(int argc, char **argv) options_set_string( &global_options, "status-right", "%%H:%%M %%d-%%b-%%y"); options_set_number(&global_options, "status-interval", 15); + options_set_number(&global_options, "set-titles", 1); paste_buffer = NULL; diff --git a/tmux.h b/tmux.h index f6c02e05..c0057020 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.144 2008-06-16 17:35:40 nicm Exp $ */ +/* $Id: tmux.h,v 1.145 2008-06-18 18:52:44 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -295,9 +295,8 @@ struct buffer { #define TTY_KCURSORON 21 #define TTY_KKEYPADOFF 22 #define TTY_KKEYPADON 23 -#define TTY_TITLE 24 -#define TTY_MOUSEON 25 -#define TTY_MOUSEOFF 26 /* XXX merge allon/off into 1 arg? */ +#define TTY_MOUSEON 24 +#define TTY_MOUSEOFF 25 /* XXX merge allon/off into 1 arg? */ /* Message codes. */ enum hdrtype { @@ -647,6 +646,8 @@ struct client { struct buffer *in; struct buffer *out; + char *title; + struct tty tty; struct timespec status_ts; @@ -786,6 +787,7 @@ u_char options_get_colours(struct options *, const char *); /* tty.c */ void tty_init(struct tty *, char *, char *); +void tty_set_title(struct tty *, const char *); int tty_open(struct tty *, char **); void tty_close(struct tty *); void tty_free(struct tty *); diff --git a/tty.c b/tty.c index 944ad8fa..89df5f33 100644 --- a/tty.c +++ b/tty.c @@ -1,4 +1,4 @@ -/* $Id: tty.c,v 1.23 2008-06-10 18:51:22 nicm Exp $ */ +/* $Id: tty.c,v 1.24 2008-06-18 18:52:44 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -342,6 +342,14 @@ tty_putc(struct tty *tty, char ch) buffer_write8(tty->out, ch); } +void +tty_set_title(struct tty *tty, const char *title) +{ + tty_puts(tty, "\e]0;"); + tty_puts(tty, title); + tty_putc(tty, '\007'); +} + void tty_vwrite(struct tty *tty, struct screen *s, int cmd, va_list ap) { @@ -544,8 +552,6 @@ tty_vwrite(struct tty *tty, struct screen *s, int cmd, va_list ap) if (key_mouse != NULL) tty_puts(tty, "\e[?1000h"); break; - case TTY_TITLE: - break; case TTY_ATTRIBUTES: ua = va_arg(ap, u_int); ub = va_arg(ap, u_int);