From: Jason Woofenden Date: Mon, 17 Nov 2014 03:57:03 +0000 (-0500) Subject: new windows open away from master, closing focuses towards master X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=commitdiff_plain;h=c0ee24356493538c83045703ce610d7a8c6603ac new windows open away from master, closing focuses towards master --- diff --git a/dwm.c b/dwm.c index 5c25c24..f873a42 100644 --- a/dwm.c +++ b/dwm.c @@ -410,14 +410,24 @@ arrangemon(Monitor *m) { void attach(Client *c) { - c->next = c->mon->clients; - c->mon->clients = c; + if (c->mon->sel) { + c->next = c->mon->sel->next; + c->mon->sel->next = c; + } else { + c->next = c->mon->clients; + c->mon->clients = c; + } } void attachstack(Client *c) { - c->snext = c->mon->stack; - c->mon->stack = c; + if (c->mon->sel) { + c->snext = c->mon->sel->snext; + c->mon->sel->snext = c; + } else { + c->snext = c->mon->stack; + c->mon->stack = c; + } } void @@ -678,14 +688,23 @@ detach(Client *c) { void detachstack(Client *c) { - Client **tc, *t; - - for(tc = &c->mon->stack; *tc && *tc != c; tc = &(*tc)->snext); - *tc = c->snext; - + Client *prev = NULL, *next_sel = NULL, *i; + for(i = c->mon->stack; i && i != c; i = i->snext) { + prev = i; + if(ISVISIBLE(i)) + next_sel = i; + } if(c == c->mon->sel) { - for(t = c->mon->stack; t && !ISVISIBLE(t); t = t->snext); - c->mon->sel = t; + if (!next_sel) { // if no visible window prev, find first visible + for(i = c->mon->stack; i && !ISVISIBLE(i); i = i->snext) + next_sel = i; + } + c->mon->sel = next_sel; + } + if (prev) { + prev->snext = c->snext; + } else { + c->mon->stack = c->snext; } } @@ -1085,7 +1104,7 @@ manage(Window w, XWindowAttributes *wa) { c->mon->sel = c; arrange(c->mon); XMapWindow(dpy, c->win); - focus(NULL); + focus(c); } void @@ -1738,7 +1757,7 @@ unmanage(Client *c, Bool destroyed) { XUngrabServer(dpy); } free(c); - focus(NULL); + focus(selmon ? selmon->sel : NULL); updateclientlist(); arrange(m); }