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

Annotation of src/usr.bin/tmux/cmd-select-layout.c, Revision 1.15

1.15    ! nicm        1: /* $OpenBSD: cmd-select-layout.c,v 1.14 2012/04/01 13:18:38 nicm Exp $ */
1.1       nicm        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:  * Switch window to selected layout.
                     25:  */
                     26:
1.11      nicm       27: void   cmd_select_layout_key_binding(struct cmd *, int);
1.1       nicm       28: int    cmd_select_layout_exec(struct cmd *, struct cmd_ctx *);
                     29:
                     30: const struct cmd_entry cmd_select_layout_entry = {
                     31:        "select-layout", "selectl",
1.14      nicm       32:        "nprut:", 0, 1,
                     33:        "[-npUu] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
1.11      nicm       34:        0,
                     35:        cmd_select_layout_key_binding,
                     36:        NULL,
                     37:        cmd_select_layout_exec
1.1       nicm       38: };
                     39:
1.12      nicm       40: const struct cmd_entry cmd_next_layout_entry = {
                     41:        "next-layout", "nextl",
                     42:        "t:", 0, 0,
                     43:        CMD_TARGET_WINDOW_USAGE,
                     44:        0,
                     45:        NULL,
                     46:        NULL,
                     47:        cmd_select_layout_exec
                     48: };
                     49:
                     50: const struct cmd_entry cmd_previous_layout_entry = {
                     51:        "previous-layout", "prevl",
                     52:        "t:", 0, 0,
                     53:        CMD_TARGET_WINDOW_USAGE,
                     54:        0,
                     55:        NULL,
                     56:        NULL,
                     57:        cmd_select_layout_exec
                     58: };
                     59:
1.1       nicm       60: void
1.11      nicm       61: cmd_select_layout_key_binding(struct cmd *self, int key)
1.1       nicm       62: {
                     63:        switch (key) {
1.11      nicm       64:        case '1' | KEYC_ESCAPE:
                     65:                self->args = args_create(1, "even-horizontal");
                     66:                break;
                     67:        case '2' | KEYC_ESCAPE:
                     68:                self->args = args_create(1, "even-vertical");
1.1       nicm       69:                break;
1.11      nicm       70:        case '3' | KEYC_ESCAPE:
                     71:                self->args = args_create(1, "main-horizontal");
1.8       nicm       72:                break;
1.11      nicm       73:        case '4' | KEYC_ESCAPE:
                     74:                self->args = args_create(1, "main-vertical");
1.3       nicm       75:                break;
1.11      nicm       76:        case '5' | KEYC_ESCAPE:
                     77:                self->args = args_create(1, "tiled");
1.9       nicm       78:                break;
1.14      nicm       79:        case 'u':
                     80:                self->args = args_create(0);
                     81:                args_set(self->args, 'u', NULL);
                     82:                break;
                     83:        case 'U':
                     84:                self->args = args_create(0);
                     85:                args_set(self->args, 'U', NULL);
                     86:                break;
1.11      nicm       87:        default:
                     88:                self->args = args_create(0);
1.1       nicm       89:                break;
                     90:        }
                     91: }
                     92:
                     93: int
                     94: cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
                     95: {
1.11      nicm       96:        struct args     *args = self->args;
                     97:        struct winlink  *wl;
1.14      nicm       98:        struct window   *w;
1.11      nicm       99:        const char      *layoutname;
1.12      nicm      100:        int              next, previous, layout;
1.1       nicm      101:
1.11      nicm      102:        if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
1.1       nicm      103:                return (-1);
1.14      nicm      104:        w = wl->window;
1.12      nicm      105:
                    106:        next = self->entry == &cmd_next_layout_entry;
                    107:        if (args_has(self->args, 'n'))
                    108:                next = 1;
                    109:        previous = self->entry == &cmd_previous_layout_entry;
                    110:        if (args_has(self->args, 'p'))
                    111:                previous = 1;
                    112:
1.14      nicm      113:        layout_list_add(w);
                    114:        if (args_has(self->args, 'U')) {
                    115:                if ((layoutname = layout_list_redo(w)) == NULL) {
1.15    ! nicm      116:                        ctx->info(ctx, "no more layout history");
1.14      nicm      117:                        return (-1);
                    118:                }
                    119:                goto set_layout;
                    120:        } else if (args_has(self->args, 'u')) {
                    121:                if ((layoutname = layout_list_undo(w)) == NULL) {
1.15    ! nicm      122:                        ctx->info(ctx, "no more layout history");
1.14      nicm      123:                        return (-1);
                    124:                }
                    125:                goto set_layout;
                    126:        }
                    127:
1.12      nicm      128:        if (next || previous) {
                    129:                if (next)
                    130:                        layout = layout_set_next(wl->window);
                    131:                else
                    132:                        layout = layout_set_previous(wl->window);
1.13      nicm      133:                server_redraw_window(wl->window);
1.12      nicm      134:                ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
                    135:                return (0);
                    136:        }
1.1       nicm      137:
1.11      nicm      138:        if (args->argc == 0)
1.6       nicm      139:                layout = wl->window->lastlayout;
1.11      nicm      140:        else
                    141:                layout = layout_set_lookup(args->argv[0]);
                    142:        if (layout != -1) {
1.10      nicm      143:                layout = layout_set_select(wl->window, layout);
1.13      nicm      144:                server_redraw_window(wl->window);
1.10      nicm      145:                ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
1.11      nicm      146:                return (0);
                    147:        }
                    148:
1.14      nicm      149:        if (args->argc == 0)
1.11      nicm      150:                return (0);
1.14      nicm      151:        layoutname = args->argv[0];
                    152:
                    153: set_layout:
                    154:        if (layout_parse(wl->window, layoutname) == -1) {
                    155:                ctx->error(ctx, "can't set layout: %s", layoutname);
                    156:                return (-1);
1.6       nicm      157:        }
1.14      nicm      158:        server_redraw_window(wl->window);
                    159:        ctx->info(ctx, "arranging in: %s", layoutname);
1.1       nicm      160:        return (0);
                    161: }