From 531869bd92f0daff3cc3c3cc0ab273846f411dc8 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 13 Nov 2015 10:00:26 +0000 Subject: [PATCH] Add window_visible_layout which ignores zoomed panes and use it for control mode (which needs to know all panes), from George Nachman. --- control-notify.c | 11 +++++++++-- format.c | 15 +++++++++++++++ tmux.1 | 9 +++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/control-notify.c b/control-notify.c index 943d670c..16a98e3a 100644 --- a/control-notify.c +++ b/control-notify.c @@ -19,6 +19,8 @@ #include +#include + #include "tmux.h" #define CONTROL_SHOULD_NOTIFY_CLIENT(c) \ @@ -65,6 +67,10 @@ control_notify_window_layout_changed(struct window *w) struct format_tree *ft; struct winlink *wl; const char *template; + char *expanded; + + template = "%layout-change #{window_id} #{window_layout} " + "#{window_visible_layout} #{window_flags}"; TAILQ_FOREACH(c, &clients, entry) { if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL) @@ -81,13 +87,14 @@ control_notify_window_layout_changed(struct window *w) */ if (w->layout_root == NULL) continue; - template = "%layout-change #{window_id} #{window_layout}"; ft = format_create(); wl = winlink_find_by_window(&s->windows, w); if (wl != NULL) { format_defaults(ft, c, NULL, wl, NULL); - control_write(c, "%s", format_expand(ft, template)); + expanded = format_expand(ft, template); + control_write(c, "%s", expanded); + free(expanded); } format_free(ft); } diff --git a/format.c b/format.c index 389026ac..9cfee277 100644 --- a/format.c +++ b/format.c @@ -48,6 +48,7 @@ void format_cb_host_short(struct format_tree *, struct format_entry *); void format_cb_pid(struct format_tree *, struct format_entry *); void format_cb_session_alerts(struct format_tree *, struct format_entry *); void format_cb_window_layout(struct format_tree *, struct format_entry *); +void format_cb_window_visible_layout(struct format_tree *, struct format_entry *); void format_cb_start_command(struct format_tree *, struct format_entry *); void format_cb_current_command(struct format_tree *, struct format_entry *); void format_cb_history_bytes(struct format_tree *, struct format_entry *); @@ -362,6 +363,18 @@ format_cb_window_layout(struct format_tree *ft, struct format_entry *fe) fe->value = layout_dump(w->layout_root); } +/* Callback for window_visible_layout. */ +void +format_cb_window_visible_layout(struct format_tree *ft, struct format_entry *fe) +{ + struct window *w = ft->w; + + if (w == NULL) + return; + + fe->value = layout_dump(w->layout_root); +} + /* Callback for pane_start_command. */ void format_cb_start_command(struct format_tree *ft, struct format_entry *fe) @@ -1024,6 +1037,8 @@ format_defaults_window(struct format_tree *ft, struct window *w) format_add(ft, "window_width", "%u", w->sx); format_add(ft, "window_height", "%u", w->sy); format_add_cb(ft, "window_layout", format_cb_window_layout); + format_add_cb(ft, "window_visible_layout", + format_cb_window_visible_layout); format_add(ft, "window_panes", "%u", window_count_panes(w)); format_add(ft, "window_zoomed_flag", "%d", !!(w->flags & WINDOW_ZOOMED)); diff --git a/tmux.1 b/tmux.1 index e0646697..3a08c8cd 100644 --- a/tmux.1 +++ b/tmux.1 @@ -3412,11 +3412,12 @@ The following variables are available, where appropriate: .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_layout" Ta "" Ta "Window layout description, ignoring zoomed window panes" .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" +.It Li "window_visible_layout" Ta "" Ta "Window layout description, respecting zoomed window panes" .It Li "window_width" Ta "" Ta "Width of window" .It Li "window_zoomed_flag" Ta "" Ta "1 if window is zoomed" .It Li "wrap_flag" Ta "" Ta "Pane wrap flag" @@ -4007,12 +4008,16 @@ or an error occurred. If present, .Ar reason describes why the client exited. -.It Ic %layout-change Ar window-id Ar window-layout +.It Ic %layout-change Ar window-id Ar window-layout Ar window-visible-layout Ar window-flags The layout of a window with ID .Ar window-id changed. The new layout is .Ar window-layout . +The window's visible layout is +.Ar window-visible-layout +and the window flags are +.Ar window-flags . .It Ic %output Ar pane-id Ar value A window pane produced output. .Ar value