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

Annotation of src/usr.bin/tmux/cmd-resize-window.c, Revision 1.6

1.6     ! nicm        1: /* $OpenBSD: cmd-resize-window.c,v 1.5 2020/04/13 10:59:58 nicm Exp $ */
1.1       nicm        2:
                      3: /*
                      4:  * Copyright (c) 2018 Nicholas Marriott <nicholas.marriott@gmail.com>
                      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 window size.
                     27:  */
                     28:
                     29: static enum cmd_retval cmd_resize_window_exec(struct cmd *,
                     30:                            struct cmdq_item *);
                     31:
                     32: const struct cmd_entry cmd_resize_window_entry = {
                     33:        .name = "resize-window",
                     34:        .alias = "resizew",
                     35:
                     36:        .args = { "aADLRt:Ux:y:", 0, 1 },
                     37:        .usage = "[-aADLRU] [-x width] [-y height] " CMD_TARGET_WINDOW_USAGE " "
                     38:                 "[adjustment]",
                     39:
                     40:        .target = { 't', CMD_FIND_WINDOW, 0 },
                     41:
                     42:        .flags = CMD_AFTERHOOK,
                     43:        .exec = cmd_resize_window_exec
                     44: };
                     45:
                     46: static enum cmd_retval
                     47: cmd_resize_window_exec(struct cmd *self, struct cmdq_item *item)
                     48: {
1.4       nicm       49:        struct args             *args = cmd_get_args(self);
1.5       nicm       50:        struct cmd_find_state   *target = cmdq_get_target(item);
                     51:        struct winlink          *wl = target->wl;
1.1       nicm       52:        struct window           *w = wl->window;
1.5       nicm       53:        struct session          *s = target->s;
1.1       nicm       54:        const char              *errstr;
                     55:        char                    *cause;
                     56:        u_int                    adjust, sx, sy;
1.3       nicm       57:        int                      xpixel = -1, ypixel = -1;
1.1       nicm       58:
1.6     ! nicm       59:        if (args_count(args) == 0)
1.1       nicm       60:                adjust = 1;
                     61:        else {
1.6     ! nicm       62:                adjust = strtonum(args_string(args, 0), 1, INT_MAX,
        !            63:                    &errstr);
1.1       nicm       64:                if (errstr != NULL) {
                     65:                        cmdq_error(item, "adjustment %s", errstr);
                     66:                        return (CMD_RETURN_ERROR);
                     67:                }
                     68:        }
                     69:
                     70:        sx = w->sx;
                     71:        sy = w->sy;
                     72:
                     73:        if (args_has(args, 'x')) {
                     74:                sx = args_strtonum(args, 'x', WINDOW_MINIMUM, WINDOW_MAXIMUM,
                     75:                    &cause);
                     76:                if (cause != NULL) {
                     77:                        cmdq_error(item, "width %s", cause);
                     78:                        free(cause);
                     79:                        return (CMD_RETURN_ERROR);
                     80:                }
                     81:        }
                     82:        if (args_has(args, 'y')) {
                     83:                sy = args_strtonum(args, 'y', WINDOW_MINIMUM, WINDOW_MAXIMUM,
                     84:                    &cause);
                     85:                if (cause != NULL) {
                     86:                        cmdq_error(item, "height %s", cause);
                     87:                        free(cause);
                     88:                        return (CMD_RETURN_ERROR);
                     89:                }
                     90:        }
                     91:
                     92:        if (args_has(args, 'L')) {
                     93:                if (sx >= adjust)
                     94:                        sx -= adjust;
                     95:        } else if (args_has(args, 'R'))
                     96:                sx += adjust;
                     97:        else if (args_has(args, 'U')) {
                     98:                if (sy >= adjust)
                     99:                        sy -= adjust;
                    100:        } else if (args_has(args, 'D'))
                    101:                sy += adjust;
                    102:
1.3       nicm      103:        if (args_has(args, 'A')) {
                    104:                default_window_size(NULL, s, w, &sx, &sy, &xpixel, &ypixel,
                    105:                    WINDOW_SIZE_LARGEST);
                    106:        } else if (args_has(args, 'a')) {
                    107:                default_window_size(NULL, s, w, &sx, &sy, &xpixel, &ypixel,
                    108:                    WINDOW_SIZE_SMALLEST);
                    109:        }
1.1       nicm      110:
                    111:        options_set_number(w->options, "window-size", WINDOW_SIZE_MANUAL);
1.3       nicm      112:        resize_window(w, sx, sy, xpixel, ypixel);
1.1       nicm      113:
                    114:        return (CMD_RETURN_NORMAL);
                    115: }