aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/resize.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-09 20:25:24 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-10 08:50:15 +1000
commit6c730a2cb2baf8be9e48c6dfa984b29214fc2d62 (patch)
treec47fc1f5c5e91d398c4fbfbcd21bf8b3523eab86 /sway/commands/resize.c
parentImplement resize grow|shrink <direction> <amount> for tiled containers (diff)
downloadsway-6c730a2cb2baf8be9e48c6dfa984b29214fc2d62.tar.gz
sway-6c730a2cb2baf8be9e48c6dfa984b29214fc2d62.tar.zst
sway-6c730a2cb2baf8be9e48c6dfa984b29214fc2d62.zip
Implement resize set <width> <height> for tiled containers
Unlike i3, this implementation allows px measurements. Also fixes a sane size check.
Diffstat (limited to 'sway/commands/resize.c')
-rw-r--r--sway/commands/resize.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/sway/commands/resize.c b/sway/commands/resize.c
index 8cf4591e..c3560985 100644
--- a/sway/commands/resize.c
+++ b/sway/commands/resize.c
@@ -231,14 +231,14 @@ static void resize_tiled(int amount, enum resize_axis axis) {
231 double pixels = -amount / minor_weight; 231 double pixels = -amount / minor_weight;
232 if (major_weight && (sibling_size + pixels / 2) < min_sane) { 232 if (major_weight && (sibling_size + pixels / 2) < min_sane) {
233 return; // Too small 233 return; // Too small
234 } else if ((sibling_size + pixels) < min_sane) { 234 } else if (!major_weight && sibling_size + pixels < min_sane) {
235 return; // Too small 235 return; // Too small
236 } 236 }
237 } else if (sibling_pos > parent_pos && major_weight) { 237 } else if (sibling_pos > parent_pos && major_weight) {
238 double pixels = -amount / major_weight; 238 double pixels = -amount / major_weight;
239 if (minor_weight && (sibling_size + pixels / 2) < min_sane) { 239 if (minor_weight && (sibling_size + pixels / 2) < min_sane) {
240 return; // Too small 240 return; // Too small
241 } else if ((sibling_size + pixels) < min_sane) { 241 } else if (!minor_weight && sibling_size + pixels < min_sane) {
242 return; // Too small 242 return; // Too small
243 } 243 }
244 } 244 }
@@ -407,8 +407,43 @@ static struct cmd_results *resize_adjust_tiled(enum resize_axis axis,
407 */ 407 */
408static struct cmd_results *resize_set_tiled(struct sway_container *con, 408static struct cmd_results *resize_set_tiled(struct sway_container *con,
409 struct resize_amount *width, struct resize_amount *height) { 409 struct resize_amount *width, struct resize_amount *height) {
410 return cmd_results_new(CMD_INVALID, "resize", 410 if (width->amount) {
411 "'resize set' is not implemented for tiled views"); 411 if (width->unit == RESIZE_UNIT_PPT ||
412 width->unit == RESIZE_UNIT_DEFAULT) {
413 // Convert to px
414 struct sway_container *parent = con->parent;
415 while (parent->type >= C_WORKSPACE && parent->layout != L_HORIZ) {
416 parent = parent->parent;
417 }
418 if (parent->type >= C_WORKSPACE) {
419 width->amount = parent->width * width->amount / 100;
420 width->unit = RESIZE_UNIT_PX;
421 }
422 }
423 if (width->unit == RESIZE_UNIT_PX) {
424 resize_tiled(width->amount - con->width, RESIZE_AXIS_HORIZONTAL);
425 }
426 }
427
428 if (height->amount) {
429 if (height->unit == RESIZE_UNIT_PPT ||
430 height->unit == RESIZE_UNIT_DEFAULT) {
431 // Convert to px
432 struct sway_container *parent = con->parent;
433 while (parent->type >= C_WORKSPACE && parent->layout != L_VERT) {
434 parent = parent->parent;
435 }
436 if (parent->type >= C_WORKSPACE) {
437 height->amount = parent->height * height->amount / 100;
438 height->unit = RESIZE_UNIT_PX;
439 }
440 }
441 if (height->unit == RESIZE_UNIT_PX) {
442 resize_tiled(height->amount - con->height, RESIZE_AXIS_VERTICAL);
443 }
444 }
445
446 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
412} 447}
413 448
414/** 449/**