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

Annotation of src/usr.bin/tmux/cmd-resize-pane.c, Revision 1.7

1.7     ! nicm        1: /* $OpenBSD: cmd-resize-pane.c,v 1.6 2009/07/30 13:45:56 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 <stdlib.h>
                     22:
                     23: #include "tmux.h"
                     24:
                     25: /*
                     26:  * Increase or decrease pane size.
                     27:  */
                     28:
                     29: void   cmd_resize_pane_init(struct cmd *, int);
                     30: int    cmd_resize_pane_exec(struct cmd *, struct cmd_ctx *);
                     31:
                     32: const struct cmd_entry cmd_resize_pane_entry = {
                     33:        "resize-pane", "resizep",
1.7     ! nicm       34:        "[-DLRU] " CMD_TARGET_PANE_USAGE " [adjustment]",
        !            35:        CMD_ARG01, "DLRU",
1.1       nicm       36:        cmd_resize_pane_init,
1.6       nicm       37:        cmd_target_parse,
1.1       nicm       38:        cmd_resize_pane_exec,
1.6       nicm       39:        cmd_target_free,
                     40:        cmd_target_print
1.1       nicm       41: };
                     42:
                     43: void
                     44: cmd_resize_pane_init(struct cmd *self, int key)
                     45: {
1.6       nicm       46:        struct cmd_target_data  *data;
1.1       nicm       47:
1.6       nicm       48:        cmd_target_init(self, key);
1.1       nicm       49:        data = self->data;
                     50:
1.4       nicm       51:        if (key == (KEYC_UP | KEYC_CTRL))
1.7     ! nicm       52:                cmd_set_flag(&data->chflags, 'U');
1.4       nicm       53:        if (key == (KEYC_DOWN | KEYC_CTRL))
1.7     ! nicm       54:                cmd_set_flag(&data->chflags, 'D');
1.4       nicm       55:        if (key == (KEYC_LEFT | KEYC_CTRL))
1.7     ! nicm       56:                cmd_set_flag(&data->chflags, 'L');
1.4       nicm       57:        if (key == (KEYC_RIGHT | KEYC_CTRL))
1.7     ! nicm       58:                cmd_set_flag(&data->chflags, 'R');
1.4       nicm       59:
                     60:        if (key == (KEYC_UP | KEYC_ESCAPE)) {
1.7     ! nicm       61:                cmd_set_flag(&data->chflags, 'U');
1.1       nicm       62:                data->arg = xstrdup("5");
1.3       nicm       63:        }
1.4       nicm       64:        if (key == (KEYC_DOWN | KEYC_ESCAPE)) {
1.7     ! nicm       65:                cmd_set_flag(&data->chflags, 'D');
1.1       nicm       66:                data->arg = xstrdup("5");
                     67:        }
1.4       nicm       68:        if (key == (KEYC_LEFT | KEYC_ESCAPE)) {
1.7     ! nicm       69:                cmd_set_flag(&data->chflags, 'L');
1.3       nicm       70:                data->arg = xstrdup("5");
                     71:        }
1.4       nicm       72:        if (key == (KEYC_RIGHT | KEYC_ESCAPE)) {
1.7     ! nicm       73:                cmd_set_flag(&data->chflags, 'R');
1.3       nicm       74:                data->arg = xstrdup("5");
                     75:        }
1.1       nicm       76: }
                     77:
                     78: int
                     79: cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
                     80: {
1.6       nicm       81:        struct cmd_target_data  *data = self->data;
1.1       nicm       82:        struct winlink          *wl;
                     83:        const char              *errstr;
                     84:        struct window_pane      *wp;
                     85:        u_int                    adjust;
                     86:
1.6       nicm       87:        if ((wl = cmd_find_pane(ctx, data->target, NULL, &wp)) == NULL)
1.1       nicm       88:                return (-1);
                     89:
                     90:        if (data->arg == NULL)
                     91:                adjust = 1;
                     92:        else {
                     93:                adjust = strtonum(data->arg, 1, INT_MAX, &errstr);
                     94:                if (errstr != NULL) {
                     95:                        ctx->error(ctx, "adjustment %s: %s", errstr, data->arg);
                     96:                        return (-1);
                     97:                }
                     98:        }
                     99:
1.7     ! nicm      100:        if (cmd_check_flag(data->chflags, 'L'))
        !           101:                layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust);
        !           102:        else if (cmd_check_flag(data->chflags, 'R'))
1.3       nicm      103:                layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust);
1.7     ! nicm      104:        else if (cmd_check_flag(data->chflags, 'U'))
        !           105:                layout_resize_pane(wp, LAYOUT_TOPBOTTOM, -adjust);
        !           106:        else if (cmd_check_flag(data->chflags, 'D'))
1.3       nicm      107:                layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust);
1.1       nicm      108:        server_redraw_window(wl->window);
                    109:
                    110:        return (0);
                    111: }