X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fworkspace.c;h=3fdb7db84ac5bfa4b23d62d71986ce405d309d49;hb=e89a25f81f00c31f933247f091894bde2809d2f8;hp=14840e4a985941e706ae4b559debceae86eee3ce;hpb=72c66a2091659c0a986a627bdb3b766628437553;p=i3%2Fi3 diff --git a/src/workspace.c b/src/workspace.c index 14840e4a..3fdb7db8 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -830,3 +830,34 @@ Con *workspace_attach_to(Con *ws) { return new; } + +/** + * Creates a new container and re-parents all of children from the given + * workspace into it. + * + * The container inherits the layout from the workspace. + */ +Con *workspace_encapsulate(Con *ws) { + if (TAILQ_EMPTY(&(ws->nodes_head))) { + ELOG("Workspace %p / %s has no children to encapsulate\n", ws, ws->name); + return NULL; + } + + Con *new = con_new(NULL, NULL); + new->parent = ws; + new->layout = ws->layout; + + DLOG("Moving children of workspace %p / %s into container %p\n", + ws, ws->name, new); + + Con *child; + while (!TAILQ_EMPTY(&(ws->nodes_head))) { + child = TAILQ_FIRST(&(ws->nodes_head)); + con_detach(child); + con_attach(child, new, true); + } + + con_attach(new, ws, true); + + return new; +}