diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-09-29 17:05:55 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-09-29 17:05:55 +1000 |
commit | 42f1fdf0153e38cfec44d816afe8b598199d1320 (patch) | |
tree | 8b2e2ce185e180d077cb947dd99ac6b4598535f9 | |
parent | Merge pull request #2724 from RedSoxFan/update-man-pages (diff) | |
download | sway-42f1fdf0153e38cfec44d816afe8b598199d1320.tar.gz sway-42f1fdf0153e38cfec44d816afe8b598199d1320.tar.zst sway-42f1fdf0153e38cfec44d816afe8b598199d1320.zip |
Return an error when resizing is a no op
-rw-r--r-- | include/sway/commands.h | 2 | ||||
-rw-r--r-- | sway/commands/resize.c | 30 |
2 files changed, 20 insertions, 12 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h index 1654eb48..370a1f7a 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h | |||
@@ -95,7 +95,7 @@ struct cmd_results *add_color(const char *name, | |||
95 | /** | 95 | /** |
96 | * TODO: Move this function and its dependent functions to container.c. | 96 | * TODO: Move this function and its dependent functions to container.c. |
97 | */ | 97 | */ |
98 | void container_resize_tiled(struct sway_container *parent, enum wlr_edges edge, | 98 | bool container_resize_tiled(struct sway_container *parent, enum wlr_edges edge, |
99 | int amount); | 99 | int amount); |
100 | 100 | ||
101 | sway_cmd cmd_assign; | 101 | sway_cmd cmd_assign; |
diff --git a/sway/commands/resize.c b/sway/commands/resize.c index 99e9dbda..1343b165 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 | ||
182 | static void resize_tiled(struct sway_container *parent, int amount, | 182 | static bool 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; | 186 | return false; |
187 | } | 187 | } |
188 | 188 | ||
189 | enum sway_container_layout parallel_layout = | 189 | enum sway_container_layout parallel_layout = |
@@ -216,7 +216,7 @@ static void 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; | 219 | return false; |
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 void 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; // Too small | 251 | return false; // Too small |
252 | } else if (!major_weight && sibling_size + pixels < min_sane) { | 252 | } else if (!major_weight && sibling_size + pixels < min_sane) { |
253 | return; // Too small | 253 | return false; // 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; // Too small | 258 | return false; // Too small |
259 | } else if (!minor_weight && sibling_size + pixels < min_sane) { | 259 | } else if (!minor_weight && sibling_size + pixels < min_sane) { |
260 | return; // Too small | 260 | return false; // 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; // Too small | 266 | return false; // Too small |
267 | } | 267 | } |
268 | } | 268 | } |
269 | } | 269 | } |
@@ -317,9 +317,10 @@ static void 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; | ||
320 | } | 321 | } |
321 | 322 | ||
322 | void container_resize_tiled(struct sway_container *parent, | 323 | bool container_resize_tiled(struct sway_container *parent, |
323 | enum wlr_edges edge, int amount) { | 324 | enum wlr_edges edge, int amount) { |
324 | enum resize_axis axis = RESIZE_AXIS_INVALID; | 325 | enum resize_axis axis = RESIZE_AXIS_INVALID; |
325 | switch (edge) { | 326 | switch (edge) { |
@@ -338,7 +339,7 @@ void container_resize_tiled(struct sway_container *parent, | |||
338 | case WLR_EDGE_NONE: | 339 | case WLR_EDGE_NONE: |
339 | break; | 340 | break; |
340 | } | 341 | } |
341 | resize_tiled(parent, amount, axis); | 342 | return resize_tiled(parent, amount, axis); |
342 | } | 343 | } |
343 | 344 | ||
344 | /** | 345 | /** |
@@ -395,6 +396,10 @@ static struct cmd_results *resize_adjust_floating(enum resize_axis axis, | |||
395 | case RESIZE_AXIS_INVALID: | 396 | case RESIZE_AXIS_INVALID: |
396 | return cmd_results_new(CMD_INVALID, "resize", "Invalid axis/direction"); | 397 | return cmd_results_new(CMD_INVALID, "resize", "Invalid axis/direction"); |
397 | } | 398 | } |
399 | if (grow_x == 0 && grow_y == 0) { | ||
400 | return cmd_results_new(CMD_INVALID, "resize", | ||
401 | "Cannot resize any further"); | ||
402 | } | ||
398 | con->x += grow_x; | 403 | con->x += grow_x; |
399 | con->y += grow_y; | 404 | con->y += grow_y; |
400 | con->width += grow_width; | 405 | con->width += grow_width; |
@@ -442,7 +447,10 @@ static struct cmd_results *resize_adjust_tiled(enum resize_axis axis, | |||
442 | } | 447 | } |
443 | } | 448 | } |
444 | 449 | ||
445 | resize_tiled(current, amount->amount, axis); | 450 | if (!resize_tiled(current, amount->amount, axis)) { |
451 | return cmd_results_new(CMD_INVALID, "resize", | ||
452 | "Cannot resize any further"); | ||
453 | } | ||
446 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 454 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
447 | } | 455 | } |
448 | 456 | ||