From ebaf54251a6e3a1b366531155ab59dbd286a4a3a Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Wed, 26 Sep 2018 18:41:18 +0100 Subject: [PATCH] Add formats for when window is larger than client, and show offset in status-right by default when larger. --- format.c | 18 ++++++++++++++++-- options-table.c | 4 +++- tmux.1 | 3 +++ tty.c | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/format.c b/format.c index e3552cba..5cdce67c 100644 --- a/format.c +++ b/format.c @@ -106,9 +106,10 @@ struct format_entry { /* Format entry tree. */ struct format_tree { - struct window *w; - struct winlink *wl; + struct client *c; struct session *s; + struct winlink *wl; + struct window *w; struct window_pane *wp; struct client *client; @@ -1395,6 +1396,7 @@ format_defaults_client(struct format_tree *ft, struct client *c) if (ft->s == NULL) ft->s = c->session; + ft->c = c; format_add(ft, "client_name", "%s", c->name); format_add(ft, "client_pid", "%ld", (long) c->pid); @@ -1463,8 +1465,11 @@ format_defaults_window(struct format_tree *ft, struct window *w) static void format_defaults_winlink(struct format_tree *ft, struct winlink *wl) { + struct client *c = ft->c; struct session *s = wl->session; struct window *w = wl->window; + int flag; + u_int ox, oy, sx, sy; if (ft->w == NULL) ft->w = wl->window; @@ -1472,6 +1477,15 @@ format_defaults_winlink(struct format_tree *ft, struct winlink *wl) format_defaults_window(ft, w); + if (c != NULL) { + flag = tty_window_offset(&c->tty, &ox, &oy, &sx, &sy); + format_add(ft, "window_bigger", "%d", flag); + if (flag) { + format_add(ft, "window_offset_x", "%u", ox); + format_add(ft, "window_offset_y", "%u", oy); + } + } + format_add(ft, "window_index", "%d", wl->idx); format_add_cb(ft, "window_stack_index", format_cb_window_stack_index); format_add(ft, "window_flags", "%s", window_printable_flags(wl)); diff --git a/options-table.c b/options-table.c index 0776f0b7..4bc7982f 100644 --- a/options-table.c +++ b/options-table.c @@ -476,7 +476,9 @@ const struct options_table_entry options_table[] = { { .name = "status-right", .type = OPTIONS_TABLE_STRING, .scope = OPTIONS_TABLE_SESSION, - .default_str = " \"#{=21:pane_title}\" %H:%M %d-%b-%y" + .default_str = "#{?window_bigger," + "[#{window_offset_x}#,#{window_offset_y}] ,}" + "\"#{=21:pane_title}\" %H:%M %d-%b-%y" }, { .name = "status-right-attr", diff --git a/tmux.1 b/tmux.1 index a85ff7a5..4d72404e 100644 --- a/tmux.1 +++ b/tmux.1 @@ -3921,6 +3921,7 @@ The following variables are available, where appropriate: .It Li "window_activity_flag" Ta "" Ta "1 if window has activity" .It Li "window_active" Ta "" Ta "1 if window active" .It Li "window_bell_flag" Ta "" Ta "1 if window has bell" +.It Li "window_bigger" Ta "" Ta "1 if window is larger than client" .It Li "window_flags" Ta "#F" Ta "Window flags" .It Li "window_format" Ta "" Ta "1 if format is for a window (not assuming the current)" .It Li "window_height" Ta "" Ta "Height of window" @@ -3930,6 +3931,8 @@ The following variables are available, where appropriate: .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_offset_x" Ta "" Ta "X offset into window if larger than client" +.It Li "window_offset_y" Ta "" Ta "Y offset into window if larger than client" .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_stack_index" Ta "" Ta "Index in session most recent stack" diff --git a/tty.c b/tty.c index 7e52755c..510a442a 100644 --- a/tty.c +++ b/tty.c @@ -815,7 +815,7 @@ tty_update_client_offset(struct client *c) c->tty.osx = sx; c->tty.osy = sy; - c->flags |= CLIENT_REDRAWWINDOW; + c->flags |= (CLIENT_REDRAWWINDOW|CLIENT_REDRAWSTATUS); } /*