From 97e45b9cfcaf34412b3e582ab05cf9f1d7b8bd77 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 29 May 2011 14:39:41 +0200 Subject: [PATCH] Bugfix: RandR: Correctly assign focused workspaces to outputs Fixes: #399 --- src/randr.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) 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 */ -- 2.39.5