aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/arrange.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree/arrange.c')
-rw-r--r--sway/tree/arrange.c106
1 files changed, 55 insertions, 51 deletions
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c
index bac9f2fa..d4003fe6 100644
--- a/sway/tree/arrange.c
+++ b/sway/tree/arrange.c
@@ -1,4 +1,3 @@
1#define _POSIX_C_SOURCE 200809L
2#include <ctype.h> 1#include <ctype.h>
3#include <stdbool.h> 2#include <stdbool.h>
4#include <stdlib.h> 3#include <stdlib.h>
@@ -55,7 +54,7 @@ static void apply_horiz_layout(list_t *children, struct wlr_box *parent) {
55 // Calculate gap size 54 // Calculate gap size
56 double inner_gap = 0; 55 double inner_gap = 0;
57 struct sway_container *child = children->items[0]; 56 struct sway_container *child = children->items[0];
58 struct sway_workspace *ws = child->workspace; 57 struct sway_workspace *ws = child->pending.workspace;
59 if (ws) { 58 if (ws) {
60 inner_gap = ws->gaps_inner; 59 inner_gap = ws->gaps_inner;
61 } 60 }
@@ -66,7 +65,7 @@ static void apply_horiz_layout(list_t *children, struct wlr_box *parent) {
66 if (layout == L_TABBED || layout == L_STACKED) { 65 if (layout == L_TABBED || layout == L_STACKED) {
67 inner_gap = 0; 66 inner_gap = 0;
68 } 67 }
69 temp = temp->parent; 68 temp = temp->pending.parent;
70 } 69 }
71 double total_gap = fmin(inner_gap * (children->length - 1), 70 double total_gap = fmin(inner_gap * (children->length - 1),
72 fmax(0, parent->width - MIN_SANE_W * children->length)); 71 fmax(0, parent->width - MIN_SANE_W * children->length));
@@ -79,15 +78,15 @@ static void apply_horiz_layout(list_t *children, struct wlr_box *parent) {
79 for (int i = 0; i < children->length; ++i) { 78 for (int i = 0; i < children->length; ++i) {
80 struct sway_container *child = children->items[i]; 79 struct sway_container *child = children->items[i];
81 child->child_total_width = child_total_width; 80 child->child_total_width = child_total_width;
82 child->x = child_x; 81 child->pending.x = child_x;
83 child->y = parent->y; 82 child->pending.y = parent->y;
84 child->width = round(child->width_fraction * child_total_width); 83 child->pending.width = round(child->width_fraction * child_total_width);
85 child->height = parent->height; 84 child->pending.height = parent->height;
86 child_x += child->width + inner_gap; 85 child_x += child->pending.width + inner_gap;
87 86
88 // Make last child use remaining width of parent 87 // Make last child use remaining width of parent
89 if (i == children->length - 1) { 88 if (i == children->length - 1) {
90 child->width = parent->x + parent->width - child->x; 89 child->pending.width = parent->x + parent->width - child->pending.x;
91 } 90 }
92 } 91 }
93} 92}
@@ -134,7 +133,7 @@ static void apply_vert_layout(list_t *children, struct wlr_box *parent) {
134 // Calculate gap size 133 // Calculate gap size
135 double inner_gap = 0; 134 double inner_gap = 0;
136 struct sway_container *child = children->items[0]; 135 struct sway_container *child = children->items[0];
137 struct sway_workspace *ws = child->workspace; 136 struct sway_workspace *ws = child->pending.workspace;
138 if (ws) { 137 if (ws) {
139 inner_gap = ws->gaps_inner; 138 inner_gap = ws->gaps_inner;
140 } 139 }
@@ -145,7 +144,7 @@ static void apply_vert_layout(list_t *children, struct wlr_box *parent) {
145 if (layout == L_TABBED || layout == L_STACKED) { 144 if (layout == L_TABBED || layout == L_STACKED) {
146 inner_gap = 0; 145 inner_gap = 0;
147 } 146 }
148 temp = temp->parent; 147 temp = temp->pending.parent;
149 } 148 }
150 double total_gap = fmin(inner_gap * (children->length - 1), 149 double total_gap = fmin(inner_gap * (children->length - 1),
151 fmax(0, parent->height - MIN_SANE_H * children->length)); 150 fmax(0, parent->height - MIN_SANE_H * children->length));
@@ -158,15 +157,15 @@ static void apply_vert_layout(list_t *children, struct wlr_box *parent) {
158 for (int i = 0; i < children->length; ++i) { 157 for (int i = 0; i < children->length; ++i) {
159 struct sway_container *child = children->items[i]; 158 struct sway_container *child = children->items[i];
160 child->child_total_height = child_total_height; 159 child->child_total_height = child_total_height;
161 child->x = parent->x; 160 child->pending.x = parent->x;
162 child->y = child_y; 161 child->pending.y = child_y;
163 child->width = parent->width; 162 child->pending.width = parent->width;
164 child->height = round(child->height_fraction * child_total_height); 163 child->pending.height = round(child->height_fraction * child_total_height);
165 child_y += child->height + inner_gap; 164 child_y += child->pending.height + inner_gap;
166 165
167 // Make last child use remaining height of parent 166 // Make last child use remaining height of parent
168 if (i == children->length - 1) { 167 if (i == children->length - 1) {
169 child->height = parent->y + parent->height - child->y; 168 child->pending.height = parent->y + parent->height - child->pending.y;
170 } 169 }
171 } 170 }
172} 171}
@@ -178,10 +177,10 @@ static void apply_tabbed_layout(list_t *children, struct wlr_box *parent) {
178 for (int i = 0; i < children->length; ++i) { 177 for (int i = 0; i < children->length; ++i) {
179 struct sway_container *child = children->items[i]; 178 struct sway_container *child = children->items[i];
180 int parent_offset = child->view ? 0 : container_titlebar_height(); 179 int parent_offset = child->view ? 0 : container_titlebar_height();
181 child->x = parent->x; 180 child->pending.x = parent->x;
182 child->y = parent->y + parent_offset; 181 child->pending.y = parent->y + parent_offset;
183 child->width = parent->width; 182 child->pending.width = parent->width;
184 child->height = parent->height - parent_offset; 183 child->pending.height = parent->height - parent_offset;
185 } 184 }
186} 185}
187 186
@@ -193,10 +192,10 @@ static void apply_stacked_layout(list_t *children, struct wlr_box *parent) {
193 struct sway_container *child = children->items[i]; 192 struct sway_container *child = children->items[i];
194 int parent_offset = child->view ? 0 : 193 int parent_offset = child->view ? 0 :
195 container_titlebar_height() * children->length; 194 container_titlebar_height() * children->length;
196 child->x = parent->x; 195 child->pending.x = parent->x;
197 child->y = parent->y + parent_offset; 196 child->pending.y = parent->y + parent_offset;
198 child->width = parent->width; 197 child->pending.width = parent->width;
199 child->height = parent->height - parent_offset; 198 child->pending.height = parent->height - parent_offset;
200 } 199 }
201} 200}
202 201
@@ -246,7 +245,7 @@ void arrange_container(struct sway_container *container) {
246 } 245 }
247 struct wlr_box box; 246 struct wlr_box box;
248 container_get_box(container, &box); 247 container_get_box(container, &box);
249 arrange_children(container->children, container->layout, &box); 248 arrange_children(container->pending.children, container->pending.layout, &box);
250 node_set_dirty(&container->node); 249 node_set_dirty(&container->node);
251} 250}
252 251
@@ -264,6 +263,9 @@ void arrange_workspace(struct sway_workspace *workspace) {
264 area->width, area->height, area->x, area->y); 263 area->width, area->height, area->x, area->y);
265 264
266 bool first_arrange = workspace->width == 0 && workspace->height == 0; 265 bool first_arrange = workspace->width == 0 && workspace->height == 0;
266 struct wlr_box prev_box;
267 workspace_get_box(workspace, &prev_box);
268
267 double prev_x = workspace->x - workspace->current_gaps.left; 269 double prev_x = workspace->x - workspace->current_gaps.left;
268 double prev_y = workspace->y - workspace->current_gaps.top; 270 double prev_y = workspace->y - workspace->current_gaps.top;
269 workspace->width = area->width; 271 workspace->width = area->width;
@@ -277,13 +279,14 @@ void arrange_workspace(struct sway_workspace *workspace) {
277 if (!first_arrange && (diff_x != 0 || diff_y != 0)) { 279 if (!first_arrange && (diff_x != 0 || diff_y != 0)) {
278 for (int i = 0; i < workspace->floating->length; ++i) { 280 for (int i = 0; i < workspace->floating->length; ++i) {
279 struct sway_container *floater = workspace->floating->items[i]; 281 struct sway_container *floater = workspace->floating->items[i];
280 container_floating_translate(floater, diff_x, diff_y);
281 double center_x = floater->x + floater->width / 2;
282 double center_y = floater->y + floater->height / 2;
283 struct wlr_box workspace_box; 282 struct wlr_box workspace_box;
284 workspace_get_box(workspace, &workspace_box); 283 workspace_get_box(workspace, &workspace_box);
285 if (!wlr_box_contains_point(&workspace_box, center_x, center_y)) { 284 floating_fix_coordinates(floater, &prev_box, &workspace_box);
286 container_floating_move_to_center(floater); 285 // Set transformation for scratchpad windows.
286 if (floater->scratchpad) {
287 struct wlr_box output_box;
288 output_get_box(output, &output_box);
289 floater->transform = output_box;
287 } 290 }
288 } 291 }
289 } 292 }
@@ -294,10 +297,10 @@ void arrange_workspace(struct sway_workspace *workspace) {
294 workspace->x, workspace->y); 297 workspace->x, workspace->y);
295 if (workspace->fullscreen) { 298 if (workspace->fullscreen) {
296 struct sway_container *fs = workspace->fullscreen; 299 struct sway_container *fs = workspace->fullscreen;
297 fs->x = output->lx; 300 fs->pending.x = output->lx;
298 fs->y = output->ly; 301 fs->pending.y = output->ly;
299 fs->width = output->width; 302 fs->pending.width = output->width;
300 fs->height = output->height; 303 fs->pending.height = output->height;
301 arrange_container(fs); 304 arrange_container(fs);
302 } else { 305 } else {
303 struct wlr_box box; 306 struct wlr_box box;
@@ -311,12 +314,13 @@ void arrange_output(struct sway_output *output) {
311 if (config->reloading) { 314 if (config->reloading) {
312 return; 315 return;
313 } 316 }
314 const struct wlr_box *output_box = wlr_output_layout_get_box( 317 struct wlr_box output_box;
315 root->output_layout, output->wlr_output); 318 wlr_output_layout_get_box(root->output_layout,
316 output->lx = output_box->x; 319 output->wlr_output, &output_box);
317 output->ly = output_box->y; 320 output->lx = output_box.x;
318 output->width = output_box->width; 321 output->ly = output_box.y;
319 output->height = output_box->height; 322 output->width = output_box.width;
323 output->height = output_box.height;
320 324
321 for (int i = 0; i < output->workspaces->length; ++i) { 325 for (int i = 0; i < output->workspaces->length; ++i) {
322 struct sway_workspace *workspace = output->workspaces->items[i]; 326 struct sway_workspace *workspace = output->workspaces->items[i];
@@ -328,19 +332,19 @@ void arrange_root(void) {
328 if (config->reloading) { 332 if (config->reloading) {
329 return; 333 return;
330 } 334 }
331 const struct wlr_box *layout_box = 335 struct wlr_box layout_box;
332 wlr_output_layout_get_box(root->output_layout, NULL); 336 wlr_output_layout_get_box(root->output_layout, NULL, &layout_box);
333 root->x = layout_box->x; 337 root->x = layout_box.x;
334 root->y = layout_box->y; 338 root->y = layout_box.y;
335 root->width = layout_box->width; 339 root->width = layout_box.width;
336 root->height = layout_box->height; 340 root->height = layout_box.height;
337 341
338 if (root->fullscreen_global) { 342 if (root->fullscreen_global) {
339 struct sway_container *fs = root->fullscreen_global; 343 struct sway_container *fs = root->fullscreen_global;
340 fs->x = root->x; 344 fs->pending.x = root->x;
341 fs->y = root->y; 345 fs->pending.y = root->y;
342 fs->width = root->width; 346 fs->pending.width = root->width;
343 fs->height = root->height; 347 fs->pending.height = root->height;
344 arrange_container(fs); 348 arrange_container(fs);
345 } else { 349 } else {
346 for (int i = 0; i < root->outputs->length; ++i) { 350 for (int i = 0; i < root->outputs->length; ++i) {