Simplify tree_close_internal
This commit makes multiple changes in tree_close_internal. I didn't split them because they are not completely independent. - Remove force_set_focus parameter This parameter was always set to `false` throughout the code base except for one case where it was set to `(con == focused)`, when killing a floating con's parent (the one with type CT_FLOATING_CON). But this case is not needed anymore since the special handling of CT_FLOATING_CONs in con_next_focused was removed in #2941. - Assume that con_next_focused does not returned a container of type CT_DOCKAREA. This is reasonable since con_next_focused uses the focus_head stack and has special handling of CT_DOCKAREA containers. - Remove is_mapped This variable was only used in the if block towards the end of tree_close_internal. Ignoring the, now removed, dockarea code and the use of force_set_focus this block performed only one useful action: focus the `next` container when `con == focused`. `con == focused` was a necessary and sufficient condition for the con_activate call: if `con != focused` we could reach the inner if blocks because of the other conditions but would never focus another container. If `con == focused` then all other conditions would be irrelevant. - Remove special handling of floating containers Since the `next` focused container is calculated through the parent for floating containers, I moved this code to con_next_focused. Also, because of the removal of force_set_focus, it appears that we can call con_on_remove_child for floating containers as well.
This commit is contained in:
11
src/con.c
11
src/con.c
@ -286,14 +286,14 @@ void con_close(Con *con, kill_window_t kill_window) {
|
||||
for (child = TAILQ_FIRST(&(con->focus_head)); child;) {
|
||||
nextchild = TAILQ_NEXT(child, focused);
|
||||
DLOG("killing child = %p.\n", child);
|
||||
tree_close_internal(child, kill_window, false, false);
|
||||
tree_close_internal(child, kill_window, false);
|
||||
child = nextchild;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
tree_close_internal(con, kill_window, false, false);
|
||||
tree_close_internal(con, kill_window, false);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1437,6 +1437,9 @@ Con *con_next_focused(Con *con) {
|
||||
DLOG("selecting workspace for dock client\n");
|
||||
return con_descend_focused(output_get_content(con->parent->parent));
|
||||
}
|
||||
if (con_is_floating(con)) {
|
||||
con = con->parent;
|
||||
}
|
||||
|
||||
/* if 'con' is not the first entry in the focus stack, use the first one as
|
||||
* it’s currently focused already */
|
||||
@ -1955,7 +1958,7 @@ static void con_on_remove_child(Con *con) {
|
||||
if (TAILQ_EMPTY(&(con->focus_head)) && !workspace_is_visible(con)) {
|
||||
LOG("Closing old workspace (%p / %s), it is empty\n", con, con->name);
|
||||
yajl_gen gen = ipc_marshal_workspace_event("empty", con, NULL);
|
||||
tree_close_internal(con, DONT_KILL_WINDOW, false, false);
|
||||
tree_close_internal(con, DONT_KILL_WINDOW, false);
|
||||
|
||||
const unsigned char *payload;
|
||||
ylength length;
|
||||
@ -1976,7 +1979,7 @@ static void con_on_remove_child(Con *con) {
|
||||
int children = con_num_children(con);
|
||||
if (children == 0) {
|
||||
DLOG("Container empty, closing\n");
|
||||
tree_close_internal(con, DONT_KILL_WINDOW, false, false);
|
||||
tree_close_internal(con, DONT_KILL_WINDOW, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user