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 /sway/tree/container.c | |
parent | dd28e6a6d6abf06d2d16e6c91aeaf942bf225af7 (diff) |
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.
Diffstat (limited to 'sway/tree/container.c')
-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) { floating_calculate_constraints(&min_width, &max_width, &min_height, &max_height); if (!con->view) { - con->width = max_width; - con->height = max_height; + con->width = fmax(min_width, fmin(con->width, max_width)); + con->height = fmax(min_height, fmin(con->height, max_height)); } else { struct sway_view *view = con->view; con->content_width = @@ -712,6 +712,22 @@ void container_floating_resize_and_center(struct sway_container *con) { } } +static void container_floating_set_default_size(struct sway_container *con) { + if (!sway_assert(con->workspace, "Expected a container on a workspace")) { + return; + } + int min_width, max_width, min_height, max_height; + floating_calculate_constraints(&min_width, &max_width, + &min_height, &max_height); + struct wlr_box *box = calloc(1, sizeof(struct wlr_box)); + workspace_get_box(con->workspace, box); + if (!con->view) { + con->width = fmax(min_width, fmin(box->width * 0.5, max_width)); + con->height = fmax(min_height, fmin(box->height * 0.75, max_height)); + } + free(box); +} + void container_set_floating(struct sway_container *container, bool enable) { if (container_is_floating(container) == enable) { return; @@ -724,6 +740,7 @@ void container_set_floating(struct sway_container *container, bool enable) { struct sway_container *old_parent = container->parent; container_detach(container); workspace_add_floating(workspace, container); + container_floating_set_default_size(container); container_floating_resize_and_center(container); if (container->view) { view_set_tiled(container->view, false); |