[BACK]Return to cmd-join-pane.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/cmd-join-pane.c, Revision 1.40

1.40    ! nicm        1: /* $OpenBSD: cmd-join-pane.c,v 1.39 2020/03/21 13:16:15 nicm Exp $ */
1.1       nicm        2:
                      3: /*
1.8       nicm        4:  * Copyright (c) 2011 George Nachman <tmux@georgester.com>
1.23      nicm        5:  * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
1.1       nicm        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 <paths.h>
                     23: #include <stdlib.h>
1.36      nicm       24: #include <string.h>
1.1       nicm       25: #include <unistd.h>
                     26:
                     27: #include "tmux.h"
                     28:
                     29: /*
1.8       nicm       30:  * Join or move a pane into another (like split/swap/kill).
1.1       nicm       31:  */
                     32:
1.29      nicm       33: static enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmdq_item *);
1.8       nicm       34:
1.1       nicm       35: const struct cmd_entry cmd_join_pane_entry = {
1.21      nicm       36:        .name = "join-pane",
                     37:        .alias = "joinp",
                     38:
1.37      nicm       39:        .args = { "bdfhvp:l:s:t:", 0, 0 },
                     40:        .usage = "[-bdfhv] [-l size] " CMD_SRCDST_PANE_USAGE,
1.21      nicm       41:
1.32      nicm       42:        .source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
                     43:        .target = { 't', CMD_FIND_PANE, 0 },
1.22      nicm       44:
                     45:        .flags = 0,
1.21      nicm       46:        .exec = cmd_join_pane_exec
1.1       nicm       47: };
                     48:
1.8       nicm       49: const struct cmd_entry cmd_move_pane_entry = {
1.21      nicm       50:        .name = "move-pane",
                     51:        .alias = "movep",
                     52:
                     53:        .args = { "bdhvp:l:s:t:", 0, 0 },
1.39      nicm       54:        .usage = "[-bdhv] [-l size] " CMD_SRCDST_PANE_USAGE,
1.21      nicm       55:
1.38      nicm       56:        .source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
1.32      nicm       57:        .target = { 't', CMD_FIND_PANE, 0 },
1.22      nicm       58:
                     59:        .flags = 0,
1.21      nicm       60:        .exec = cmd_join_pane_exec
1.8       nicm       61: };
1.1       nicm       62:
1.26      nicm       63: static enum cmd_retval
1.29      nicm       64: cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
1.1       nicm       65: {
1.40    ! nicm       66:        struct args             *args = cmd_get_args(self);
1.31      nicm       67:        struct cmd_find_state   *current = &item->shared->current;
1.5       nicm       68:        struct session          *dst_s;
                     69:        struct winlink          *src_wl, *dst_wl;
                     70:        struct window           *src_w, *dst_w;
                     71:        struct window_pane      *src_wp, *dst_wp;
1.39      nicm       72:        char                    *cause = NULL;
1.36      nicm       73:        int                      size, percentage, dst_idx, not_same_window;
                     74:        int                      flags;
1.5       nicm       75:        enum layout_type         type;
                     76:        struct layout_cell      *lc;
1.26      nicm       77:
1.40    ! nicm       78:        if (cmd_get_entry(self) == &cmd_join_pane_entry)
1.26      nicm       79:                not_same_window = 1;
                     80:        else
                     81:                not_same_window = 0;
1.1       nicm       82:
1.32      nicm       83:        dst_s = item->target.s;
                     84:        dst_wl = item->target.wl;
                     85:        dst_wp = item->target.wp;
1.1       nicm       86:        dst_w = dst_wl->window;
1.3       nicm       87:        dst_idx = dst_wl->idx;
1.14      nicm       88:        server_unzoom_window(dst_w);
1.1       nicm       89:
1.32      nicm       90:        src_wl = item->source.wl;
                     91:        src_wp = item->source.wp;
1.1       nicm       92:        src_w = src_wl->window;
1.14      nicm       93:        server_unzoom_window(src_w);
1.1       nicm       94:
1.8       nicm       95:        if (not_same_window && src_w == dst_w) {
1.29      nicm       96:                cmdq_error(item, "can't join a pane to its own window");
1.12      nicm       97:                return (CMD_RETURN_ERROR);
1.1       nicm       98:        }
1.8       nicm       99:        if (!not_same_window && src_wp == dst_wp) {
1.29      nicm      100:                cmdq_error(item, "source and target panes must be different");
1.12      nicm      101:                return (CMD_RETURN_ERROR);
1.8       nicm      102:        }
1.1       nicm      103:
                    104:        type = LAYOUT_TOPBOTTOM;
1.5       nicm      105:        if (args_has(args, 'h'))
1.1       nicm      106:                type = LAYOUT_LEFTRIGHT;
                    107:
                    108:        size = -1;
1.39      nicm      109:        if (args_has(args, 'l')) {
                    110:                if (type == LAYOUT_TOPBOTTOM) {
                    111:                        size = args_percentage(args, 'l', 0, INT_MAX,
                    112:                            dst_wp->sy, &cause);
                    113:                } else {
                    114:                        size = args_percentage(args, 'l', 0, INT_MAX,
                    115:                            dst_wp->sx, &cause);
                    116:                }
                    117:        } else if (args_has(args, 'p')) {
                    118:                percentage = args_strtonum(args, 'p', 0, 100, &cause);
                    119:                if (cause == NULL) {
1.36      nicm      120:                        if (type == LAYOUT_TOPBOTTOM)
                    121:                                size = (dst_wp->sy * percentage) / 100;
                    122:                        else
                    123:                                size = (dst_wp->sx * percentage) / 100;
1.5       nicm      124:                }
1.39      nicm      125:        }
                    126:        if (cause != NULL) {
                    127:                cmdq_error(item, "size %s", cause);
                    128:                free(cause);
                    129:                return (CMD_RETURN_ERROR);
1.1       nicm      130:        }
1.37      nicm      131:
                    132:        flags = 0;
1.34      nicm      133:        if (args_has(args, 'b'))
1.37      nicm      134:                flags |= SPAWN_BEFORE;
                    135:        if (args_has(args, 'f'))
                    136:                flags |= SPAWN_FULLSIZE;
                    137:
1.34      nicm      138:        lc = layout_split_pane(dst_wp, type, size, flags);
1.8       nicm      139:        if (lc == NULL) {
1.29      nicm      140:                cmdq_error(item, "create pane failed: pane too small");
1.12      nicm      141:                return (CMD_RETURN_ERROR);
1.1       nicm      142:        }
                    143:
                    144:        layout_close_pane(src_wp);
                    145:
1.16      nicm      146:        window_lost_pane(src_w, src_wp);
1.1       nicm      147:        TAILQ_REMOVE(&src_w->panes, src_wp, entry);
                    148:
                    149:        src_wp->window = dst_w;
1.35      nicm      150:        options_set_parent(src_wp->options, dst_w->options);
                    151:        src_wp->flags |= PANE_STYLECHANGED;
1.1       nicm      152:        TAILQ_INSERT_AFTER(&dst_w->panes, dst_wp, src_wp, entry);
                    153:        layout_assign_pane(lc, src_wp);
                    154:
                    155:        recalculate_sizes();
                    156:
                    157:        server_redraw_window(src_w);
                    158:        server_redraw_window(dst_w);
                    159:
1.5       nicm      160:        if (!args_has(args, 'd')) {
1.34      nicm      161:                window_set_active_pane(dst_w, src_wp, 1);
1.3       nicm      162:                session_select(dst_s, dst_idx);
1.33      nicm      163:                cmd_find_from_session(current, dst_s, 0);
1.1       nicm      164:                server_redraw_session(dst_s);
                    165:        } else
                    166:                server_status_session(dst_s);
                    167:
1.24      nicm      168:        if (window_count_panes(src_w) == 0)
                    169:                server_kill_window(src_w);
                    170:        else
1.30      nicm      171:                notify_window("window-layout-changed", src_w);
                    172:        notify_window("window-layout-changed", dst_w);
1.24      nicm      173:
1.12      nicm      174:        return (CMD_RETURN_NORMAL);
1.1       nicm      175: }