]> git.sur5r.net Git - i3/i3/blobdiff - src/workspace.c
Merge branch 'master' into next
[i3/i3] / src / workspace.c
index 14840e4a985941e706ae4b559debceae86eee3ce..ed00c9a7c89f12ef54e00be8f3b4240ccaee6cdb 100644 (file)
@@ -212,6 +212,7 @@ Con *create_workspace_on_output(Output *output, Con *content) {
 
     ws->fullscreen_mode = CF_OUTPUT;
 
+    ws->workspace_layout = config.default_layout;
     _workspace_apply_default_orientation(ws);
 
     return ws;
@@ -357,11 +358,16 @@ static void _workspace_show(Con *workspace) {
     /* Remember currently focused workspace for switching back to it later with
      * the 'workspace back_and_forth' command.
      * NOTE: We have to duplicate the name as the original will be freed when
-     * the corresponding workspace is cleaned up. */
-
-    FREE(previous_workspace_name);
-    if (current)
-        previous_workspace_name = sstrdup(current->name);
+     * the corresponding workspace is cleaned up.
+     * NOTE: Internal cons such as __i3_scratch (when a scratchpad window is
+     * focused) are skipped, see bug #868. */
+    if (current && !con_is_internal(current)) {
+        FREE(previous_workspace_name);
+        if (current) {
+            previous_workspace_name = sstrdup(current->name);
+            DLOG("Setting previous_workspace_name = %s\n", previous_workspace_name);
+        }
+    }
 
     workspace_reassign_sticky(workspace);
 
@@ -767,7 +773,6 @@ void ws_force_orientation(Con *ws, orientation_t orientation) {
     /* 1: create a new split container */
     Con *split = con_new(NULL, NULL);
     split->parent = ws;
-    split->split = true;
 
     /* 2: copy layout from workspace */
     split->layout = ws->layout;
@@ -819,7 +824,6 @@ Con *workspace_attach_to(Con *ws) {
     /* 1: create a new split container */
     Con *new = con_new(NULL, NULL);
     new->parent = ws;
-    new->split = true;
 
     /* 2: set the requested layout on the split con */
     new->layout = ws->workspace_layout;
@@ -830,3 +834,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;
+}