]> git.sur5r.net Git - i3/i3/commitdiff
Bugfix: RandR: Correctly assign focused workspaces to outputs
authorMichael Stapelberg <michael@stapelberg.de>
Sun, 29 May 2011 12:39:41 +0000 (14:39 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Sun, 29 May 2011 12:39:41 +0000 (14:39 +0200)
Fixes: #399
src/randr.c

index a6b84ddccbccecc681b9577a65c4b0f72e9bc0e7..bf02518f3dca1bc090d5a65114c728c6da767e75 100644 (file)
@@ -306,11 +306,31 @@ void init_ws_for_output(Output *output, Con *content) {
         /* if so, move it over */
         LOG("Moving workspace \"%s\" from output \"%s\" to \"%s\" due to assignment\n",
             workspace->name, workspace_out->name, output->name);
-        DLOG("Detaching workspace = %p / %s\n", workspace, workspace->name);
+
+        /* if the workspace is currently visible on that output, we need to
+         * switch to a different workspace - otherwise the output would end up
+         * with no active workspace */
+        bool visible = workspace_is_visible(workspace);
+        Con *previous = NULL;
+        if (visible && (previous = TAILQ_NEXT(workspace, focused))) {
+            LOG("Switching to previously used workspace \"%s\" on output \"%s\"\n",
+                previous->name, workspace_out->name);
+            workspace_show(previous->name);
+        }
+
         con_detach(workspace);
-        DLOG("Re-attaching current = %p / %s\n", workspace, workspace->name);
         con_attach(workspace, content, false);
-        DLOG("Done, next\n");
+
+        /* In case the workspace we just moved was visible but there was no
+         * other workspace to switch to, we need to initialize the source
+         * output aswell */
+        if (visible && previous == NULL) {
+            LOG("There is no workspace left on \"%s\", re-initializing\n",
+                workspace_out->name);
+            init_ws_for_output(get_output_by_name(workspace_out->name),
+                               output_get_content(workspace_out));
+            DLOG("Done re-initializing, continuing with \"%s\"\n", output->name);
+        }
     }
 
     /* if a workspace exists, we are done now */