aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/resize.c
diff options
context:
space:
mode:
authorLibravatar Pedro CĂ´rte-Real <pedro@pedrocr.net>2019-07-28 02:44:32 +0100
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-07-27 23:36:16 -0400
commitcefc608cb942ce260dcbfc13079e29e684893bfa (patch)
tree4a7a04a1de16d3aedc60c1b9a97ff541d4a0a2b7 /sway/commands/resize.c
parentRemove all wayland-server.h includes (diff)
downloadsway-cefc608cb942ce260dcbfc13079e29e684893bfa.tar.gz
sway-cefc608cb942ce260dcbfc13079e29e684893bfa.tar.zst
sway-cefc608cb942ce260dcbfc13079e29e684893bfa.zip
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
Diffstat (limited to 'sway/commands/resize.c')
-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,
160 } 160 }
161 161
162 // Apply new dimensions 162 // Apply new dimensions
163 int sibling_amount = prev ? amount / 2 : amount; 163 int sibling_amount = prev ? ceil((double)amount / 2.0) : amount;
164 164
165 if (is_horizontal(axis)) { 165 if (is_horizontal(axis)) {
166 if (con->width + amount < MIN_SANE_W) { 166 if (con->width + amount < MIN_SANE_W) {
@@ -173,13 +173,15 @@ void container_resize_tiled(struct sway_container *con,
173 return; 173 return;
174 } 174 }
175 175
176 con->width_fraction += 176 double amount_fraction =
177 ((double)amount / con->width) * con->width_fraction; 177 ((double)amount / con->width) * con->width_fraction;
178 next->width_fraction -= 178 double sibling_amount_fraction =
179 ((double)sibling_amount / con->width) * con->width_fraction; 179 prev ? amount_fraction / 2.0 : amount_fraction;
180
181 con->width_fraction += amount_fraction;
182 next->width_fraction -= sibling_amount_fraction;
180 if (prev) { 183 if (prev) {
181 prev->width_fraction -= 184 prev->width_fraction -= sibling_amount_fraction;
182 ((double)sibling_amount / con->width) * con->width_fraction;
183 } 185 }
184 } else { 186 } else {
185 if (con->height + amount < MIN_SANE_H) { 187 if (con->height + amount < MIN_SANE_H) {
@@ -192,13 +194,15 @@ void container_resize_tiled(struct sway_container *con,
192 return; 194 return;
193 } 195 }
194 196
195 con->height_fraction += 197 double amount_fraction =
196 ((double)amount / con->height) * con->height_fraction; 198 ((double)amount / con->height) * con->height_fraction;
197 next->height_fraction -= 199 double sibling_amount_fraction =
198 ((double)sibling_amount / con->height) * con->height_fraction; 200 prev ? amount_fraction / 2.0 : amount_fraction;
201
202 con->height_fraction += amount_fraction;
203 next->height_fraction -= sibling_amount_fraction;
199 if (prev) { 204 if (prev) {
200 prev->height_fraction -= 205 prev->height_fraction -= sibling_amount_fraction;
201 ((double)sibling_amount / con->height) * con->height_fraction;
202 } 206 }
203 } 207 }
204 208