diff options
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r-- | sway/tree/container.c | 64 |
1 files changed, 43 insertions, 21 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index d448df22..33043941 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -611,56 +611,78 @@ size_t container_titlebar_height(void) { | |||
611 | return config->font_height + config->titlebar_v_padding * 2; | 611 | return config->font_height + config->titlebar_v_padding * 2; |
612 | } | 612 | } |
613 | 613 | ||
614 | void container_init_floating(struct sway_container *con) { | 614 | void floating_calculate_constraints(int *min_width, int *max_width, |
615 | struct sway_workspace *ws = con->workspace; | 615 | int *min_height, int *max_height) { |
616 | int min_width, min_height; | ||
617 | int max_width, max_height; | ||
618 | |||
619 | if (config->floating_minimum_width == -1) { // no minimum | 616 | if (config->floating_minimum_width == -1) { // no minimum |
620 | min_width = 0; | 617 | *min_width = 0; |
621 | } else if (config->floating_minimum_width == 0) { // automatic | 618 | } else if (config->floating_minimum_width == 0) { // automatic |
622 | min_width = 75; | 619 | *min_width = 75; |
623 | } else { | 620 | } else { |
624 | min_width = config->floating_minimum_width; | 621 | *min_width = config->floating_minimum_width; |
625 | } | 622 | } |
626 | 623 | ||
627 | if (config->floating_minimum_height == -1) { // no minimum | 624 | if (config->floating_minimum_height == -1) { // no minimum |
628 | min_height = 0; | 625 | *min_height = 0; |
629 | } else if (config->floating_minimum_height == 0) { // automatic | 626 | } else if (config->floating_minimum_height == 0) { // automatic |
630 | min_height = 50; | 627 | *min_height = 50; |
631 | } else { | 628 | } else { |
632 | min_height = config->floating_minimum_height; | 629 | *min_height = config->floating_minimum_height; |
633 | } | 630 | } |
634 | 631 | ||
632 | struct wlr_box *box = wlr_output_layout_get_box(root->output_layout, NULL); | ||
633 | |||
635 | if (config->floating_maximum_width == -1) { // no maximum | 634 | if (config->floating_maximum_width == -1) { // no maximum |
636 | max_width = INT_MAX; | 635 | *max_width = INT_MAX; |
637 | } else if (config->floating_maximum_width == 0) { // automatic | 636 | } else if (config->floating_maximum_width == 0) { // automatic |
638 | max_width = ws->width * 0.6666; | 637 | *max_width = box->width; |
639 | } else { | 638 | } else { |
640 | max_width = config->floating_maximum_width; | 639 | *max_width = config->floating_maximum_width; |
641 | } | 640 | } |
642 | 641 | ||
643 | if (config->floating_maximum_height == -1) { // no maximum | 642 | if (config->floating_maximum_height == -1) { // no maximum |
644 | max_height = INT_MAX; | 643 | *max_height = INT_MAX; |
645 | } else if (config->floating_maximum_height == 0) { // automatic | 644 | } else if (config->floating_maximum_height == 0) { // automatic |
646 | max_height = ws->height * 0.6666; | 645 | *max_height = box->height; |
647 | } else { | 646 | } else { |
648 | max_height = config->floating_maximum_height; | 647 | *max_height = config->floating_maximum_height; |
649 | } | 648 | } |
650 | 649 | ||
650 | } | ||
651 | |||
652 | void container_init_floating(struct sway_container *con) { | ||
653 | struct sway_workspace *ws = con->workspace; | ||
654 | int min_width, max_width, min_height, max_height; | ||
655 | floating_calculate_constraints(&min_width, &max_width, | ||
656 | &min_height, &max_height); | ||
657 | |||
651 | if (!con->view) { | 658 | if (!con->view) { |
652 | con->width = max_width; | 659 | con->width = max_width; |
653 | con->height = max_height; | 660 | con->height = max_height; |
654 | con->x = ws->x + (ws->width - con->width) / 2; | 661 | if (con->width > ws->width || con->height > ws->height) { |
655 | con->y = ws->y + (ws->height - con->height) / 2; | 662 | struct wlr_box *ob = wlr_output_layout_get_box(root->output_layout, |
663 | ws->output->wlr_output); | ||
664 | con->x = ob->x + (ob->width - con->width) / 2; | ||
665 | con->y = ob->y + (ob->height - con->height) / 2; | ||
666 | } else { | ||
667 | con->x = ws->x + (ws->width - con->width) / 2; | ||
668 | con->y = ws->y + (ws->height - con->height) / 2; | ||
669 | } | ||
656 | } else { | 670 | } else { |
657 | struct sway_view *view = con->view; | 671 | struct sway_view *view = con->view; |
658 | con->content_width = | 672 | con->content_width = |
659 | fmax(min_width, fmin(view->natural_width, max_width)); | 673 | fmax(min_width, fmin(view->natural_width, max_width)); |
660 | con->content_height = | 674 | con->content_height = |
661 | fmax(min_height, fmin(view->natural_height, max_height)); | 675 | fmax(min_height, fmin(view->natural_height, max_height)); |
662 | con->content_x = ws->x + (ws->width - con->content_width) / 2; | 676 | if (con->content_width > ws->width |
663 | con->content_y = ws->y + (ws->height - con->content_height) / 2; | 677 | || con->content_height > ws->height) { |
678 | struct wlr_box *ob = wlr_output_layout_get_box(root->output_layout, | ||
679 | ws->output->wlr_output); | ||
680 | con->content_x = ob->x + (ob->width - con->content_width) / 2; | ||
681 | con->content_y = ob->y + (ob->height - con->content_height) / 2; | ||
682 | } else { | ||
683 | con->content_x = ws->x + (ws->width - con->content_width) / 2; | ||
684 | con->content_y = ws->y + (ws->height - con->content_height) / 2; | ||
685 | } | ||
664 | 686 | ||
665 | // If the view's border is B_NONE then these properties are ignored. | 687 | // If the view's border is B_NONE then these properties are ignored. |
666 | con->border_top = con->border_bottom = true; | 688 | con->border_top = con->border_bottom = true; |