4 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
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>
28 * Join a pane into another (like split/swap/kill).
31 void cmd_join_pane_key_binding(struct cmd
*, int);
32 int cmd_join_pane_exec(struct cmd
*, struct cmd_ctx
*);
34 const struct cmd_entry cmd_join_pane_entry
= {
37 "[-dhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
39 cmd_join_pane_key_binding
,
45 cmd_join_pane_key_binding(struct cmd
*self
, int key
)
49 self
->args
= args_create(0);
50 args_set(self
->args
, 'h', NULL
);
53 self
->args
= args_create(0);
59 cmd_join_pane_exec(struct cmd
*self
, struct cmd_ctx
*ctx
)
61 struct args
*args
= self
->args
;
62 struct session
*dst_s
;
63 struct winlink
*src_wl
, *dst_wl
;
64 struct window
*src_w
, *dst_w
;
65 struct window_pane
*src_wp
, *dst_wp
;
67 int size
, percentage
, dst_idx
;
68 enum layout_type type
;
69 struct layout_cell
*lc
;
71 dst_wl
= cmd_find_pane(ctx
, args_get(args
, 't'), &dst_s
, &dst_wp
);
74 dst_w
= dst_wl
->window
;
75 dst_idx
= dst_wl
->idx
;
77 src_wl
= cmd_find_pane(ctx
, args_get(args
, 's'), NULL
, &src_wp
);
80 src_w
= src_wl
->window
;
83 ctx
->error(ctx
, "can't join a pane to its own window");
87 type
= LAYOUT_TOPBOTTOM
;
88 if (args_has(args
, 'h'))
89 type
= LAYOUT_LEFTRIGHT
;
92 if (args_has(args
, 'l')) {
93 size
= args_strtonum(args
, 'l', 0, INT_MAX
, &cause
);
95 ctx
->error(ctx
, "size %s", cause
);
99 } else if (args_has(args
, 'p')) {
100 percentage
= args_strtonum(args
, 'p', 0, 100, &cause
);
102 ctx
->error(ctx
, "percentage %s", cause
);
106 if (type
== LAYOUT_TOPBOTTOM
)
107 size
= (dst_wp
->sy
* percentage
) / 100;
109 size
= (dst_wp
->sx
* percentage
) / 100;
112 if ((lc
= layout_split_pane(dst_wp
, type
, size
)) == NULL
) {
113 ctx
->error(ctx
, "create pane failed: pane too small");
117 layout_close_pane(src_wp
);
119 if (src_w
->active
== src_wp
) {
120 src_w
->active
= TAILQ_PREV(src_wp
, window_panes
, entry
);
121 if (src_w
->active
== NULL
)
122 src_w
->active
= TAILQ_NEXT(src_wp
, entry
);
124 TAILQ_REMOVE(&src_w
->panes
, src_wp
, entry
);
126 if (window_count_panes(src_w
) == 0)
127 server_kill_window(src_w
);
129 src_wp
->window
= dst_w
;
130 TAILQ_INSERT_AFTER(&dst_w
->panes
, dst_wp
, src_wp
, entry
);
131 layout_assign_pane(lc
, src_wp
);
135 server_redraw_window(src_w
);
136 server_redraw_window(dst_w
);
138 if (!args_has(args
, 'd')) {
139 window_set_active_pane(dst_w
, src_wp
);
140 session_select(dst_s
, dst_idx
);
141 server_redraw_session(dst_s
);
143 server_status_session(dst_s
);