The branch, master has been updated
       via  dc2adc6bc1f1b2dc25252ff9703fe5b3fe4d8786 (commit)
       via  771744426e3cd3fbf746e5c9554b8119e5f6faf2 (commit)
      from  7981e653d805fd3fa31cf7897704b3a328edf0f2 (commit)

- Log -----------------------------------------------------------------
commit dc2adc6bc1f1b2dc25252ff9703fe5b3fe4d8786
Merge: 7981e65 7717444
Author: Thomas Adam <tho...@xteddy.org>
Commit: Thomas Adam <tho...@xteddy.org>

    Merge branch 'obsd-master'

 cmd-select-layout.c |   69 +++++++++++++++++++++++++++++++++++---------------
 tmux.1              |    8 +++--
 tmux.h              |    1 +
 window.c            |    1 +
 4 files changed, 55 insertions(+), 24 deletions(-)



commit 771744426e3cd3fbf746e5c9554b8119e5f6faf2
Author: nicm <nicm>
Commit: nicm <nicm>

    Add select-layout -o to undo the last layout change (apply the previously
    set layout).
---
 cmd-select-layout.c |   69 +++++++++++++++++++++++++++++++++++---------------
 tmux.1              |    8 +++--
 tmux.h              |    1 +
 window.c            |    1 +
 4 files changed, 55 insertions(+), 24 deletions(-)

diff --git a/cmd-select-layout.c b/cmd-select-layout.c
index 77137b7..14737dc 100644
--- a/cmd-select-layout.c
+++ b/cmd-select-layout.c
@@ -18,6 +18,8 @@
 
 #include <sys/types.h>
 
+#include <stdlib.h>
+
 #include "tmux.h"
 
 /*
@@ -28,8 +30,8 @@ enum cmd_retval        cmd_select_layout_exec(struct cmd *, 
struct cmd_q *);
 
 const struct cmd_entry cmd_select_layout_entry = {
        "select-layout", "selectl",
-       "npt:", 0, 1,
-       "[-np] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
+       "nopt:", 0, 1,
+       "[-nop] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
        0,
        cmd_select_layout_exec
 };
@@ -55,46 +57,71 @@ cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq)
 {
        struct args     *args = self->args;
        struct winlink  *wl;
+       struct window   *w;
        const char      *layoutname;
+       char            *oldlayout;
        int              next, previous, layout;
 
        if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
                return (CMD_RETURN_ERROR);
-       server_unzoom_window(wl->window);
+       w = wl->window;
+
+       server_unzoom_window(w);
 
        next = self->entry == &cmd_next_layout_entry;
-       if (args_has(self->args, 'n'))
+       if (args_has(args, 'n'))
                next = 1;
        previous = self->entry == &cmd_previous_layout_entry;
-       if (args_has(self->args, 'p'))
+       if (args_has(args, 'p'))
                previous = 1;
 
+       oldlayout = w->old_layout;
+       w->old_layout = layout_dump(w->layout_root);
+
        if (next || previous) {
                if (next)
-                       layout = layout_set_next(wl->window);
+                       layout_set_next(w);
                else
-                       layout = layout_set_previous(wl->window);
-               server_redraw_window(wl->window);
-               return (CMD_RETURN_NORMAL);
+                       layout_set_previous(w);
+               goto changed;
        }
 
-       if (args->argc == 0)
-               layout = wl->window->lastlayout;
-       else
-               layout = layout_set_lookup(args->argv[0]);
-       if (layout != -1) {
-               layout = layout_set_select(wl->window, layout);
-               server_redraw_window(wl->window);
-               return (CMD_RETURN_NORMAL);
+       if (!args_has(args, 'o')) {
+               if (args->argc == 0)
+                       layout = w->lastlayout;
+               else
+                       layout = layout_set_lookup(args->argv[0]);
+               if (layout != -1) {
+                       layout_set_select(w, layout);
+                       goto changed;
+               }
        }
 
-       if (args->argc != 0) {
+       if (args->argc != 0)
                layoutname = args->argv[0];
-               if (layout_parse(wl->window, layoutname) == -1) {
+       else if (args_has(args, 'o'))
+               layoutname = oldlayout;
+       else
+               layoutname = NULL;
+
+       if (layoutname != NULL) {
+               if (layout_parse(w, layoutname) == -1) {
                        cmdq_error(cmdq, "can't set layout: %s", layoutname);
-                       return (CMD_RETURN_ERROR);
+                       goto error;
                }
-               server_redraw_window(wl->window);
+               goto changed;
        }
+
+       free(oldlayout);
        return (CMD_RETURN_NORMAL);
+
+changed:
+       free(oldlayout);
+       server_redraw_window(w);
+       return (CMD_RETURN_NORMAL);
+
+error:
+       free(w->old_layout);
+       w->old_layout = oldlayout;
+       return (CMD_RETURN_ERROR);
 }
diff --git a/tmux.1 b/tmux.1
index cd7ec39..5bf7782 100644
--- a/tmux.1
+++ b/tmux.1
@@ -442,8 +442,8 @@ otherwise the current window in
 .Em session
 is chosen.
 .Pp
-The following special tokens are available to indicate particular windows. Each
-has a single-character alternative form.
+The following special tokens are available to indicate particular windows.
+Each has a single-character alternative form.
 .Bl -column "XXXXXXXXXX" "X"
 .It Sy "Token" Ta Sy "" Ta Sy "Meaning"
 .It Li "{start}" Ta "^" Ta "The lowest-numbered window"
@@ -1775,7 +1775,7 @@ lower) with
 .Fl U
 or downward (numerically higher).
 .It Xo Ic select-layout
-.Op Fl np
+.Op Fl nop
 .Op Fl t Ar target-window
 .Op Ar layout-name
 .Xc
@@ -1792,6 +1792,8 @@ are equivalent to the
 and
 .Ic previous-layout
 commands.
+.Fl o
+applies the last set layout if possible (undoes the most recent layout change).
 .It Xo Ic select-pane
 .Op Fl DdegLlRU
 .Op Fl P Ar style
diff --git a/tmux.h b/tmux.h
index ee36f4b..b315114 100644
--- a/tmux.h
+++ b/tmux.h
@@ -965,6 +965,7 @@ struct window {
        int              lastlayout;
        struct layout_cell *layout_root;
        struct layout_cell *saved_layout_root;
+       char            *old_layout;
 
        u_int            sx;
        u_int            sy;
diff --git a/window.c b/window.c
index 31f20a1..e4e4115 100644
--- a/window.c
+++ b/window.c
@@ -344,6 +344,7 @@ window_destroy(struct window *w)
 
        if (w->layout_root != NULL)
                layout_free(w);
+       free(w->old_layout);
 
        if (event_initialized(&w->name_timer))
                evtimer_del(&w->name_timer);


-----------------------------------------------------------------------

Summary of changes:
 cmd-select-layout.c |   69 +++++++++++++++++++++++++++++++++++---------------
 tmux.1              |    8 +++--
 tmux.h              |    1 +
 window.c            |    1 +
 4 files changed, 55 insertions(+), 24 deletions(-)


hooks/post-receive
-- 
tmux

------------------------------------------------------------------------------
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-cvs mailing list
tmux-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-cvs

Reply via email to