4 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
28 void window_name_callback(unused
int, unused
short, void *);
31 queue_window_name(struct window
*w
)
36 tv
.tv_usec
= NAME_INTERVAL
* 1000L;
38 if (event_initialized(&w
->name_timer
))
39 evtimer_del(&w
->name_timer
);
40 evtimer_set(&w
->name_timer
, window_name_callback
, w
);
41 evtimer_add(&w
->name_timer
, &tv
);
45 window_name_callback(unused
int fd
, unused
short events
, void *data
)
47 struct window
*w
= data
;
50 if (w
->active
== NULL
)
53 if (!options_get_number(&w
->options
, "automatic-rename")) {
54 if (event_initialized(&w
->name_timer
))
55 event_del(&w
->name_timer
);
60 name
= format_window_name(w
);
61 if (strcmp(name
, w
->name
) != 0) {
62 window_set_name(w
, name
);
63 server_status_window(w
);
69 default_window_name(struct window
*w
)
71 if (w
->active
->cmd
!= NULL
&& *w
->active
->cmd
!= '\0')
72 return (parse_window_name(w
->active
->cmd
));
73 return (parse_window_name(w
->active
->shell
));
77 format_window_name(struct window
*w
)
79 struct format_tree
*ft
;
84 format_window_pane(ft
, w
->active
);
86 fmt
= options_get_string(&w
->options
, "automatic-rename-format");
87 name
= format_expand(ft
, fmt
);
94 parse_window_name(const char *in
)
96 char *copy
, *name
, *ptr
;
98 name
= copy
= xstrdup(in
);
99 if (strncmp(name
, "exec ", (sizeof "exec ") - 1) == 0)
100 name
= name
+ (sizeof "exec ") - 1;
102 while (*name
== ' ' || *name
== '-')
104 if ((ptr
= strchr(name
, ' ')) != NULL
)
108 ptr
= name
+ strlen(name
) - 1;
109 while (ptr
> name
&& !isalnum((u_char
)*ptr
))
114 name
= basename(name
);
115 name
= xstrdup(name
);