From b484ed5f9d4214ff6bdf205d0beec2207d3ed272 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 14 Mar 2011 23:50:29 +0100 Subject: [PATCH] When making floating cons tiling, re-insert next to the next focused *tiling* con (Thanks mseed) Fixes: #337 and #350 --- include/con.h | 10 ++++++++++ src/con.c | 26 ++++++++++++++++++++++++++ src/floating.c | 3 ++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/include/con.h b/include/con.h index 8ffa7ce2..1dd65a6e 100644 --- a/include/con.h +++ b/include/con.h @@ -167,6 +167,16 @@ Con *con_get_next(Con *con, char way, orientation_t orientation); */ Con *con_descend_focused(Con *con); +/** + * Returns the focused con inside this client, descending the tree as far as + * possible. This comes in handy when attaching a con to a workspace at the + * currently focused position, for example. + * + * Works like con_descend_focused but considers only tiling cons. + * + */ +Con *con_descend_tiling_focused(Con *con); + /** * Returns a "relative" Rect which contains the amount of pixels that need to * be added to the original Rect to get the final position (obviously the diff --git a/src/con.c b/src/con.c index 0ed4436a..04db250b 100644 --- a/src/con.c +++ b/src/con.c @@ -694,6 +694,32 @@ Con *con_descend_focused(Con *con) { return next; } +/* + * Returns the focused con inside this client, descending the tree as far as + * possible. This comes in handy when attaching a con to a workspace at the + * currently focused position, for example. + * + * Works like con_descend_focused but considers only tiling cons. + * + */ +Con *con_descend_tiling_focused(Con *con) { + Con *next = con; + Con *before; + Con *child; + do { + before = next; + TAILQ_FOREACH(child, &(next->focus_head), focused) { + if (child->type == CT_FLOATING_CON) + continue; + + next = child; + break; + } + } while (before != next); + return next; +} + + /* * Returns a "relative" Rect which contains the amount of pixels that need to * be added to the original Rect to get the final position (obviously the diff --git a/src/floating.c b/src/floating.c index fe878f75..ef500bf6 100644 --- a/src/floating.c +++ b/src/floating.c @@ -175,7 +175,8 @@ void floating_disable(Con *con, bool automatic) { /* 3: re-attach to the parent of the currently focused con on the workspace * this floating con was on */ - Con *focused = con_descend_focused(con_get_workspace(con)); + Con *focused = con_descend_tiling_focused(con_get_workspace(con)); + /* if there is no other container on this workspace, focused will be the * workspace itself */ if (focused->type == CT_WORKSPACE) -- 2.39.5