aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/container.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-03-02 02:29:28 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-03-04 12:50:47 -0500
commita3b9f2dcfa649d9141f7bbb39e5eb951560eef72 (patch)
treefe8e29aed212a23fbdb66237170f5e4b4d79c139 /sway/tree/container.c
parentMinor fix of code duplication. (diff)
downloadsway-a3b9f2dcfa649d9141f7bbb39e5eb951560eef72.tar.gz
sway-a3b9f2dcfa649d9141f7bbb39e5eb951560eef72.tar.zst
sway-a3b9f2dcfa649d9141f7bbb39e5eb951560eef72.zip
floating_maximum_size: change default behavior
This changes the way zero (which is the default) is interpreted for both the width and height of `floating_maximum_size`. It now refers to the width and height of the entire output layout, which matches i3's behavior. This also removes duplicated code to calculate the floating constraints in three files. Before this, `container_init_floating` used two-thirds of the workspace width/height as the max and the entire workspace width/height was used everywhere else. Now, all callers use a single function `floating_calculate_constraints`.
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r--sway/tree/container.c64
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
614void container_init_floating(struct sway_container *con) { 614void 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
652void 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;