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

1.32    ! nicm        1: /* $OpenBSD: cmd-refresh-client.c,v 1.31 2020/04/13 08:26:27 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.29      nicm       37:        .args = { "cC:DF:lLRSt:U", 0, 1 },
                     38:        .usage = "[-cDlLRSU] [-C XxY] [-F flags] " CMD_TARGET_CLIENT_USAGE
                     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;
1.29      nicm       53:        char            *copy, *next, *s;
1.28      nicm       54:        u_int            x, y, adjust;
1.24      nicm       55:
1.28      nicm       56:        if (args_has(args, 'c') ||
                     57:            args_has(args, 'L') ||
                     58:            args_has(args, 'R') ||
                     59:            args_has(args, 'U') ||
                     60:            args_has(args, 'D'))
                     61:        {
                     62:                if (args->argc == 0)
                     63:                        adjust = 1;
                     64:                else {
                     65:                        adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
                     66:                        if (errstr != NULL) {
                     67:                                cmdq_error(item, "adjustment %s", errstr);
                     68:                                return (CMD_RETURN_ERROR);
                     69:                        }
                     70:                }
                     71:
                     72:                if (args_has(args, 'c'))
1.32    ! nicm       73:                        tc->pan_window = NULL;
1.28      nicm       74:                else {
1.32    ! nicm       75:                        w = tc->session->curw->window;
        !            76:                        if (tc->pan_window != w) {
        !            77:                                tc->pan_window = w;
        !            78:                                tc->pan_ox = tty->oox;
        !            79:                                tc->pan_oy = tty->ooy;
1.28      nicm       80:                        }
                     81:                        if (args_has(args, 'L')) {
1.32    ! nicm       82:                                if (tc->pan_ox > adjust)
        !            83:                                        tc->pan_ox -= adjust;
1.28      nicm       84:                                else
1.32    ! nicm       85:                                        tc->pan_ox = 0;
1.28      nicm       86:                        } else if (args_has(args, 'R')) {
1.32    ! nicm       87:                                tc->pan_ox += adjust;
        !            88:                                if (tc->pan_ox > w->sx - tty->osx)
        !            89:                                        tc->pan_ox = w->sx - tty->osx;
1.28      nicm       90:                        } else if (args_has(args, 'U')) {
1.32    ! nicm       91:                                if (tc->pan_oy > adjust)
        !            92:                                        tc->pan_oy -= adjust;
1.28      nicm       93:                                else
1.32    ! nicm       94:                                        tc->pan_oy = 0;
1.28      nicm       95:                        } else if (args_has(args, 'D')) {
1.32    ! nicm       96:                                tc->pan_oy += adjust;
        !            97:                                if (tc->pan_oy > w->sy - tty->osy)
        !            98:                                        tc->pan_oy = w->sy - tty->osy;
1.28      nicm       99:                        }
                    100:                }
1.32    ! nicm      101:                tty_update_client_offset(tc);
        !           102:                server_redraw_client(tc);
1.28      nicm      103:                return (CMD_RETURN_NORMAL);
                    104:        }
1.1       nicm      105:
1.27      nicm      106:        if (args_has(args, 'l')) {
1.32    ! nicm      107:                tty_putcode_ptr2(&tc->tty, TTYC_MS, "", "?");
1.29      nicm      108:                return (CMD_RETURN_NORMAL);
                    109:        }
                    110:
                    111:        if (args_has(args, 'C') || args_has(args, 'F')) {
                    112:                if (args_has(args, 'C')) {
1.32    ! nicm      113:                        if (!(tc->flags & CLIENT_CONTROL)) {
1.29      nicm      114:                                cmdq_error(item, "not a control client");
                    115:                                return (CMD_RETURN_ERROR);
                    116:                        }
                    117:                        size = args_get(args, 'C');
                    118:                        if (sscanf(size, "%u,%u", &x, &y) != 2 &&
                    119:                            sscanf(size, "%ux%u", &x, &y) != 2) {
                    120:                                cmdq_error(item, "bad size argument");
                    121:                                return (CMD_RETURN_ERROR);
                    122:                        }
                    123:                        if (x < WINDOW_MINIMUM || x > WINDOW_MAXIMUM ||
                    124:                            y < WINDOW_MINIMUM || y > WINDOW_MAXIMUM) {
                    125:                                cmdq_error(item, "size too small or too big");
                    126:                                return (CMD_RETURN_ERROR);
                    127:                        }
1.32    ! nicm      128:                        tty_set_size(&tc->tty, x, y, 0, 0);
        !           129:                        tc->flags |= CLIENT_SIZECHANGED;
1.29      nicm      130:                        recalculate_sizes();
                    131:                }
                    132:                if (args_has(args, 'F')) {
1.32    ! nicm      133:                        if (!(tc->flags & CLIENT_CONTROL)) {
1.29      nicm      134:                                cmdq_error(item, "not a control client");
                    135:                                return (CMD_RETURN_ERROR);
                    136:                        }
                    137:                        s = copy = xstrdup(args_get(args, 'F'));
                    138:                        while ((next = strsep(&s, ",")) != NULL) {
                    139:                                /* Unknown flags are ignored. */
                    140:                                if (strcmp(next, "no-output") == 0)
1.32    ! nicm      141:                                        tc->flags |= CLIENT_CONTROL_NOOUTPUT;
1.29      nicm      142:                        }
                    143:                        free(copy);
1.8       nicm      144:                }
1.28      nicm      145:                return (CMD_RETURN_NORMAL);
                    146:        }
                    147:
                    148:        if (args_has(args, 'S')) {
1.32    ! nicm      149:                tc->flags |= CLIENT_STATUSFORCE;
        !           150:                server_status_client(tc);
1.15      nicm      151:        } else {
1.32    ! nicm      152:                tc->flags |= CLIENT_STATUSFORCE;
        !           153:                server_redraw_client(tc);
1.15      nicm      154:        }
1.7       nicm      155:        return (CMD_RETURN_NORMAL);
1.1       nicm      156: }