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