[dwm] fibonacci layout patch [update for dwm-5.0.1]

From: Madhu <enometh_AT_meer.net>
Date: Tue, 29 Jul 2008 12:01:47 +0530 (IST)

Attached is a slightly different implementation of the fibonacci()
function that respects `mfact' for the master window [and lets you
resize your master window with M-j M-k] This worked under hg tip
(1314). Comments, insights welcome. --Madhu

void
fibonacci(int shape) {

        /* shape = 2 ==> dwindle
         * shape = 1 ==> counter clockwise spiral
         * shape = 0 ==> clockwise spiral
         */

        unsigned int i, n, nx, ny, nw, nh;
        unsigned int mw, NX0;
        Client *c;

        for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next), n++);
        if (n == 0)
                return;

        /* master */
        c = nexttiled(clients);
        mw = mfact * ww;
        resize(c, wx, wy, (n == 1 ? ww : mw) - 2 * c->bw, wh - 2 * c->bw, resizehints);

        if (--n == 0)
                return;

        nx = NX0 = (wx + mw > c->x + c->w) ? c->x + c->w + 2 * c->bw : wx + mw;
        ny = wy;
        nw = (wx + mw > c->x + c->w) ? wx + ww - nx : ww - mw;
        nh = wh;

        for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next)) {
                if((i % 2 && (nw / 2) > 2 * c->bw)
                   || (!(i % 2) && (nh / 2) > 2 * c->bw))
                {
                        if ((i+1) < n) {
                                if (i % 2)
                                        nw /= 2;
                                else
                                        nh /= 2;
                        }
                        if ((i % 4) == 0) {
                                if (shape == 2)
                                        nx += nw;
                                else if (shape == 1) {
                                        nx += nw;
                                        if ((i+1) < n)
                                                ny += nh;
                                }
                                else
                                        nx += nw;
                        }
                        else if ((i % 4) == 1) {
                                if (shape == 2)
                                        ny += nh;
                                else if (shape == 1) {
                                        ny -= nh;
                                        if ((i+1) < n)
                                                nx += nw;
                                }
                                else {
                                        ny += nh;
                                        if ((i+1) < n)
                                                nx += nw;
                                }
                        }
                        else if ((i % 4) == 2) {
                                if (shape == 2)
                                        nx += nw;
                                else if (shape == 1)
                                        nx -= nw;
                                else {
                                        nx -= nw;
                                        if (i+1 < n)
                                                ny += nh;
                                }
                        }
                        else if ((i % 4) == 3) {
                                if (shape == 2)
                                        ny += nh;
                                else if (shape == 1)
                                        ny += nh;
                                else
                                        ny -= nh;
                        }
                        if (i == 0)
                                nx = NX0;
                        i++;
                }
                resize(c, nx, ny, nw - 2 * c->bw, nh - 2 * c->bw, resizehints);
        }
}
Received on Tue Jul 29 2008 - 06:31:47 UTC

This archive was generated by hypermail 2.2.0 : Tue Jul 29 2008 - 06:36:04 UTC