Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 149 lines (128 sloc) 3.938 kb
0f2e3364 » orebokech
2012-01-21 Import upstream snapshot from SVN r2670
1 /* $Id: cmd-split-window.c 2664 2012-01-20 21:21:32Z tcunha $ */
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
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 * Split a window (add a new pane).
28 */
29
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
30 void cmd_split_window_key_binding(struct cmd *, int);
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
31 int cmd_split_window_exec(struct cmd *, struct cmd_ctx *);
32
33 const struct cmd_entry cmd_split_window_entry = {
34 "split-window", "splitw",
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
35 "dl:hp:Pt:v", 0, 1,
36 "[-dhvP] [-p percentage|-l size] [-t target-pane] [command]",
37 0,
38 cmd_split_window_key_binding,
39 NULL,
40 cmd_split_window_exec
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
41 };
42
43 void
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
44 cmd_split_window_key_binding(struct cmd *self, int key)
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
45 {
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
46 self->args = args_create(0);
47 if (key == '%')
48 args_set(self->args, 'h', NULL);
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
49 }
50
51 int
52 cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
53 {
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
54 struct args *args = self->args;
55 struct session *s;
56 struct winlink *wl;
57 struct window *w;
58 struct window_pane *wp, *new_wp = NULL;
59 struct environ env;
0f2e3364 » orebokech
2012-01-21 Import upstream snapshot from SVN r2670
60 const char *cmd, *cwd, *shell;
61 char *cause, *new_cause;
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
62 u_int hlimit, paneidx;
63 int size, percentage;
64 enum layout_type type;
65 struct layout_cell *lc;
66
67 if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
68 return (-1);
69 w = wl->window;
70
71 environ_init(&env);
72 environ_copy(&global_environ, &env);
73 environ_copy(&s->environ, &env);
74 server_fill_environ(s, &env);
75
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
76 if (args->argc == 0)
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
77 cmd = options_get_string(&s->options, "default-command");
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
78 else
79 cmd = args->argv[0];
4ecaa511 » orebokech
2011-12-09 Import upstream snapshot from SVN r2647
80 cwd = cmd_get_default_path(ctx);
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
81
dda8e8e5 » kfebert
2010-03-13 Imported Upstream version 1.2
82 type = LAYOUT_TOPBOTTOM;
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
83 if (args_has(args, 'h'))
dda8e8e5 » kfebert
2010-03-13 Imported Upstream version 1.2
84 type = LAYOUT_LEFTRIGHT;
85
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
86 size = -1;
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
87 if (args_has(args, 'l')) {
88 size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
89 if (cause != NULL) {
b0169484 » orebokech
2011-10-03 Import upstream snapshot from SVN r2608
90 xasprintf(&new_cause, "size %s", cause);
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
91 xfree(cause);
b0169484 » orebokech
2011-10-03 Import upstream snapshot from SVN r2608
92 cause = new_cause;
93 goto error;
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
94 }
95 } else if (args_has(args, 'p')) {
96 percentage = args_strtonum(args, 'p', 0, INT_MAX, &cause);
97 if (cause != NULL) {
b0169484 » orebokech
2011-10-03 Import upstream snapshot from SVN r2608
98 xasprintf(&new_cause, "percentage %s", cause);
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
99 xfree(cause);
b0169484 » orebokech
2011-10-03 Import upstream snapshot from SVN r2608
100 cause = new_cause;
101 goto error;
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
102 }
dda8e8e5 » kfebert
2010-03-13 Imported Upstream version 1.2
103 if (type == LAYOUT_TOPBOTTOM)
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
104 size = (wp->sy * percentage) / 100;
dda8e8e5 » kfebert
2010-03-13 Imported Upstream version 1.2
105 else
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
106 size = (wp->sx * percentage) / 100;
dda8e8e5 » kfebert
2010-03-13 Imported Upstream version 1.2
107 }
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
108 hlimit = options_get_number(&s->options, "history-limit");
109
110 shell = options_get_string(&s->options, "default-shell");
111 if (*shell == '\0' || areshell(shell))
112 shell = _PATH_BSHELL;
113
dda8e8e5 » kfebert
2010-03-13 Imported Upstream version 1.2
114 if ((lc = layout_split_pane(wp, type, size)) == NULL) {
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
115 cause = xstrdup("pane too small");
116 goto error;
117 }
dda8e8e5 » kfebert
2010-03-13 Imported Upstream version 1.2
118 new_wp = window_add_pane(w, hlimit);
119 if (window_pane_spawn(
120 new_wp, cmd, shell, cwd, &env, s->tio, &cause) != 0)
121 goto error;
122 layout_assign_pane(lc, new_wp);
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
123
124 server_redraw_window(w);
125
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
126 if (!args_has(args, 'd')) {
dda8e8e5 » kfebert
2010-03-13 Imported Upstream version 1.2
127 window_set_active_pane(w, new_wp);
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
128 session_select(s, wl->idx);
129 server_redraw_session(s);
130 } else
131 server_status_session(s);
132
133 environ_free(&env);
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
134
135 if (args_has(args, 'P')) {
d8734749 » orebokech
2011-11-25 Import upstream snapshot from SVN r2642
136 if (window_pane_index(new_wp, &paneidx) != 0)
137 fatalx("index not found");
7216c39c » kfebert
2011-07-09 Imported Upstream version 1.5
138 ctx->print(ctx, "%s:%u.%u", s->name, wl->idx, paneidx);
139 }
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
140 return (0);
141
142 error:
143 environ_free(&env);
dda8e8e5 » kfebert
2010-03-13 Imported Upstream version 1.2
144 if (new_wp != NULL)
145 window_remove_pane(w, new_wp);
8fade26b » Karl Ferdinand Ebert
2009-11-22 Imported Upstream version 1.1
146 ctx->error(ctx, "create pane failed: %s", cause);
147 xfree(cause);
148 return (-1);
149 }
Something went wrong with that request. Please try again.