summaryrefslogtreecommitdiffstats
path: root/names.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2009-11-04 23:54:57 +0000
committerNicholas Marriott <nicm@openbsd.org>2009-11-04 23:54:57 +0000
commit44d6a2c435ab68df25ed7b14473e6f69870e8a9a (patch)
treea89bce807ac501ffc4efdc7ef1d63dadde7212c3 /names.c
parent946ed972734f5c95f67e30aff99a58de0179b2d5 (diff)
Change window name change to use a timer event rather than a gettimeofday()
check every loop.
Diffstat (limited to 'names.c')
-rw-r--r--names.c97
1 files changed, 47 insertions, 50 deletions
diff --git a/names.c b/names.c
index fe26938d..d9335ac5 100644
--- a/names.c
+++ b/names.c
@@ -25,67 +25,64 @@
#include "tmux.h"
+void window_name_callback(unused int, unused short, void *);
char *parse_window_name(const char *);
void
-set_window_names(void)
+queue_window_name(struct window *w)
{
- struct window *w;
- u_int i;
- char *name, *wname;
- struct timeval tv, tv2;
+ struct timeval tv;
- if (gettimeofday(&tv, NULL) != 0)
- fatal("gettimeofday failed");
+ tv.tv_sec = 0;
+ tv.tv_usec = NAME_INTERVAL * 1000L;
- for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
- w = ARRAY_ITEM(&windows, i);
- if (w == NULL || w->active == NULL)
- continue;
+ evtimer_del(&w->name_timer);
+ evtimer_set(&w->name_timer, window_name_callback, w);
+ evtimer_add(&w->name_timer, &tv);
+}
- if (timercmp(&tv, &w->name_timer, <))
- continue;
- memcpy(&w->name_timer, &tv, sizeof w->name_timer);
- tv2.tv_sec = 0;
- tv2.tv_usec = NAME_INTERVAL * 1000L;
- timeradd(&w->name_timer, &tv2, &w->name_timer);
+void
+window_name_callback(unused int fd, unused short events, void *data)
+{
+ struct window *w = data;
+ char *name, *wname;
- if (!options_get_number(&w->options, "automatic-rename"))
- continue;
+ queue_window_name(w); /* XXX even if the option is off? */
+ if (!options_get_number(&w->options, "automatic-rename"))
+ return;
- if (w->active->screen != &w->active->base)
- name = NULL;
+ if (w->active->screen != &w->active->base)
+ name = NULL;
+ else
+ name = get_proc_name(w->active->fd, w->active->tty);
+ if (name == NULL)
+ wname = default_window_name(w);
+ else {
+ /*
+ * If tmux is using the default command, it will be a login
+ * shell and argv[0] may have a - prefix. Remove this if it is
+ * present. Ick.
+ */
+ if (w->active->cmd != NULL && *w->active->cmd == '\0' &&
+ name != NULL && name[0] == '-' && name[1] != '\0')
+ wname = parse_window_name(name + 1);
else
- name = get_proc_name(w->active->fd, w->active->tty);
- if (name == NULL)
- wname = default_window_name(w);
- else {
- /*
- * If tmux is using the default command, it will be a
- * login shell and argv[0] may have a - prefix. Remove
- * this if it is present. Ick.
- */
- if (w->active->cmd != NULL && *w->active->cmd == '\0' &&
- name != NULL && name[0] == '-' && name[1] != '\0')
- wname = parse_window_name(name + 1);
- else
wname = parse_window_name(name);
- xfree(name);
- }
-
- if (w->active->fd == -1) {
- xasprintf(&name, "%s[dead]", wname);
- xfree(wname);
- wname = name;
- }
-
- if (strcmp(wname, w->name) == 0)
- xfree(wname);
- else {
- xfree(w->name);
- w->name = wname;
- server_status_window(w);
- }
+ xfree(name);
+ }
+
+ if (w->active->fd == -1) {
+ xasprintf(&name, "%s[dead]", wname);
+ xfree(wname);
+ wname = name;
+ }
+
+ if (strcmp(wname, w->name) == 0)
+ xfree(wname);
+ else {
+ xfree(w->name);
+ w->name = wname;
+ server_status_window(w);
}
}