diff --git a/client.c b/client.c index dbbd5a3..5874886 100644 --- a/client.c +++ b/client.c @@ -414,4 +414,25 @@ void ensureactive() { void ensureactiveonmonitor(int monitor) { if (!current) shuffleonmonitor(monitor); +} + +Window getrevert(Client* c) { + int m; + Client* cc; + + if (!c) { + return 0; + } + + if (c->trans) { + return c->trans; + } else { + m = getmonitorbyclient(c); + for (cc = c->revert; cc && cc->revert; cc = cc->revert) { + if (getmonitorbyclient(cc) == m) { + return cc->window; + } + } + } + return 0; } \ No newline at end of file diff --git a/event.c b/event.c index 2a4c220..5849c7a 100644 --- a/event.c +++ b/event.c @@ -255,14 +255,15 @@ void mapreq(XMapRequestEvent* e) { } void unmap(XUnmapEvent* e) { - Client* c; - int monitor; + Client *c, *revertc; + Window revert; + int m; curtime = CurrentTime; c = getclient(e->window, 0); if (c) { - monitor = getmonitorbyclient(c); + m = getmonitorbyclient(c); switch (c->state) { case IconicState: if (e->send_event) { @@ -271,8 +272,14 @@ void unmap(XUnmapEvent* e) { } break; case NormalState: - if (c == current) - shuffleonmonitor(monitor); + if (c == current) { + if (revertc = getclient(getrevert(c), 0)) { + top(revertc); + active(revertc); + } else { + shuffleonmonitor(m); + } + } if (!c->reparenting) withdraw(c); break; @@ -345,7 +352,8 @@ void newwindow(XCreateWindowEvent* e) { void destroy(Window w) { int i; - Client* c; + Client *c, *revertc; + Window revert; int monitor; curtime = CurrentTime; @@ -353,14 +361,20 @@ void destroy(Window w) { if (c == 0) return; + revert = getrevert(c); monitor = getmonitorbyclient(c); + if (numvirtuals > 1) for (i = 0; i < numvirtuals; i++) if (currents[i] == c) currents[i] = 0; rmclient(c); - ensureactiveonmonitor(monitor); + + if (!current && (revertc = getclient(revert, 0))) { + top(revertc); + active(revertc); + } /* flush any errors generated by the window's sudden demise */ ignore_badwindow = 1; @@ -383,8 +397,10 @@ void clientmesg(XClientMessageEvent* e) { perror("ryudo: exec failed"); exit(1); } - if (e->message_type == wm_protocols) + + if (e->message_type == wm_protocols) { return; + } if (e->message_type == wm_change_state) { c = getclient(e->window, 0); if (e->format == 32 && e->data.l[0] == IconicState && c != 0) { diff --git a/fns.h b/fns.h index c85e5ed..a54aaa2 100644 --- a/fns.h +++ b/fns.h @@ -103,6 +103,7 @@ int isterminalwindow(Client* c); void ensureactive(); void ensureactiveonmonitor(int); void shuffleonmonitor(int); +Window getrevert(Client*); /* grab.c */ int menuhit(); diff --git a/menu.c b/menu.c index fe64416..0dc210f 100644 --- a/menu.c +++ b/menu.c @@ -310,19 +310,30 @@ void move(Client* c, int but) { } void delete (Client* c, int shift) { - // int v; + Client* revertc; + if (c == 0) return; - // v = c->virt; + + if (c == current) { + if (revertc = getclient(getrevert(c), 0)) { + top(revertc); + active(revertc); + } else { + nofocus(); + } + } + if ((c->proto & Pdelete) && !shift) sendcmessage(c->window, wm_protocols, wm_delete, 0, 0); else XKillClient(dpy, c->window); /* let event clean up */ - ensureactive(); } void hide(Client* c) { int monitor; + Client* revertc; + if (c == 0 || numhidden == MAXHIDDEN) return; if (hidden(c)) { @@ -333,8 +344,14 @@ void hide(Client* c) { XUnmapWindow(dpy, c->parent); XUnmapWindow(dpy, c->window); setstate(c, IconicState); - if (c == current) - nofocus(); + if (c == current) { + if (revertc = getclient(getrevert(c), 0)) { + top(revertc); + active(revertc); + } else { + nofocus(); + } + } if (reversehide) { memmove(hiddenc + 1, hiddenc, numhidden * sizeof hiddenc[0]); memmove(