diff options
-rw-r--r-- | include/sway/tree/container.h | 5 | ||||
-rw-r--r-- | sway/desktop/xwayland.c | 2 | ||||
-rw-r--r-- | sway/tree/container.c | 41 | ||||
-rw-r--r-- | sway/tree/output.c | 2 | ||||
-rw-r--r-- | sway/tree/root.c | 10 |
5 files changed, 31 insertions, 29 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index d2508994..964061db 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h | |||
@@ -215,10 +215,7 @@ size_t container_titlebar_height(void); | |||
215 | void floating_calculate_constraints(int *min_width, int *max_width, | 215 | void floating_calculate_constraints(int *min_width, int *max_width, |
216 | int *min_height, int *max_height); | 216 | int *min_height, int *max_height); |
217 | 217 | ||
218 | /** | 218 | void container_floating_resize_and_center(struct sway_container *con); |
219 | * Resize and center the container in its workspace. | ||
220 | */ | ||
221 | void container_init_floating(struct sway_container *container); | ||
222 | 219 | ||
223 | void container_set_floating(struct sway_container *container, bool enable); | 220 | void container_set_floating(struct sway_container *container, bool enable); |
224 | 221 | ||
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index f5ade8dc..37d0b986 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c | |||
@@ -435,7 +435,7 @@ static void handle_request_configure(struct wl_listener *listener, void *data) { | |||
435 | // Respect minimum and maximum sizes | 435 | // Respect minimum and maximum sizes |
436 | view->natural_width = ev->width; | 436 | view->natural_width = ev->width; |
437 | view->natural_height = ev->height; | 437 | view->natural_height = ev->height; |
438 | container_init_floating(view->container); | 438 | container_floating_resize_and_center(view->container); |
439 | 439 | ||
440 | configure(view, view->container->content_x, | 440 | configure(view, view->container->content_x, |
441 | view->container->content_y, | 441 | view->container->content_y, |
diff --git a/sway/tree/container.c b/sway/tree/container.c index f84ce360..b7ea2b7e 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -649,8 +649,31 @@ void floating_calculate_constraints(int *min_width, int *max_width, | |||
649 | 649 | ||
650 | } | 650 | } |
651 | 651 | ||
652 | void container_init_floating(struct sway_container *con) { | 652 | static void floating_natural_resize(struct sway_container *con) { |
653 | int min_width, max_width, min_height, max_height; | ||
654 | floating_calculate_constraints(&min_width, &max_width, | ||
655 | &min_height, &max_height); | ||
656 | if (!con->view) { | ||
657 | con->width = max_width; | ||
658 | con->height = max_height; | ||
659 | } else { | ||
660 | struct sway_view *view = con->view; | ||
661 | con->content_width = | ||
662 | fmax(min_width, fmin(view->natural_width, max_width)); | ||
663 | con->content_height = | ||
664 | fmax(min_height, fmin(view->natural_height, max_height)); | ||
665 | container_set_geometry_from_content(con); | ||
666 | } | ||
667 | } | ||
668 | |||
669 | void container_floating_resize_and_center(struct sway_container *con) { | ||
653 | struct sway_workspace *ws = con->workspace; | 670 | struct sway_workspace *ws = con->workspace; |
671 | if (!ws) { | ||
672 | // On scratchpad, just resize | ||
673 | floating_natural_resize(con); | ||
674 | return; | ||
675 | } | ||
676 | |||
654 | struct wlr_box *ob = wlr_output_layout_get_box(root->output_layout, | 677 | struct wlr_box *ob = wlr_output_layout_get_box(root->output_layout, |
655 | ws->output->wlr_output); | 678 | ws->output->wlr_output); |
656 | if (!ob) { | 679 | if (!ob) { |
@@ -662,13 +685,8 @@ void container_init_floating(struct sway_container *con) { | |||
662 | return; | 685 | return; |
663 | } | 686 | } |
664 | 687 | ||
665 | int min_width, max_width, min_height, max_height; | 688 | floating_natural_resize(con); |
666 | floating_calculate_constraints(&min_width, &max_width, | ||
667 | &min_height, &max_height); | ||
668 | |||
669 | if (!con->view) { | 689 | if (!con->view) { |
670 | con->width = max_width; | ||
671 | con->height = max_height; | ||
672 | if (con->width > ws->width || con->height > ws->height) { | 690 | if (con->width > ws->width || con->height > ws->height) { |
673 | con->x = ob->x + (ob->width - con->width) / 2; | 691 | con->x = ob->x + (ob->width - con->width) / 2; |
674 | con->y = ob->y + (ob->height - con->height) / 2; | 692 | con->y = ob->y + (ob->height - con->height) / 2; |
@@ -677,11 +695,6 @@ void container_init_floating(struct sway_container *con) { | |||
677 | con->y = ws->y + (ws->height - con->height) / 2; | 695 | con->y = ws->y + (ws->height - con->height) / 2; |
678 | } | 696 | } |
679 | } else { | 697 | } else { |
680 | struct sway_view *view = con->view; | ||
681 | con->content_width = | ||
682 | fmax(min_width, fmin(view->natural_width, max_width)); | ||
683 | con->content_height = | ||
684 | fmax(min_height, fmin(view->natural_height, max_height)); | ||
685 | if (con->content_width > ws->width | 698 | if (con->content_width > ws->width |
686 | || con->content_height > ws->height) { | 699 | || con->content_height > ws->height) { |
687 | con->content_x = ob->x + (ob->width - con->content_width) / 2; | 700 | con->content_x = ob->x + (ob->width - con->content_width) / 2; |
@@ -711,7 +724,7 @@ void container_set_floating(struct sway_container *container, bool enable) { | |||
711 | struct sway_container *old_parent = container->parent; | 724 | struct sway_container *old_parent = container->parent; |
712 | container_detach(container); | 725 | container_detach(container); |
713 | workspace_add_floating(workspace, container); | 726 | workspace_add_floating(workspace, container); |
714 | container_init_floating(container); | 727 | container_floating_resize_and_center(container); |
715 | if (container->view) { | 728 | if (container->view) { |
716 | view_set_tiled(container->view, false); | 729 | view_set_tiled(container->view, false); |
717 | if (container->view->using_csd) { | 730 | if (container->view->using_csd) { |
@@ -995,7 +1008,7 @@ void container_fullscreen_disable(struct sway_container *con) { | |||
995 | // criteria, it needs to be reinitialized as floating to get the proper | 1008 | // criteria, it needs to be reinitialized as floating to get the proper |
996 | // size and location | 1009 | // size and location |
997 | if (container_is_floating(con) && (con->width == 0 || con->height == 0)) { | 1010 | if (container_is_floating(con) && (con->width == 0 || con->height == 0)) { |
998 | container_init_floating(con); | 1011 | container_floating_resize_and_center(con); |
999 | } | 1012 | } |
1000 | 1013 | ||
1001 | con->fullscreen_mode = FULLSCREEN_NONE; | 1014 | con->fullscreen_mode = FULLSCREEN_NONE; |
diff --git a/sway/tree/output.c b/sway/tree/output.c index 28303652..b3589be5 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c | |||
@@ -77,7 +77,7 @@ static void restore_workspaces(struct sway_output *output) { | |||
77 | floater->y > output->ly + output->height || | 77 | floater->y > output->ly + output->height || |
78 | floater->x + floater->width < output->lx || | 78 | floater->x + floater->width < output->lx || |
79 | floater->y + floater->height < output->ly) { | 79 | floater->y + floater->height < output->ly) { |
80 | container_init_floating(floater); | 80 | container_floating_resize_and_center(floater); |
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
diff --git a/sway/tree/root.c b/sway/tree/root.c index 5dde9f22..bc9c610d 100644 --- a/sway/tree/root.c +++ b/sway/tree/root.c | |||
@@ -124,15 +124,7 @@ void root_scratchpad_show(struct sway_container *con) { | |||
124 | struct wlr_box workspace_box; | 124 | struct wlr_box workspace_box; |
125 | workspace_get_box(new_ws, &workspace_box); | 125 | workspace_get_box(new_ws, &workspace_box); |
126 | if (!wlr_box_contains_point(&workspace_box, center_lx, center_ly)) { | 126 | if (!wlr_box_contains_point(&workspace_box, center_lx, center_ly)) { |
127 | // Maybe resize it | 127 | container_floating_resize_and_center(con); |
128 | if (con->width > new_ws->width || con->height > new_ws->height) { | ||
129 | container_init_floating(con); | ||
130 | } | ||
131 | |||
132 | // Center it | ||
133 | double new_lx = new_ws->x + (new_ws->width - con->width) / 2; | ||
134 | double new_ly = new_ws->y + (new_ws->height - con->height) / 2; | ||
135 | container_floating_move_to(con, new_lx, new_ly); | ||
136 | } | 128 | } |
137 | 129 | ||
138 | arrange_workspace(new_ws); | 130 | arrange_workspace(new_ws); |