diff options
Diffstat (limited to 'sway/commands/resize.c')
-rw-r--r-- | sway/commands/resize.c | 111 |
1 files changed, 70 insertions, 41 deletions
diff --git a/sway/commands/resize.c b/sway/commands/resize.c index 8635b309..a90d578e 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c @@ -404,13 +404,10 @@ static struct cmd_results *resize_adjust_floating(enum resize_axis axis, con->width += grow_width; con->height += grow_height; - if (con->view) { - struct sway_view *view = con->view; - view->x += grow_x; - view->y += grow_y; - view->width += grow_width; - view->height += grow_height; - } + con->content_x += grow_x; + con->content_y += grow_y; + con->content_width += grow_width; + con->content_height += grow_height; arrange_container(con); @@ -499,7 +496,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); } } @@ -511,25 +508,46 @@ static struct cmd_results *resize_set_tiled(struct sway_container *con, */ static struct cmd_results *resize_set_floating(struct sway_container *con, struct resize_amount *width, struct resize_amount *height) { - int min_width, max_width, min_height, max_height; + int min_width, max_width, min_height, max_height, grow_width = 0, grow_height = 0; calculate_constraints(&min_width, &max_width, &min_height, &max_height); - width->amount = fmax(min_width, fmin(width->amount, max_width)); - height->amount = fmax(min_height, fmin(height->amount, max_height)); - int grow_width = width->amount - con->width; - int grow_height = height->amount - con->height; - con->x -= grow_width / 2; - con->y -= grow_height / 2; - con->width = width->amount; - con->height = height->amount; - - if (con->view) { - struct sway_view *view = con->view; - view->x -= grow_width / 2; - view->y -= grow_height / 2; - view->width += grow_width; - view->height += grow_height; + + if (width->amount) { + if (width->unit == RESIZE_UNIT_PPT || + width->unit == RESIZE_UNIT_DEFAULT) { + // Convert to px + width->amount = con->workspace->width * width->amount / 100; + width->unit = RESIZE_UNIT_PX; + } + if (width->unit == RESIZE_UNIT_PX) { + width->amount = fmax(min_width, fmin(width->amount, max_width)); + grow_width = width->amount - con->width; + + con->x -= grow_width / 2; + con->width = width->amount; + } } + if (height->amount) { + if (height->unit == RESIZE_UNIT_PPT || + height->unit == RESIZE_UNIT_DEFAULT) { + // Convert to px + height->amount = con->workspace->height * height->amount / 100; + height->unit = RESIZE_UNIT_PX; + } + if (height->unit == RESIZE_UNIT_PX) { + height->amount = fmax(min_height, fmin(height->amount, max_height)); + grow_height = height->amount - con->height; + + con->y -= grow_height / 2; + con->height = height->amount; + } + } + + con->content_x -= grow_width / 2; + con->content_y -= grow_height / 2; + con->content_width += grow_width; + con->content_height += grow_height; + arrange_container(con); return cmd_results_new(CMD_SUCCESS, NULL, NULL); @@ -538,34 +556,45 @@ static struct cmd_results *resize_set_floating(struct sway_container *con, /** * resize set <args> * - * args: <width> [px|ppt] <height> [px|ppt] + * args: [width] <width> [px|ppt] + * : height <height> [px|ppt] + * : [width] <width> [px|ppt] [height] <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 <width> <height>'"; + const char *usage = "Expected 'resize set [width] <width> [px|ppt]' or " + "'resize set height <height> [px|ppt]' or " + "'resize set [width] <width> [px|ppt] [height] <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 |