rem: if (focused) oapp = wApplicationOf(focused->main_window);
add: if (old_focused) oapp = wApplicationOf(old_focused->main_window);
context: wSetFocusTo(WScreen *scr, WWindow  *wwin){    WWindow *focused=scr->focused_window;    int timestamp=LastTimestamp;    WApplication *oapp=NULL, *napp=NULL;    int wasfocused;    LastFocusChange = timestamp;/* * This is a hack, because XSetInputFocus() should have a proper * timestamp instead of CurrentTime but it seems that some times * clients will not receive focus properly that way.    if (ignoreTimestamp)*/      timestamp = CurrentTime;    if (focused)	oapp = wApplicationOf(focused->main_window);    if (wwin == NULL) {	XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);	if (focused) {	    wWindowUnfocus(focused);	}	if (oapp) {	    wAppMenuUnmap(oapp->menu);#ifdef NEWAPPICON	    wApplicationDeactivate(oapp);#endif	}#ifdef KWM_HINTS	wKWMUpdateActiveWindowHint(scr);	wKWMSendEventMessage(NULL, WKWMFocusWindow);#endif	return;    }    wasfocused = wwin->flags.focused;    napp = wApplicationOf(wwin->main_window);    /* remember last workspace where the app has been */    if (napp) 	napp->last_workspace = wwin->screen_ptr->current_workspace;    if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {	/* install colormap if colormap mode is lock mode */	if (wPreferences.colormap_mode==WKF_CLICK)	    wColormapInstallForWindow(scr, wwin);	/* set input focus */	switch (wwin->focus_mode) {	 case WFM_NO_INPUT:	    XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);	    break;	 case WFM_PASSIVE:	 case WFM_LOCALLY_ACTIVE:	    XSetInputFocus(dpy, wwin->client_win, RevertToParent, timestamp);	    break;	 case WFM_GLOBALLY_ACTIVE:	    break;	}	XFlush(dpy);	if (wwin->protocols.TAKE_FOCUS) {	    wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);	}	XSync(dpy, False);    } else {	XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);    }    if (WFLAGP(wwin, no_focusable))	return;    /* if this is not the focused window focus it */    if (focused!=wwin) {	/* change the focus window list order */	if (wwin->prev)	  wwin->prev->next = wwin->next;	if (wwin->next)	  wwin->next->prev = wwin->prev;	wwin->prev = focused;	focused->next = wwin;	wwin->next = NULL;	scr->focused_window = wwin;	if (oapp && oapp != napp) {	    wAppMenuUnmap(oapp->menu);#ifdef NEWAPPICON	    wApplicationDeactivate(oapp);#endif	}    }    wWindowFocus(wwin, focused);    if (napp && !wasfocused) {#ifdef USER_MENU	wUserMenuRefreshInstances(napp->menu, wwin);#endif /* USER_MENU */    if (wwin->flags.mapped)    	wAppMenuMap(napp->menu, wwin);#ifdef NEWAPPICON	wApplicationActivate(napp);#endif    }#ifdef KWM_HINTS    wKWMUpdateActiveWindowHint(scr);    wKWMSendEventMessage(wwin, WKWMFocusWindow);#endif    XFlush(dpy);}