rem: UpdateSwitchMenu(scr, wwin, ACTION_REMOVE);
context: wUnmanageWindow(WWindow *wwin, Bool restore, Bool destroyed){    WCoreWindow *frame = wwin->frame->core;    WWindow *owner = NULL;    WWindow *newFocusedWindow = NULL;    int wasFocused;    WScreen *scr = wwin->screen_ptr;#ifdef KWM_HINTS    wwin->frame->workspace = -1;    wKWMUpdateClientWorkspace(wwin);#endif    /* First close attribute editor window if open */    if (wwin->flags.inspector_open) {	wCloseInspectorForWindow(wwin);    }    /* Close window menu if it's open for this window */    if (wwin->flags.menu_open_for_me) {	CloseWindowMenu(scr);    }    if (!destroyed) {	if (!wwin->flags.internal_window)	    XRemoveFromSaveSet(dpy, wwin->client_win);	XSelectInput(dpy, wwin->client_win, NoEventMask);	XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);	XUngrabKey(dpy, AnyKey, AnyModifier, wwin->client_win);    }    XUnmapWindow(dpy, frame->window);    XUnmapWindow(dpy, wwin->client_win);    /* deselect window */    wSelectWindow(wwin, False);        /* remove all pending events on window */    /* I think this only matters for autoraise */    if (wPreferences.raise_delay)        WMDeleteTimerWithClientData(wwin->frame->core);    XFlush(dpy);    UpdateSwitchMenu(scr, wwin, ACTION_REMOVE);    /* reparent the window back to the root */    if (restore)	wClientRestore(wwin);    if (wwin->transient_for!=scr->root_win) {	owner = wWindowFor(wwin->transient_for);	if (owner) {	    if (!owner->flags.semi_focused) {		owner = NULL;	    } else {		owner->flags.semi_focused = 0;	    }	}    }    wasFocused = wwin->flags.focused;        /* remove from window focus list */    if (!wwin->prev && !wwin->next) {	/* was the only window */	scr->focused_window = NULL;	newFocusedWindow = NULL;    } else {	WWindow *tmp;	if (wwin->prev)	  wwin->prev->next = wwin->next;	if (wwin->next)	  wwin->next->prev = wwin->prev;	else {	    scr->focused_window = wwin->prev;	    scr->focused_window->next = NULL;	}	if (wPreferences.focus_mode==WKF_CLICK) {           /* if in click to focus mode and the window            * was a transient, focus the owner window              */           tmp = NULL;           if (wPreferences.focus_mode==WKF_CLICK) {               tmp = wWindowFor(wwin->transient_for);               if (tmp && (!tmp->flags.mapped || WFLAGP(tmp, no_focusable))) {                   tmp = NULL;               }           }           /* otherwise, focus the next one in the focus list */           if (!tmp) {              tmp = scr->focused_window;              while (tmp) {               /* look for one in the window list first */                 if (!WFLAGP(tmp, no_focusable) && !WFLAGP(tmp, skip_window_list)                     && (tmp->flags.mapped || tmp->flags.shaded))                     break;                 tmp = tmp->prev;              }              if (!tmp) {                 /* if unsuccessful, choose any focusable window */                 tmp = scr->focused_window;                 while (tmp) {                    if (!WFLAGP(tmp, no_focusable)                         && (tmp->flags.mapped || tmp->flags.shaded))                         break;                    tmp = tmp->prev;                 }              }           }	   newFocusedWindow = tmp;	} else if (wPreferences.focus_mode==WKF_SLOPPY) {            unsigned int mask;            int foo;            Window bar, win;            /*  This is to let the root window get the keyboard input             * if Sloppy focus mode and no other window get focus.             * This way keybindings will not freeze.             */            tmp = NULL;            if (XQueryPointer(dpy, scr->root_win, &bar, &win,                              &foo, &foo, &foo, &foo, &mask))                tmp = wWindowFor(win);            if (tmp == wwin)                tmp = NULL;	    newFocusedWindow = tmp;        } else {	    newFocusedWindow = NULL;	}    }    if (!wwin->flags.internal_window) {#ifdef GNOME_STUFF	wGNOMERemoveClient(wwin);#endif#ifdef KWM_HINTS	wKWMSendEventMessage(wwin, WKWMRemoveWindow);#endif    }#ifdef DEBUG    printf("destroying window %x frame %x\n", (unsigned)wwin->client_win,	   (unsigned)frame->window);#endif    if (wasFocused) {	if (newFocusedWindow != owner && owner) {	    if (wwin->flags.is_gnustep == 0)	      wFrameWindowChangeState(owner->frame, WS_UNFOCUSED);	}	wSetFocusTo(scr, newFocusedWindow);    }    wWindowDestroy(wwin);    XFlush(dpy);}