diff --git a/client.c b/client.c index cefd5dab..5b00a8e1 100644 --- a/client.c +++ b/client.c @@ -217,6 +217,9 @@ client_ban(client_t *c) if(client_hasstrut(c)) wibox_update_positions(); + if(globalconf.screens.tab[c->phys_screen].prev_client_focus == c) + globalconf.screens.tab[c->phys_screen].prev_client_focus = NULL; + /* Wait until the last moment to take away the focus from the window. */ if(globalconf.screens.tab[c->phys_screen].client_focus == c) client_unfocus(c); @@ -230,7 +233,11 @@ void client_focus_update(client_t *c) { if(!client_maybevisible(c, c->screen)) + { + /* Focus previously focused client */ + client_focus(globalconf.screen_focus->prev_client_focus); return; + } /* stop hiding client */ c->ishidden = false; @@ -240,6 +247,7 @@ client_focus_update(client_t *c) client_unban(c); globalconf.screen_focus = &globalconf.screens.tab[c->phys_screen]; + globalconf.screen_focus->prev_client_focus = c; globalconf.screen_focus->client_focus = c; /* Some layouts use focused client differently, so call them back. @@ -1224,6 +1232,9 @@ client_unmanage(client_t *c) tc->transient_for = NULL; } + if(globalconf.screens.tab[c->phys_screen].prev_client_focus == c) + globalconf.screens.tab[c->phys_screen].prev_client_focus = NULL; + if(globalconf.screens.tab[c->phys_screen].client_focus == c) client_unfocus(c); diff --git a/screen.h b/screen.h index 8e6ebef1..7a68fd9e 100644 --- a/screen.h +++ b/screen.h @@ -43,6 +43,8 @@ struct a_screen /** Systray window parent */ xcb_window_t parent; } systray; + /** Previously focused client */ + client_t *prev_client_focus; /** Focused client */ client_t *client_focus; /** The monitor of startup notifications */