movestack.c (1278B)
1 void 2 movestack(const Arg *arg) 3 { 4 Client *c = NULL, *p = NULL, *pc = NULL, *i; 5 if (arg->i > 0) { 6 if (!selmon->sel) 7 return; 8 /* find the client after selmon->sel */ 9 for (c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next); 10 if (!c) 11 for (c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next); 12 } 13 else { 14 /* find the client before selmon->sel */ 15 for (i = selmon->clients; i != selmon->sel; i = i->next) 16 if(ISVISIBLE(i) && !i->isfloating) 17 c = i; 18 if (!c) 19 for (; i; i = i->next) 20 if (ISVISIBLE(i) && !i->isfloating) 21 c = i; 22 } 23 24 /* find the client before selmon->sel and c */ 25 for (i = selmon->clients; i && (!p || !pc); i = i->next) { 26 if (i->next == selmon->sel) 27 p = i; 28 if (i->next == c) 29 pc = i; 30 } 31 32 /* swap c and selmon->sel selmon->clients in the selmon->clients list */ 33 if (c && c != selmon->sel) { 34 Client *temp = selmon->sel->next==c?selmon->sel:selmon->sel->next; 35 selmon->sel->next = c->next==selmon->sel?c:c->next; 36 c->next = temp; 37 38 if (p && p != c) 39 p->next = c; 40 if (pc && pc != selmon->sel) 41 pc->next = selmon->sel; 42 43 if (selmon->sel == selmon->clients) 44 selmon->clients = c; 45 else if (c == selmon->clients) 46 selmon->clients = selmon->sel; 47 48 arrange(selmon); 49 } 50 } 51