diff options
author | Derek Stevens <nilix@nilfm.cc> | 2022-03-04 23:57:25 -0700 |
---|---|---|
committer | Derek Stevens <nilix@nilfm.cc> | 2022-03-04 23:57:25 -0700 |
commit | 4ad722c1aa7c7013470c499a25498d51b564a2fc (patch) | |
tree | 299f588b14db6da31365c930c581b14635d6a93d | |
parent | 1f72f88bde30230ea114635fb5b5a5b2aaccbe89 (diff) |
fix heuristics for focusing windows after hiding or deleting current
-rw-r--r-- | client.c | 21 | ||||
-rw-r--r-- | event.c | 32 | ||||
-rw-r--r-- | fns.h | 1 | ||||
-rw-r--r-- | menu.c | 27 |
4 files changed, 68 insertions, 13 deletions
@@ -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 @@ -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) { @@ -103,6 +103,7 @@ int isterminalwindow(Client* c); void ensureactive(); void ensureactiveonmonitor(int); void shuffleonmonitor(int); +Window getrevert(Client*); /* grab.c */ int menuhit(); @@ -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( |