[BACK]Return to cmd-rotate-window.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/cmd-rotate-window.c, Revision 1.1

1.1     ! nicm        1: /* $OpenBSD$ */
        !             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:
        !            27: void   cmd_rotate_window_init(struct cmd *, int);
        !            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",
        !            32:        "[-DU] " CMD_TARGET_WINDOW_USAGE,
        !            33:        CMD_BIGUFLAG|CMD_BIGDFLAG,
        !            34:        cmd_rotate_window_init,
        !            35:        cmd_target_parse,
        !            36:        cmd_rotate_window_exec,
        !            37:        cmd_target_send,
        !            38:        cmd_target_recv,
        !            39:        cmd_target_free,
        !            40:        cmd_target_print
        !            41: };
        !            42:
        !            43: void
        !            44: cmd_rotate_window_init(struct cmd *self, int key)
        !            45: {
        !            46:        struct cmd_target_data  *data;
        !            47:
        !            48:        cmd_target_init(self, key);
        !            49:        data = self->data;
        !            50:
        !            51:        if (key == KEYC_ADDESC('o'))
        !            52:                data->flags |= CMD_BIGDFLAG;
        !            53: }
        !            54:
        !            55: int
        !            56: cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
        !            57: {
        !            58:        struct cmd_target_data  *data = self->data;
        !            59:        struct winlink          *wl;
        !            60:        struct window           *w;
        !            61:        struct window_pane      *wp, *wp2;
        !            62:        u_int                    sx, sy, xoff, yoff;
        !            63:
        !            64:        if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
        !            65:                return (-1);
        !            66:        w = wl->window;
        !            67:
        !            68:        if (data->flags & CMD_BIGDFLAG) {
        !            69:                wp = TAILQ_LAST(&w->panes, window_panes);
        !            70:                TAILQ_REMOVE(&w->panes, wp, entry);
        !            71:                TAILQ_INSERT_HEAD(&w->panes, wp, entry);
        !            72:
        !            73:                xoff = wp->xoff; yoff = wp->yoff;
        !            74:                sx = wp->sx; sy = wp->sy;
        !            75:                TAILQ_FOREACH(wp, &w->panes, entry) {
        !            76:                        if ((wp2 = TAILQ_NEXT(wp, entry)) == NULL)
        !            77:                                break;
        !            78:                        wp->xoff = wp2->xoff; wp->yoff = wp2->yoff;
        !            79:                        window_pane_resize(wp, wp2->sx, wp2->sy);
        !            80:                }
        !            81:                wp->xoff = xoff; wp->yoff = yoff;
        !            82:                window_pane_resize(wp, sx, sy);
        !            83:
        !            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:        } else {
        !            88:                wp = TAILQ_FIRST(&w->panes);
        !            89:                TAILQ_REMOVE(&w->panes, wp, entry);
        !            90:                TAILQ_INSERT_TAIL(&w->panes, wp, entry);
        !            91:
        !            92:                xoff = wp->xoff; yoff = wp->yoff;
        !            93:                sx = wp->sx; sy = wp->sy;
        !            94:                TAILQ_FOREACH_REVERSE(wp, &w->panes, window_panes, entry) {
        !            95:                        if ((wp2 = TAILQ_PREV(wp, window_panes, entry)) == NULL)
        !            96:                                break;
        !            97:                        wp->xoff = wp2->xoff; wp->yoff = wp2->yoff;
        !            98:                        window_pane_resize(wp, wp2->sx, wp2->sy);
        !            99:                }
        !           100:                wp->xoff = xoff; wp->yoff = yoff;
        !           101:                window_pane_resize(wp, sx, sy);
        !           102:
        !           103:                if ((wp = TAILQ_NEXT(w->active, entry)) == NULL)
        !           104:                        wp = TAILQ_FIRST(&w->panes);
        !           105:                window_set_active_pane(w, wp);
        !           106:        }
        !           107:
        !           108:        layout_refresh(w, 0);
        !           109:
        !           110:        return (0);
        !           111: }