From c248e96b849a125d88d0fffc744d0f98b8c558d9 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Thu, 8 Nov 2018 14:17:49 -0500 Subject: resize set: implement width and height keywords This implements the following syntaxes from `i3 4.16`: * `resize set [width] [px|ppt]` * `resize set height [px|ppt]` * `resize set [width] [px|ppt] [height] [px|ppt]` Additionally, a bug was fixed that caused setting the height of a tiled container to change the width instead due to a typo. --- sway/commands/resize.c | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'sway/commands/resize.c') diff --git a/sway/commands/resize.c b/sway/commands/resize.c index 8635b309..a82bec20 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c @@ -499,7 +499,7 @@ static struct cmd_results *resize_set_tiled(struct sway_container *con, } if (height->unit == RESIZE_UNIT_PX) { resize_tiled(con, height->amount - con->height, - RESIZE_AXIS_HORIZONTAL); + RESIZE_AXIS_VERTICAL); } } @@ -538,34 +538,45 @@ static struct cmd_results *resize_set_floating(struct sway_container *con, /** * resize set * - * args: [px|ppt] [px|ppt] + * args: [width] [px|ppt] + * : height [px|ppt] + * : [width] [px|ppt] [height] [px|ppt] */ static struct cmd_results *cmd_resize_set(int argc, char **argv) { struct cmd_results *error; - if ((error = checkarg(argc, "resize", EXPECTED_AT_LEAST, 2))) { + if ((error = checkarg(argc, "resize", EXPECTED_AT_LEAST, 1))) { return error; } - const char *usage = "Expected 'resize set '"; + const char *usage = "Expected 'resize set [width] [px|ppt]' or " + "'resize set height [px|ppt]' or " + "'resize set [width] [px|ppt] [height] [px|ppt]'"; // Width - struct resize_amount width; - int num_consumed_args = parse_resize_amount(argc, argv, &width); - argc -= num_consumed_args; - argv += num_consumed_args; - if (width.unit == RESIZE_UNIT_INVALID) { - return cmd_results_new(CMD_INVALID, "resize", usage); + struct resize_amount width = {0}; + if (argc >= 2 && !strcmp(argv[0], "width") && strcmp(argv[1], "height")) { + argc--; argv++; } - if (!argc) { - return cmd_results_new(CMD_INVALID, "resize", usage); + if (strcmp(argv[0], "height")) { + int num_consumed_args = parse_resize_amount(argc, argv, &width); + argc -= num_consumed_args; + argv += num_consumed_args; + if (width.unit == RESIZE_UNIT_INVALID) { + return cmd_results_new(CMD_INVALID, "resize set", usage); + } } // Height - struct resize_amount height; - num_consumed_args = parse_resize_amount(argc, argv, &height); - argc -= num_consumed_args; - argv += num_consumed_args; - if (height.unit == RESIZE_UNIT_INVALID) { - return cmd_results_new(CMD_INVALID, "resize", usage); + struct resize_amount height = {0}; + if (argc) { + if (argc >= 2 && !strcmp(argv[0], "height")) { + argc--; argv++; + } + int num_consumed_args = parse_resize_amount(argc, argv, &height); + argc -= num_consumed_args; + argv += num_consumed_args; + if (width.unit == RESIZE_UNIT_INVALID) { + return cmd_results_new(CMD_INVALID, "resize set", usage); + } } // If 0, don't resize that dimension -- cgit v1.2.3