From 4ecc6d965801b07677c69434172ce18e25b2e58e Mon Sep 17 00:00:00 2001 From: Ryan McBride Date: Wed, 21 Jan 2009 08:45:36 +0000 Subject: [PATCH] Fix some workspace switching nits: - Don't XMapRaised windows if they need to be moved/resized first. - Keep focus in the current region if possible. --- scrotwm.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/scrotwm.c b/scrotwm.c index 621942e..50ff0f4 100644 --- a/scrotwm.c +++ b/scrotwm.c @@ -220,6 +220,7 @@ struct workspace { struct layout *cur_layout; /* current layout handlers */ struct ws_win *focus; /* may be NULL */ struct swm_region *r; /* may be NULL */ + struct swm_region *prev_r; /* may be NULL */ struct ws_win_list winlist; /* list of windows in ws */ /* stacker state */ @@ -768,26 +769,33 @@ switchws(struct swm_region *r, union arg *args) other_r = new_ws->r; if (!other_r) { - /* if the other workspace is hidden, switch windows */ - /* map new window first to prevent ugly blinking */ - TAILQ_FOREACH(win, &new_ws->winlist, entry) - XMapRaised(display, win->id); - - TAILQ_FOREACH(win, &old_ws->winlist, entry) - XUnmapWindow(display, win->id); + /* + * If the other workspace is hidden and the workspace was + * previously mapped here, just swap switch windows. + * map new window first to prevent ugly blinking + */ + if (new_ws->restack == 0 && new_ws->prev_r == this_r) { + TAILQ_FOREACH(win, &new_ws->winlist, entry) + XMapRaised(display, win->id); + TAILQ_FOREACH(win, &old_ws->winlist, entry) + XUnmapWindow(display, win->id); + } + old_ws->prev_r = old_ws->r; old_ws->r = NULL; - old_ws->restack = 1; } else { other_r->ws = old_ws; old_ws->r = other_r; } this_r->ws = new_ws; + new_ws->prev_r = new_ws->r; new_ws->r = this_r; ignore_enter = 1; /* set focus */ - if (new_ws->focus) + if (!new_ws->focus) + new_ws->focus = TAILQ_FIRST(&new_ws->winlist); + if (new_ws->focus ) focus_win(new_ws->focus); stack(); bar_update(); @@ -1607,8 +1615,12 @@ destroynotify(XEvent *e) TAILQ_REMOVE(&ws->winlist, win, entry); set_win_state(win, WithdrawnState); free(win); + + if (ws->r == NULL) + ws->restack = 1; + else + stack(); } - stack(); } void -- 1.7.10.4