aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/resize.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-11-08 14:17:49 -0500
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-11-08 14:17:49 -0500
commitc248e96b849a125d88d0fffc744d0f98b8c558d9 (patch)
tree375c263c1d5fcd87a98c8f4a4932307b9f6f8468 /sway/commands/resize.c
parentMerge pull request #3089 from sghctoma/fix-clang-build (diff)
downloadsway-c248e96b849a125d88d0fffc744d0f98b8c558d9.tar.gz
sway-c248e96b849a125d88d0fffc744d0f98b8c558d9.tar.zst
sway-c248e96b849a125d88d0fffc744d0f98b8c558d9.zip
resize set: implement width and height keywords
This implements the following syntaxes from `i3 4.16`: * `resize set [width] <width> [px|ppt]` * `resize set height <height> [px|ppt]` * `resize set [width] <width> [px|ppt] [height] <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.
Diffstat (limited to 'sway/commands/resize.c')
-rw-r--r--sway/commands/resize.c47
1 files changed, 29 insertions, 18 deletions
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,
499 } 499 }
500 if (height->unit == RESIZE_UNIT_PX) { 500 if (height->unit == RESIZE_UNIT_PX) {
501 resize_tiled(con, height->amount - con->height, 501 resize_tiled(con, height->amount - con->height,
502 RESIZE_AXIS_HORIZONTAL); 502 RESIZE_AXIS_VERTICAL);
503 } 503 }
504 } 504 }
505 505
@@ -538,34 +538,45 @@ static struct cmd_results *resize_set_floating(struct sway_container *con,
538/** 538/**
539 * resize set <args> 539 * resize set <args>
540 * 540 *
541 * args: <width> [px|ppt] <height> [px|ppt] 541 * args: [width] <width> [px|ppt]
542 * : height <height> [px|ppt]
543 * : [width] <width> [px|ppt] [height] <height> [px|ppt]
542 */ 544 */
543static struct cmd_results *cmd_resize_set(int argc, char **argv) { 545static struct cmd_results *cmd_resize_set(int argc, char **argv) {
544 struct cmd_results *error; 546 struct cmd_results *error;
545 if ((error = checkarg(argc, "resize", EXPECTED_AT_LEAST, 2))) { 547 if ((error = checkarg(argc, "resize", EXPECTED_AT_LEAST, 1))) {
546 return error; 548 return error;
547 } 549 }
548 const char *usage = "Expected 'resize set <width> <height>'"; 550 const char *usage = "Expected 'resize set [width] <width> [px|ppt]' or "
551 "'resize set height <height> [px|ppt]' or "
552 "'resize set [width] <width> [px|ppt] [height] <height> [px|ppt]'";
549 553
550 // Width 554 // Width
551 struct resize_amount width; 555 struct resize_amount width = {0};
552 int num_consumed_args = parse_resize_amount(argc, argv, &width); 556 if (argc >= 2 && !strcmp(argv[0], "width") && strcmp(argv[1], "height")) {
553 argc -= num_consumed_args; 557 argc--; argv++;
554 argv += num_consumed_args;
555 if (width.unit == RESIZE_UNIT_INVALID) {
556 return cmd_results_new(CMD_INVALID, "resize", usage);
557 } 558 }
558 if (!argc) { 559 if (strcmp(argv[0], "height")) {
559 return cmd_results_new(CMD_INVALID, "resize", usage); 560 int num_consumed_args = parse_resize_amount(argc, argv, &width);
561 argc -= num_consumed_args;
562 argv += num_consumed_args;
563 if (width.unit == RESIZE_UNIT_INVALID) {
564 return cmd_results_new(CMD_INVALID, "resize set", usage);
565 }
560 } 566 }
561 567
562 // Height 568 // Height
563 struct resize_amount height; 569 struct resize_amount height = {0};
564 num_consumed_args = parse_resize_amount(argc, argv, &height); 570 if (argc) {
565 argc -= num_consumed_args; 571 if (argc >= 2 && !strcmp(argv[0], "height")) {
566 argv += num_consumed_args; 572 argc--; argv++;
567 if (height.unit == RESIZE_UNIT_INVALID) { 573 }
568 return cmd_results_new(CMD_INVALID, "resize", usage); 574 int num_consumed_args = parse_resize_amount(argc, argv, &height);
575 argc -= num_consumed_args;
576 argv += num_consumed_args;
577 if (width.unit == RESIZE_UNIT_INVALID) {
578 return cmd_results_new(CMD_INVALID, "resize set", usage);
579 }
569 } 580 }
570 581
571 // If 0, don't resize that dimension 582 // If 0, don't resize that dimension