diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-08-09 20:25:24 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-08-10 08:50:15 +1000 |
commit | 6c730a2cb2baf8be9e48c6dfa984b29214fc2d62 (patch) | |
tree | c47fc1f5c5e91d398c4fbfbcd21bf8b3523eab86 | |
parent | 9395d3c93c7d4dd37cadaea2ca56b3341074863a (diff) |
Implement resize set <width> <height> for tiled containers
Unlike i3, this implementation allows px measurements.
Also fixes a sane size check.
-rw-r--r-- | sway/commands/resize.c | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/sway/commands/resize.c b/sway/commands/resize.c index 8cf4591e..c3560985 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c @@ -231,14 +231,14 @@ static void resize_tiled(int amount, enum resize_axis axis) { double pixels = -amount / minor_weight; if (major_weight && (sibling_size + pixels / 2) < min_sane) { return; // Too small - } else if ((sibling_size + pixels) < min_sane) { + } else if (!major_weight && sibling_size + pixels < min_sane) { return; // Too small } } else if (sibling_pos > parent_pos && major_weight) { double pixels = -amount / major_weight; if (minor_weight && (sibling_size + pixels / 2) < min_sane) { return; // Too small - } else if ((sibling_size + pixels) < min_sane) { + } else if (!minor_weight && sibling_size + pixels < min_sane) { return; // Too small } } @@ -407,8 +407,43 @@ static struct cmd_results *resize_adjust_tiled(enum resize_axis axis, */ static struct cmd_results *resize_set_tiled(struct sway_container *con, struct resize_amount *width, struct resize_amount *height) { - return cmd_results_new(CMD_INVALID, "resize", - "'resize set' is not implemented for tiled views"); + if (width->amount) { + if (width->unit == RESIZE_UNIT_PPT || + width->unit == RESIZE_UNIT_DEFAULT) { + // Convert to px + struct sway_container *parent = con->parent; + while (parent->type >= C_WORKSPACE && parent->layout != L_HORIZ) { + parent = parent->parent; + } + if (parent->type >= C_WORKSPACE) { + width->amount = parent->width * width->amount / 100; + width->unit = RESIZE_UNIT_PX; + } + } + if (width->unit == RESIZE_UNIT_PX) { + resize_tiled(width->amount - con->width, RESIZE_AXIS_HORIZONTAL); + } + } + + if (height->amount) { + if (height->unit == RESIZE_UNIT_PPT || + height->unit == RESIZE_UNIT_DEFAULT) { + // Convert to px + struct sway_container *parent = con->parent; + while (parent->type >= C_WORKSPACE && parent->layout != L_VERT) { + parent = parent->parent; + } + if (parent->type >= C_WORKSPACE) { + height->amount = parent->height * height->amount / 100; + height->unit = RESIZE_UNIT_PX; + } + } + if (height->unit == RESIZE_UNIT_PX) { + resize_tiled(height->amount - con->height, RESIZE_AXIS_VERTICAL); + } + } + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); } /** |