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 enum cmd_retval
cmd_rotate_window_exec(struct cmd
*, struct cmd_q
*);
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
,
36 cmd_rotate_window_exec
40 cmd_rotate_window_key_binding(struct cmd
*self
, int key
)
42 self
->args
= args_create(0);
43 if (key
== ('o' | KEYC_ESCAPE
))
44 args_set(self
->args
, 'D', NULL
);
48 cmd_rotate_window_exec(struct cmd
*self
, struct cmd_q
*cmdq
)
50 struct args
*args
= self
->args
;
53 struct window_pane
*wp
, *wp2
;
54 struct layout_cell
*lc
;
55 u_int sx
, sy
, xoff
, yoff
;
57 if ((wl
= cmd_find_window(cmdq
, args_get(args
, 't'), NULL
)) == NULL
)
58 return (CMD_RETURN_ERROR
);
61 if (args_has(self
->args
, 'D')) {
62 wp
= TAILQ_LAST(&w
->panes
, window_panes
);
63 TAILQ_REMOVE(&w
->panes
, wp
, entry
);
64 TAILQ_INSERT_HEAD(&w
->panes
, wp
, entry
);
67 xoff
= wp
->xoff
; yoff
= wp
->yoff
;
68 sx
= wp
->sx
; sy
= wp
->sy
;
69 TAILQ_FOREACH(wp
, &w
->panes
, entry
) {
70 if ((wp2
= TAILQ_NEXT(wp
, entry
)) == NULL
)
72 wp
->layout_cell
= wp2
->layout_cell
;
73 if (wp
->layout_cell
!= NULL
)
74 wp
->layout_cell
->wp
= wp
;
75 wp
->xoff
= wp2
->xoff
; wp
->yoff
= wp2
->yoff
;
76 window_pane_resize(wp
, wp2
->sx
, wp2
->sy
);
79 if (wp
->layout_cell
!= NULL
)
80 wp
->layout_cell
->wp
= wp
;
81 wp
->xoff
= xoff
; wp
->yoff
= yoff
;
82 window_pane_resize(wp
, sx
, sy
);
84 if ((wp
= TAILQ_PREV(w
->active
, window_panes
, entry
)) == NULL
)
85 wp
= TAILQ_LAST(&w
->panes
, window_panes
);
86 window_set_active_pane(w
, wp
);
87 server_redraw_window(w
);
89 wp
= TAILQ_FIRST(&w
->panes
);
90 TAILQ_REMOVE(&w
->panes
, wp
, entry
);
91 TAILQ_INSERT_TAIL(&w
->panes
, wp
, entry
);
94 xoff
= wp
->xoff
; yoff
= wp
->yoff
;
95 sx
= wp
->sx
; sy
= wp
->sy
;
96 TAILQ_FOREACH_REVERSE(wp
, &w
->panes
, window_panes
, entry
) {
97 if ((wp2
= TAILQ_PREV(wp
, window_panes
, entry
)) == NULL
)
99 wp
->layout_cell
= wp2
->layout_cell
;
100 if (wp
->layout_cell
!= NULL
)
101 wp
->layout_cell
->wp
= wp
;
102 wp
->xoff
= wp2
->xoff
; wp
->yoff
= wp2
->yoff
;
103 window_pane_resize(wp
, wp2
->sx
, wp2
->sy
);
105 wp
->layout_cell
= lc
;
106 if (wp
->layout_cell
!= NULL
)
107 wp
->layout_cell
->wp
= wp
;
108 wp
->xoff
= xoff
; wp
->yoff
= yoff
;
109 window_pane_resize(wp
, sx
, sy
);
111 if ((wp
= TAILQ_NEXT(w
->active
, entry
)) == NULL
)
112 wp
= TAILQ_FIRST(&w
->panes
);
113 window_set_active_pane(w
, wp
);
114 server_redraw_window(w
);
117 return (CMD_RETURN_NORMAL
);