From: Michael Stapelberg Date: Sun, 29 May 2011 12:39:41 +0000 (+0200) Subject: Bugfix: RandR: Correctly assign focused workspaces to outputs X-Git-Tag: tree-pr4~99 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=97e45b9cfcaf34412b3e582ab05cf9f1d7b8bd77;p=i3%2Fi3 Bugfix: RandR: Correctly assign focused workspaces to outputs Fixes: #399 --- diff --git a/src/randr.c b/src/randr.c index a6b84ddc..bf02518f 100644 --- a/src/randr.c +++ b/src/randr.c @@ -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 */