Annotation of src/usr.bin/tmux/cmd-rotate-window.c, Revision 1.29
1.29 ! nicm 1: /* $OpenBSD: cmd-rotate-window.c,v 1.28 2020/04/13 08:26:27 nicm Exp $ */
1.1 nicm 2:
3: /*
1.19 nicm 4: * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
1.1 nicm 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:
1.21 nicm 27: static enum cmd_retval cmd_rotate_window_exec(struct cmd *,
28: struct cmdq_item *);
1.1 nicm 29:
30: const struct cmd_entry cmd_rotate_window_entry = {
1.17 nicm 31: .name = "rotate-window",
32: .alias = "rotatew",
33:
1.27 nicm 34: .args = { "Dt:UZ", 0, 0 },
35: .usage = "[-DUZ] " CMD_TARGET_WINDOW_USAGE,
1.17 nicm 36:
1.23 nicm 37: .target = { 't', CMD_FIND_WINDOW, 0 },
1.18 nicm 38:
39: .flags = 0,
1.17 nicm 40: .exec = cmd_rotate_window_exec
1.1 nicm 41: };
42:
1.20 nicm 43: static enum cmd_retval
1.21 nicm 44: cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
1.1 nicm 45: {
1.28 nicm 46: struct args *args = cmd_get_args(self);
1.29 ! nicm 47: struct cmdq_shared *shared = cmdq_get_shared(item);
! 48: struct cmd_find_state *current = &shared->current;
! 49: struct cmd_find_state *target = cmdq_get_target(item);
! 50: struct winlink *wl = target->wl;
1.16 nicm 51: struct window *w = wl->window;
1.1 nicm 52: struct window_pane *wp, *wp2;
1.7 nicm 53: struct layout_cell *lc;
1.1 nicm 54: u_int sx, sy, xoff, yoff;
1.22 nicm 55:
1.28 nicm 56: window_push_zoom(w, args_has(args, 'Z'));
1.1 nicm 57:
1.28 nicm 58: if (args_has(args, 'D')) {
1.1 nicm 59: wp = TAILQ_LAST(&w->panes, window_panes);
60: TAILQ_REMOVE(&w->panes, wp, entry);
61: TAILQ_INSERT_HEAD(&w->panes, wp, entry);
62:
1.7 nicm 63: lc = wp->layout_cell;
1.1 nicm 64: xoff = wp->xoff; yoff = wp->yoff;
1.3 ray 65: sx = wp->sx; sy = wp->sy;
1.1 nicm 66: TAILQ_FOREACH(wp, &w->panes, entry) {
67: if ((wp2 = TAILQ_NEXT(wp, entry)) == NULL)
68: break;
1.7 nicm 69: wp->layout_cell = wp2->layout_cell;
70: if (wp->layout_cell != NULL)
71: wp->layout_cell->wp = wp;
1.1 nicm 72: wp->xoff = wp2->xoff; wp->yoff = wp2->yoff;
73: window_pane_resize(wp, wp2->sx, wp2->sy);
74: }
1.7 nicm 75: wp->layout_cell = lc;
76: if (wp->layout_cell != NULL)
77: wp->layout_cell->wp = wp;
1.1 nicm 78: wp->xoff = xoff; wp->yoff = yoff;
79: window_pane_resize(wp, sx, sy);
80:
81: if ((wp = TAILQ_PREV(w->active, window_panes, entry)) == NULL)
82: wp = TAILQ_LAST(&w->panes, window_panes);
83: } else {
84: wp = TAILQ_FIRST(&w->panes);
85: TAILQ_REMOVE(&w->panes, wp, entry);
86: TAILQ_INSERT_TAIL(&w->panes, wp, entry);
87:
1.7 nicm 88: lc = wp->layout_cell;
1.1 nicm 89: xoff = wp->xoff; yoff = wp->yoff;
90: sx = wp->sx; sy = wp->sy;
91: TAILQ_FOREACH_REVERSE(wp, &w->panes, window_panes, entry) {
92: if ((wp2 = TAILQ_PREV(wp, window_panes, entry)) == NULL)
93: break;
1.7 nicm 94: wp->layout_cell = wp2->layout_cell;
95: if (wp->layout_cell != NULL)
96: wp->layout_cell->wp = wp;
1.1 nicm 97: wp->xoff = wp2->xoff; wp->yoff = wp2->yoff;
98: window_pane_resize(wp, wp2->sx, wp2->sy);
99: }
1.7 nicm 100: wp->layout_cell = lc;
101: if (wp->layout_cell != NULL)
102: wp->layout_cell->wp = wp;
1.1 nicm 103: wp->xoff = xoff; wp->yoff = yoff;
104: window_pane_resize(wp, sx, sy);
105:
106: if ((wp = TAILQ_NEXT(w->active, entry)) == NULL)
107: wp = TAILQ_FIRST(&w->panes);
108: }
1.27 nicm 109:
110: window_set_active_pane(w, wp, 1);
111: cmd_find_from_winlink_pane(current, wl, wp, 0);
112: window_pop_zoom(w);
113: server_redraw_window(w);
1.1 nicm 114:
1.12 nicm 115: return (CMD_RETURN_NORMAL);
1.1 nicm 116: }