mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Add a format window_linked which is 1 if a window has been linked
multiple times, also remove the default space in window_flags and use a conditional to add it in window-status-format (this means additional flags can be added in the option without extra spaces). From Thomas Adam with tweaks by me.
This commit is contained in:
		@@ -45,24 +45,17 @@ const struct cmd_entry cmd_unlink_window_entry = {
 | 
			
		||||
enum cmd_retval
 | 
			
		||||
cmd_kill_window_exec(struct cmd *self, struct cmd_q *cmdq)
 | 
			
		||||
{
 | 
			
		||||
	struct args		*args = self->args;
 | 
			
		||||
	struct winlink		*wl, *wl2, *wl3;
 | 
			
		||||
	struct window		*w;
 | 
			
		||||
	struct session		*s;
 | 
			
		||||
	struct session_group	*sg;
 | 
			
		||||
	u_int			 references;
 | 
			
		||||
	struct args	*args = self->args;
 | 
			
		||||
	struct winlink	*wl, *wl2, *wl3;
 | 
			
		||||
	struct window	*w;
 | 
			
		||||
	struct session	*s;
 | 
			
		||||
 | 
			
		||||
	if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
 | 
			
		||||
		return (CMD_RETURN_ERROR);
 | 
			
		||||
	w = wl->window;
 | 
			
		||||
 | 
			
		||||
	if (self->entry == &cmd_unlink_window_entry) {
 | 
			
		||||
		sg = session_group_find(s);
 | 
			
		||||
		if (sg != NULL)
 | 
			
		||||
			references = session_group_count(sg);
 | 
			
		||||
		else
 | 
			
		||||
			references = 1;
 | 
			
		||||
		if (!args_has(self->args, 'k') && w->references == references) {
 | 
			
		||||
		if (!args_has(self->args, 'k') && !session_is_linked(s, w)) {
 | 
			
		||||
			cmdq_error(cmdq, "window only linked to one session");
 | 
			
		||||
			return (CMD_RETURN_ERROR);
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								format.c
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								format.c
									
									
									
									
									
								
							@@ -621,6 +621,7 @@ format_defaults_winlink(struct format_tree *ft, struct session *s,
 | 
			
		||||
	    !!(wl->flags & WINLINK_SILENCE));
 | 
			
		||||
	format_add(ft, "window_last_flag", "%d",
 | 
			
		||||
	    !!(wl == TAILQ_FIRST(&s->lastw)));
 | 
			
		||||
	format_add(ft, "window_linked", "%d", session_is_linked(s, wl->window));
 | 
			
		||||
 | 
			
		||||
	free(flags);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -737,7 +737,7 @@ const struct options_table_entry window_options_table[] = {
 | 
			
		||||
 | 
			
		||||
	{ .name = "window-status-current-format",
 | 
			
		||||
	  .type = OPTIONS_TABLE_STRING,
 | 
			
		||||
	  .default_str = "#I:#W#F"
 | 
			
		||||
	  .default_str = "#I:#W#{?window_flags,#{window_flags}, }"
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
	{ .name = "window-status-current-style",
 | 
			
		||||
@@ -753,7 +753,7 @@ const struct options_table_entry window_options_table[] = {
 | 
			
		||||
 | 
			
		||||
	{ .name = "window-status-format",
 | 
			
		||||
	  .type = OPTIONS_TABLE_STRING,
 | 
			
		||||
	  .default_str = "#I:#W#F"
 | 
			
		||||
	  .default_str = "#I:#W#{?window_flags,#{window_flags}, }"
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
	{ .name = "window-status-last-attr",
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										14
									
								
								session.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								session.c
									
									
									
									
									
								
							@@ -337,6 +337,20 @@ session_has(struct session *s, struct window *w)
 | 
			
		||||
	return (0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Return 1 if a window is linked outside this session (not including session
 | 
			
		||||
 * groups). The window must be in this session!
 | 
			
		||||
 */
 | 
			
		||||
int
 | 
			
		||||
session_is_linked(struct session *s, struct window *w)
 | 
			
		||||
{
 | 
			
		||||
	struct session_group	*sg;
 | 
			
		||||
 | 
			
		||||
	if ((sg = session_group_find(s)) != NULL)
 | 
			
		||||
		return (w->references != session_group_count(sg));
 | 
			
		||||
	return (w->references != 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct winlink *
 | 
			
		||||
session_next_alert(struct winlink *wl)
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								tmux.1
									
									
									
									
									
								
							@@ -3345,6 +3345,7 @@ The following variables are available, where appropriate:
 | 
			
		||||
.It Li "window_index" Ta "#I" Ta "Index of window"
 | 
			
		||||
.It Li "window_last_flag" Ta "" Ta "1 if window is the last used"
 | 
			
		||||
.It Li "window_layout" Ta "" Ta "Window layout description"
 | 
			
		||||
.It Li "window_linked" Ta "" Ta "1 if window is linked across sessions"
 | 
			
		||||
.It Li "window_name" Ta "#W" Ta "Name of window"
 | 
			
		||||
.It Li "window_panes" Ta "" Ta "Number of panes in window"
 | 
			
		||||
.It Li "window_silence_flag" Ta "" Ta "1 if window has silence alert"
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								tmux.h
									
									
									
									
									
								
							@@ -2328,6 +2328,7 @@ struct winlink	*session_attach(struct session *, struct window *, int,
 | 
			
		||||
		     char **);
 | 
			
		||||
int		 session_detach(struct session *, struct winlink *);
 | 
			
		||||
int		 session_has(struct session *, struct window *);
 | 
			
		||||
int		 session_is_linked(struct session *, struct window *);
 | 
			
		||||
int		 session_next(struct session *, int);
 | 
			
		||||
int		 session_previous(struct session *, int);
 | 
			
		||||
int		 session_select(struct session *, int);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								window.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								window.c
									
									
									
									
									
								
							@@ -643,7 +643,7 @@ window_destroy_panes(struct window *w)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Return list of printable window flag symbols. No flags is just a space. */
 | 
			
		||||
/* Retuns the printable flags on a window, empty string if no flags set. */
 | 
			
		||||
char *
 | 
			
		||||
window_printable_flags(struct session *s, struct winlink *wl)
 | 
			
		||||
{
 | 
			
		||||
@@ -663,8 +663,6 @@ window_printable_flags(struct session *s, struct winlink *wl)
 | 
			
		||||
		flags[pos++] = '-';
 | 
			
		||||
	if (wl->window->flags & WINDOW_ZOOMED)
 | 
			
		||||
		flags[pos++] = 'Z';
 | 
			
		||||
	if (pos == 0)
 | 
			
		||||
		flags[pos++] = ' ';
 | 
			
		||||
	flags[pos] = '\0';
 | 
			
		||||
	return (xstrdup(flags));
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user