diff options
-rw-r--r-- | include/sway/tree/container.h | 1 | ||||
-rw-r--r-- | sway/tree/container.c | 19 | ||||
-rw-r--r-- | sway/tree/view.c | 29 |
3 files changed, 31 insertions, 18 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 71935697..e4f74b08 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h | |||
@@ -84,6 +84,7 @@ struct sway_container { | |||
84 | // Includes borders | 84 | // Includes borders |
85 | double x, y; | 85 | double x, y; |
86 | double width, height; | 86 | double width, height; |
87 | double saved_x, saved_y; | ||
87 | double saved_width, saved_height; | 88 | double saved_width, saved_height; |
88 | 89 | ||
89 | list_t *children; | 90 | list_t *children; |
diff --git a/sway/tree/container.c b/sway/tree/container.c index c16f1748..fd7ee2c3 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -906,23 +906,6 @@ size_t container_titlebar_height() { | |||
906 | return config->font_height + TITLEBAR_V_PADDING * 2; | 906 | return config->font_height + TITLEBAR_V_PADDING * 2; |
907 | } | 907 | } |
908 | 908 | ||
909 | static void configure_floating_view(struct sway_view *view) { | ||
910 | struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); | ||
911 | int max_width = ws->width * 0.6666; | ||
912 | int max_height = ws->height * 0.6666; | ||
913 | int width = | ||
914 | view->natural_width > max_width ? max_width : view->natural_width; | ||
915 | int height = | ||
916 | view->natural_height > max_height ? max_height : view->natural_height; | ||
917 | struct sway_container *output = ws->parent; | ||
918 | int lx = output->x + (ws->width - width) / 2; | ||
919 | int ly = output->y + (ws->height - height) / 2; | ||
920 | |||
921 | view->border_left = view->border_right = view->border_bottom = true; | ||
922 | view_set_maximized(view, false); | ||
923 | view_configure(view, lx, ly, width, height); | ||
924 | } | ||
925 | |||
926 | void container_set_floating(struct sway_container *container, bool enable) { | 909 | void container_set_floating(struct sway_container *container, bool enable) { |
927 | if (container_is_floating(container) == enable) { | 910 | if (container_is_floating(container) == enable) { |
928 | return; | 911 | return; |
@@ -936,7 +919,7 @@ void container_set_floating(struct sway_container *container, bool enable) { | |||
936 | container_remove_child(container); | 919 | container_remove_child(container); |
937 | container_add_child(workspace->sway_workspace->floating, container); | 920 | container_add_child(workspace->sway_workspace->floating, container); |
938 | if (container->type == C_VIEW) { | 921 | if (container->type == C_VIEW) { |
939 | configure_floating_view(container->sway_view); | 922 | view_autoconfigure(container->sway_view); |
940 | } | 923 | } |
941 | seat_set_focus(seat, seat_get_focus_inactive(seat, container)); | 924 | seat_set_focus(seat, seat_get_focus_inactive(seat, container)); |
942 | container_reap_empty_recursive(workspace); | 925 | container_reap_empty_recursive(workspace); |
diff --git a/sway/tree/view.c b/sway/tree/view.c index 8548d9b8..65961dd9 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -126,6 +126,23 @@ void view_configure(struct sway_view *view, double ox, double oy, int width, | |||
126 | } | 126 | } |
127 | } | 127 | } |
128 | 128 | ||
129 | static void view_autoconfigure_floating(struct sway_view *view) { | ||
130 | struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); | ||
131 | int max_width = ws->width * 0.6666; | ||
132 | int max_height = ws->height * 0.6666; | ||
133 | int width = | ||
134 | view->natural_width > max_width ? max_width : view->natural_width; | ||
135 | int height = | ||
136 | view->natural_height > max_height ? max_height : view->natural_height; | ||
137 | struct sway_container *output = ws->parent; | ||
138 | int lx = output->x + (ws->width - width) / 2; | ||
139 | int ly = output->y + (ws->height - height) / 2; | ||
140 | |||
141 | view->border_left = view->border_right = view->border_bottom = true; | ||
142 | view_set_maximized(view, false); | ||
143 | view_configure(view, lx, ly, width, height); | ||
144 | } | ||
145 | |||
129 | void view_autoconfigure(struct sway_view *view) { | 146 | void view_autoconfigure(struct sway_view *view) { |
130 | if (!sway_assert(view->swayc, | 147 | if (!sway_assert(view->swayc, |
131 | "Called view_autoconfigure() on a view without a swayc")) { | 148 | "Called view_autoconfigure() on a view without a swayc")) { |
@@ -140,6 +157,11 @@ void view_autoconfigure(struct sway_view *view) { | |||
140 | return; | 157 | return; |
141 | } | 158 | } |
142 | 159 | ||
160 | if (container_is_floating(view->swayc)) { | ||
161 | view_autoconfigure_floating(view); | ||
162 | return; | ||
163 | } | ||
164 | |||
143 | struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); | 165 | struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); |
144 | 166 | ||
145 | int other_views = 0; | 167 | int other_views = 0; |
@@ -261,6 +283,8 @@ void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { | |||
261 | view_set_fullscreen(workspace->sway_workspace->fullscreen, false); | 283 | view_set_fullscreen(workspace->sway_workspace->fullscreen, false); |
262 | } | 284 | } |
263 | workspace->sway_workspace->fullscreen = view; | 285 | workspace->sway_workspace->fullscreen = view; |
286 | view->swayc->saved_x = view->swayc->x; | ||
287 | view->swayc->saved_y = view->swayc->y; | ||
264 | view->swayc->saved_width = view->swayc->width; | 288 | view->swayc->saved_width = view->swayc->width; |
265 | view->swayc->saved_height = view->swayc->height; | 289 | view->swayc->saved_height = view->swayc->height; |
266 | 290 | ||
@@ -283,6 +307,11 @@ void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { | |||
283 | workspace->sway_workspace->fullscreen = NULL; | 307 | workspace->sway_workspace->fullscreen = NULL; |
284 | view->swayc->width = view->swayc->saved_width; | 308 | view->swayc->width = view->swayc->saved_width; |
285 | view->swayc->height = view->swayc->saved_height; | 309 | view->swayc->height = view->swayc->saved_height; |
310 | if (container_is_floating(view->swayc)) { | ||
311 | view->swayc->x = view->swayc->saved_x; | ||
312 | view->swayc->y = view->swayc->saved_y; | ||
313 | view_autoconfigure(view); | ||
314 | } | ||
286 | } | 315 | } |
287 | } | 316 | } |
288 | 317 | ||