diff options
author | Trevor Slocum <trevor@rocketnine.space> | 2018-11-16 07:30:46 -0800 |
---|---|---|
committer | Trevor Slocum <trevor@rocketnine.space> | 2018-11-16 07:30:46 -0800 |
commit | f4ccc51da0990b728601393671dbbf4b66d81033 (patch) | |
tree | 48b9ace50cf01eeff510242101ce140d55f478ea /sway/commands/resize.c | |
parent | Merge pull request #3130 from RyanDwyer/fix-mode-double-free (diff) | |
download | sway-f4ccc51da0990b728601393671dbbf4b66d81033.tar.gz sway-f4ccc51da0990b728601393671dbbf4b66d81033.tar.zst sway-f4ccc51da0990b728601393671dbbf4b66d81033.zip |
resize set: convert ppt to px for floating containers
Diffstat (limited to 'sway/commands/resize.c')
-rw-r--r-- | sway/commands/resize.c | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/sway/commands/resize.c b/sway/commands/resize.c index a82bec20..94ffbbe1 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c | |||
@@ -511,16 +511,40 @@ static struct cmd_results *resize_set_tiled(struct sway_container *con, | |||
511 | */ | 511 | */ |
512 | static struct cmd_results *resize_set_floating(struct sway_container *con, | 512 | static struct cmd_results *resize_set_floating(struct sway_container *con, |
513 | struct resize_amount *width, struct resize_amount *height) { | 513 | struct resize_amount *width, struct resize_amount *height) { |
514 | int min_width, max_width, min_height, max_height; | 514 | int min_width, max_width, min_height, max_height, grow_width, grow_height; |
515 | calculate_constraints(&min_width, &max_width, &min_height, &max_height); | 515 | calculate_constraints(&min_width, &max_width, &min_height, &max_height); |
516 | width->amount = fmax(min_width, fmin(width->amount, max_width)); | 516 | |
517 | height->amount = fmax(min_height, fmin(height->amount, max_height)); | 517 | if (width->amount) { |
518 | int grow_width = width->amount - con->width; | 518 | if (width->unit == RESIZE_UNIT_PPT || |
519 | int grow_height = height->amount - con->height; | 519 | width->unit == RESIZE_UNIT_DEFAULT) { |
520 | con->x -= grow_width / 2; | 520 | // Convert to px |
521 | con->y -= grow_height / 2; | 521 | width->amount = con->workspace->width * width->amount / 100; |
522 | con->width = width->amount; | 522 | width->unit = RESIZE_UNIT_PX; |
523 | con->height = height->amount; | 523 | } |
524 | if (width->unit == RESIZE_UNIT_PX) { | ||
525 | width->amount = fmax(min_width, fmin(width->amount, max_width)); | ||
526 | grow_width = width->amount - con->width; | ||
527 | |||
528 | con->x -= grow_width / 2; | ||
529 | con->width = width->amount; | ||
530 | } | ||
531 | } | ||
532 | |||
533 | if (height->amount) { | ||
534 | if (height->unit == RESIZE_UNIT_PPT || | ||
535 | height->unit == RESIZE_UNIT_DEFAULT) { | ||
536 | // Convert to px | ||
537 | height->amount = con->workspace->height * height->amount / 100; | ||
538 | height->unit = RESIZE_UNIT_PX; | ||
539 | } | ||
540 | if (height->unit == RESIZE_UNIT_PX) { | ||
541 | height->amount = fmax(min_height, fmin(height->amount, max_height)); | ||
542 | grow_height = height->amount - con->height; | ||
543 | |||
544 | con->y -= grow_height / 2; | ||
545 | con->height = height->amount; | ||
546 | } | ||
547 | } | ||
524 | 548 | ||
525 | if (con->view) { | 549 | if (con->view) { |
526 | struct sway_view *view = con->view; | 550 | struct sway_view *view = con->view; |