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

1.38    ! nicm        1: /* $OpenBSD: cmd-refresh-client.c,v 1.37 2020/06/05 07:33:57 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.35      nicm       37:        .args = { "A:cC:Df:F:lLRSt:U", 0, 1 },
                     38:        .usage = "[-cDlLRSU] [-A pane:state] [-C XxY] [-f flags] "
                     39:                 CMD_TARGET_CLIENT_USAGE " [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.35      nicm       45: static void
                     46: cmd_refresh_client_update_offset(struct client *tc, const char *value)
                     47: {
                     48:        struct window_pane      *wp;
                     49:        char                    *copy, *colon;
                     50:        u_int                    pane;
                     51:
                     52:        if (*value != '%')
                     53:                return;
                     54:        copy = xstrdup(value);
                     55:        if ((colon = strchr(copy, ':')) == NULL)
                     56:                goto out;
                     57:        *colon++ = '\0';
                     58:
                     59:        if (sscanf(copy, "%%%u", &pane) != 1)
                     60:                goto out;
                     61:        wp = window_pane_find_by_id(pane);
                     62:        if (wp == NULL)
                     63:                goto out;
                     64:
                     65:        if (strcmp(colon, "on") == 0)
1.36      nicm       66:                control_set_pane_on(tc, wp);
1.35      nicm       67:        else if (strcmp(colon, "off") == 0)
1.36      nicm       68:                control_set_pane_off(tc, wp);
1.37      nicm       69:        else if (strcmp(colon, "continue") == 0)
                     70:                control_continue_pane(tc, wp);
1.38    ! nicm       71:        else if (strcmp(colon, "pause") == 0)
        !            72:                control_pause_pane(tc, wp);
1.35      nicm       73:
                     74: out:
                     75:        free(copy);
                     76: }
                     77:
1.20      nicm       78: static enum cmd_retval
1.22      nicm       79: cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
1.1       nicm       80: {
1.35      nicm       81:        struct args             *args = cmd_get_args(self);
                     82:        struct client           *tc = cmdq_get_target_client(item);
                     83:        struct tty              *tty = &tc->tty;
                     84:        struct window           *w;
                     85:        const char              *size, *errstr, *value;
                     86:        u_int                    x, y, adjust;
                     87:        struct args_value       *av;
1.24      nicm       88:
1.28      nicm       89:        if (args_has(args, 'c') ||
                     90:            args_has(args, 'L') ||
                     91:            args_has(args, 'R') ||
                     92:            args_has(args, 'U') ||
                     93:            args_has(args, 'D'))
                     94:        {
                     95:                if (args->argc == 0)
                     96:                        adjust = 1;
                     97:                else {
                     98:                        adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
                     99:                        if (errstr != NULL) {
                    100:                                cmdq_error(item, "adjustment %s", errstr);
                    101:                                return (CMD_RETURN_ERROR);
                    102:                        }
                    103:                }
                    104:
                    105:                if (args_has(args, 'c'))
1.32      nicm      106:                        tc->pan_window = NULL;
1.28      nicm      107:                else {
1.32      nicm      108:                        w = tc->session->curw->window;
                    109:                        if (tc->pan_window != w) {
                    110:                                tc->pan_window = w;
                    111:                                tc->pan_ox = tty->oox;
                    112:                                tc->pan_oy = tty->ooy;
1.28      nicm      113:                        }
                    114:                        if (args_has(args, 'L')) {
1.32      nicm      115:                                if (tc->pan_ox > adjust)
                    116:                                        tc->pan_ox -= adjust;
1.28      nicm      117:                                else
1.32      nicm      118:                                        tc->pan_ox = 0;
1.28      nicm      119:                        } else if (args_has(args, 'R')) {
1.32      nicm      120:                                tc->pan_ox += adjust;
                    121:                                if (tc->pan_ox > w->sx - tty->osx)
                    122:                                        tc->pan_ox = w->sx - tty->osx;
1.28      nicm      123:                        } else if (args_has(args, 'U')) {
1.32      nicm      124:                                if (tc->pan_oy > adjust)
                    125:                                        tc->pan_oy -= adjust;
1.28      nicm      126:                                else
1.32      nicm      127:                                        tc->pan_oy = 0;
1.28      nicm      128:                        } else if (args_has(args, 'D')) {
1.32      nicm      129:                                tc->pan_oy += adjust;
                    130:                                if (tc->pan_oy > w->sy - tty->osy)
                    131:                                        tc->pan_oy = w->sy - tty->osy;
1.28      nicm      132:                        }
                    133:                }
1.32      nicm      134:                tty_update_client_offset(tc);
                    135:                server_redraw_client(tc);
1.28      nicm      136:                return (CMD_RETURN_NORMAL);
                    137:        }
1.1       nicm      138:
1.27      nicm      139:        if (args_has(args, 'l')) {
1.32      nicm      140:                tty_putcode_ptr2(&tc->tty, TTYC_MS, "", "?");
1.29      nicm      141:                return (CMD_RETURN_NORMAL);
                    142:        }
                    143:
1.33      nicm      144:        if (args_has(args, 'F')) /* -F is an alias for -f */
                    145:                server_client_set_flags(tc, args_get(args, 'F'));
                    146:        if (args_has(args, 'f'))
                    147:                server_client_set_flags(tc, args_get(args, 'f'));
                    148:
1.35      nicm      149:        if (args_has(args, 'A')) {
                    150:                if (~tc->flags & CLIENT_CONTROL)
                    151:                        goto not_control_client;
                    152:                value = args_first_value(args, 'A', &av);
                    153:                while (value != NULL) {
                    154:                        cmd_refresh_client_update_offset(tc, value);
                    155:                        value = args_next_value(&av);
                    156:                }
                    157:                return (CMD_RETURN_NORMAL);
                    158:        }
1.33      nicm      159:        if (args_has(args, 'C')) {
1.35      nicm      160:                if (~tc->flags & CLIENT_CONTROL)
                    161:                        goto not_control_client;
1.34      nicm      162:                size = args_get(args, 'C');
                    163:                if (sscanf(size, "%u,%u", &x, &y) != 2 &&
                    164:                    sscanf(size, "%ux%u", &x, &y) != 2) {
                    165:                        cmdq_error(item, "bad size argument");
                    166:                        return (CMD_RETURN_ERROR);
                    167:                }
                    168:                if (x < WINDOW_MINIMUM || x > WINDOW_MAXIMUM ||
                    169:                    y < WINDOW_MINIMUM || y > WINDOW_MAXIMUM) {
                    170:                        cmdq_error(item, "size too small or too big");
                    171:                        return (CMD_RETURN_ERROR);
1.8       nicm      172:                }
1.34      nicm      173:                tty_set_size(&tc->tty, x, y, 0, 0);
                    174:                tc->flags |= CLIENT_SIZECHANGED;
1.37      nicm      175:                recalculate_sizes_now(1);
1.28      nicm      176:                return (CMD_RETURN_NORMAL);
                    177:        }
                    178:
                    179:        if (args_has(args, 'S')) {
1.32      nicm      180:                tc->flags |= CLIENT_STATUSFORCE;
                    181:                server_status_client(tc);
1.15      nicm      182:        } else {
1.32      nicm      183:                tc->flags |= CLIENT_STATUSFORCE;
                    184:                server_redraw_client(tc);
1.15      nicm      185:        }
1.7       nicm      186:        return (CMD_RETURN_NORMAL);
1.35      nicm      187:
                    188: not_control_client:
                    189:        cmdq_error(item, "not a control client");
                    190:        return (CMD_RETURN_ERROR);
1.1       nicm      191: }