summaryrefslogtreecommitdiffstats
path: root/cmd-refresh-client.c
diff options
context:
space:
mode:
authornicm <nicm>2021-08-27 17:15:57 +0000
committernicm <nicm>2021-08-27 17:15:57 +0000
commitfd756a150b43d319d08ac4117f34edef9e0438c4 (patch)
tree003f77b6051466412eba1fa0260b9e95c89e3923 /cmd-refresh-client.c
parent24636be42b4b0463afe5c72e1d982f28729a0579 (diff)
Allow control mode clients to set a hard limit on the window width and
height, GitHub issue 2594.
Diffstat (limited to 'cmd-refresh-client.c')
-rw-r--r--cmd-refresh-client.c72
1 files changed, 55 insertions, 17 deletions
diff --git a/cmd-refresh-client.c b/cmd-refresh-client.c
index 24a49dcb..821558ae 100644
--- a/cmd-refresh-client.c
+++ b/cmd-refresh-client.c
@@ -77,6 +77,58 @@ out:
free(copy);
}
+static enum cmd_retval
+cmd_refresh_client_control_client_size(struct cmd *self, struct cmdq_item *item)
+{
+ struct args *args = cmd_get_args(self);
+ struct client *tc = cmdq_get_target_client(item);
+ const char *size = args_get(args, 'C');
+ u_int w, x, y;
+ struct client_window *cw;
+
+ if (sscanf(size, "@%u:%ux%u", &w, &x, &y) == 3) {
+ if (x < WINDOW_MINIMUM || x > WINDOW_MAXIMUM ||
+ y < WINDOW_MINIMUM || y > WINDOW_MAXIMUM) {
+ cmdq_error(item, "size too small or too big");
+ return (CMD_RETURN_ERROR);
+ }
+ log_debug("%s: client %s window @%u: size %ux%u", __func__,
+ tc->name, w, x, y);
+ cw = server_client_add_client_window(tc, w);
+ cw->sx = x;
+ cw->sy = y;
+ tc->flags |= CLIENT_WINDOWSIZECHANGED;
+ recalculate_sizes_now(1);
+ return (CMD_RETURN_NORMAL);
+ }
+ if (sscanf(size, "@%u:", &w) == 1) {
+ cw = server_client_get_client_window(tc, w);
+ if (cw != NULL) {
+ log_debug("%s: client %s window @%u: no size", __func__,
+ tc->name, w);
+ cw->sx = 0;
+ cw->sy = 0;
+ recalculate_sizes_now(1);
+ }
+ return (CMD_RETURN_NORMAL);
+ }
+
+ if (sscanf(size, "%u,%u", &x, &y) != 2 &&
+ sscanf(size, "%ux%u", &x, &y) != 2) {
+ cmdq_error(item, "bad size argument");
+ return (CMD_RETURN_ERROR);
+ }
+ if (x < WINDOW_MINIMUM || x > WINDOW_MAXIMUM ||
+ y < WINDOW_MINIMUM || y > WINDOW_MAXIMUM) {
+ cmdq_error(item, "size too small or too big");
+ return (CMD_RETURN_ERROR);
+ }
+ tty_set_size(&tc->tty, x, y, 0, 0);
+ tc->flags |= CLIENT_SIZECHANGED;
+ recalculate_sizes_now(1);
+ return (CMD_RETURN_NORMAL);
+}
+
static void
cmd_refresh_client_update_offset(struct client *tc, const char *value)
{
@@ -117,8 +169,8 @@ cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
struct client *tc = cmdq_get_target_client(item);
struct tty *tty = &tc->tty;
struct window *w;
- const char *size, *errstr;
- u_int x, y, adjust;
+ const char *errstr;
+ u_int adjust;
struct args_value *av;
if (args_has(args, 'c') ||
@@ -205,21 +257,7 @@ cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
if (args_has(args, 'C')) {
if (~tc->flags & CLIENT_CONTROL)
goto not_control_client;
- size = args_get(args, 'C');
- if (sscanf(size, "%u,%u", &x, &y) != 2 &&
- sscanf(size, "%ux%u", &x, &y) != 2) {
- cmdq_error(item, "bad size argument");
- return (CMD_RETURN_ERROR);
- }
- if (x < WINDOW_MINIMUM || x > WINDOW_MAXIMUM ||
- y < WINDOW_MINIMUM || y > WINDOW_MAXIMUM) {
- cmdq_error(item, "size too small or too big");
- return (CMD_RETURN_ERROR);
- }
- tty_set_size(&tc->tty, x, y, 0, 0);
- tc->flags |= CLIENT_SIZECHANGED;
- recalculate_sizes_now(1);
- return (CMD_RETURN_NORMAL);
+ return (cmd_refresh_client_control_client_size(self, item));
}
if (args_has(args, 'S')) {