Address @emersion's comments

This commit is contained in:
Drew DeVault 2018-04-06 11:52:23 -04:00
parent 603e0e42c5
commit b5baa78dc3

View file

@ -103,12 +103,13 @@ static int index_child(const struct sway_container *child) {
void container_insert_child(struct sway_container *parent, void container_insert_child(struct sway_container *parent,
struct sway_container *child, int i) { struct sway_container *child, int i) {
struct sway_container *old_parent = NULL; struct sway_container *old_parent = child->parent;
if (old_parent) {
container_remove_child(child);
}
list_insert(parent->children, i, child); list_insert(parent->children, i, child);
child->parent = parent; child->parent = parent;
if (old_parent && old_parent != parent) { wl_signal_emit(&child->events.reparent, old_parent);
wl_signal_emit(&child->events.reparent, old_parent);
}
} }
struct sway_container *container_add_sibling(struct sway_container *fixed, struct sway_container *container_add_sibling(struct sway_container *fixed,
@ -123,9 +124,7 @@ struct sway_container *container_add_sibling(struct sway_container *fixed,
int i = index_child(fixed); int i = index_child(fixed);
list_insert(parent->children, i + 1, active); list_insert(parent->children, i + 1, active);
active->parent = parent; active->parent = parent;
if (old_parent && old_parent != parent) { wl_signal_emit(&active->events.reparent, old_parent);
wl_signal_emit(&active->events.reparent, old_parent);
}
return active->parent; return active->parent;
} }
@ -268,6 +267,7 @@ static void workspace_rejigger(struct sway_container *ws,
container_flatten(ws); container_flatten(ws);
container_reap_empty_recursive(original_parent); container_reap_empty_recursive(original_parent);
wl_signal_emit(&child->events.reparent, original_parent);
arrange_windows(ws, -1, -1); arrange_windows(ws, -1, -1);
} }
@ -287,6 +287,7 @@ void container_move(struct sway_container *container,
if (parent != container_flatten(parent)) { if (parent != container_flatten(parent)) {
// Special case: we were the last one in this container, so flatten it // Special case: we were the last one in this container, so flatten it
// and leave // and leave
update_debug_tree();
return; return;
} }
@ -353,7 +354,6 @@ void container_move(struct sway_container *container,
"promoting descendant to sibling"); "promoting descendant to sibling");
// Special case // Special case
struct sway_container *old_parent = container->parent; struct sway_container *old_parent = container->parent;
container_remove_child(container);
container_insert_child(current->parent, container, container_insert_child(current->parent, container,
index + (offs < 0 ? 0 : 1)); index + (offs < 0 ? 0 : 1));
container->width = container->height = 0; container->width = container->height = 0;
@ -390,7 +390,6 @@ void container_move(struct sway_container *container,
arrange_windows(sibling->parent, -1, -1); arrange_windows(sibling->parent, -1, -1);
} else { } else {
wlr_log(L_DEBUG, "Promoting to sibling of cousin"); wlr_log(L_DEBUG, "Promoting to sibling of cousin");
container_remove_child(container);
container_insert_child(sibling->parent, container, container_insert_child(sibling->parent, container,
index_child(sibling) + (offs > 0 ? 0 : 1)); index_child(sibling) + (offs > 0 ? 0 : 1));
container->width = container->height = 0; container->width = container->height = 0;
@ -404,7 +403,6 @@ void container_move(struct sway_container *container,
int limit = container_limit(sibling, move_dir); int limit = container_limit(sibling, move_dir);
wlr_log(L_DEBUG, "Reparenting container (paralell)"); wlr_log(L_DEBUG, "Reparenting container (paralell)");
limit = limit != 0 ? limit + 1 : limit; // Convert to index limit = limit != 0 ? limit + 1 : limit; // Convert to index
container_remove_child(container);
container_insert_child(sibling, container, limit); container_insert_child(sibling, container, limit);
container->width = container->height = 0; container->width = container->height = 0;
arrange_windows(sibling, -1, -1); arrange_windows(sibling, -1, -1);