GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.bin/tmux/cmd-move-window.c Lines: 0 35 0.0 %
Date: 2017-11-13 Branches: 0 18 0.0 %

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