Annotation of src/usr.bin/tmux/cmd-move-window.c, Revision 1.31
1.31 ! nicm 1: /* $OpenBSD: cmd-move-window.c,v 1.30 2020/04/13 08:26:27 nicm Exp $ */
1.1 nicm 2:
3: /*
1.25 nicm 4: * Copyright (c) 2008 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: * Move a window.
27: */
28:
1.28 nicm 29: static enum cmd_retval cmd_move_window_exec(struct cmd *, struct cmdq_item *);
1.1 nicm 30:
31: const struct cmd_entry cmd_move_window_entry = {
1.23 nicm 32: .name = "move-window",
33: .alias = "movew",
34:
35: .args = { "adkrs:t:", 0, 0 },
36: .usage = "[-dkr] " CMD_SRCDST_WINDOW_USAGE,
37:
1.29 nicm 38: .source = { 's', CMD_FIND_WINDOW, 0 },
39: /* -t is special */
1.24 nicm 40:
41: .flags = 0,
1.23 nicm 42: .exec = cmd_move_window_exec
1.1 nicm 43: };
44:
1.18 nicm 45: const struct cmd_entry cmd_link_window_entry = {
1.23 nicm 46: .name = "link-window",
47: .alias = "linkw",
48:
49: .args = { "adks:t:", 0, 0 },
50: .usage = "[-dk] " CMD_SRCDST_WINDOW_USAGE,
51:
1.29 nicm 52: .source = { 's', CMD_FIND_WINDOW, 0 },
53: /* -t is special */
1.24 nicm 54:
55: .flags = 0,
1.23 nicm 56: .exec = cmd_move_window_exec
1.18 nicm 57: };
58:
1.27 nicm 59: static enum cmd_retval
1.28 nicm 60: cmd_move_window_exec(struct cmd *self, struct cmdq_item *item)
1.1 nicm 61: {
1.31 ! nicm 62: struct args *args = cmd_get_args(self);
! 63: struct cmd_find_state *source = cmdq_get_source(item);
! 64: struct cmd_find_state target;
! 65: const char *tflag = args_get(args, 't');
! 66: struct session *src;
! 67: struct session *dst;
! 68: struct winlink *wl;
! 69: char *cause;
! 70: int idx, kflag, dflag, sflag;
1.11 nicm 71:
1.12 nicm 72: if (args_has(args, 'r')) {
1.31 ! nicm 73: if (cmd_find_target(&target, item, tflag, CMD_FIND_SESSION,
! 74: CMD_FIND_QUIET) != 0)
1.29 nicm 75: return (CMD_RETURN_ERROR);
76:
1.31 ! nicm 77: session_renumber_windows(target.s);
1.11 nicm 78: recalculate_sizes();
1.31 ! nicm 79: server_status_session(target.s);
1.11 nicm 80:
1.14 nicm 81: return (CMD_RETURN_NORMAL);
1.11 nicm 82: }
1.31 ! nicm 83: if (cmd_find_target(&target, item, tflag, CMD_FIND_WINDOW,
1.29 nicm 84: CMD_FIND_WINDOW_INDEX) != 0)
85: return (CMD_RETURN_ERROR);
1.31 ! nicm 86: src = source->s;
! 87: dst = target.s;
! 88: wl = source->wl;
! 89: idx = target.idx;
1.1 nicm 90:
1.30 nicm 91: kflag = args_has(args, 'k');
92: dflag = args_has(args, 'd');
93: sflag = args_has(args, 's');
1.20 nicm 94:
1.30 nicm 95: if (args_has(args, 'a')) {
1.22 nicm 96: if ((idx = winlink_shuffle_up(dst, dst->curw)) == -1)
1.20 nicm 97: return (CMD_RETURN_ERROR);
98: }
99:
1.31 ! nicm 100: if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
1.28 nicm 101: cmdq_error(item, "can't link window: %s", cause);
1.13 nicm 102: free(cause);
1.14 nicm 103: return (CMD_RETURN_ERROR);
1.1 nicm 104: }
1.30 nicm 105: if (cmd_get_entry(self) == &cmd_move_window_entry)
1.18 nicm 106: server_unlink_window(src, wl);
1.19 nicm 107:
108: /*
109: * Renumber the winlinks in the src session only, the destination
110: * session already has the correct winlink id to us, either
111: * automatically or specified by -s.
112: */
1.21 nicm 113: if (!sflag && options_get_number(src->options, "renumber-windows"))
1.19 nicm 114: session_renumber_windows(src);
115:
1.1 nicm 116: recalculate_sizes();
117:
1.14 nicm 118: return (CMD_RETURN_NORMAL);
1.1 nicm 119: }