On Sun, Jan 13, 2008 at 10:40:11PM +0100, Christian Garbs wrote: > On Sat, Jan 12, 2008 at 06:44:32PM +0100, Marc Andre Tanner wrote: > > > dvtm-0.3 is out > > Great! > > Here are some very low priority wishlist items (I can live fine > without them, but they might be interesting): > > * With xtermset -T it is possible to change the title of an xterm. > dwm can read the title and display it in the bar. I use it when I > ssh to another machines. Other programs (links for example) use > this feature as well. > Would it be possible so catch these title-changes and display them > in the client title in dvtm? > I guess it is some kind of escape-sequence that would have to be > handled by madtty, but I really don't know how it works.
Ok, i think the attached patch applied to current master should do the trick. At least xtermset and elinks seem to work. Regards, Marc -- Marc Andre Tanner >< http://www.brain-dump.org/ >< GPG key: CF7D56C0
diff --git a/dvtm.c b/dvtm.c index 6fb9ead..8953193 100644 --- a/dvtm.c +++ b/dvtm.c @@ -37,7 +37,7 @@ struct Client { WINDOW *window; madtty_t *term; const char *cmd; - const char *title; + char title[256]; uint8_t order; pid_t pid; int pty; @@ -429,8 +429,8 @@ draw_border(Client *c){ curs_set(0); getyx(c->window, y, x); mvwprintw(c->window, 0, 2, TITLE, - c->title ? c->title : "", - c->title ? SEPARATOR : "", + *c->title ? c->title : "", + *c->title ? SEPARATOR : "", c->order); wmove(c->window, y, x); curs_set(1); @@ -523,6 +523,22 @@ killclient(const char *args[]){ kill(-sel->pid, SIGKILL); } +int +title_escape_seq_handler(madtty_t *term, char *es){ + Client *c; + unsigned int l; + if(es[0] != ']' || (es[1] && (es[1] < '0' || es[1] > '9')) || (es[2] && es[2] != ';')) + return MADTTY_HANDLER_NOWAY; + if((l = strlen(es)) < 3 || es[l - 1] != '\07') + return MADTTY_HANDLER_NOTYET; + es[l - 1] = '\0'; + c = (Client *)madtty_get_data(term); + strncpy(c->title, es + 3, sizeof(c->title)); + draw_border(c); + debug("window title: %s\n", c->title); + return MADTTY_HANDLER_OK; +} + void create(const char *args[]){ const char *pargs[] = { "/bin/sh", "-c", args[0], NULL }; @@ -530,8 +546,11 @@ create(const char *args[]){ c->window = newwin(wah, waw, way, wax); c->term = madtty_create(height-2, width-2); c->cmd = args[0]; - c->title = args[1]; + if(args[1]) + strncpy(c->title, args[1], sizeof(c->title)); c->pid = madtty_forkpty(c->term, "/bin/sh", pargs, &c->pty); + madtty_set_data(c->term, c); + madtty_set_handler(c->term, title_escape_seq_handler); c->w = width; c->h = height; c->x = wax;