mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 09:26:05 +00:00 
			
		
		
		
	Change window name change to use a timer event rather than a gettimeofday()
check every loop.
This commit is contained in:
		
							
								
								
									
										101
									
								
								names.c
									
									
									
									
									
								
							
							
						
						
									
										101
									
								
								names.c
									
									
									
									
									
								
							@@ -25,67 +25,64 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "tmux.h"
 | 
					#include "tmux.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void	 window_name_callback(unused int, unused short, void *);
 | 
				
			||||||
char	*parse_window_name(const char *);
 | 
					char	*parse_window_name(const char *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
set_window_names(void)
 | 
					queue_window_name(struct window *w)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct window	*w;
 | 
						struct timeval	tv;
 | 
				
			||||||
	u_int		 i;
 | 
					
 | 
				
			||||||
 | 
						tv.tv_sec = 0;
 | 
				
			||||||
 | 
						tv.tv_usec = NAME_INTERVAL * 1000L;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						evtimer_del(&w->name_timer);
 | 
				
			||||||
 | 
						evtimer_set(&w->name_timer, window_name_callback, w);
 | 
				
			||||||
 | 
						evtimer_add(&w->name_timer, &tv);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					window_name_callback(unused int fd, unused short events, void *data)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct window	*w = data;
 | 
				
			||||||
	char		*name, *wname;
 | 
						char		*name, *wname;
 | 
				
			||||||
	struct timeval	 tv, tv2;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (gettimeofday(&tv, NULL) != 0)
 | 
						queue_window_name(w);	/* XXX even if the option is off? */
 | 
				
			||||||
		fatal("gettimeofday failed");
 | 
						if (!options_get_number(&w->options, "automatic-rename"))
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
 | 
						if (w->active->screen != &w->active->base)
 | 
				
			||||||
		w = ARRAY_ITEM(&windows, i);
 | 
							name = NULL;
 | 
				
			||||||
		if (w == NULL || w->active == NULL)
 | 
						else
 | 
				
			||||||
			continue;
 | 
							name = get_proc_name(w->active->fd, w->active->tty);
 | 
				
			||||||
 | 
						if (name == NULL)
 | 
				
			||||||
		if (timercmp(&tv, &w->name_timer, <))
 | 
							wname = default_window_name(w);
 | 
				
			||||||
			continue;
 | 
						else {
 | 
				
			||||||
		memcpy(&w->name_timer, &tv, sizeof w->name_timer);
 | 
							/* 
 | 
				
			||||||
		tv2.tv_sec = 0;
 | 
							 * If tmux is using the default command, it will be a login
 | 
				
			||||||
		tv2.tv_usec = NAME_INTERVAL * 1000L;
 | 
							 * shell and argv[0] may have a - prefix. Remove this if it is
 | 
				
			||||||
		timeradd(&w->name_timer, &tv2, &w->name_timer);
 | 
							 * present. Ick.
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
		if (!options_get_number(&w->options, "automatic-rename"))
 | 
							if (w->active->cmd != NULL && *w->active->cmd == '\0' &&
 | 
				
			||||||
			continue;
 | 
							    name != NULL && name[0] == '-' && name[1] != '\0')
 | 
				
			||||||
 | 
								wname = parse_window_name(name + 1);
 | 
				
			||||||
		if (w->active->screen != &w->active->base)
 | 
					 | 
				
			||||||
			name = NULL;
 | 
					 | 
				
			||||||
		else
 | 
							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);
 | 
									wname = parse_window_name(name);
 | 
				
			||||||
			xfree(name);
 | 
							xfree(name);
 | 
				
			||||||
		}
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
		if (w->active->fd == -1) {
 | 
						if (w->active->fd == -1) {
 | 
				
			||||||
			xasprintf(&name, "%s[dead]", wname);
 | 
							xasprintf(&name, "%s[dead]", wname);
 | 
				
			||||||
			xfree(wname);
 | 
							xfree(wname);
 | 
				
			||||||
			wname = name;
 | 
							wname = name;
 | 
				
			||||||
		}
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
		if (strcmp(wname, w->name) == 0)
 | 
						if (strcmp(wname, w->name) == 0)
 | 
				
			||||||
			xfree(wname);
 | 
							xfree(wname);
 | 
				
			||||||
		else {
 | 
						else {
 | 
				
			||||||
			xfree(w->name);
 | 
							xfree(w->name);
 | 
				
			||||||
			w->name = wname;
 | 
							w->name = wname;
 | 
				
			||||||
			server_status_window(w);
 | 
							server_status_window(w);
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -91,8 +91,6 @@ server_window_loop(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		server_window_check_alive(w);
 | 
							server_window_check_alive(w);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	set_window_names();
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Check for bell in window. */
 | 
					/* Check for bell in window. */
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										4
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								tmux.h
									
									
									
									
									
								
							@@ -810,7 +810,7 @@ TAILQ_HEAD(window_panes, window_pane);
 | 
				
			|||||||
/* Window structure. */
 | 
					/* Window structure. */
 | 
				
			||||||
struct window {
 | 
					struct window {
 | 
				
			||||||
	char		*name;
 | 
						char		*name;
 | 
				
			||||||
	struct timeval	 name_timer;
 | 
						struct event	 name_timer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct window_pane *active;
 | 
						struct window_pane *active;
 | 
				
			||||||
	struct window_panes panes;
 | 
						struct window_panes panes;
 | 
				
			||||||
@@ -1851,7 +1851,7 @@ void		 window_choose_ready(struct window_pane *,
 | 
				
			|||||||
		     u_int, void (*)(void *, int), void (*)(void *), void *);
 | 
							     u_int, void (*)(void *, int), void (*)(void *), void *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* names.c */
 | 
					/* names.c */
 | 
				
			||||||
void		 set_window_names(void);
 | 
					void		 queue_window_name(struct window *);
 | 
				
			||||||
char 		*default_window_name(struct window *);
 | 
					char 		*default_window_name(struct window *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* session.c */
 | 
					/* session.c */
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										13
									
								
								window.c
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								window.c
									
									
									
									
									
								
							@@ -212,7 +212,7 @@ window_create1(u_int sx, u_int sy)
 | 
				
			|||||||
	struct window	*w;
 | 
						struct window	*w;
 | 
				
			||||||
	u_int		 i;
 | 
						u_int		 i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	w = xmalloc(sizeof *w);
 | 
						w = xcalloc(1, sizeof *w);
 | 
				
			||||||
	w->name = NULL;
 | 
						w->name = NULL;
 | 
				
			||||||
	w->flags = 0;
 | 
						w->flags = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -225,6 +225,8 @@ window_create1(u_int sx, u_int sy)
 | 
				
			|||||||
	w->sx = sx;
 | 
						w->sx = sx;
 | 
				
			||||||
	w->sy = sy;
 | 
						w->sy = sy;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						queue_window_name(w);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	options_init(&w->options, &global_w_options);
 | 
						options_init(&w->options, &global_w_options);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
 | 
						for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
 | 
				
			||||||
@@ -278,6 +280,8 @@ window_destroy(struct window *w)
 | 
				
			|||||||
	if (w->layout_root != NULL)
 | 
						if (w->layout_root != NULL)
 | 
				
			||||||
		layout_free(w);
 | 
							layout_free(w);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						evtimer_del(&w->name_timer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	options_free(&w->options);
 | 
						options_free(&w->options);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	window_destroy_panes(w);
 | 
						window_destroy_panes(w);
 | 
				
			||||||
@@ -480,7 +484,6 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
 | 
				
			|||||||
	ARRAY_DECL(, char *)	 varlist;
 | 
						ARRAY_DECL(, char *)	 varlist;
 | 
				
			||||||
	struct environ_entry	*envent;
 | 
						struct environ_entry	*envent;
 | 
				
			||||||
	const char		*ptr;
 | 
						const char		*ptr;
 | 
				
			||||||
	struct timeval	 	 tv;
 | 
					 | 
				
			||||||
	struct termios		 tio2;
 | 
						struct termios		 tio2;
 | 
				
			||||||
	u_int		 	 i;
 | 
						u_int		 	 i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -508,12 +511,6 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
 | 
				
			|||||||
	ws.ws_col = screen_size_x(&wp->base);
 | 
						ws.ws_col = screen_size_x(&wp->base);
 | 
				
			||||||
	ws.ws_row = screen_size_y(&wp->base);
 | 
						ws.ws_row = screen_size_y(&wp->base);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (gettimeofday(&wp->window->name_timer, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("gettimeofday failed");
 | 
					 | 
				
			||||||
	tv.tv_sec = 0;
 | 
					 | 
				
			||||||
	tv.tv_usec = NAME_INTERVAL * 1000L;
 | 
					 | 
				
			||||||
	timeradd(&wp->window->name_timer, &tv, &wp->window->name_timer);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 	switch (wp->pid = forkpty(&wp->fd, wp->tty, NULL, &ws)) {
 | 
					 	switch (wp->pid = forkpty(&wp->fd, wp->tty, NULL, &ws)) {
 | 
				
			||||||
	case -1:
 | 
						case -1:
 | 
				
			||||||
		wp->fd = -1;
 | 
							wp->fd = -1;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user