4 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
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.
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.
19 #include <sys/types.h>
24 * Rotate the panes in a window.
27 void cmd_rotate_window_key_binding(struct cmd
*, int);
28 int cmd_rotate_window_exec(struct cmd
*, struct cmd_ctx
*);
30 const struct cmd_entry cmd_rotate_window_entry
= {
31 "rotate-window", "rotatew",
33 "[-DU] " CMD_TARGET_WINDOW_USAGE
,
35 cmd_rotate_window_key_binding
,
37 cmd_rotate_window_exec
41 cmd_rotate_window_key_binding(struct cmd
*self
, int key
)
43 self
->args
= args_create(0);
44 if (key
== ('o' | KEYC_ESCAPE
))
45 args_set(self
->args
, 'D', NULL
);
49 cmd_rotate_window_exec(struct cmd
*self
, struct cmd_ctx
*ctx
)
51 struct args
*args
= self
->args
;
54 struct window_pane
*wp
, *wp2
;
55 struct layout_cell
*lc
;
56 u_int sx
, sy
, xoff
, yoff
;
58 if ((wl
= cmd_find_window(ctx
, args_get(args
, 't'), NULL
)) == NULL
)
62 if (args_has(self
->args
, 'D')) {
63 wp
= TAILQ_LAST(&w
->panes
, window_panes
);
64 TAILQ_REMOVE(&w
->panes
, wp
, entry
);
65 TAILQ_INSERT_HEAD(&w
->panes
, wp
, entry
);
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
)
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
);
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
);
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
);
90 wp
= TAILQ_FIRST(&w
->panes
);
91 TAILQ_REMOVE(&w
->panes
, wp
, entry
);
92 TAILQ_INSERT_TAIL(&w
->panes
, wp
, entry
);
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
)
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
);
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
);
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
);