diff options
-rw-r--r-- | sway/tree/container.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index b7ea2b7e..064d85f6 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -654,8 +654,8 @@ static void floating_natural_resize(struct sway_container *con) { | |||
654 | floating_calculate_constraints(&min_width, &max_width, | 654 | floating_calculate_constraints(&min_width, &max_width, |
655 | &min_height, &max_height); | 655 | &min_height, &max_height); |
656 | if (!con->view) { | 656 | if (!con->view) { |
657 | con->width = max_width; | 657 | con->width = fmax(min_width, fmin(con->width, max_width)); |
658 | con->height = max_height; | 658 | con->height = fmax(min_height, fmin(con->height, max_height)); |
659 | } else { | 659 | } else { |
660 | struct sway_view *view = con->view; | 660 | struct sway_view *view = con->view; |
661 | con->content_width = | 661 | con->content_width = |
@@ -712,6 +712,22 @@ void container_floating_resize_and_center(struct sway_container *con) { | |||
712 | } | 712 | } |
713 | } | 713 | } |
714 | 714 | ||
715 | static void container_floating_set_default_size(struct sway_container *con) { | ||
716 | if (!sway_assert(con->workspace, "Expected a container on a workspace")) { | ||
717 | return; | ||
718 | } | ||
719 | int min_width, max_width, min_height, max_height; | ||
720 | floating_calculate_constraints(&min_width, &max_width, | ||
721 | &min_height, &max_height); | ||
722 | struct wlr_box *box = calloc(1, sizeof(struct wlr_box)); | ||
723 | workspace_get_box(con->workspace, box); | ||
724 | if (!con->view) { | ||
725 | con->width = fmax(min_width, fmin(box->width * 0.5, max_width)); | ||
726 | con->height = fmax(min_height, fmin(box->height * 0.75, max_height)); | ||
727 | } | ||
728 | free(box); | ||
729 | } | ||
730 | |||
715 | void container_set_floating(struct sway_container *container, bool enable) { | 731 | void container_set_floating(struct sway_container *container, bool enable) { |
716 | if (container_is_floating(container) == enable) { | 732 | if (container_is_floating(container) == enable) { |
717 | return; | 733 | return; |
@@ -724,6 +740,7 @@ void container_set_floating(struct sway_container *container, bool enable) { | |||
724 | struct sway_container *old_parent = container->parent; | 740 | struct sway_container *old_parent = container->parent; |
725 | container_detach(container); | 741 | container_detach(container); |
726 | workspace_add_floating(workspace, container); | 742 | workspace_add_floating(workspace, container); |
743 | container_floating_set_default_size(container); | ||
727 | container_floating_resize_and_center(container); | 744 | container_floating_resize_and_center(container); |
728 | if (container->view) { | 745 | if (container->view) { |
729 | view_set_tiled(container->view, false); | 746 | view_set_tiled(container->view, false); |