Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 120 lines (104 sloc) 3.503 kB
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
1 /* $Id: cmd-rotate-window.c 2553 2011-07-09 09:42:33Z tcunha $ */
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
2
3 /*
4 * Copyright (c) 2009 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 "tmux.h"
22
23 /*
24 * Rotate the panes in a window.
25 */
26
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
27 void cmd_rotate_window_key_binding(struct cmd *, int);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
28 int cmd_rotate_window_exec(struct cmd *, struct cmd_ctx *);
29
30 const struct cmd_entry cmd_rotate_window_entry = {
31 "rotate-window", "rotatew",
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
32 "Dt:U", 0, 0,
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
33 "[-DU] " CMD_TARGET_WINDOW_USAGE,
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
34 0,
35 cmd_rotate_window_key_binding,
36 NULL,
37 cmd_rotate_window_exec
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
38 };
39
40 void
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
41 cmd_rotate_window_key_binding(struct cmd *self, int key)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
42 {
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
43 self->args = args_create(0);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
44 if (key == ('o' | KEYC_ESCAPE))
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
45 args_set(self->args, 'D', NULL);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
46 }
47
48 int
49 cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
50 {
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
51 struct args *args = self->args;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
52 struct winlink *wl;
53 struct window *w;
54 struct window_pane *wp, *wp2;
55 struct layout_cell *lc;
56 u_int sx, sy, xoff, yoff;
57
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
58 if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
59 return (-1);
60 w = wl->window;
61
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
62 if (args_has(self->args, 'D')) {
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
63 wp = TAILQ_LAST(&w->panes, window_panes);
64 TAILQ_REMOVE(&w->panes, wp, entry);
65 TAILQ_INSERT_HEAD(&w->panes, wp, entry);
66
67 lc = wp->layout_cell;
68 xoff = wp->xoff; yoff = wp->yoff;
69 sx = wp->sx; sy = wp->sy;
70 TAILQ_FOREACH(wp, &w->panes, entry) {
71 if ((wp2 = TAILQ_NEXT(wp, entry)) == NULL)
72 break;
73 wp->layout_cell = wp2->layout_cell;
74 if (wp->layout_cell != NULL)
75 wp->layout_cell->wp = wp;
76 wp->xoff = wp2->xoff; wp->yoff = wp2->yoff;
77 window_pane_resize(wp, wp2->sx, wp2->sy);
78 }
79 wp->layout_cell = lc;
80 if (wp->layout_cell != NULL)
81 wp->layout_cell->wp = wp;
82 wp->xoff = xoff; wp->yoff = yoff;
83 window_pane_resize(wp, sx, sy);
84
85 if ((wp = TAILQ_PREV(w->active, window_panes, entry)) == NULL)
86 wp = TAILQ_LAST(&w->panes, window_panes);
87 window_set_active_pane(w, wp);
88 server_redraw_window(w);
89 } else {
90 wp = TAILQ_FIRST(&w->panes);
91 TAILQ_REMOVE(&w->panes, wp, entry);
92 TAILQ_INSERT_TAIL(&w->panes, wp, entry);
93
94 lc = wp->layout_cell;
95 xoff = wp->xoff; yoff = wp->yoff;
96 sx = wp->sx; sy = wp->sy;
97 TAILQ_FOREACH_REVERSE(wp, &w->panes, window_panes, entry) {
98 if ((wp2 = TAILQ_PREV(wp, window_panes, entry)) == NULL)
99 break;
100 wp->layout_cell = wp2->layout_cell;
101 if (wp->layout_cell != NULL)
102 wp->layout_cell->wp = wp;
103 wp->xoff = wp2->xoff; wp->yoff = wp2->yoff;
104 window_pane_resize(wp, wp2->sx, wp2->sy);
105 }
106 wp->layout_cell = lc;
107 if (wp->layout_cell != NULL)
108 wp->layout_cell->wp = wp;
109 wp->xoff = xoff; wp->yoff = yoff;
110 window_pane_resize(wp, sx, sy);
111
112 if ((wp = TAILQ_NEXT(w->active, entry)) == NULL)
113 wp = TAILQ_FIRST(&w->panes);
114 window_set_active_pane(w, wp);
115 server_redraw_window(w);
116 }
117
118 return (0);
119 }
Something went wrong with that request. Please try again.