[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.2

1.2     ! nicm        1: /* $OpenBSD: cmd-resize-pane.c,v 1.1 2009/06/01 22:58:49 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",
                     34:        CMD_PANE_WINDOW_USAGE "[-DU] [adjustment]",
1.2     ! nicm       35:        CMD_ARG01, CMD_CHFLAG('D')|CMD_CHFLAG('U'),
1.1       nicm       36:        cmd_resize_pane_init,
                     37:        cmd_pane_parse,
                     38:        cmd_resize_pane_exec,
                     39:                cmd_pane_send,
                     40:        cmd_pane_recv,
                     41:        cmd_pane_free,
                     42:        cmd_pane_print
                     43: };
                     44:
                     45: void
                     46: cmd_resize_pane_init(struct cmd *self, int key)
                     47: {
                     48:        struct cmd_pane_data    *data;
                     49:
                     50:        cmd_pane_init(self, key);
                     51:        data = self->data;
                     52:
                     53:        if (key == KEYC_ADDCTL(KEYC_DOWN))
1.2     ! nicm       54:                data->chflags |= CMD_CHFLAG('D');
1.1       nicm       55:
                     56:        if (key == KEYC_ADDESC(KEYC_UP))
                     57:                data->arg = xstrdup("5");
                     58:        if (key == KEYC_ADDESC(KEYC_DOWN)) {
1.2     ! nicm       59:                data->chflags |= CMD_CHFLAG('D');
1.1       nicm       60:                data->arg = xstrdup("5");
                     61:        }
                     62: }
                     63:
                     64: int
                     65: cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
                     66: {
                     67:        struct cmd_pane_data    *data = self->data;
                     68:        struct winlink          *wl;
                     69:        const char              *errstr;
                     70:        struct window_pane      *wp;
                     71:        u_int                    adjust;
                     72:
                     73:        if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
                     74:                return (-1);
                     75:        if (data->pane == -1)
                     76:                wp = wl->window->active;
                     77:        else {
                     78:                wp = window_pane_at_index(wl->window, data->pane);
                     79:                if (wp == NULL) {
                     80:                        ctx->error(ctx, "no pane: %d", data->pane);
                     81:                        return (-1);
                     82:                }
                     83:        }
                     84:
                     85:        if (data->arg == NULL)
                     86:                adjust = 1;
                     87:        else {
                     88:                adjust = strtonum(data->arg, 1, INT_MAX, &errstr);
                     89:                if (errstr != NULL) {
                     90:                        ctx->error(ctx, "adjustment %s: %s", errstr, data->arg);
                     91:                        return (-1);
                     92:                }
                     93:        }
                     94:
1.2     ! nicm       95:        if (!(data->chflags & CMD_CHFLAG('D')))
1.1       nicm       96:                adjust = -adjust;
                     97:        if (layout_resize(wp, adjust) != 0) {
                     98:                ctx->error(ctx, "layout %s "
                     99:                    "does not support resizing", layout_name(wp->window));
                    100:                return (-1);
                    101:        }
                    102:        server_redraw_window(wl->window);
                    103:
                    104:        return (0);
                    105: }