diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-06-06 22:57:34 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-06-09 10:11:25 +1000 |
commit | bb66e6d578fdc68fb33d0fde921390d74f20bb31 (patch) | |
tree | 99d3763eee97acb870c16a762c0ee40af787c295 /sway/tree/layout.c | |
parent | Make main properties be the pending state (diff) | |
download | sway-bb66e6d578fdc68fb33d0fde921390d74f20bb31.tar.gz sway-bb66e6d578fdc68fb33d0fde921390d74f20bb31.tar.zst sway-bb66e6d578fdc68fb33d0fde921390d74f20bb31.zip |
Refactor everything that needs to arrange windows
* The arrange_foo functions are now replaced with arrange_and_commit, or
with manually created transactions and arrange_windows x2.
* The arrange functions are now only called from the highest level
functions rather than from both high level and low level functions.
* Due to the previous point, view_set_fullscreen_raw and
view_set_fullscreen are both merged into one function again.
* Floating and fullscreen are now working with transactions.
Diffstat (limited to 'sway/tree/layout.c')
-rw-r--r-- | sway/tree/layout.c | 71 |
1 files changed, 18 insertions, 53 deletions
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 6d4cd088..65b61495 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -22,7 +22,7 @@ struct sway_container root_container; | |||
22 | 22 | ||
23 | static void output_layout_handle_change(struct wl_listener *listener, | 23 | static void output_layout_handle_change(struct wl_listener *listener, |
24 | void *data) { | 24 | void *data) { |
25 | arrange_root(); | 25 | arrange_and_commit(&root_container); |
26 | } | 26 | } |
27 | 27 | ||
28 | void layout_init(void) { | 28 | void layout_init(void) { |
@@ -56,18 +56,17 @@ static int index_child(const struct sway_container *child) { | |||
56 | return -1; | 56 | return -1; |
57 | } | 57 | } |
58 | 58 | ||
59 | static void container_handle_fullscreen_reparent(struct sway_container *viewcon, | 59 | static void container_handle_fullscreen_reparent(struct sway_container *con, |
60 | struct sway_container *old_parent) { | 60 | struct sway_container *old_parent) { |
61 | if (viewcon->type != C_VIEW || !viewcon->sway_view->is_fullscreen) { | 61 | if (con->type != C_VIEW || !con->sway_view->is_fullscreen) { |
62 | return; | 62 | return; |
63 | } | 63 | } |
64 | struct sway_view *view = viewcon->sway_view; | 64 | struct sway_view *view = con->sway_view; |
65 | struct sway_container *old_workspace = old_parent; | 65 | struct sway_container *old_workspace = old_parent; |
66 | if (old_workspace && old_workspace->type != C_WORKSPACE) { | 66 | if (old_workspace && old_workspace->type != C_WORKSPACE) { |
67 | old_workspace = container_parent(old_workspace, C_WORKSPACE); | 67 | old_workspace = container_parent(old_workspace, C_WORKSPACE); |
68 | } | 68 | } |
69 | struct sway_container *new_workspace = container_parent(view->swayc, | 69 | struct sway_container *new_workspace = container_parent(con, C_WORKSPACE); |
70 | C_WORKSPACE); | ||
71 | if (old_workspace == new_workspace) { | 70 | if (old_workspace == new_workspace) { |
72 | return; | 71 | return; |
73 | } | 72 | } |
@@ -78,15 +77,19 @@ static void container_handle_fullscreen_reparent(struct sway_container *viewcon, | |||
78 | 77 | ||
79 | // Mark the new workspace as fullscreen | 78 | // Mark the new workspace as fullscreen |
80 | if (new_workspace->sway_workspace->fullscreen) { | 79 | if (new_workspace->sway_workspace->fullscreen) { |
81 | view_set_fullscreen_raw( | 80 | view_set_fullscreen(new_workspace->sway_workspace->fullscreen, false); |
82 | new_workspace->sway_workspace->fullscreen, false); | ||
83 | } | 81 | } |
84 | new_workspace->sway_workspace->fullscreen = view; | 82 | new_workspace->sway_workspace->fullscreen = view; |
85 | // Resize view to new output dimensions | 83 | // Resize view to new output dimensions |
86 | struct sway_container *output = new_workspace->parent; | 84 | struct sway_container *output = new_workspace->parent; |
87 | view_configure(view, 0, 0, output->width, output->height); | 85 | view->x = output->x; |
88 | view->swayc->width = output->width; | 86 | view->y = output->y; |
89 | view->swayc->height = output->height; | 87 | view->width = output->width; |
88 | view->height = output->height; | ||
89 | con->x = output->x; | ||
90 | con->y = output->y; | ||
91 | con->width = output->width; | ||
92 | con->height = output->height; | ||
90 | } | 93 | } |
91 | 94 | ||
92 | void container_insert_child(struct sway_container *parent, | 95 | void container_insert_child(struct sway_container *parent, |
@@ -188,18 +191,7 @@ void container_move_to(struct sway_container *container, | |||
188 | } | 191 | } |
189 | container_notify_subtree_changed(old_parent); | 192 | container_notify_subtree_changed(old_parent); |
190 | container_notify_subtree_changed(new_parent); | 193 | container_notify_subtree_changed(new_parent); |
191 | if (old_parent) { | 194 | |
192 | if (old_parent->type == C_OUTPUT) { | ||
193 | arrange_output(old_parent); | ||
194 | } else { | ||
195 | arrange_children_of(old_parent); | ||
196 | } | ||
197 | } | ||
198 | if (new_parent->type == C_OUTPUT) { | ||
199 | arrange_output(new_parent); | ||
200 | } else { | ||
201 | arrange_children_of(new_parent); | ||
202 | } | ||
203 | // If view was moved to a fullscreen workspace, refocus the fullscreen view | 195 | // If view was moved to a fullscreen workspace, refocus the fullscreen view |
204 | struct sway_container *new_workspace = container; | 196 | struct sway_container *new_workspace = container; |
205 | if (new_workspace->type != C_WORKSPACE) { | 197 | if (new_workspace->type != C_WORKSPACE) { |
@@ -214,7 +206,8 @@ void container_move_to(struct sway_container *container, | |||
214 | if (focus_ws->type != C_WORKSPACE) { | 206 | if (focus_ws->type != C_WORKSPACE) { |
215 | focus_ws = container_parent(focus_ws, C_WORKSPACE); | 207 | focus_ws = container_parent(focus_ws, C_WORKSPACE); |
216 | } | 208 | } |
217 | seat_set_focus(seat, new_workspace->sway_workspace->fullscreen->swayc); | 209 | seat_set_focus(seat, |
210 | new_workspace->sway_workspace->fullscreen->swayc); | ||
218 | if (focus_ws != new_workspace) { | 211 | if (focus_ws != new_workspace) { |
219 | seat_set_focus(seat, focus); | 212 | seat_set_focus(seat, focus); |
220 | } | 213 | } |
@@ -308,7 +301,6 @@ static void workspace_rejigger(struct sway_container *ws, | |||
308 | container_reap_empty_recursive(original_parent); | 301 | container_reap_empty_recursive(original_parent); |
309 | wl_signal_emit(&child->events.reparent, original_parent); | 302 | wl_signal_emit(&child->events.reparent, original_parent); |
310 | container_create_notify(new_parent); | 303 | container_create_notify(new_parent); |
311 | arrange_workspace(ws); | ||
312 | } | 304 | } |
313 | 305 | ||
314 | static void move_out_of_tabs_stacks(struct sway_container *container, | 306 | static void move_out_of_tabs_stacks(struct sway_container *container, |
@@ -319,11 +311,6 @@ static void move_out_of_tabs_stacks(struct sway_container *container, | |||
319 | wlr_log(L_DEBUG, "Changing layout of %zd", current->parent->id); | 311 | wlr_log(L_DEBUG, "Changing layout of %zd", current->parent->id); |
320 | current->parent->layout = move_dir == | 312 | current->parent->layout = move_dir == |
321 | MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT; | 313 | MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT; |
322 | if (current->parent->type == C_WORKSPACE) { | ||
323 | arrange_workspace(current->parent); | ||
324 | } else { | ||
325 | arrange_children_of(current->parent); | ||
326 | } | ||
327 | return; | 314 | return; |
328 | } | 315 | } |
329 | 316 | ||
@@ -339,11 +326,6 @@ static void move_out_of_tabs_stacks(struct sway_container *container, | |||
339 | container_flatten(new_parent->parent); | 326 | container_flatten(new_parent->parent); |
340 | } | 327 | } |
341 | container_create_notify(new_parent); | 328 | container_create_notify(new_parent); |
342 | if (is_workspace) { | ||
343 | arrange_workspace(new_parent->parent); | ||
344 | } else { | ||
345 | arrange_children_of(new_parent); | ||
346 | } | ||
347 | container_notify_subtree_changed(new_parent); | 329 | container_notify_subtree_changed(new_parent); |
348 | } | 330 | } |
349 | 331 | ||
@@ -367,10 +349,7 @@ void container_move(struct sway_container *container, | |||
367 | 349 | ||
368 | struct sway_container *new_parent = container_flatten(parent); | 350 | struct sway_container *new_parent = container_flatten(parent); |
369 | if (new_parent != parent) { | 351 | if (new_parent != parent) { |
370 | // Special case: we were the last one in this container, so flatten it | 352 | // Special case: we were the last one in this container, so leave |
371 | // and leave | ||
372 | arrange_children_of(new_parent); | ||
373 | update_debug_tree(); | ||
374 | return; | 353 | return; |
375 | } | 354 | } |
376 | 355 | ||
@@ -452,12 +431,9 @@ void container_move(struct sway_container *container, | |||
452 | wlr_log(L_DEBUG, "Hit limit, " | 431 | wlr_log(L_DEBUG, "Hit limit, " |
453 | "promoting descendant to sibling"); | 432 | "promoting descendant to sibling"); |
454 | // Special case | 433 | // Special case |
455 | struct sway_container *old_parent = container->parent; | ||
456 | container_insert_child(current->parent, container, | 434 | container_insert_child(current->parent, container, |
457 | index + (offs < 0 ? 0 : 1)); | 435 | index + (offs < 0 ? 0 : 1)); |
458 | container->width = container->height = 0; | 436 | container->width = container->height = 0; |
459 | arrange_children_of(current->parent); | ||
460 | arrange_children_of(old_parent); | ||
461 | return; | 437 | return; |
462 | } | 438 | } |
463 | } else { | 439 | } else { |
@@ -491,14 +467,11 @@ void container_move(struct sway_container *container, | |||
491 | wlr_log(L_DEBUG, "Swapping siblings"); | 467 | wlr_log(L_DEBUG, "Swapping siblings"); |
492 | sibling->parent->children->items[index + offs] = container; | 468 | sibling->parent->children->items[index + offs] = container; |
493 | sibling->parent->children->items[index] = sibling; | 469 | sibling->parent->children->items[index] = sibling; |
494 | arrange_children_of(sibling->parent); | ||
495 | } else { | 470 | } else { |
496 | wlr_log(L_DEBUG, "Promoting to sibling of cousin"); | 471 | wlr_log(L_DEBUG, "Promoting to sibling of cousin"); |
497 | container_insert_child(sibling->parent, container, | 472 | container_insert_child(sibling->parent, container, |
498 | index_child(sibling) + (offs > 0 ? 0 : 1)); | 473 | index_child(sibling) + (offs > 0 ? 0 : 1)); |
499 | container->width = container->height = 0; | 474 | container->width = container->height = 0; |
500 | arrange_children_of(sibling->parent); | ||
501 | arrange_children_of(old_parent); | ||
502 | } | 475 | } |
503 | sibling = NULL; | 476 | sibling = NULL; |
504 | break; | 477 | break; |
@@ -512,8 +485,6 @@ void container_move(struct sway_container *container, | |||
512 | "(move dir: %d)", limit, move_dir); | 485 | "(move dir: %d)", limit, move_dir); |
513 | container_insert_child(sibling, container, limit); | 486 | container_insert_child(sibling, container, limit); |
514 | container->width = container->height = 0; | 487 | container->width = container->height = 0; |
515 | arrange_children_of(sibling); | ||
516 | arrange_children_of(old_parent); | ||
517 | sibling = NULL; | 488 | sibling = NULL; |
518 | } else { | 489 | } else { |
519 | wlr_log(L_DEBUG, "Reparenting container (perpendicular)"); | 490 | wlr_log(L_DEBUG, "Reparenting container (perpendicular)"); |
@@ -537,8 +508,6 @@ void container_move(struct sway_container *container, | |||
537 | container_add_child(sibling, container); | 508 | container_add_child(sibling, container); |
538 | } | 509 | } |
539 | container->width = container->height = 0; | 510 | container->width = container->height = 0; |
540 | arrange_children_of(sibling); | ||
541 | arrange_children_of(old_parent); | ||
542 | sibling = NULL; | 511 | sibling = NULL; |
543 | } | 512 | } |
544 | break; | 513 | break; |
@@ -863,7 +832,6 @@ struct sway_container *container_split(struct sway_container *child, | |||
863 | // Special case: this just behaves like splitt | 832 | // Special case: this just behaves like splitt |
864 | child->prev_layout = child->layout; | 833 | child->prev_layout = child->layout; |
865 | child->layout = layout; | 834 | child->layout = layout; |
866 | arrange_children_of(child); | ||
867 | return child; | 835 | return child; |
868 | } | 836 | } |
869 | 837 | ||
@@ -1044,9 +1012,6 @@ void container_swap(struct sway_container *con1, struct sway_container *con2) { | |||
1044 | prev_workspace_name = stored_prev_name; | 1012 | prev_workspace_name = stored_prev_name; |
1045 | } | 1013 | } |
1046 | 1014 | ||
1047 | arrange_children_of(con1->parent); | ||
1048 | arrange_children_of(con2->parent); | ||
1049 | |||
1050 | if (fs1 && con2->type == C_VIEW) { | 1015 | if (fs1 && con2->type == C_VIEW) { |
1051 | view_set_fullscreen(con2->sway_view, true); | 1016 | view_set_fullscreen(con2->sway_view, true); |
1052 | } | 1017 | } |