]> git.sur5r.net Git - i3/i3/blobdiff - src/workspace.c
bugfix: fix workspace back_and_forth after displaying a scratchpad window
[i3/i3] / src / workspace.c
index 853311816538f516caf9200f94c9d354abf78247..1e7071875cd97f186986723f193d2c6e9bba6fa6 100644 (file)
@@ -73,6 +73,7 @@ Con *workspace_get(const char *num, bool *created) {
         workspace->type = CT_WORKSPACE;
         FREE(workspace->name);
         workspace->name = sstrdup(num);
+        workspace->workspace_layout = config.default_layout;
         /* We set ->num to the number if this workspace’s name begins with a
          * positive number. Otherwise it’s a named ws and num will be -1. */
         char *endptr = NULL;
@@ -211,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;
@@ -338,11 +340,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);
 
@@ -699,6 +706,7 @@ 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;
@@ -715,9 +723,10 @@ void ws_force_orientation(Con *ws, orientation_t orientation) {
 
     /* 4: switch workspace layout */
     ws->layout = (orientation == HORIZ) ? L_SPLITH : L_SPLITV;
+    DLOG("split->layout = %d, ws->layout = %d\n", split->layout, ws->layout);
 
     /* 5: attach the new split container to the workspace */
-    DLOG("Attaching new split to ws\n");
+    DLOG("Attaching new split (%p) to ws (%p)\n", split, ws);
     con_attach(split, ws, false);
 
     /* 6: fix the percentages */
@@ -740,7 +749,7 @@ void ws_force_orientation(Con *ws, orientation_t orientation) {
 Con *workspace_attach_to(Con *ws) {
     DLOG("Attaching a window to workspace %p / %s\n", ws, ws->name);
 
-    if (config.default_layout == L_DEFAULT) {
+    if (ws->workspace_layout == L_DEFAULT) {
         DLOG("Default layout, just attaching it to the workspace itself.\n");
         return ws;
     }
@@ -752,7 +761,7 @@ Con *workspace_attach_to(Con *ws) {
     new->split = true;
 
     /* 2: set the requested layout on the split con */
-    new->layout = config.default_layout;
+    new->layout = ws->workspace_layout;
 
     /* 4: attach the new split container to the workspace */
     DLOG("Attaching new split %p to workspace %p\n", new, ws);