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

Annotation of src/usr.bin/tmux/cmd-break-pane.c, Revision 1.60

1.60    ! nicm        1: /* $OpenBSD: cmd-break-pane.c,v 1.59 2020/06/13 09:05:53 nicm Exp $ */
1.1       nicm        2:
                      3: /*
1.36      nicm        4:  * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
1.1       nicm        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.40      nicm       31: static enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmdq_item *);
1.1       nicm       32:
                     33: const struct cmd_entry cmd_break_pane_entry = {
1.34      nicm       34:        .name = "break-pane",
                     35:        .alias = "breakp",
                     36:
1.60    ! nicm       37:        .args = { "abdPF:n:s:t:", 0, 0, NULL },
1.59      nicm       38:        .usage = "[-abdP] [-F format] [-n window-name] [-s src-pane] "
1.45      nicm       39:                 "[-t dst-window]",
1.34      nicm       40:
1.45      nicm       41:        .source = { 's', CMD_FIND_PANE, 0 },
                     42:        .target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX },
1.35      nicm       43:
                     44:        .flags = 0,
1.34      nicm       45:        .exec = cmd_break_pane_exec
1.1       nicm       46: };
                     47:
1.38      nicm       48: static enum cmd_retval
1.40      nicm       49: cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
1.1       nicm       50: {
1.51      nicm       51:        struct args             *args = cmd_get_args(self);
1.54      nicm       52:        struct cmd_find_state   *current = cmdq_get_current(item);
1.52      nicm       53:        struct cmd_find_state   *target = cmdq_get_target(item);
                     54:        struct cmd_find_state   *source = cmdq_get_source(item);
1.55      nicm       55:        struct client           *tc = cmdq_get_target_client(item);
1.52      nicm       56:        struct winlink          *wl = source->wl;
                     57:        struct session          *src_s = source->s;
                     58:        struct session          *dst_s = target->s;
                     59:        struct window_pane      *wp = source->wp;
1.33      nicm       60:        struct window           *w = wl->window;
1.59      nicm       61:        char                    *name, *cause, *cp;
                     62:        int                      idx = target->idx, before;
1.13      nicm       63:        const char              *template;
1.1       nicm       64:
1.59      nicm       65:        before = args_has(args, 'b');
                     66:        if (args_has(args, 'a') || before) {
1.56      nicm       67:                if (target->wl != NULL)
1.59      nicm       68:                        idx = winlink_shuffle_up(dst_s, target->wl, before);
1.56      nicm       69:                else
1.59      nicm       70:                        idx = winlink_shuffle_up(dst_s, dst_s->curw, before);
1.56      nicm       71:                if (idx == -1)
                     72:                        return (CMD_RETURN_ERROR);
1.27      nicm       73:        }
1.56      nicm       74:        server_unzoom_window(w);
1.1       nicm       75:
1.28      nicm       76:        if (window_count_panes(w) == 1) {
1.56      nicm       77:                if (server_link_window(src_s, wl, dst_s, idx, 0,
                     78:                    !args_has(args, 'd'), &cause) != 0) {
                     79:                        cmdq_error(item, "%s", cause);
                     80:                        free(cause);
                     81:                        return (CMD_RETURN_ERROR);
1.58      nicm       82:                }
                     83:                if (args_has(args, 'n')) {
                     84:                        window_set_name(w, args_get(args, 'n'));
                     85:                        options_set_number(w->options, "automatic-rename", 0);
1.56      nicm       86:                }
                     87:                server_unlink_window(src_s, wl);
                     88:                return (CMD_RETURN_NORMAL);
                     89:        }
                     90:        if (idx != -1 && winlink_find_by_index(&dst_s->windows, idx) != NULL) {
                     91:                cmdq_error(item, "index in use: %d", idx);
1.16      nicm       92:                return (CMD_RETURN_ERROR);
1.1       nicm       93:        }
1.21      nicm       94:
1.11      nicm       95:        TAILQ_REMOVE(&w->panes, wp, entry);
1.57      nicm       96:        server_client_remove_pane(wp);
1.23      nicm       97:        window_lost_pane(w, wp);
1.9       nicm       98:        layout_close_pane(wp);
1.1       nicm       99:
1.50      nicm      100:        w = wp->window = window_create(w->sx, w->sy, w->xpixel, w->ypixel);
1.48      nicm      101:        options_set_parent(wp->options, w->options);
                    102:        wp->flags |= PANE_STYLECHANGED;
1.9       nicm      103:        TAILQ_INSERT_HEAD(&w->panes, wp, entry);
                    104:        w->active = wp;
1.55      nicm      105:        w->latest = tc;
1.41      nicm      106:
                    107:        if (!args_has(args, 'n')) {
                    108:                name = default_window_name(w);
                    109:                window_set_name(w, name);
                    110:                free(name);
                    111:        } else {
                    112:                window_set_name(w, args_get(args, 'n'));
                    113:                options_set_number(w->options, "automatic-rename", 0);
                    114:        }
                    115:
1.21      nicm      116:        layout_init(w, wp);
1.30      nicm      117:        wp->flags |= PANE_CHANGED;
1.1       nicm      118:
1.27      nicm      119:        if (idx == -1)
1.29      nicm      120:                idx = -1 - options_get_number(dst_s->options, "base-index");
1.28      nicm      121:        wl = session_attach(dst_s, w, idx, &cause); /* can't fail */
1.51      nicm      122:        if (!args_has(args, 'd')) {
1.28      nicm      123:                session_select(dst_s, wl->idx);
1.46      nicm      124:                cmd_find_from_session(current, dst_s, 0);
1.44      nicm      125:        }
1.1       nicm      126:
1.28      nicm      127:        server_redraw_session(src_s);
                    128:        if (src_s != dst_s)
                    129:                server_redraw_session(dst_s);
                    130:        server_status_session_group(src_s);
                    131:        if (src_s != dst_s)
                    132:                server_status_session_group(dst_s);
1.1       nicm      133:
1.13      nicm      134:        if (args_has(args, 'P')) {
1.14      nicm      135:                if ((template = args_get(args, 'F')) == NULL)
1.17      nicm      136:                        template = BREAK_PANE_TEMPLATE;
1.55      nicm      137:                cp = format_single(item, template, tc, dst_s, wl, wp);
1.40      nicm      138:                cmdq_print(item, "%s", cp);
1.15      nicm      139:                free(cp);
1.13      nicm      140:        }
1.16      nicm      141:        return (CMD_RETURN_NORMAL);
1.1       nicm      142: }