From f462a9a215e1079bd9a047f7097972527df49184 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Thu, 27 Jan 2011 16:04:17 +0100 Subject: [PATCH] re-insert floating cons next to the currently focused con of the appropriate workspace --- include/con.h | 8 ++++++++ src/con.c | 12 ++++++++++++ src/floating.c | 6 ++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/include/con.h b/include/con.h index 5788aea2..de537218 100644 --- a/include/con.h +++ b/include/con.h @@ -152,6 +152,14 @@ Con *con_next_focused(Con *con); */ Con *con_get_next(Con *con, char way, orientation_t orientation); +/** + * 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. + * + */ +Con *con_descend_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 5e3f9283..2f02bfcd 100644 --- a/src/con.c +++ b/src/con.c @@ -627,6 +627,18 @@ Con *con_get_next(Con *con, char way, orientation_t orientation) { 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. + * + */ +Con *con_descend_focused(Con *con) { + Con *next = con; + while (!TAILQ_EMPTY(&(next->focus_head))) + next = TAILQ_FIRST(&(next->focus_head)); + return next; +} /* * Returns a "relative" Rect which contains the amount of pixels that need to diff --git a/src/floating.c b/src/floating.c index 50987de4..b4d21963 100644 --- a/src/floating.c +++ b/src/floating.c @@ -149,8 +149,10 @@ void floating_disable(Con *con, bool automatic) { TAILQ_REMOVE(&(con->parent->parent->focus_head), con->parent, focused); tree_close(con->parent, false, false); - /* 3: re-attach to previous parent */ - con->parent = con_get_workspace(con); + /* 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->parent = focused->parent; /* XXX: We adjust the percentage value to start with a fair value. Floating * cons always have 1.0 as percent which doesn’t work so well when -- 2.39.5