On Sun, May 03, 2015 at 09:08:51AM +0100, Nicholas Marriott wrote:
> Possibly you should just add the format and then add
> #{?window_references,+,,} to window-status-format yourself rather than
> making it a new fixed flag.

Yeah, fair enough.  I've done this, and hence this leaves an extra space
in most cases due to how window_printable_flags() is calculated.  See
the patch attached which shoves this out into its own flag as well.  The
commit message explains the rationale.

> Also I think the count will be incorrect if the window is linked into
> multiple non-grouped sessions and also in grouped sessions, if you don't
> want to make it exact a 0 or 1 would be better.

Done.   Now, the flag window_linked considered only unique windows
linked across sessions (via linkw)---even in the case of a grouped
session.

-- Thomas Adam

-- 
"Deep in my heart I wish I was wrong.  But deep in my heart I know I am
not." -- Morrissey ("Girl Least Likely To" -- off of Viva Hate.)
commit 271172b384842868a1d371e4065b92f532fe0d53
Author: Thomas Adam <tho...@xteddy.org>
Date:   Sat May 2 22:51:36 2015 +0100

    Window flags: window_has_flags/window_linked
    
    This primarily adds support for a new flag, 'window_linked' to indicate
    whether the given window is linked across multiple sessions.  In the case of
    grouped sessions, only those windows explicitly linked via lastw are
    counted.  This is so that the flag doesn't always return 1 for windows in
    grouped sessions.
    
    Because this flag is useful in also being able to update the window_flags in
    the status line, this also introduces another flag 'window_has_flags' to
    return 1 or 0 depending on if the window has any printable flags.  Since
    window_linked is not part of the default printable flags, conditionally
    adding this to window-status{,-current}-format can often mean an extra space
    is printed.  Therefore, this flag can be used to retain this behaviour, and
    the default options have been retained as a result.
    
    This means it's now entirely possible to override the window printable flags
    through formats alone, albeit long-winded.

diff --git a/format.c b/format.c
index 9e9b6c8..b45286b 100644
--- a/format.c
+++ b/format.c
@@ -602,16 +602,18 @@ format_defaults_winlink(struct format_tree *ft, struct session *s,
 {
 	struct window	*w = wl->window;
 	char		*flags;
+	int		 window_has_flags;
 
 	if (ft->w == NULL)
 		ft->w = wl->window;
 
-	flags = window_printable_flags(s, wl);
+	window_has_flags = window_printable_flags(s, wl, &flags);
 
 	format_defaults_window(ft, w);
 
 	format_add(ft, "window_index", "%d", wl->idx);
 	format_add(ft, "window_flags", "%s", flags);
+	format_add(ft, "window_has_flags", "%d", window_has_flags);
 	format_add(ft, "window_active", "%d", wl == s->curw);
 
 	format_add(ft, "window_bell_flag", "%d",
@@ -622,6 +624,8 @@ 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_count_window_refs(s, wl) > 1);
 
 	free(flags);
 }
diff --git a/options-table.c b/options-table.c
index a4f3ac4..c57128d 100644
--- a/options-table.c
+++ b/options-table.c
@@ -736,7 +736,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_has_flags,#{window_flags},} "
 	},
 
 	{ .name = "window-status-current-style",
@@ -752,7 +752,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_has_flags,#{window_flags}, }"
 	},
 
 	{ .name = "window-status-last-attr",
diff --git a/session.c b/session.c
index 7d86f68..072c84b 100644
--- a/session.c
+++ b/session.c
@@ -659,3 +659,22 @@ session_renumber_windows(struct session *s)
 	RB_FOREACH_SAFE(wl, winlinks, &old_wins, wl1)
 		winlink_remove(&old_wins, wl);
 }
+
+/*
+ * Returns the number of refences on a window, which may be across a session
+ * group.
+ */
+u_int
+session_count_window_refs(struct session *s, struct winlink *wl)
+{
+	struct session_group	*sg;
+
+	if ((sg = session_group_find(s)) != NULL) {
+		/*
+		 * We only want to consider unique links for each session in a
+		 * group, and not all of them.
+		 */
+		return (session_group_count(sg) - wl->window->references);
+	} else
+		return (wl->window->references);
+}
diff --git a/tmux.1 b/tmux.1
index b97fd8a..f2861b9 100644
--- a/tmux.1
+++ b/tmux.1
@@ -3345,11 +3345,13 @@ The following variables are available, where appropriate:
 .It Li "window_bell_flag" Ta "" Ta "1 if window has bell"
 .It Li "window_find_matches" Ta "" Ta "Matched data from the find-window"
 .It Li "window_flags" Ta "#F" Ta "Window flags"
+.It Li "window_has_flags" Ta "1 if the window has flags"
 .It Li "window_height" Ta "" Ta "Height of window"
 .It Li "window_id" Ta "" Ta "Unique window ID"
 .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"
diff --git a/tmux.h b/tmux.h
index dddd4f8..f0f0c60 100644
--- a/tmux.h
+++ b/tmux.h
@@ -2193,7 +2193,8 @@ void		 window_pane_key(struct window_pane *, struct client *,
 int		 window_pane_visible(struct window_pane *);
 char		*window_pane_search(
 		     struct window_pane *, const char *, u_int *);
-char		*window_printable_flags(struct session *, struct winlink *);
+int		 window_printable_flags(struct session *, struct winlink *,
+		     char **);
 struct window_pane *window_pane_find_up(struct window_pane *);
 struct window_pane *window_pane_find_down(struct window_pane *);
 struct window_pane *window_pane_find_left(struct window_pane *);
@@ -2340,6 +2341,7 @@ void		 session_group_synchronize_to(struct session *);
 void		 session_group_synchronize_from(struct session *);
 void		 session_group_synchronize1(struct session *, struct session *);
 void		 session_renumber_windows(struct session *);
+u_int		 session_count_window_refs(struct session *, struct winlink *);
 
 /* utf8.c */
 void		 utf8_build(void);
diff --git a/window.c b/window.c
index 57e8ae4..548a0e1 100644
--- a/window.c
+++ b/window.c
@@ -642,9 +642,11 @@ window_destroy_panes(struct window *w)
 	}
 }
 
-/* Return list of printable window flag symbols. No flags is just a space. */
-char *
-window_printable_flags(struct session *s, struct winlink *wl)
+/* Set the printable flags on a window.  Returns whether there are flags on
+ * the window or not.
+ */
+int
+window_printable_flags(struct session *s, struct winlink *wl, char **pflags)
 {
 	char	flags[32];
 	int	pos;
@@ -662,10 +664,10 @@ 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));
+	*pflags = xstrdup(flags);
+
+	return (pos > 0);
 }
 
 struct window_pane *
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to