X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=dwm.c;h=f873a42ffbc45722f1fdf6dada558781c9f2946c;hp=5c25c2426c6d18ec3ddffbd135d903afafa17e8b;hb=62330c6674634fb32a1296ca710512804d45176a;hpb=99144036af9457eb08c709d3fba7f6ffb42039dc 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); }