From 50914e04833105eb12cfb0916365c8365be1cdb8 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Thu, 30 Dec 2010 23:01:58 +0100 Subject: [PATCH] Bugfix: Correctly change focus when closing a split-container The problem was i3 leaving an invalid focus pointer valid (after killing the container) because the container itself is not mapped (if it has no x11 window, for example split containers). --- src/tree.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/tree.c b/src/tree.c index baa11ced..5b3f0df5 100644 --- a/src/tree.c +++ b/src/tree.c @@ -140,6 +140,16 @@ static void fix_floating_parent(Con *con, Con *vanishing) { fix_floating_parent(child, vanishing); } +static bool _is_con_mapped(Con *con) { + Con *child; + + TAILQ_FOREACH(child, &(con->nodes_head), nodes) + if (_is_con_mapped(child)) + return true; + + return con->mapped; +} + /* * Closes the given container including all children * @@ -148,6 +158,13 @@ void tree_close(Con *con, bool kill_window, bool dont_kill_parent) { bool was_mapped = con->mapped; Con *parent = con->parent; + if (!was_mapped) { + /* Even if the container itself is not mapped, its children may be + * mapped (for example split containers don't have a mapped window on + * their own but usually contain mapped children). */ + was_mapped = _is_con_mapped(con); + } + /* check floating clients and adjust old_parent if necessary */ fix_floating_parent(croot, con); @@ -231,6 +248,10 @@ void tree_close_con() { return; } + /* There *should* be no possibility to focus outputs / root container */ + assert(focused->type != CT_OUTPUT); + assert(focused->type != CT_ROOT); + /* Kill con */ tree_close(focused, true, false); }