Annotation of embedaddon/tmux/cmd-break-pane.c, revision 1.1
1.1 ! misho 1: /* $OpenBSD$ */
! 2:
! 3: /*
! 4: * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
! 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: */
! 28:
! 29: #define BREAK_PANE_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
! 30:
! 31: static enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmdq_item *);
! 32:
! 33: const struct cmd_entry cmd_break_pane_entry = {
! 34: .name = "break-pane",
! 35: .alias = "breakp",
! 36:
! 37: .args = { "dPF:n:s:t:", 0, 0 },
! 38: .usage = "[-dP] [-F format] [-n window-name] [-s src-pane] [-t dst-window]",
! 39:
! 40: .sflag = CMD_PANE,
! 41: .tflag = CMD_WINDOW_INDEX,
! 42:
! 43: .flags = 0,
! 44: .exec = cmd_break_pane_exec
! 45: };
! 46:
! 47: static enum cmd_retval
! 48: cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
! 49: {
! 50: struct args *args = self->args;
! 51: struct client *c = item->state.c;
! 52: struct winlink *wl = item->state.sflag.wl;
! 53: struct session *src_s = item->state.sflag.s;
! 54: struct session *dst_s = item->state.tflag.s;
! 55: struct window_pane *wp = item->state.sflag.wp;
! 56: struct window *w = wl->window;
! 57: char *name, *cause;
! 58: int idx = item->state.tflag.idx;
! 59: const char *template;
! 60: char *cp;
! 61:
! 62: if (idx != -1 && winlink_find_by_index(&dst_s->windows, idx) != NULL) {
! 63: cmdq_error(item, "index %d already in use", idx);
! 64: return (CMD_RETURN_ERROR);
! 65: }
! 66:
! 67: if (window_count_panes(w) == 1) {
! 68: cmdq_error(item, "can't break with only one pane");
! 69: return (CMD_RETURN_ERROR);
! 70: }
! 71: server_unzoom_window(w);
! 72:
! 73: TAILQ_REMOVE(&w->panes, wp, entry);
! 74: window_lost_pane(w, wp);
! 75: layout_close_pane(wp);
! 76:
! 77: w = wp->window = window_create(dst_s->sx, dst_s->sy);
! 78: TAILQ_INSERT_HEAD(&w->panes, wp, entry);
! 79: w->active = wp;
! 80:
! 81: if (!args_has(args, 'n')) {
! 82: name = default_window_name(w);
! 83: window_set_name(w, name);
! 84: free(name);
! 85: } else {
! 86: window_set_name(w, args_get(args, 'n'));
! 87: options_set_number(w->options, "automatic-rename", 0);
! 88: }
! 89:
! 90: layout_init(w, wp);
! 91: wp->flags |= PANE_CHANGED;
! 92:
! 93: if (idx == -1)
! 94: idx = -1 - options_get_number(dst_s->options, "base-index");
! 95: wl = session_attach(dst_s, w, idx, &cause); /* can't fail */
! 96: if (!args_has(self->args, 'd'))
! 97: session_select(dst_s, wl->idx);
! 98:
! 99: server_redraw_session(src_s);
! 100: if (src_s != dst_s)
! 101: server_redraw_session(dst_s);
! 102: server_status_session_group(src_s);
! 103: if (src_s != dst_s)
! 104: server_status_session_group(dst_s);
! 105:
! 106: if (args_has(args, 'P')) {
! 107: if ((template = args_get(args, 'F')) == NULL)
! 108: template = BREAK_PANE_TEMPLATE;
! 109: cp = format_single(item, template, c, dst_s, wl, wp);
! 110: cmdq_print(item, "%s", cp);
! 111: free(cp);
! 112: }
! 113: return (CMD_RETURN_NORMAL);
! 114: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>