summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFurkan Sahin <furkan-dev@proton.me>2019-07-28 02:44:32 +0100
committerFurkan Sahin <furkan-dev@proton.me>2019-07-28 02:44:32 +0100
commitaed17c6410cb76f02732316a7f7b0ab1a40664e5 (patch)
tree4a7a04a1de16d3aedc60c1b9a97ff541d4a0a2b7
parent3a3f847f4166fefda9e1bfc231bc06d622449b07 (diff)
Fix resize sibling amount calculations
Sibling amounts were being calculated after the original fraction had been altered. This led to broken resize amounts. Fix that by calculating things upfront before adjusting values which also makes the code cleaner. For sanity checks also calculate the sibling amount with the ceiling so we never go below the sanity check even by one pixel. Fixes #4386
-rw-r--r--sway/commands/resize.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/sway/commands/resize.c b/sway/commands/resize.c
index 4cefe60b..0c9af12d 100644
--- a/sway/commands/resize.c
+++ b/sway/commands/resize.c
@@ -160,7 +160,7 @@ void container_resize_tiled(struct sway_container *con,
}
// Apply new dimensions
- int sibling_amount = prev ? amount / 2 : amount;
+ int sibling_amount = prev ? ceil((double)amount / 2.0) : amount;
if (is_horizontal(axis)) {
if (con->width + amount < MIN_SANE_W) {
@@ -173,13 +173,15 @@ void container_resize_tiled(struct sway_container *con,
return;
}
- con->width_fraction +=
+ double amount_fraction =
((double)amount / con->width) * con->width_fraction;
- next->width_fraction -=
- ((double)sibling_amount / con->width) * con->width_fraction;
+ double sibling_amount_fraction =
+ prev ? amount_fraction / 2.0 : amount_fraction;
+
+ con->width_fraction += amount_fraction;
+ next->width_fraction -= sibling_amount_fraction;
if (prev) {
- prev->width_fraction -=
- ((double)sibling_amount / con->width) * con->width_fraction;
+ prev->width_fraction -= sibling_amount_fraction;
}
} else {
if (con->height + amount < MIN_SANE_H) {
@@ -192,13 +194,15 @@ void container_resize_tiled(struct sway_container *con,
return;
}
- con->height_fraction +=
+ double amount_fraction =
((double)amount / con->height) * con->height_fraction;
- next->height_fraction -=
- ((double)sibling_amount / con->height) * con->height_fraction;
+ double sibling_amount_fraction =
+ prev ? amount_fraction / 2.0 : amount_fraction;
+
+ con->height_fraction += amount_fraction;
+ next->height_fraction -= sibling_amount_fraction;
if (prev) {
- prev->height_fraction -=
- ((double)sibling_amount / con->height) * con->height_fraction;
+ prev->height_fraction -= sibling_amount_fraction;
}
}