aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/resize.c
diff options
context:
space:
mode:
authorLibravatar Pedro CĂ´rte-Real <pedro@pedrocr.net>2019-06-28 22:21:20 +0100
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-07-14 11:13:55 -0400
commite3a3917d3afb66fc8ba3eebb7aed603d3b7ce844 (patch)
tree6af979d7b1c1aeed9d88f168a9a0d1e1f7e663c0 /sway/commands/resize.c
parentLayout correctly with several new windows (diff)
downloadsway-e3a3917d3afb66fc8ba3eebb7aed603d3b7ce844.tar.gz
sway-e3a3917d3afb66fc8ba3eebb7aed603d3b7ce844.tar.zst
sway-e3a3917d3afb66fc8ba3eebb7aed603d3b7ce844.zip
Layout tiled using a width/height fraction
Instead of using container->width/height as both the input and output of the layout calculation have container->width_fraction/height_fraction as the share of the parent this container occupies and calculate the layout based on that. That way the container arrangement can always be recalculated even if width/height have been altered by things like fullscreen. To do this several parts are reworked: - The vertical and horizontal arrangement code is ajusted to work with fractions instead of directly with width/height - The resize code is then changed to manipulate the fractions when working on tiled containers. - Finally the places that manipulated width/height are adjusted to match. The adjusted parts are container split, swap, and the input seat code. It's possible that some parts of the code are now adjusting width and height only for those to be immediately recalculated. That's harmless and since non-tiled containers are still sized with width/height directly it may avoid breaking other corner cases. Fixes #3547 Fixes #4297
Diffstat (limited to 'sway/commands/resize.c')
-rw-r--r--sway/commands/resize.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/sway/commands/resize.c b/sway/commands/resize.c
index 440937f0..28f2552e 100644
--- a/sway/commands/resize.c
+++ b/sway/commands/resize.c
@@ -174,10 +174,14 @@ void container_resize_tiled(struct sway_container *con,
174 if (prev && prev->width - sibling_amount < MIN_SANE_W) { 174 if (prev && prev->width - sibling_amount < MIN_SANE_W) {
175 return; 175 return;
176 } 176 }
177 con->width += amount; 177
178 next->width -= sibling_amount; 178 con->width_fraction +=
179 ((double)amount / con->width) * con->width_fraction;
180 next->width_fraction -=
181 ((double)sibling_amount / con->width) * con->width_fraction;
179 if (prev) { 182 if (prev) {
180 prev->width -= sibling_amount; 183 prev->width_fraction -=
184 ((double)sibling_amount / con->width) * con->width_fraction;
181 } 185 }
182 } else { 186 } else {
183 if (con->height + amount < MIN_SANE_H) { 187 if (con->height + amount < MIN_SANE_H) {
@@ -189,10 +193,14 @@ void container_resize_tiled(struct sway_container *con,
189 if (prev && prev->height - sibling_amount < MIN_SANE_H) { 193 if (prev && prev->height - sibling_amount < MIN_SANE_H) {
190 return; 194 return;
191 } 195 }
192 con->height += amount; 196
193 next->height -= sibling_amount; 197 con->height_fraction +=
198 ((double)amount / con->height) * con->height_fraction;
199 next->height_fraction -=
200 ((double)sibling_amount / con->height) * con->height_fraction;
194 if (prev) { 201 if (prev) {
195 prev->height -= sibling_amount; 202 prev->height_fraction -=
203 ((double)sibling_amount / con->height) * con->height_fraction;
196 } 204 }
197 } 205 }
198 206
@@ -280,10 +288,11 @@ static struct cmd_results *resize_adjust_tiled(uint32_t axis,
280 } 288 }
281 } 289 }
282 290
283 double old_width = current->width; 291 double old_width = current->width_fraction;
284 double old_height = current->height; 292 double old_height = current->height_fraction;
285 container_resize_tiled(current, axis, amount->amount); 293 container_resize_tiled(current, axis, amount->amount);
286 if (current->width == old_width && current->height == old_height) { 294 if (current->width_fraction == old_width &&
295 current->height_fraction == old_height) {
287 return cmd_results_new(CMD_INVALID, "Cannot resize any further"); 296 return cmd_results_new(CMD_INVALID, "Cannot resize any further");
288 } 297 }
289 return cmd_results_new(CMD_SUCCESS, NULL); 298 return cmd_results_new(CMD_SUCCESS, NULL);