aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/resize.c
diff options
context:
space:
mode:
authorRyan Dwyer <ryandwyer1@gmail.com>2018-08-09 20:25:24 +1000
committerRyan Dwyer <ryandwyer1@gmail.com>2018-08-10 08:50:15 +1000
commit6c730a2cb2baf8be9e48c6dfa984b29214fc2d62 (patch)
treec47fc1f5c5e91d398c4fbfbcd21bf8b3523eab86 /sway/commands/resize.c
parent9395d3c93c7d4dd37cadaea2ca56b3341074863a (diff)
Implement resize set <width> <height> for tiled containers
Unlike i3, this implementation allows px measurements. Also fixes a sane size check.
Diffstat (limited to 'sway/commands/resize.c')
-rw-r--r--sway/commands/resize.c43
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);
}
/**