1 |
|
|
/* $OpenBSD: cmd-rotate-window.c,v 1.19 2016/01/19 15:59:12 nicm Exp $ */ |
2 |
|
|
|
3 |
|
|
/* |
4 |
|
|
* Copyright (c) 2009 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 "tmux.h" |
22 |
|
|
|
23 |
|
|
/* |
24 |
|
|
* Rotate the panes in a window. |
25 |
|
|
*/ |
26 |
|
|
|
27 |
|
|
enum cmd_retval cmd_rotate_window_exec(struct cmd *, struct cmd_q *); |
28 |
|
|
|
29 |
|
|
const struct cmd_entry cmd_rotate_window_entry = { |
30 |
|
|
.name = "rotate-window", |
31 |
|
|
.alias = "rotatew", |
32 |
|
|
|
33 |
|
|
.args = { "Dt:U", 0, 0 }, |
34 |
|
|
.usage = "[-DU] " CMD_TARGET_WINDOW_USAGE, |
35 |
|
|
|
36 |
|
|
.tflag = CMD_WINDOW, |
37 |
|
|
|
38 |
|
|
.flags = 0, |
39 |
|
|
.exec = cmd_rotate_window_exec |
40 |
|
|
}; |
41 |
|
|
|
42 |
|
|
enum cmd_retval |
43 |
|
|
cmd_rotate_window_exec(struct cmd *self, struct cmd_q *cmdq) |
44 |
|
|
{ |
45 |
|
|
struct winlink *wl = cmdq->state.tflag.wl; |
46 |
|
|
struct window *w = wl->window; |
47 |
|
|
struct window_pane *wp, *wp2; |
48 |
|
|
struct layout_cell *lc; |
49 |
|
|
u_int sx, sy, xoff, yoff; |
50 |
|
|
|
51 |
|
|
if (args_has(self->args, 'D')) { |
52 |
|
|
wp = TAILQ_LAST(&w->panes, window_panes); |
53 |
|
|
TAILQ_REMOVE(&w->panes, wp, entry); |
54 |
|
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry); |
55 |
|
|
|
56 |
|
|
lc = wp->layout_cell; |
57 |
|
|
xoff = wp->xoff; yoff = wp->yoff; |
58 |
|
|
sx = wp->sx; sy = wp->sy; |
59 |
|
|
TAILQ_FOREACH(wp, &w->panes, entry) { |
60 |
|
|
if ((wp2 = TAILQ_NEXT(wp, entry)) == NULL) |
61 |
|
|
break; |
62 |
|
|
wp->layout_cell = wp2->layout_cell; |
63 |
|
|
if (wp->layout_cell != NULL) |
64 |
|
|
wp->layout_cell->wp = wp; |
65 |
|
|
wp->xoff = wp2->xoff; wp->yoff = wp2->yoff; |
66 |
|
|
window_pane_resize(wp, wp2->sx, wp2->sy); |
67 |
|
|
} |
68 |
|
|
wp->layout_cell = lc; |
69 |
|
|
if (wp->layout_cell != NULL) |
70 |
|
|
wp->layout_cell->wp = wp; |
71 |
|
|
wp->xoff = xoff; wp->yoff = yoff; |
72 |
|
|
window_pane_resize(wp, sx, sy); |
73 |
|
|
|
74 |
|
|
if ((wp = TAILQ_PREV(w->active, window_panes, entry)) == NULL) |
75 |
|
|
wp = TAILQ_LAST(&w->panes, window_panes); |
76 |
|
|
window_set_active_pane(w, wp); |
77 |
|
|
server_redraw_window(w); |
78 |
|
|
} else { |
79 |
|
|
wp = TAILQ_FIRST(&w->panes); |
80 |
|
|
TAILQ_REMOVE(&w->panes, wp, entry); |
81 |
|
|
TAILQ_INSERT_TAIL(&w->panes, wp, entry); |
82 |
|
|
|
83 |
|
|
lc = wp->layout_cell; |
84 |
|
|
xoff = wp->xoff; yoff = wp->yoff; |
85 |
|
|
sx = wp->sx; sy = wp->sy; |
86 |
|
|
TAILQ_FOREACH_REVERSE(wp, &w->panes, window_panes, entry) { |
87 |
|
|
if ((wp2 = TAILQ_PREV(wp, window_panes, entry)) == NULL) |
88 |
|
|
break; |
89 |
|
|
wp->layout_cell = wp2->layout_cell; |
90 |
|
|
if (wp->layout_cell != NULL) |
91 |
|
|
wp->layout_cell->wp = wp; |
92 |
|
|
wp->xoff = wp2->xoff; wp->yoff = wp2->yoff; |
93 |
|
|
window_pane_resize(wp, wp2->sx, wp2->sy); |
94 |
|
|
} |
95 |
|
|
wp->layout_cell = lc; |
96 |
|
|
if (wp->layout_cell != NULL) |
97 |
|
|
wp->layout_cell->wp = wp; |
98 |
|
|
wp->xoff = xoff; wp->yoff = yoff; |
99 |
|
|
window_pane_resize(wp, sx, sy); |
100 |
|
|
|
101 |
|
|
if ((wp = TAILQ_NEXT(w->active, entry)) == NULL) |
102 |
|
|
wp = TAILQ_FIRST(&w->panes); |
103 |
|
|
window_set_active_pane(w, wp); |
104 |
|
|
server_redraw_window(w); |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
return (CMD_RETURN_NORMAL); |
108 |
|
|
} |