Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 146 lines (122 sloc) 3.715 kB
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
1 /* $Id: cmd-join-pane.c 2553 2011-07-09 09:42:33Z tcunha $ */
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
2
3 /*
4 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
5 *
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.
9 *
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.
17 */
18
19 #include <sys/types.h>
20
21 #include <stdlib.h>
22 #include <unistd.h>
23
24 #include "tmux.h"
25
26 /*
27 * Join a pane into another (like split/swap/kill).
28 */
29
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
30 void cmd_join_pane_key_binding(struct cmd *, int);
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
31 int cmd_join_pane_exec(struct cmd *, struct cmd_ctx *);
32
33 const struct cmd_entry cmd_join_pane_entry = {
34 "join-pane", "joinp",
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
35 "dhvp:l:s:t:", 0, 0,
77c63de @orebokech Import upstream version 1.4
orebokech authored
36 "[-dhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
37 0,
38 cmd_join_pane_key_binding,
39 NULL,
40 cmd_join_pane_exec
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
41 };
42
43 void
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
44 cmd_join_pane_key_binding(struct cmd *self, int key)
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
45 {
46 switch (key) {
47 case '%':
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
48 self->args = args_create(0);
49 args_set(self->args, 'h', NULL);
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
50 break;
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
51 default:
52 self->args = args_create(0);
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
53 break;
54 }
55 }
56
57 int
58 cmd_join_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
59 {
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
60 struct args *args = self->args;
61 struct session *dst_s;
62 struct winlink *src_wl, *dst_wl;
63 struct window *src_w, *dst_w;
64 struct window_pane *src_wp, *dst_wp;
65 char *cause;
66 int size, percentage, dst_idx;
67 enum layout_type type;
68 struct layout_cell *lc;
69
70 dst_wl = cmd_find_pane(ctx, args_get(args, 't'), &dst_s, &dst_wp);
71 if (dst_wl == NULL)
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
72 return (-1);
73 dst_w = dst_wl->window;
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
74 dst_idx = dst_wl->idx;
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
75
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
76 src_wl = cmd_find_pane(ctx, args_get(args, 's'), NULL, &src_wp);
77 if (src_wl == NULL)
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
78 return (-1);
79 src_w = src_wl->window;
80
81 if (src_w == dst_w) {
82 ctx->error(ctx, "can't join a pane to its own window");
83 return (-1);
84 }
85
86 type = LAYOUT_TOPBOTTOM;
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
87 if (args_has(args, 'h'))
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
88 type = LAYOUT_LEFTRIGHT;
89
90 size = -1;
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
91 if (args_has(args, 'l')) {
92 size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
93 if (cause != NULL) {
94 ctx->error(ctx, "size %s", cause);
95 xfree(cause);
96 return (-1);
97 }
98 } else if (args_has(args, 'p')) {
99 percentage = args_strtonum(args, 'p', 0, 100, &cause);
100 if (cause != NULL) {
101 ctx->error(ctx, "percentage %s", cause);
102 xfree(cause);
103 return (-1);
104 }
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
105 if (type == LAYOUT_TOPBOTTOM)
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
106 size = (dst_wp->sy * percentage) / 100;
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
107 else
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
108 size = (dst_wp->sx * percentage) / 100;
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
109 }
110
111 if ((lc = layout_split_pane(dst_wp, type, size)) == NULL) {
112 ctx->error(ctx, "create pane failed: pane too small");
113 return (-1);
114 }
115
116 layout_close_pane(src_wp);
117
118 if (src_w->active == src_wp) {
119 src_w->active = TAILQ_PREV(src_wp, window_panes, entry);
120 if (src_w->active == NULL)
121 src_w->active = TAILQ_NEXT(src_wp, entry);
122 }
123 TAILQ_REMOVE(&src_w->panes, src_wp, entry);
124
125 if (window_count_panes(src_w) == 0)
126 server_kill_window(src_w);
127
128 src_wp->window = dst_w;
129 TAILQ_INSERT_AFTER(&dst_w->panes, dst_wp, src_wp, entry);
130 layout_assign_pane(lc, src_wp);
131
132 recalculate_sizes();
133
134 server_redraw_window(src_w);
135 server_redraw_window(dst_w);
136
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
137 if (!args_has(args, 'd')) {
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
138 window_set_active_pane(dst_w, src_wp);
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
139 session_select(dst_s, dst_idx);
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
140 server_redraw_session(dst_s);
141 } else
142 server_status_session(dst_s);
143
144 return (0);
145 }
Something went wrong with that request. Please try again.