diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2019-03-29 12:15:17 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-03-31 17:49:05 -0600 |
commit | 0676ace97fdd0054af6b0a4950e219ebd0a18de4 (patch) | |
tree | da38135b541ccf96f93c59f6a8d46c873f148b93 | |
parent | Fix xwayland configure request scratchpad crash (diff) | |
download | sway-0676ace97fdd0054af6b0a4950e219ebd0a18de4.tar.gz sway-0676ace97fdd0054af6b0a4950e219ebd0a18de4.tar.zst sway-0676ace97fdd0054af6b0a4950e219ebd0a18de4.zip |
floating: fix size of non-view containers
This fixes the sizing of floating non-view containers. On master, the
floater will get set to the maximum width and height, which by default
is the entire output layout. When setting a non-view container to
floating, this will set a sane default size of 50% of the workspace
width and 75% of the workspace height, or whatever the closest is that
the minimum and maximum floating width/height values allow for. On all
future calls to `floating_natural_resize`, the width and height will be
kept unless they need to be changed to respect the min/max floating
width/height values.
-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); |