diff -r 8b109976c594 config.default.h --- a/config.default.h Thu Aug 17 10:06:36 2006 +0200 +++ b/config.default.h Fri Aug 18 14:31:29 2006 +0200 @@ -14,6 +14,7 @@ const char *tags[] = { "0", "1", "2", "3 #define BORDERCOLOR "#9999CC" #define MODKEY Mod1Mask #define MASTERW 60 /* percent */ +#define MASTERH 60 /* percent */ #define KEYS \ static Key key[] = { \ @@ -23,6 +24,7 @@ static Key key[] = { \ { MODKEY|ShiftMask, XK_Tab, focusprev, { 0 } }, \ { MODKEY, XK_Return, zoom, { 0 } }, \ { MODKEY, XK_m, togglemax, { 0 } }, \ + { MODKEY, XK_t, togglelayout, { 0 } }, \ { MODKEY|ShiftMask, XK_0, tag, { .i = 0 } }, \ { MODKEY|ShiftMask, XK_1, tag, { .i = 1 } }, \ { MODKEY|ShiftMask, XK_2, tag, { .i = 2 } }, \ diff -r 8b109976c594 dwm.h --- a/dwm.h Thu Aug 17 10:06:36 2006 +0200 +++ b/dwm.h Fri Aug 18 14:31:29 2006 +0200 @@ -69,12 +69,12 @@ struct Client { extern const char *tags[]; extern char stext[1024]; -extern int screen, sx, sy, sw, sh, bx, by, bw, bh, mw; +extern int screen, sx, sy, sw, sh, bx, by, bw, bh, mw, mh; extern unsigned int ntags, numlockmask; extern void (*handler[LASTEvent])(XEvent *); extern void (*arrange)(Arg *); extern Atom wmatom[WMLast], netatom[NetLast]; -extern Bool running, issel, *seltag; +extern Bool running, issel, *seltag, rows; extern Client *clients, *sel; extern Cursor cursor[CurLast]; extern DC dc; @@ -129,6 +129,7 @@ extern void togglemode(Arg *arg); extern void togglemode(Arg *arg); extern void toggletag(Arg *arg); extern void toggleview(Arg *arg); +extern void togglelayout(Arg *arg); extern void view(Arg *arg); /* util.c */ diff -r 8b109976c594 main.c --- a/main.c Thu Aug 17 10:06:36 2006 +0200 +++ b/main.c Fri Aug 18 14:31:29 2006 +0200 @@ -96,11 +96,12 @@ xerrorstart(Display *dsply, XErrorEvent char stext[1024]; Bool *seltag; -int screen, sx, sy, sw, sh, bx, by, bw, bh, mw; +int screen, sx, sy, sw, sh, bx, by, bw, bh, mw, mh; unsigned int ntags, numlockmask; Atom wmatom[WMLast], netatom[NetLast]; Bool running = True; Bool issel = True; +Bool rows = False; /* columns or rows */ Client *clients = NULL; Client *sel = NULL; Cursor cursor[CurLast]; @@ -253,6 +254,7 @@ main(int argc, char *argv[]) sw = DisplayWidth(dpy, screen); sh = DisplayHeight(dpy, screen); mw = (sw * MASTERW) / 100; + mh = (sh * MASTERH) / 100; bx = by = 0; bw = sw; diff -r 8b109976c594 tag.c --- a/tag.c Thu Aug 17 10:06:36 2006 +0200 +++ b/tag.c Fri Aug 18 14:31:29 2006 +0200 @@ -56,21 +56,41 @@ dofloat(Arg *arg) restack(); } -void -dotile(Arg *arg) -{ - int h, i, n, w; - Client *c; - - w = sw - mw; +int +countclients(){ + int n; + Client *c; for(n = 0, c = clients; c; c = c->next) if(isvisible(c) && !c->isfloat) n++; - - if(n > 1) - h = (sh - bh) / (n - 1); - else - h = sh - bh; + return n; +} + +void +dotile(Arg *arg) +{ + int i, extra; + int xoff, yoff, woff, hoff; + Client *c; + int n = countclients(); + int h = n>2 ? ( rows ? (sh-bh)/(n-2):sh-mh):0; + int w = n>2 ? (!rows ? sw/(n-2) :sw-mw):0; + int dims[] = { + /* + x, y, w, h + */ + 0, bh, 0, -bh, /* 0 master n=1 */ + 0, bh, -sw+mw, -bh, /* 4 master n=2 columns */ + mw, bh, -mw, -bh, /* - slave n=2 columns */ + 0, bh, 0, -sh+mh-bh, /* 12 master n=2 rows */ + 0, mh, 0, -mh, /* - slave n=2 rows */ + 0, bh, -sw+mw, -sh+mh-bh, /* 20 master n>2 columns */ + mw, bh, -mw, -sh+mh-bh, /* - slave n>2 columns */ + 0, mh, -sw+w, -sh+h, /* - other n>2 columns */ + 0, bh, -sw+mw, -sh+mh-bh, /* 32 master n>2 rows */ + 0, mh, -sw+mw, -mh, /* - slave n>2 rows */ + mw, bh, -sw+w, -sh+h, /* - other n>2 rows */ + }; for(i = 0, c = clients; c; c = c->next) { c->ismax = False; @@ -79,33 +99,29 @@ dotile(Arg *arg) resize(c, True, TopLeft); continue; } - if(n == 1) { - c->x = sx; - c->y = sy + bh; - c->w = sw - 2; - c->h = sh - 2 - bh; - } - else if(i == 0) { - c->x = sx; - c->y = sy + bh; - c->w = mw - 2; - c->h = sh - 2 - bh; - } - else if(h > bh) { - c->x = sx + mw; - c->y = sy + (i - 1) * h + bh; - c->w = w - 2; - if(i + 1 == n) - c->h = sh - c->y - 2; - else - c->h = h - 2; - } - else { /* fallback if h < bh */ - c->x = sx + mw; - c->y = sy + bh; - c->w = w - 2; - c->h = sh - 2 - bh; - } + extra = 0; + if (n>2) { + extra += 20; + extra += i>1 ? 8 : 4*i; + if (rows) + extra += 12; + } + else { + extra += (4+4*i) - ((4+4*i)*(2-n)); + if (rows) + extra += 8-8*(2-n); + } + + xoff = dims[0+extra]; + yoff = dims[1+extra]; + woff = dims[2+extra]; + hoff = dims[3+extra]; + + c->x = sx + xoff + (i>1 ? 1:0)*(i-2)*w*(rows ? 0 : 1); + c->y = sy + yoff + (i>1 ? 1:0)*(i-2)*h*(rows ? 1 : 0); + c->w = sw + woff - 2; /* 2 x 1 pix border */ + c->h = sh + hoff - 2; + resize(c, False, TopLeft); i++; } @@ -326,3 +342,11 @@ view(Arg *arg) seltag[arg->i] = True; arrange(NULL); } + +void +togglelayout(Arg *arg) +{ + rows = !rows; + arrange(NULL); +} +