diff --git a/dwm.c b/dwm.c index 1d78655..a9e0ea4 100644 --- a/dwm.c +++ b/dwm.c @@ -160,6 +160,7 @@ static Bool applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool inter static void arrange(Monitor *m); static void arrangemon(Monitor *m); static void attach(Client *c); +static void attachabove(Client *c); static void attachstack(Client *c); static void buttonpress(XEvent *e); static void checkotherwm(void); @@ -418,6 +419,19 @@ attach(Client *c) { } void +attachabove(Client *c) { + if(c->mon->sel == NULL || c->mon->sel == c->mon->clients || c->mon->sel->isfloating) { + attach(c); + return; + } + + Client *at; + for(at = c->mon->clients; at->next != c->mon->sel; at = at->next); + c->next = at->next; + at->next = c; +} + +void attachstack(Client *c) { c->snext = c->mon->stack; c->mon->stack = c; @@ -1155,7 +1169,7 @@ manage(Window w, XWindowAttributes *wa) { c->isfloating = c->oldstate = trans != None || c->isfixed; if(c->isfloating) XRaiseWindow(dpy, c->win); - attach(c); + attachabove(c); attachstack(c); XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */ setclientstate(c, NormalState); @@ -1480,7 +1494,7 @@ sendmon(Client *c, Monitor *m) { detachstack(c); c->mon = m; c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */ - attach(c); + attachabove(c); attachstack(c); focus(NULL); arrange(NULL); @@ -1900,7 +1914,7 @@ updategeom(void) { m->clients = c->next; detachstack(c); c->mon = mons; - attach(c); + attachabove(c); attachstack(c); } if(m == selmon)