diff --git a/client.c b/client.c index ac186dadf..e17951d24 100644 --- a/client.c +++ b/client.c @@ -286,15 +286,8 @@ client_focus(client_t *c) if (!window_hasproto(c->win, WM_TAKE_FOCUS) && c->nofocus) return; - /* unfocus current selected client - * We don't really need to unfocus here, - * because client already received FocusOut event. - * What we need to do is call unfocus hook, to - * inform lua script, about this event. - */ - if(globalconf.screen_focus->client_focus - && c != globalconf.screen_focus->client_focus) - client_unfocus_hook(globalconf.screen_focus->client_focus); + /* Save current focused client */ + client_t *focused_before = globalconf.screen_focus->client_focus; /* stop hiding c */ c->ishidden = false; @@ -319,6 +312,15 @@ client_focus(client_t *c) * And anyway, we have maybe unhidden */ client_need_arrange(c); + /* unfocus current selected client + * We don't really need to unfocus here, + * because client already received FocusOut event. + * What we need to do is call unfocus hook, to + * inform lua script, about this event. + */ + if(focused_before && c != focused_before) + client_unfocus_hook(focused_before); + /* execute hook */ if(globalconf.hooks.focus != LUA_REFNIL) {