aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/resize.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-10-09 22:25:21 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-10-09 22:25:21 +1000
commit61699a11463d5a1168358ba5f7fece6401ab0654 (patch)
tree3f597e3a0534927e532597a6e2b5ddc59d1c0cfd /sway/commands/resize.c
parentMerge pull request #2804 from Emantor/swaynag-double-free (diff)
downloadsway-61699a11463d5a1168358ba5f7fece6401ab0654.tar.gz
sway-61699a11463d5a1168358ba5f7fece6401ab0654.tar.zst
sway-61699a11463d5a1168358ba5f7fece6401ab0654.zip
resize: Determine if anything changed using before/after check
Returning a boolean from container_resize_tiled and resize_tiled doesn't work in all cases. This patch changes it back to void and does a before/after check to see if the container was resized.
Diffstat (limited to 'sway/commands/resize.c')
-rw-r--r--sway/commands/resize.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/sway/commands/resize.c b/sway/commands/resize.c
index 1343b165..6de14ca3 100644
--- a/sway/commands/resize.c
+++ b/sway/commands/resize.c
@@ -179,11 +179,11 @@ static void container_recursive_resize(struct sway_container *container,
179 } 179 }
180} 180}
181 181
182static bool resize_tiled(struct sway_container *parent, int amount, 182static void resize_tiled(struct sway_container *parent, int amount,
183 enum resize_axis axis) { 183 enum resize_axis axis) {
184 struct sway_container *focused = parent; 184 struct sway_container *focused = parent;
185 if (!parent) { 185 if (!parent) {
186 return false; 186 return;
187 } 187 }
188 188
189 enum sway_container_layout parallel_layout = 189 enum sway_container_layout parallel_layout =
@@ -216,7 +216,7 @@ static bool resize_tiled(struct sway_container *parent, int amount,
216 } 216 }
217 if (!parent) { 217 if (!parent) {
218 // Can't resize in this direction 218 // Can't resize in this direction
219 return false; 219 return;
220 } 220 }
221 221
222 // Implement up/down/left/right direction by zeroing one of the weights, 222 // Implement up/down/left/right direction by zeroing one of the weights,
@@ -248,22 +248,22 @@ static bool resize_tiled(struct sway_container *parent, int amount,
248 if (sibling_pos < parent_pos && minor_weight) { 248 if (sibling_pos < parent_pos && minor_weight) {
249 double pixels = -amount / minor_weight; 249 double pixels = -amount / minor_weight;
250 if (major_weight && (sibling_size + pixels / 2) < min_sane) { 250 if (major_weight && (sibling_size + pixels / 2) < min_sane) {
251 return false; // Too small 251 return; // Too small
252 } else if (!major_weight && sibling_size + pixels < min_sane) { 252 } else if (!major_weight && sibling_size + pixels < min_sane) {
253 return false; // Too small 253 return; // Too small
254 } 254 }
255 } else if (sibling_pos > parent_pos && major_weight) { 255 } else if (sibling_pos > parent_pos && major_weight) {
256 double pixels = -amount / major_weight; 256 double pixels = -amount / major_weight;
257 if (minor_weight && (sibling_size + pixels / 2) < min_sane) { 257 if (minor_weight && (sibling_size + pixels / 2) < min_sane) {
258 return false; // Too small 258 return; // Too small
259 } else if (!minor_weight && sibling_size + pixels < min_sane) { 259 } else if (!minor_weight && sibling_size + pixels < min_sane) {
260 return false; // Too small 260 return; // Too small
261 } 261 }
262 } 262 }
263 } else { 263 } else {
264 double pixels = amount; 264 double pixels = amount;
265 if (parent_size + pixels < min_sane) { 265 if (parent_size + pixels < min_sane) {
266 return false; // Too small 266 return; // Too small
267 } 267 }
268 } 268 }
269 } 269 }
@@ -317,10 +317,9 @@ static bool resize_tiled(struct sway_container *parent, int amount,
317 } else { 317 } else {
318 arrange_workspace(parent->workspace); 318 arrange_workspace(parent->workspace);
319 } 319 }
320 return true;
321} 320}
322 321
323bool container_resize_tiled(struct sway_container *parent, 322void container_resize_tiled(struct sway_container *parent,
324 enum wlr_edges edge, int amount) { 323 enum wlr_edges edge, int amount) {
325 enum resize_axis axis = RESIZE_AXIS_INVALID; 324 enum resize_axis axis = RESIZE_AXIS_INVALID;
326 switch (edge) { 325 switch (edge) {
@@ -339,7 +338,7 @@ bool container_resize_tiled(struct sway_container *parent,
339 case WLR_EDGE_NONE: 338 case WLR_EDGE_NONE:
340 break; 339 break;
341 } 340 }
342 return resize_tiled(parent, amount, axis); 341 resize_tiled(parent, amount, axis);
343} 342}
344 343
345/** 344/**
@@ -447,7 +446,10 @@ static struct cmd_results *resize_adjust_tiled(enum resize_axis axis,
447 } 446 }
448 } 447 }
449 448
450 if (!resize_tiled(current, amount->amount, axis)) { 449 double old_width = current->width;
450 double old_height = current->height;
451 resize_tiled(current, amount->amount, axis);
452 if (current->width == old_width && current->height == old_height) {
451 return cmd_results_new(CMD_INVALID, "resize", 453 return cmd_results_new(CMD_INVALID, "resize",
452 "Cannot resize any further"); 454 "Cannot resize any further");
453 } 455 }