greetings,
> I'm fiddling with a function that makes it possible to rearrang the
> clients in the stack. My efforts so far has been pretty unsuccessfully. 
> My thought was that one should be able change places between the
> selected client with the client above or belowe. 
 here is my implementation of this functionality from my personal
customized dwm. This is a section in my layout.c; two functions named
pushup and pushdown that move the current selected client in the list.

regards,
 Mate
void
pushup(const char *arg) {
        Client *c;
        if(!sel || lt->arrange != tile || sel->isfloating)
                return;

        if((c = prevtiled(sel->prev))) {
                Client *selprev = sel->prev;
                Client *selnext = sel->next;
                Client *cprev = c->prev;
                Client *cnext = c->next;

                if(cprev) {
                        if(cnext == sel) {
                                cprev->next = sel;
                                sel->prev = cprev;
                                if(selnext)
                                        selnext->prev = c;
                                c->next = selnext;
                                sel->next = c;
                                c->prev = sel;
                        } else {
                                cprev->next = sel;
                                sel->prev = cprev;
                                sel->next = cnext;
                                cnext->prev = sel;

                                selprev->next = c;
                                c->prev = selprev;
                                if(selnext)
                                        selnext->prev = c;
                                c->next = selnext;
                        }
                } else {
                        detach(sel);
                        attach(sel);
                }
        } else {
                c = sel;
                Client *d;
                while((d = nexttiled(c->next)))
                        c = d;
                if(c && c != sel) {
                        detach(sel);
                        if(c->next) {
                                d = c->next;
                                c->next = sel;
                                sel->prev = c;
                                sel->next = d;
                                d->prev = sel;
                        } else {
                                c->next = sel;
                                sel->prev = c;
                        }
                }
        }

        focus(sel);
        lt->arrange();
}

void
pushdown(const char *arg) {
        Client *c;
        if(!sel || lt->arrange != tile || sel->isfloating)
                return;

        if((c = nexttiled(sel->next))) {
                Client *selprev = sel->prev;
                Client *selnext = sel->next;
                Client *cprev = c->prev;
                Client *cnext = c->next;

                if(selprev) {
                        if(selnext == c) {
                                selprev->next = c;
                                c->prev = selprev;
                                c->next = sel;
                                sel->prev = c;
                                sel->next = cnext;
                                if(cnext)
                                        cnext->prev = sel;
                        } else {
                                selprev->next = c;
                                c->prev = selprev;
                                selnext->prev = c;
                                c->next = selnext;

                                cprev->next = sel;
                                sel->prev = cprev;

                                if(cnext)
                                        cnext->prev = sel;
                                sel->next = cnext;
                        }
                } else {
                        detach(c);
                        attach(c);
                }
        } else {
                detach(sel);
                attach(sel);
        }

        focus(sel);
        lt->arrange();
}

Reply via email to