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

Annotation of src/usr.bin/tmux/cmd-refresh-client.c, Revision 1.34

1.34    ! nicm        1: /* $OpenBSD: cmd-refresh-client.c,v 1.33 2020/05/16 15:45:29 nicm Exp $ */
1.1       nicm        2:
                      3: /*
1.19      nicm        4:  * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
1.1       nicm        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:
1.28      nicm       21: #include <stdlib.h>
1.29      nicm       22: #include <string.h>
1.28      nicm       23:
1.1       nicm       24: #include "tmux.h"
                     25:
                     26: /*
                     27:  * Refresh client.
                     28:  */
                     29:
1.23      nicm       30: static enum cmd_retval cmd_refresh_client_exec(struct cmd *,
                     31:                            struct cmdq_item *);
1.1       nicm       32:
                     33: const struct cmd_entry cmd_refresh_client_entry = {
1.17      nicm       34:        .name = "refresh-client",
                     35:        .alias = "refresh",
                     36:
1.33      nicm       37:        .args = { "cC:Df:F:lLRSt:U", 0, 1 },
                     38:        .usage = "[-cDlLRSU] [-C XxY] [-f flags] " CMD_TARGET_CLIENT_USAGE
1.29      nicm       39:                " [adjustment]",
1.17      nicm       40:
1.32      nicm       41:        .flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
1.17      nicm       42:        .exec = cmd_refresh_client_exec
1.1       nicm       43: };
                     44:
1.20      nicm       45: static enum cmd_retval
1.22      nicm       46: cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
1.1       nicm       47: {
1.31      nicm       48:        struct args     *args = cmd_get_args(self);
1.32      nicm       49:        struct client   *tc = cmdq_get_target_client(item);
                     50:        struct tty      *tty = &tc->tty;
1.28      nicm       51:        struct window   *w;
                     52:        const char      *size, *errstr;
                     53:        u_int            x, y, adjust;
1.24      nicm       54:
1.28      nicm       55:        if (args_has(args, 'c') ||
                     56:            args_has(args, 'L') ||
                     57:            args_has(args, 'R') ||
                     58:            args_has(args, 'U') ||
                     59:            args_has(args, 'D'))
                     60:        {
                     61:                if (args->argc == 0)
                     62:                        adjust = 1;
                     63:                else {
                     64:                        adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
                     65:                        if (errstr != NULL) {
                     66:                                cmdq_error(item, "adjustment %s", errstr);
                     67:                                return (CMD_RETURN_ERROR);
                     68:                        }
                     69:                }
                     70:
                     71:                if (args_has(args, 'c'))
1.32      nicm       72:                        tc->pan_window = NULL;
1.28      nicm       73:                else {
1.32      nicm       74:                        w = tc->session->curw->window;
                     75:                        if (tc->pan_window != w) {
                     76:                                tc->pan_window = w;
                     77:                                tc->pan_ox = tty->oox;
                     78:                                tc->pan_oy = tty->ooy;
1.28      nicm       79:                        }
                     80:                        if (args_has(args, 'L')) {
1.32      nicm       81:                                if (tc->pan_ox > adjust)
                     82:                                        tc->pan_ox -= adjust;
1.28      nicm       83:                                else
1.32      nicm       84:                                        tc->pan_ox = 0;
1.28      nicm       85:                        } else if (args_has(args, 'R')) {
1.32      nicm       86:                                tc->pan_ox += adjust;
                     87:                                if (tc->pan_ox > w->sx - tty->osx)
                     88:                                        tc->pan_ox = w->sx - tty->osx;
1.28      nicm       89:                        } else if (args_has(args, 'U')) {
1.32      nicm       90:                                if (tc->pan_oy > adjust)
                     91:                                        tc->pan_oy -= adjust;
1.28      nicm       92:                                else
1.32      nicm       93:                                        tc->pan_oy = 0;
1.28      nicm       94:                        } else if (args_has(args, 'D')) {
1.32      nicm       95:                                tc->pan_oy += adjust;
                     96:                                if (tc->pan_oy > w->sy - tty->osy)
                     97:                                        tc->pan_oy = w->sy - tty->osy;
1.28      nicm       98:                        }
                     99:                }
1.32      nicm      100:                tty_update_client_offset(tc);
                    101:                server_redraw_client(tc);
1.28      nicm      102:                return (CMD_RETURN_NORMAL);
                    103:        }
1.1       nicm      104:
1.27      nicm      105:        if (args_has(args, 'l')) {
1.32      nicm      106:                tty_putcode_ptr2(&tc->tty, TTYC_MS, "", "?");
1.29      nicm      107:                return (CMD_RETURN_NORMAL);
                    108:        }
                    109:
1.33      nicm      110:        if (args_has(args, 'F')) /* -F is an alias for -f */
                    111:                server_client_set_flags(tc, args_get(args, 'F'));
                    112:        if (args_has(args, 'f'))
                    113:                server_client_set_flags(tc, args_get(args, 'f'));
                    114:
                    115:        if (args_has(args, 'C')) {
1.34    ! nicm      116:                if (~tc->flags & CLIENT_CONTROL) {
        !           117:                        cmdq_error(item, "not a control client");
        !           118:                        return (CMD_RETURN_ERROR);
        !           119:                }
        !           120:                size = args_get(args, 'C');
        !           121:                if (sscanf(size, "%u,%u", &x, &y) != 2 &&
        !           122:                    sscanf(size, "%ux%u", &x, &y) != 2) {
        !           123:                        cmdq_error(item, "bad size argument");
        !           124:                        return (CMD_RETURN_ERROR);
        !           125:                }
        !           126:                if (x < WINDOW_MINIMUM || x > WINDOW_MAXIMUM ||
        !           127:                    y < WINDOW_MINIMUM || y > WINDOW_MAXIMUM) {
        !           128:                        cmdq_error(item, "size too small or too big");
        !           129:                        return (CMD_RETURN_ERROR);
1.8       nicm      130:                }
1.34    ! nicm      131:                tty_set_size(&tc->tty, x, y, 0, 0);
        !           132:                tc->flags |= CLIENT_SIZECHANGED;
        !           133:                recalculate_sizes();
1.28      nicm      134:                return (CMD_RETURN_NORMAL);
                    135:        }
                    136:
                    137:        if (args_has(args, 'S')) {
1.32      nicm      138:                tc->flags |= CLIENT_STATUSFORCE;
                    139:                server_status_client(tc);
1.15      nicm      140:        } else {
1.32      nicm      141:                tc->flags |= CLIENT_STATUSFORCE;
                    142:                server_redraw_client(tc);
1.15      nicm      143:        }
1.7       nicm      144:        return (CMD_RETURN_NORMAL);
1.1       nicm      145: }