4 * Copyright (c) 2011 George Nachman <tmux@georgester.com>
5 * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
16 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
17 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/types.h>
29 * Join or move a pane into another (like split/swap/kill).
32 static enum cmd_retval
cmd_join_pane_exec(struct cmd
*, struct cmdq_item
*);
34 const struct cmd_entry cmd_join_pane_entry
= {
38 .args
= { "bdfhvp:l:s:t:", 0, 0, NULL
},
39 .usage
= "[-bdfhv] [-l size] " CMD_SRCDST_PANE_USAGE
,
41 .source
= { 's', CMD_FIND_PANE
, CMD_FIND_DEFAULT_MARKED
},
42 .target
= { 't', CMD_FIND_PANE
, 0 },
45 .exec
= cmd_join_pane_exec
48 const struct cmd_entry cmd_move_pane_entry
= {
52 .args
= { "bdfhvp:l:s:t:", 0, 0, NULL
},
53 .usage
= "[-bdfhv] [-l size] " CMD_SRCDST_PANE_USAGE
,
55 .source
= { 's', CMD_FIND_PANE
, CMD_FIND_DEFAULT_MARKED
},
56 .target
= { 't', CMD_FIND_PANE
, 0 },
59 .exec
= cmd_join_pane_exec
62 static enum cmd_retval
63 cmd_join_pane_exec(struct cmd
*self
, struct cmdq_item
*item
)
65 struct args
*args
= cmd_get_args(self
);
66 struct cmd_find_state
*current
= cmdq_get_current(item
);
67 struct cmd_find_state
*target
= cmdq_get_target(item
);
68 struct cmd_find_state
*source
= cmdq_get_source(item
);
69 struct session
*dst_s
;
70 struct winlink
*src_wl
, *dst_wl
;
71 struct window
*src_w
, *dst_w
;
72 struct window_pane
*src_wp
, *dst_wp
;
76 enum layout_type type
;
77 struct layout_cell
*lc
;
83 dst_w
= dst_wl
->window
;
84 dst_idx
= dst_wl
->idx
;
85 server_unzoom_window(dst_w
);
89 src_w
= src_wl
->window
;
90 server_unzoom_window(src_w
);
92 if (src_wp
== dst_wp
) {
93 cmdq_error(item
, "source and target panes must be different");
94 return (CMD_RETURN_ERROR
);
97 type
= LAYOUT_TOPBOTTOM
;
98 if (args_has(args
, 'h'))
99 type
= LAYOUT_LEFTRIGHT
;
101 /* If the 'p' flag is dropped then this bit can be moved into 'l'. */
102 if (args_has(args
, 'l') || args_has(args
, 'p')) {
103 if (args_has(args
, 'f')) {
104 if (type
== LAYOUT_TOPBOTTOM
)
109 if (type
== LAYOUT_TOPBOTTOM
)
117 if (args_has(args
, 'l')) {
118 size
= args_percentage_and_expand(args
, 'l', 0, INT_MAX
, curval
,
120 } else if (args_has(args
, 'p')) {
121 size
= args_strtonum_and_expand(args
, 'l', 0, 100, item
,
124 size
= curval
* size
/ 100;
127 cmdq_error(item
, "size %s", cause
);
129 return (CMD_RETURN_ERROR
);
133 if (args_has(args
, 'b'))
134 flags
|= SPAWN_BEFORE
;
135 if (args_has(args
, 'f'))
136 flags
|= SPAWN_FULLSIZE
;
138 lc
= layout_split_pane(dst_wp
, type
, size
, flags
);
140 cmdq_error(item
, "create pane failed: pane too small");
141 return (CMD_RETURN_ERROR
);
144 layout_close_pane(src_wp
);
146 server_client_remove_pane(src_wp
);
147 window_lost_pane(src_w
, src_wp
);
148 TAILQ_REMOVE(&src_w
->panes
, src_wp
, entry
);
150 src_wp
->window
= dst_w
;
151 options_set_parent(src_wp
->options
, dst_w
->options
);
152 src_wp
->flags
|= PANE_STYLECHANGED
;
153 if (flags
& SPAWN_BEFORE
)
154 TAILQ_INSERT_BEFORE(dst_wp
, src_wp
, entry
);
156 TAILQ_INSERT_AFTER(&dst_w
->panes
, dst_wp
, src_wp
, entry
);
157 layout_assign_pane(lc
, src_wp
, 0);
158 colour_palette_from_option(&src_wp
->palette
, src_wp
->options
);
162 server_redraw_window(src_w
);
163 server_redraw_window(dst_w
);
165 if (!args_has(args
, 'd')) {
166 window_set_active_pane(dst_w
, src_wp
, 1);
167 session_select(dst_s
, dst_idx
);
168 cmd_find_from_session(current
, dst_s
, 0);
169 server_redraw_session(dst_s
);
171 server_status_session(dst_s
);
173 if (window_count_panes(src_w
) == 0)
174 server_kill_window(src_w
, 1);
176 notify_window("window-layout-changed", src_w
);
177 notify_window("window-layout-changed", dst_w
);
179 return (CMD_RETURN_NORMAL
);