diff --git a/src/workspace.c b/src/workspace.c index 380ffec0..69db16cf 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -586,6 +586,26 @@ void wWorkspaceForceChange(WScreen * scr, int workspace) if (!foc) foc = foc2; + /* + * Check that the window we want to focus still exists, because the application owning it + * could decide to unmap/destroy it in response to unmap any of its other window following + * the workspace change, this happening during our 'ProcessPendingEvents' loop. + */ + if (foc != NULL) { + WWindow *parse; + Bool found; + + found = False; + for (parse = scr->focused_window; parse != NULL; parse = parse->prev) { + if (parse == foc) { + found = True; + break; + } + } + if (!found) + foc = NULL; + } + if (scr->focused_window->flags.mapped && !foc) { foc = scr->focused_window; }