4 * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
26 * Switch window to selected layout.
29 static enum cmd_retval
cmd_select_layout_exec(struct cmd
*,
32 const struct cmd_entry cmd_select_layout_entry
= {
33 .name
= "select-layout",
36 .args
= { "Enopt:", 0, 1, NULL
},
37 .usage
= "[-Enop] " CMD_TARGET_PANE_USAGE
" [layout-name]",
39 .target
= { 't', CMD_FIND_PANE
, 0 },
41 .flags
= CMD_AFTERHOOK
,
42 .exec
= cmd_select_layout_exec
45 const struct cmd_entry cmd_next_layout_entry
= {
46 .name
= "next-layout",
49 .args
= { "t:", 0, 0, NULL
},
50 .usage
= CMD_TARGET_WINDOW_USAGE
,
52 .target
= { 't', CMD_FIND_WINDOW
, 0 },
54 .flags
= CMD_AFTERHOOK
,
55 .exec
= cmd_select_layout_exec
58 const struct cmd_entry cmd_previous_layout_entry
= {
59 .name
= "previous-layout",
62 .args
= { "t:", 0, 0, NULL
},
63 .usage
= CMD_TARGET_WINDOW_USAGE
,
65 .target
= { 't', CMD_FIND_WINDOW
, 0 },
67 .flags
= CMD_AFTERHOOK
,
68 .exec
= cmd_select_layout_exec
71 static enum cmd_retval
72 cmd_select_layout_exec(struct cmd
*self
, struct cmdq_item
*item
)
74 struct args
*args
= cmd_get_args(self
);
75 struct cmd_find_state
*target
= cmdq_get_target(item
);
76 struct winlink
*wl
= target
->wl
;
77 struct window
*w
= wl
->window
;
78 struct window_pane
*wp
= target
->wp
;
79 const char *layoutname
;
80 char *oldlayout
, *cause
;
81 int next
, previous
, layout
;
83 server_unzoom_window(w
);
85 next
= (cmd_get_entry(self
) == &cmd_next_layout_entry
);
86 if (args_has(args
, 'n'))
88 previous
= (cmd_get_entry(self
) == &cmd_previous_layout_entry
);
89 if (args_has(args
, 'p'))
92 oldlayout
= w
->old_layout
;
93 w
->old_layout
= layout_dump(w
->layout_root
);
95 if (next
|| previous
) {
99 layout_set_previous(w
);
103 if (args_has(args
, 'E')) {
104 layout_spread_out(wp
);
108 if (args_count(args
) != 0)
109 layoutname
= args_string(args
, 0);
110 else if (args_has(args
, 'o'))
111 layoutname
= oldlayout
;
115 if (!args_has(args
, 'o')) {
116 if (layoutname
== NULL
)
117 layout
= w
->lastlayout
;
119 layout
= layout_set_lookup(layoutname
);
121 layout_set_select(w
, layout
);
126 if (layoutname
!= NULL
) {
127 if (layout_parse(w
, layoutname
, &cause
) == -1) {
128 cmdq_error(item
, "%s: %s", cause
, layoutname
);
136 return (CMD_RETURN_NORMAL
);
141 server_redraw_window(w
);
142 notify_window("window-layout-changed", w
);
143 return (CMD_RETURN_NORMAL
);
147 w
->old_layout
= oldlayout
;
148 return (CMD_RETURN_ERROR
);