Annotation of src/usr.bin/tmux/cmd-link-window.c, Revision 1.5
1.5 ! nicm 1: /* $OpenBSD: cmd-link-window.c,v 1.4 2009/07/26 12:58:44 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_free,
39: cmd_srcdst_print
40: };
41:
42: int
43: cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
44: {
45: struct cmd_srcdst_data *data = self->data;
46: struct session *dst;
47: struct winlink *wl_src, *wl_dst;
48: char *cause;
49: int idx;
50:
51: if ((wl_src = cmd_find_window(ctx, data->src, NULL)) == NULL)
52: return (-1);
1.2 nicm 53: if ((idx = cmd_find_index(ctx, data->dst, &dst)) == -2)
1.1 nicm 54: return (-1);
55:
56: wl_dst = NULL;
57: if (idx != -1)
58: wl_dst = winlink_find_by_index(&dst->windows, idx);
59: if (wl_dst != NULL) {
60: if (wl_dst->window == wl_src->window)
61: return (0);
62:
1.3 nicm 63: if (data->chflags & CMD_CHFLAG('k')) {
1.1 nicm 64: /*
65: * Can't use session_detach as it will destroy session
66: * if this makes it empty.
67: */
68: session_alert_cancel(dst, wl_dst);
69: winlink_stack_remove(&dst->lastw, wl_dst);
70: winlink_remove(&dst->windows, wl_dst);
71:
72: /* Force select/redraw if current. */
73: if (wl_dst == dst->curw) {
1.3 nicm 74: data->chflags &= ~CMD_CHFLAG('d');
1.1 nicm 75: dst->curw = NULL;
76: }
77: }
78: }
79:
1.5 ! nicm 80: if (idx == -1)
! 81: idx = -1 - options_get_number(&dst->options, "base-index");
1.1 nicm 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: }