diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2019-03-29 12:26:08 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-03-31 17:49:05 -0600 |
commit | 679c058fac986314675bacf7a7b01d263fb0db39 (patch) | |
tree | 1d5ade6a8e4304f18fe6ac5943e3ac6aa68f4136 | |
parent | floating: fix size of non-view containers (diff) | |
download | sway-679c058fac986314675bacf7a7b01d263fb0db39.tar.gz sway-679c058fac986314675bacf7a7b01d263fb0db39.tar.zst sway-679c058fac986314675bacf7a7b01d263fb0db39.zip |
scratchpad: set initial size
This matches i3's behavior of setting scratchpad containers to 50% of
the workspace's width and 75% of the workspace's height, bound by the
minimum and maximum floating width/height.
-rw-r--r-- | include/sway/tree/container.h | 2 | ||||
-rw-r--r-- | sway/tree/container.c | 15 | ||||
-rw-r--r-- | sway/tree/root.c | 2 |
3 files changed, 16 insertions, 3 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 964061db..8448d705 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h | |||
@@ -217,6 +217,8 @@ void floating_calculate_constraints(int *min_width, int *max_width, | |||
217 | 217 | ||
218 | void container_floating_resize_and_center(struct sway_container *con); | 218 | void container_floating_resize_and_center(struct sway_container *con); |
219 | 219 | ||
220 | void container_floating_set_default_size(struct sway_container *con); | ||
221 | |||
220 | void container_set_floating(struct sway_container *container, bool enable); | 222 | void container_set_floating(struct sway_container *container, bool enable); |
221 | 223 | ||
222 | void container_set_geometry_from_content(struct sway_container *con); | 224 | void container_set_geometry_from_content(struct sway_container *con); |
diff --git a/sway/tree/container.c b/sway/tree/container.c index 064d85f6..02b4d1b0 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -712,19 +712,28 @@ 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) { | 715 | void container_floating_set_default_size(struct sway_container *con) { |
716 | if (!sway_assert(con->workspace, "Expected a container on a workspace")) { | 716 | if (!sway_assert(con->workspace, "Expected a container on a workspace")) { |
717 | return; | 717 | return; |
718 | } | 718 | } |
719 | |||
719 | int min_width, max_width, min_height, max_height; | 720 | int min_width, max_width, min_height, max_height; |
720 | floating_calculate_constraints(&min_width, &max_width, | 721 | floating_calculate_constraints(&min_width, &max_width, |
721 | &min_height, &max_height); | 722 | &min_height, &max_height); |
722 | struct wlr_box *box = calloc(1, sizeof(struct wlr_box)); | 723 | struct wlr_box *box = calloc(1, sizeof(struct wlr_box)); |
723 | workspace_get_box(con->workspace, box); | 724 | workspace_get_box(con->workspace, box); |
725 | |||
726 | double width = fmax(min_width, fmin(box->width * 0.5, max_width)); | ||
727 | double height = fmax(min_height, fmin(box->height * 0.75, max_height)); | ||
724 | if (!con->view) { | 728 | if (!con->view) { |
725 | con->width = fmax(min_width, fmin(box->width * 0.5, max_width)); | 729 | con->width = width; |
726 | con->height = fmax(min_height, fmin(box->height * 0.75, max_height)); | 730 | con->height = height; |
731 | } else { | ||
732 | con->content_width = width; | ||
733 | con->content_height = height; | ||
734 | container_set_geometry_from_content(con); | ||
727 | } | 735 | } |
736 | |||
728 | free(box); | 737 | free(box); |
729 | } | 738 | } |
730 | 739 | ||
diff --git a/sway/tree/root.c b/sway/tree/root.c index bc9c610d..3d93405e 100644 --- a/sway/tree/root.c +++ b/sway/tree/root.c | |||
@@ -62,6 +62,8 @@ void root_scratchpad_add_container(struct sway_container *con) { | |||
62 | struct sway_container *parent = con->parent; | 62 | struct sway_container *parent = con->parent; |
63 | struct sway_workspace *workspace = con->workspace; | 63 | struct sway_workspace *workspace = con->workspace; |
64 | container_set_floating(con, true); | 64 | container_set_floating(con, true); |
65 | container_floating_set_default_size(con); | ||
66 | container_floating_move_to_center(con); | ||
65 | container_detach(con); | 67 | container_detach(con); |
66 | con->scratchpad = true; | 68 | con->scratchpad = true; |
67 | list_add(root->scratchpad, con); | 69 | list_add(root->scratchpad, con); |