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

Annotation of src/usr.bin/tmux/cmd-link-window.c, Revision 1.3

1.3     ! nicm        1: /* $OpenBSD: cmd-link-window.c,v 1.2 2009/07/13 17:47:46 nicm Exp $ */
1.1       nicm        2:
                      3: /*
                      4:  * Copyright (c) 2007 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:  * Link a window into another session.
                     27:  */
                     28:
                     29: int    cmd_link_window_exec(struct cmd *, struct cmd_ctx *);
                     30:
                     31: const struct cmd_entry cmd_link_window_entry = {
                     32:        "link-window", "linkw",
                     33:        "[-dk] " CMD_SRCDST_WINDOW_USAGE,
1.3     ! nicm       34:        0, CMD_CHFLAG('d')|CMD_CHFLAG('k'),
1.1       nicm       35:        cmd_srcdst_init,
                     36:        cmd_srcdst_parse,
                     37:        cmd_link_window_exec,
                     38:        cmd_srcdst_send,
                     39:        cmd_srcdst_recv,
                     40:        cmd_srcdst_free,
                     41:        cmd_srcdst_print
                     42: };
                     43:
                     44: int
                     45: cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
                     46: {
                     47:        struct cmd_srcdst_data  *data = self->data;
                     48:        struct session          *dst;
                     49:        struct winlink          *wl_src, *wl_dst;
                     50:        char                    *cause;
                     51:        int                      idx;
                     52:
                     53:        if ((wl_src = cmd_find_window(ctx, data->src, NULL)) == NULL)
                     54:                return (-1);
1.2       nicm       55:        if ((idx = cmd_find_index(ctx, data->dst, &dst)) == -2)
1.1       nicm       56:                return (-1);
                     57:
                     58:        wl_dst = NULL;
                     59:        if (idx != -1)
                     60:                wl_dst = winlink_find_by_index(&dst->windows, idx);
                     61:        if (wl_dst != NULL) {
                     62:                if (wl_dst->window == wl_src->window)
                     63:                        return (0);
                     64:
1.3     ! nicm       65:                if (data->chflags & CMD_CHFLAG('k')) {
1.1       nicm       66:                        /*
                     67:                         * Can't use session_detach as it will destroy session
                     68:                         * if this makes it empty.
                     69:                         */
                     70:                        session_alert_cancel(dst, wl_dst);
                     71:                        winlink_stack_remove(&dst->lastw, wl_dst);
                     72:                        winlink_remove(&dst->windows, wl_dst);
                     73:
                     74:                        /* Force select/redraw if current. */
                     75:                        if (wl_dst == dst->curw) {
1.3     ! nicm       76:                                data->chflags &= ~CMD_CHFLAG('d');
1.1       nicm       77:                                dst->curw = NULL;
                     78:                        }
                     79:                }
                     80:        }
                     81:
                     82:        wl_dst = session_attach(dst, wl_src->window, idx, &cause);
                     83:        if (wl_dst == NULL) {
                     84:                ctx->error(ctx, "create session failed: %s", cause);
                     85:                xfree(cause);
                     86:                return (-1);
                     87:        }
                     88:
1.3     ! nicm       89:        if (data->chflags & CMD_CHFLAG('d'))
1.1       nicm       90:                server_status_session(dst);
                     91:        else {
                     92:                session_select(dst, wl_dst->idx);
                     93:                server_redraw_session(dst);
                     94:        }
                     95:        recalculate_sizes();
                     96:
                     97:        return (0);
                     98: }