File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / tmux / cmd-join-pane.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Jun 14 12:22:44 2017 UTC (7 years ago) by misho
Branches: tmux, MAIN
CVS tags: v2_4p0, v2_4, HEAD
tmux 2.4

    1: /* $OpenBSD$ */
    2: 
    3: /*
    4:  * Copyright (c) 2011 George Nachman <tmux@georgester.com>
    5:  * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
    6:  *
    7:  * Permission to use, copy, modify, and distribute this software for any
    8:  * purpose with or without fee is hereby granted, provided that the above
    9:  * copyright notice and this permission notice appear in all copies.
   10:  *
   11:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
   12:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
   13:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
   14:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
   15:  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
   16:  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
   17:  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   18:  */
   19: 
   20: #include <sys/types.h>
   21: 
   22: #include <stdlib.h>
   23: #include <unistd.h>
   24: 
   25: #include "tmux.h"
   26: 
   27: /*
   28:  * Join or move a pane into another (like split/swap/kill).
   29:  */
   30: 
   31: static enum cmd_retval	cmd_join_pane_exec(struct cmd *, struct cmdq_item *);
   32: 
   33: const struct cmd_entry cmd_join_pane_entry = {
   34: 	.name = "join-pane",
   35: 	.alias = "joinp",
   36: 
   37: 	.args = { "bdhvp:l:s:t:", 0, 0 },
   38: 	.usage = "[-bdhv] [-p percentage|-l size] " CMD_SRCDST_PANE_USAGE,
   39: 
   40: 	.sflag = CMD_PANE_MARKED,
   41: 	.tflag = CMD_PANE,
   42: 
   43: 	.flags = 0,
   44: 	.exec = cmd_join_pane_exec
   45: };
   46: 
   47: const struct cmd_entry cmd_move_pane_entry = {
   48: 	.name = "move-pane",
   49: 	.alias = "movep",
   50: 
   51: 	.args = { "bdhvp:l:s:t:", 0, 0 },
   52: 	.usage = "[-bdhv] [-p percentage|-l size] " CMD_SRCDST_PANE_USAGE,
   53: 
   54: 	.sflag = CMD_PANE,
   55: 	.tflag = CMD_PANE,
   56: 
   57: 	.flags = 0,
   58: 	.exec = cmd_join_pane_exec
   59: };
   60: 
   61: static enum cmd_retval
   62: cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
   63: {
   64: 	struct args		*args = self->args;
   65: 	struct session		*dst_s;
   66: 	struct winlink		*src_wl, *dst_wl;
   67: 	struct window		*src_w, *dst_w;
   68: 	struct window_pane	*src_wp, *dst_wp;
   69: 	char			*cause;
   70: 	int			 size, percentage, dst_idx;
   71: 	enum layout_type	 type;
   72: 	struct layout_cell	*lc;
   73: 	int			 not_same_window;
   74: 
   75: 	if (self->entry == &cmd_join_pane_entry)
   76: 		not_same_window = 1;
   77: 	else
   78: 		not_same_window = 0;
   79: 
   80: 	dst_s = item->state.tflag.s;
   81: 	dst_wl = item->state.tflag.wl;
   82: 	dst_wp = item->state.tflag.wp;
   83: 	dst_w = dst_wl->window;
   84: 	dst_idx = dst_wl->idx;
   85: 	server_unzoom_window(dst_w);
   86: 
   87: 	src_wl = item->state.sflag.wl;
   88: 	src_wp = item->state.sflag.wp;
   89: 	src_w = src_wl->window;
   90: 	server_unzoom_window(src_w);
   91: 
   92: 	if (not_same_window && src_w == dst_w) {
   93: 		cmdq_error(item, "can't join a pane to its own window");
   94: 		return (CMD_RETURN_ERROR);
   95: 	}
   96: 	if (!not_same_window && src_wp == dst_wp) {
   97: 		cmdq_error(item, "source and target panes must be different");
   98: 		return (CMD_RETURN_ERROR);
   99: 	}
  100: 
  101: 	type = LAYOUT_TOPBOTTOM;
  102: 	if (args_has(args, 'h'))
  103: 		type = LAYOUT_LEFTRIGHT;
  104: 
  105: 	size = -1;
  106: 	if (args_has(args, 'l')) {
  107: 		size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
  108: 		if (cause != NULL) {
  109: 			cmdq_error(item, "size %s", cause);
  110: 			free(cause);
  111: 			return (CMD_RETURN_ERROR);
  112: 		}
  113: 	} else if (args_has(args, 'p')) {
  114: 		percentage = args_strtonum(args, 'p', 0, 100, &cause);
  115: 		if (cause != NULL) {
  116: 			cmdq_error(item, "percentage %s", cause);
  117: 			free(cause);
  118: 			return (CMD_RETURN_ERROR);
  119: 		}
  120: 		if (type == LAYOUT_TOPBOTTOM)
  121: 			size = (dst_wp->sy * percentage) / 100;
  122: 		else
  123: 			size = (dst_wp->sx * percentage) / 100;
  124: 	}
  125: 	lc = layout_split_pane(dst_wp, type, size, args_has(args, 'b'), 0);
  126: 	if (lc == NULL) {
  127: 		cmdq_error(item, "create pane failed: pane too small");
  128: 		return (CMD_RETURN_ERROR);
  129: 	}
  130: 
  131: 	layout_close_pane(src_wp);
  132: 
  133: 	window_lost_pane(src_w, src_wp);
  134: 	TAILQ_REMOVE(&src_w->panes, src_wp, entry);
  135: 
  136: 	src_wp->window = dst_w;
  137: 	TAILQ_INSERT_AFTER(&dst_w->panes, dst_wp, src_wp, entry);
  138: 	layout_assign_pane(lc, src_wp);
  139: 
  140: 	recalculate_sizes();
  141: 
  142: 	server_redraw_window(src_w);
  143: 	server_redraw_window(dst_w);
  144: 
  145: 	if (!args_has(args, 'd')) {
  146: 		window_set_active_pane(dst_w, src_wp);
  147: 		session_select(dst_s, dst_idx);
  148: 		server_redraw_session(dst_s);
  149: 	} else
  150: 		server_status_session(dst_s);
  151: 
  152: 	if (window_count_panes(src_w) == 0)
  153: 		server_kill_window(src_w);
  154: 	else
  155: 		notify_window("window-layout-changed", src_w);
  156: 	notify_window("window-layout-changed", dst_w);
  157: 
  158: 	return (CMD_RETURN_NORMAL);
  159: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>