Annotation of src/usr.bin/tmux/cmd-break-pane.c, Revision 1.30
1.30 ! nicm 1: /* $OpenBSD: cmd-break-pane.c,v 1.29 2015/10/27 15:58:42 nicm Exp $ */
1.1 nicm 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:
23: #include "tmux.h"
24:
25: /*
26: * Break pane off into a window.
27: */
1.25 nicm 28:
29: #define BREAK_PANE_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
1.1 nicm 30:
1.20 nicm 31: enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmd_q *);
1.1 nicm 32:
33: const struct cmd_entry cmd_break_pane_entry = {
34: "break-pane", "breakp",
1.27 nicm 35: "dPF:s:t:", 0, 0,
36: "[-dP] [-F format] " CMD_SRCDST_PANE_USAGE,
1.10 nicm 37: 0,
38: cmd_break_pane_exec
1.1 nicm 39: };
40:
1.16 nicm 41: enum cmd_retval
1.20 nicm 42: cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq)
1.1 nicm 43: {
1.10 nicm 44: struct args *args = self->args;
1.1 nicm 45: struct winlink *wl;
1.28 nicm 46: struct session *src_s;
47: struct session *dst_s;
1.1 nicm 48: struct window_pane *wp;
49: struct window *w;
1.12 nicm 50: char *name;
1.1 nicm 51: char *cause;
1.27 nicm 52: int idx;
1.13 nicm 53: struct format_tree *ft;
54: const char *template;
55: char *cp;
1.1 nicm 56:
1.28 nicm 57: wl = cmd_find_pane(cmdq, args_get(args, 's'), &src_s, &wp);
58: if (wl == NULL)
1.16 nicm 59: return (CMD_RETURN_ERROR);
1.28 nicm 60: if ((idx = cmd_find_index(cmdq, args_get(args, 't'), &dst_s)) == -2)
1.27 nicm 61: return (CMD_RETURN_ERROR);
1.28 nicm 62: if (idx != -1 && winlink_find_by_index(&dst_s->windows, idx) != NULL) {
1.27 nicm 63: cmdq_error(cmdq, "index %d already in use", idx);
64: return (CMD_RETURN_ERROR);
65: }
1.28 nicm 66: w = wl->window;
1.1 nicm 67:
1.28 nicm 68: if (window_count_panes(w) == 1) {
1.20 nicm 69: cmdq_error(cmdq, "can't break with only one pane");
1.16 nicm 70: return (CMD_RETURN_ERROR);
1.1 nicm 71: }
1.21 nicm 72: server_unzoom_window(w);
73:
1.11 nicm 74: TAILQ_REMOVE(&w->panes, wp, entry);
1.23 nicm 75: window_lost_pane(w, wp);
1.9 nicm 76: layout_close_pane(wp);
1.1 nicm 77:
1.28 nicm 78: w = wp->window = window_create1(dst_s->sx, dst_s->sy);
1.9 nicm 79: TAILQ_INSERT_HEAD(&w->panes, wp, entry);
80: w->active = wp;
1.12 nicm 81: name = default_window_name(w);
82: window_set_name(w, name);
1.15 nicm 83: free(name);
1.21 nicm 84: layout_init(w, wp);
1.30 ! nicm 85: wp->flags |= PANE_CHANGED;
1.1 nicm 86:
1.27 nicm 87: if (idx == -1)
1.29 nicm 88: idx = -1 - options_get_number(dst_s->options, "base-index");
1.28 nicm 89: wl = session_attach(dst_s, w, idx, &cause); /* can't fail */
1.10 nicm 90: if (!args_has(self->args, 'd'))
1.28 nicm 91: session_select(dst_s, wl->idx);
1.1 nicm 92:
1.28 nicm 93: server_redraw_session(src_s);
94: if (src_s != dst_s)
95: server_redraw_session(dst_s);
96: server_status_session_group(src_s);
97: if (src_s != dst_s)
98: server_status_session_group(dst_s);
1.1 nicm 99:
1.13 nicm 100: if (args_has(args, 'P')) {
1.14 nicm 101: if ((template = args_get(args, 'F')) == NULL)
1.17 nicm 102: template = BREAK_PANE_TEMPLATE;
1.14 nicm 103:
1.13 nicm 104: ft = format_create();
1.28 nicm 105: format_defaults(ft, cmd_find_client(cmdq, NULL, 1), dst_s, wl,
106: wp);
1.13 nicm 107:
108: cp = format_expand(ft, template);
1.20 nicm 109: cmdq_print(cmdq, "%s", cp);
1.15 nicm 110: free(cp);
1.13 nicm 111:
112: format_free(ft);
113: }
1.16 nicm 114: return (CMD_RETURN_NORMAL);
1.1 nicm 115: }