diff --git c/config.def.h w/config.def.h index 9efa774..7ee7f9d 100644 --- c/config.def.h +++ w/config.def.h @@ -39,9 +39,14 @@ static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen win static const Layout layouts[] = { /* symbol arrange function */ - { "[]=", tile }, /* first entry is default */ + { "|+|", tatami }, /* first entry is default */ { "><>", NULL }, /* no layout function means floating behavior */ + { "[]=", tile }, { "[M]", monocle }, + { "|M|", centeredmaster }, + { ">M>", centeredfloatingmaster }, + { "TTT", bstack }, + { "===", bstackhoriz }, }; /* key definitions */ @@ -74,9 +79,14 @@ static const Key keys[] = { { MODKEY, XK_Return, zoom, {0} }, { MODKEY, XK_Tab, view, {0} }, { MODKEY|ShiftMask, XK_c, killclient, {0} }, - { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, - { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, - { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, + { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, /* tatami */ + { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, /* floating */ + { MODKEY|ShiftMask, XK_t, setlayout, {.v = &layouts[2]} }, /* tile */ + { MODKEY, XK_m, setlayout, {.v = &layouts[3]} }, /* monocle */ + { MODKEY, XK_u, setlayout, {.v = &layouts[4]} }, /* centeredmaster */ + { MODKEY|ShiftMask, XK_u, setlayout, {.v = &layouts[5]} }, /* centeredfloatingmaster */ + { MODKEY, XK_g, setlayout, {.v = &layouts[6]} }, /* bstack */ + { MODKEY|ShiftMask, XK_g, setlayout, {.v = &layouts[7]} }, /* bstackhoriz */ { MODKEY, XK_space, setlayout, {0} }, { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, { MODKEY, XK_0, view, {.ui = ~0 } }, diff --git c/dwm.c w/dwm.c index 1443802..b1c07e8 100644 --- c/dwm.c +++ w/dwm.c @@ -232,6 +232,11 @@ static int xerror(Display *dpy, XErrorEvent *ee); static int xerrordummy(Display *dpy, XErrorEvent *ee); static int xerrorstart(Display *dpy, XErrorEvent *ee); static void zoom(const Arg *arg); +static void tatami(Monitor *m); +static void bstack(Monitor *m); +static void bstackhoriz(Monitor *m); +static void centeredmaster(Monitor *m); +static void centeredfloatingmaster(Monitor *m); /* variables */ static const char broken[] = "broken"; @@ -2162,3 +2167,327 @@ main(int argc, char *argv[]) XCloseDisplay(dpy); return EXIT_SUCCESS; } + +void +tatami(Monitor *m) +{ + unsigned int i, n, nx, ny, nw, nh, + mats, tc, + tnx, tny, tnw, tnh; + Client *c; + + for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), ++n); + if(n == 0) + return; + + nx = m->wx; + ny = 0; + nw = m->ww; + nh = m->wh; + + c = nexttiled(m->clients); + + if(n != 1) nw = m->ww * m->mfact; + ny = m->wy; + + resize(c, nx, ny, nw - 2 * c->bw, nh - 2 * c->bw, False); + + c = nexttiled(c->next); + + nx += nw; + nw = m->ww - nw; + + if(n>1) + { + + tc = n-1; + mats = tc/5; + + nh/=(mats + (tc % 5 > 0)); + + for(i = 0; c && (i < (tc % 5)); c = nexttiled(c->next)) + { + tnw=nw; + tnx=nx; + tnh=nh; + tny=ny; + switch(tc - (mats*5)) + { + case 1://fill + break; + case 2://up and down + if((i % 5) == 0) //up + tnh/=2; + else if((i % 5) == 1) //down + { + tnh/=2; + tny += nh/2; + } + break; + case 3://bottom, up-left and up-right + if((i % 5) == 0) //up-left + { + tnw = nw/2; + tnh = (2*nh)/3; + } + else if((i % 5) == 1)//up-right + { + tnx += nw/2; + tnw = nw/2; + tnh = (2*nh)/3; + } + else if((i % 5) == 2)//bottom + { + tnh = nh/3; + tny += (2*nh)/3; + } + break; + case 4://bottom, left, right and top + if((i % 5) == 0) //top + { + tnh = (nh)/4; + } + else if((i % 5) == 1)//left + { + tnw = nw/2; + tny += nh/4; + tnh = (nh)/2; + } + else if((i % 5) == 2)//right + { + tnx += nw/2; + tnw = nw/2; + tny += nh/4; + tnh = (nh)/2; + } + else if((i % 5) == 3)//bottom + { + tny += (3*nh)/4; + tnh = (nh)/4; + } + break; + } + ++i; + resize(c, tnx, tny, tnw - 2 * c->bw, tnh - 2 * c->bw, False); + } + + ++mats; + + for(i = 0; c && (mats>0); c = nexttiled(c->next)) { + + if((i%5)==0) + { + --mats; + if(((tc % 5) > 0)||(i>=5)) + ny+=nh; + } + + tnw=nw; + tnx=nx; + tnh=nh; + tny=ny; + + + switch(i % 5) + { + case 0: //top-left-vert + tnw = (nw)/3; + tnh = (nh*2)/3; + break; + case 1: //top-right-hor + tnx += (nw)/3; + tnw = (nw*2)/3; + tnh = (nh)/3; + break; + case 2: //center + tnx += (nw)/3; + tnw = (nw)/3; + tny += (nh)/3; + tnh = (nh)/3; + break; + case 3: //bottom-right-vert + tnx += (nw*2)/3; + tnw = (nw)/3; + tny += (nh)/3; + tnh = (nh*2)/3; + break; + case 4: //(oldest) bottom-left-hor + tnw = (2*nw)/3; + tny += (2*nh)/3; + tnh = (nh)/3; + break; + default: + break; + } + + ++i; + //i%=5; + resize(c, tnx, tny, tnw - 2 * c->bw, tnh - 2 * c->bw, False); + } + } +} + +void +bstack(Monitor *m) { + int w, h, mh, mx, tx, ty, tw; + unsigned int i, n; + Client *c; + + for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); + if (n == 0) + return; + if (n > m->nmaster) { + mh = m->nmaster ? m->mfact * m->wh : 0; + tw = m->ww / (n - m->nmaster); + ty = m->wy + mh; + } else { + mh = m->wh; + tw = m->ww; + ty = m->wy; + } + for (i = mx = 0, tx = m->wx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) { + if (i < m->nmaster) { + w = (m->ww - mx) / (MIN(n, m->nmaster) - i); + resize(c, m->wx + mx, m->wy, w - (2 * c->bw), mh - (2 * c->bw), 0); + mx += WIDTH(c); + } else { + h = m->wh - mh; + resize(c, tx, ty, tw - (2 * c->bw), h - (2 * c->bw), 0); + if (tw != m->ww) + tx += WIDTH(c); + } + } +} + +void +bstackhoriz(Monitor *m) { + int w, mh, mx, tx, ty, th; + unsigned int i, n; + Client *c; + + for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); + if (n == 0) + return; + if (n > m->nmaster) { + mh = m->nmaster ? m->mfact * m->wh : 0; + th = (m->wh - mh) / (n - m->nmaster); + ty = m->wy + mh; + } else { + th = mh = m->wh; + ty = m->wy; + } + for (i = mx = 0, tx = m->wx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) { + if (i < m->nmaster) { + w = (m->ww - mx) / (MIN(n, m->nmaster) - i); + resize(c, m->wx + mx, m->wy, w - (2 * c->bw), mh - (2 * c->bw), 0); + mx += WIDTH(c); + } else { + resize(c, tx, ty, m->ww - (2 * c->bw), th - (2 * c->bw), 0); + if (th != m->wh) + ty += HEIGHT(c); + } + } +} + +void +centeredmaster(Monitor *m) +{ + unsigned int i, n, h, mw, mx, my, oty, ety, tw; + Client *c; + + /* count number of clients in the selected monitor */ + for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); + if (n == 0) + return; + + /* initialize areas */ + mw = m->ww; + mx = 0; + my = 0; + tw = mw; + + if (n > m->nmaster) { + /* go mfact box in the center if more than nmaster clients */ + mw = m->nmaster ? m->ww * m->mfact : 0; + tw = m->ww - mw; + + if (n - m->nmaster > 1) { + /* only one client */ + mx = (m->ww - mw) / 2; + tw = (m->ww - mw) / 2; + } + } + + oty = 0; + ety = 0; + for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) + if (i < m->nmaster) { + /* nmaster clients are stacked vertically, in the center + * of the screen */ + h = (m->wh - my) / (MIN(n, m->nmaster) - i); + resize(c, m->wx + mx, m->wy + my, mw - (2*c->bw), + h - (2*c->bw), 0); + my += HEIGHT(c); + } else { + /* stack clients are stacked vertically */ + if ((i - m->nmaster) % 2 ) { + h = (m->wh - ety) / ( (1 + n - i) / 2); + resize(c, m->wx, m->wy + ety, tw - (2*c->bw), + h - (2*c->bw), 0); + ety += HEIGHT(c); + } else { + h = (m->wh - oty) / ((1 + n - i) / 2); + resize(c, m->wx + mx + mw, m->wy + oty, + tw - (2*c->bw), h - (2*c->bw), 0); + oty += HEIGHT(c); + } + } +} + +void +centeredfloatingmaster(Monitor *m) +{ + unsigned int i, n, w, mh, mw, mx, mxo, my, myo, tx; + Client *c; + + /* count number of clients in the selected monitor */ + for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); + if (n == 0) + return; + + /* initialize nmaster area */ + if (n > m->nmaster) { + /* go mfact box in the center if more than nmaster clients */ + if (m->ww > m->wh) { + mw = m->nmaster ? m->ww * m->mfact : 0; + mh = m->nmaster ? m->wh * 0.9 : 0; + } else { + mh = m->nmaster ? m->wh * m->mfact : 0; + mw = m->nmaster ? m->ww * 0.9 : 0; + } + mx = mxo = (m->ww - mw) / 2; + my = myo = (m->wh - mh) / 2; + } else { + /* go fullscreen if all clients are in the master area */ + mh = m->wh; + mw = m->ww; + mx = mxo = 0; + my = myo = 0; + } + + for(i = tx = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) + if (i < m->nmaster) { + /* nmaster clients are stacked horizontally, in the center + * of the screen */ + w = (mw + mxo - mx) / (MIN(n, m->nmaster) - i); + resize(c, m->wx + mx, m->wy + my, w - (2*c->bw), + mh - (2*c->bw), 0); + mx += WIDTH(c); + } else { + /* stack clients are stacked horizontally */ + w = (m->ww - tx) / (n - i); + resize(c, m->wx + tx, m->wy, w - (2*c->bw), + m->wh - (2*c->bw), 0); + tx += WIDTH(c); + } +}