Annotation of src/usr.bin/tmux/cmd-refresh-client.c, Revision 1.43
1.43 ! nicm 1: /* $OpenBSD: cmd-refresh-client.c,v 1.42 2021/08/20 19:50:16 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.43 ! nicm 37: .args = { "A:B:cC:Df:F:lLRSt:U", 0, 1, NULL },
1.39 nicm 38: .usage = "[-cDlLRSU] [-A pane:state] [-B name:what:format] "
39: "[-C XxY] [-f flags] " 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
1.39 nicm 46: cmd_refresh_client_update_subscription(struct client *tc, const char *value)
47: {
48: char *copy, *split, *name, *what;
49: enum control_sub_type subtype;
50: int subid = -1;
51:
52: copy = name = xstrdup(value);
53: if ((split = strchr(copy, ':')) == NULL) {
54: control_remove_sub(tc, copy);
55: goto out;
56: }
57: *split++ = '\0';
58:
59: what = split;
60: if ((split = strchr(what, ':')) == NULL)
61: goto out;
62: *split++ = '\0';
63:
64: if (strcmp(what, "%*") == 0)
65: subtype = CONTROL_SUB_ALL_PANES;
66: else if (sscanf(what, "%%%d", &subid) == 1 && subid >= 0)
67: subtype = CONTROL_SUB_PANE;
68: else if (strcmp(what, "@*") == 0)
69: subtype = CONTROL_SUB_ALL_WINDOWS;
70: else if (sscanf(what, "@%d", &subid) == 1 && subid >= 0)
71: subtype = CONTROL_SUB_WINDOW;
72: else
73: subtype = CONTROL_SUB_SESSION;
74: control_add_sub(tc, name, subtype, subid, split);
75:
76: out:
77: free(copy);
78: }
79:
80: static void
1.35 nicm 81: cmd_refresh_client_update_offset(struct client *tc, const char *value)
82: {
83: struct window_pane *wp;
1.39 nicm 84: char *copy, *split;
1.35 nicm 85: u_int pane;
86:
87: if (*value != '%')
88: return;
89: copy = xstrdup(value);
1.39 nicm 90: if ((split = strchr(copy, ':')) == NULL)
1.35 nicm 91: goto out;
1.39 nicm 92: *split++ = '\0';
1.35 nicm 93:
94: if (sscanf(copy, "%%%u", &pane) != 1)
95: goto out;
96: wp = window_pane_find_by_id(pane);
97: if (wp == NULL)
98: goto out;
99:
1.39 nicm 100: if (strcmp(split, "on") == 0)
1.36 nicm 101: control_set_pane_on(tc, wp);
1.39 nicm 102: else if (strcmp(split, "off") == 0)
1.36 nicm 103: control_set_pane_off(tc, wp);
1.39 nicm 104: else if (strcmp(split, "continue") == 0)
1.37 nicm 105: control_continue_pane(tc, wp);
1.39 nicm 106: else if (strcmp(split, "pause") == 0)
1.38 nicm 107: control_pause_pane(tc, wp);
1.35 nicm 108:
109: out:
110: free(copy);
111: }
112:
1.20 nicm 113: static enum cmd_retval
1.22 nicm 114: cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
1.1 nicm 115: {
1.35 nicm 116: struct args *args = cmd_get_args(self);
117: struct client *tc = cmdq_get_target_client(item);
118: struct tty *tty = &tc->tty;
119: struct window *w;
1.41 nicm 120: const char *size, *errstr;
1.35 nicm 121: u_int x, y, adjust;
122: struct args_value *av;
1.24 nicm 123:
1.28 nicm 124: if (args_has(args, 'c') ||
125: args_has(args, 'L') ||
126: args_has(args, 'R') ||
127: args_has(args, 'U') ||
128: args_has(args, 'D'))
129: {
1.42 nicm 130: if (args_count(args) == 0)
1.28 nicm 131: adjust = 1;
132: else {
1.42 nicm 133: adjust = strtonum(args_string(args, 0), 1, INT_MAX,
134: &errstr);
1.28 nicm 135: if (errstr != NULL) {
136: cmdq_error(item, "adjustment %s", errstr);
137: return (CMD_RETURN_ERROR);
138: }
139: }
140:
141: if (args_has(args, 'c'))
1.32 nicm 142: tc->pan_window = NULL;
1.28 nicm 143: else {
1.32 nicm 144: w = tc->session->curw->window;
145: if (tc->pan_window != w) {
146: tc->pan_window = w;
147: tc->pan_ox = tty->oox;
148: tc->pan_oy = tty->ooy;
1.28 nicm 149: }
150: if (args_has(args, 'L')) {
1.32 nicm 151: if (tc->pan_ox > adjust)
152: tc->pan_ox -= adjust;
1.28 nicm 153: else
1.32 nicm 154: tc->pan_ox = 0;
1.28 nicm 155: } else if (args_has(args, 'R')) {
1.32 nicm 156: tc->pan_ox += adjust;
157: if (tc->pan_ox > w->sx - tty->osx)
158: tc->pan_ox = w->sx - tty->osx;
1.28 nicm 159: } else if (args_has(args, 'U')) {
1.32 nicm 160: if (tc->pan_oy > adjust)
161: tc->pan_oy -= adjust;
1.28 nicm 162: else
1.32 nicm 163: tc->pan_oy = 0;
1.28 nicm 164: } else if (args_has(args, 'D')) {
1.32 nicm 165: tc->pan_oy += adjust;
166: if (tc->pan_oy > w->sy - tty->osy)
167: tc->pan_oy = w->sy - tty->osy;
1.28 nicm 168: }
169: }
1.32 nicm 170: tty_update_client_offset(tc);
171: server_redraw_client(tc);
1.28 nicm 172: return (CMD_RETURN_NORMAL);
173: }
1.1 nicm 174:
1.27 nicm 175: if (args_has(args, 'l')) {
1.32 nicm 176: tty_putcode_ptr2(&tc->tty, TTYC_MS, "", "?");
1.29 nicm 177: return (CMD_RETURN_NORMAL);
178: }
179:
1.33 nicm 180: if (args_has(args, 'F')) /* -F is an alias for -f */
181: server_client_set_flags(tc, args_get(args, 'F'));
182: if (args_has(args, 'f'))
183: server_client_set_flags(tc, args_get(args, 'f'));
184:
1.35 nicm 185: if (args_has(args, 'A')) {
186: if (~tc->flags & CLIENT_CONTROL)
187: goto not_control_client;
1.40 nicm 188: av = args_first_value(args, 'A');
189: while (av != NULL) {
190: cmd_refresh_client_update_offset(tc, av->value);
1.41 nicm 191: av = args_next_value(av);
1.39 nicm 192: }
193: return (CMD_RETURN_NORMAL);
194: }
195: if (args_has(args, 'B')) {
196: if (~tc->flags & CLIENT_CONTROL)
197: goto not_control_client;
1.40 nicm 198: av = args_first_value(args, 'B');
199: while (av != NULL) {
1.41 nicm 200: cmd_refresh_client_update_subscription(tc, av->value);
1.40 nicm 201: av = args_next_value(av);
1.35 nicm 202: }
203: return (CMD_RETURN_NORMAL);
204: }
1.33 nicm 205: if (args_has(args, 'C')) {
1.35 nicm 206: if (~tc->flags & CLIENT_CONTROL)
207: goto not_control_client;
1.34 nicm 208: size = args_get(args, 'C');
209: if (sscanf(size, "%u,%u", &x, &y) != 2 &&
210: sscanf(size, "%ux%u", &x, &y) != 2) {
211: cmdq_error(item, "bad size argument");
212: return (CMD_RETURN_ERROR);
213: }
214: if (x < WINDOW_MINIMUM || x > WINDOW_MAXIMUM ||
215: y < WINDOW_MINIMUM || y > WINDOW_MAXIMUM) {
216: cmdq_error(item, "size too small or too big");
217: return (CMD_RETURN_ERROR);
1.8 nicm 218: }
1.34 nicm 219: tty_set_size(&tc->tty, x, y, 0, 0);
220: tc->flags |= CLIENT_SIZECHANGED;
1.37 nicm 221: recalculate_sizes_now(1);
1.28 nicm 222: return (CMD_RETURN_NORMAL);
223: }
224:
225: if (args_has(args, 'S')) {
1.32 nicm 226: tc->flags |= CLIENT_STATUSFORCE;
227: server_status_client(tc);
1.15 nicm 228: } else {
1.32 nicm 229: tc->flags |= CLIENT_STATUSFORCE;
230: server_redraw_client(tc);
1.15 nicm 231: }
1.7 nicm 232: return (CMD_RETURN_NORMAL);
1.35 nicm 233:
234: not_control_client:
235: cmdq_error(item, "not a control client");
236: return (CMD_RETURN_ERROR);
1.1 nicm 237: }