--- config.def.h | 29 ++++++- dwm.c | 223 ++++++++++++++++++++++++++++++++++++++++++++++++-- fibonacci.c | 71 ++++++++++++++++ gaplessgrid.c | 40 +++++++++ 4 files changed, 351 insertions(+), 12 deletions(-) create mode 100644 fibonacci.c create mode 100644 gaplessgrid.c diff --git a/config.def.h b/config.def.h index 1c0b587..7672129 100644 --- a/config.def.h +++ b/config.def.h _AT_@ -2,6 +2,7 @@ /* appearance */ static const unsigned int borderpx = 1; /* border pixel of windows */ +static const unsigned int gappx = 5; /* gaps between windows */ static const unsigned int snap = 32; /* snap pixel */ static const int showbar = 1; /* 0 means no bar */ static const int topbar = 1; /* 0 means bottom bar */ _AT_@ -36,11 +37,21 @@ static const float mfact = 0.55; /* factor of master area size [0.05..0.95] static const int nmaster = 1; /* number of clients in master area */ static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ +#include "fibonacci.c" +#include "gaplessgrid.c" static const Layout layouts[] = { /* symbol arrange function */ - { "[]=", tile }, /* first entry is default */ - { "><>", NULL }, /* no layout function means floating behavior */ + { "[]=", tile }, /* first entry is default */ + { "###", gaplessgrid }, + { "[_AT_]", spiral }, + { "[\\]", dwindle }, + { "|M|", centeredmaster }, + { ">M>", centeredfloatingmaster }, + { "TTT", bstack }, + { "===", bstackhoriz }, { "[M]", monocle }, + { "><>", NULL }, /* no layout function means floating behavior */ + { NULL, NULL }, }; /* key definitions */ _AT_@ -74,8 +85,15 @@ static Key keys[] = { { 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_g, setlayout, {.v = &layouts[1]} }, + { MODKEY, XK_q, setlayout, {.v = &layouts[2]} }, + { MODKEY, XK_a, setlayout, {.v = &layouts[3]} }, + { MODKEY, XK_u, setlayout, {.v = &layouts[4]} }, + { MODKEY, XK_o, setlayout, {.v = &layouts[5]} }, + { MODKEY, XK_x, setlayout, {.v = &layouts[6]} }, + { MODKEY, XK_y, setlayout, {.v = &layouts[7]} }, + { MODKEY, XK_m, setlayout, {.v = &layouts[8]} }, + { MODKEY, XK_f, setlayout, {.v = &layouts[9]} }, { MODKEY, XK_space, setlayout, {0} }, { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, { MODKEY, XK_0, view, {.ui = ~0 } }, _AT_@ -84,6 +102,9 @@ static Key keys[] = { { MODKEY, XK_period, focusmon, {.i = +1 } }, { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, + { MODKEY, XK_minus, setgaps, {.i = -1 } }, + { MODKEY, XK_equal, setgaps, {.i = +1 } }, + { MODKEY|ShiftMask, XK_equal, setgaps, {.i = 0 } }, TAGKEYS( XK_1, 0) TAGKEYS( XK_2, 1) TAGKEYS( XK_3, 2) diff --git a/dwm.c b/dwm.c index 4465af1..9f06978 100644 --- a/dwm.c +++ b/dwm.c _AT_@ -119,6 +119,7 @@ struct Monitor { int by; /* bar geometry */ int mx, my, mw, mh; /* screen size */ int wx, wy, ww, wh; /* window area */ + int gappx; /* gaps between windows */ unsigned int seltags; unsigned int sellt; unsigned int tagset[2]; _AT_@ -199,6 +200,7 @@ static void sendmon(Client *c, Monitor *m); static void setclientstate(Client *c, long state); static void setfocus(Client *c); static void setfullscreen(Client *c, int fullscreen); +static void setgaps(const Arg *arg); static void setlayout(const Arg *arg); static void setmfact(const Arg *arg); static void setup(void); _AT_@ -233,6 +235,10 @@ 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 centeredmaster(Monitor *m); +static void centeredfloatingmaster(Monitor *m); +static void bstack(Monitor *m); +static void bstackhoriz(Monitor *m); /* variables */ static const char broken[] = "broken"; _AT_@ -638,6 +644,7 @@ createmon(void) m->nmaster = nmaster; m->showbar = showbar; m->topbar = topbar; + m->gappx = gappx; m->lt[0] = &layouts[0]; m->lt[1] = &layouts[1 % LENGTH(layouts)]; strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol); _AT_@ -1497,6 +1504,16 @@ setfullscreen(Client *c, int fullscreen) } } +void +setgaps(const Arg *arg) +{ + if ((arg->i == 0) || (selmon->gappx + arg->i < 0)) + selmon->gappx = 0; + else + selmon->gappx += arg->i; + arrange(selmon); +} + void setlayout(const Arg *arg) { _AT_@ -1679,20 +1696,25 @@ tile(Monitor *m) for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); if (n == 0) return; + if(n == 1){ + c = nexttiled(m->clients); + resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0); + return; + } if (n > m->nmaster) mw = m->nmaster ? m->ww * m->mfact : 0; else - mw = m->ww; - for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) + mw = m->ww - m->gappx; + for (i = 0, my = ty = m->gappx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) if (i < m->nmaster) { - h = (m->wh - my) / (MIN(n, m->nmaster) - i); - resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0); - my += HEIGHT(c); + h = (m->wh - my) / (MIN(n, m->nmaster) - i) - m->gappx; + resize(c, m->wx + m->gappx, m->wy + my, mw - (2*c->bw) - m->gappx, h - (2*c->bw), 0); + my += HEIGHT(c) + m->gappx; } else { - h = (m->wh - ty) / (n - i); - resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0); - ty += HEIGHT(c); + h = (m->wh - ty) / (n - i) - m->gappx; + resize(c, m->wx + mw + m->gappx, m->wy + ty, m->ww - mw - 2*(c->bw + m->gappx), h - (2*c->bw), 0); + ty += HEIGHT(c) + m->gappx; } } _AT_@ -2147,3 +2169,188 @@ main(int argc, char *argv[]) XCloseDisplay(dpy); return EXIT_SUCCESS; } + +static 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 == 1){ + c = nexttiled(m->clients); + resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 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->gappx, m->wy + m->gappx, w - 2 * (c->bw + m->gappx), mh - 2 *(c->bw + m->gappx), 0); + mx += WIDTH(c) + m->gappx; + } else { + h = m->wh - mh; + resize(c, tx + m->gappx, ty + m->gappx, tw - 2 * (c->bw + m->gappx), h - 2 * (c->bw + m->gappx), 0); + if (tw != m->ww) + tx += WIDTH(c) + m->gappx; + } + } +} + +static 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 == 1){ + c = nexttiled(m->clients); + resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 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->gappx, m->wy + m->gappx, w - 2 * (c->bw + m->gappx), mh - 2 * (c->bw + m->gappx), 0); + mx += WIDTH(c) + m->gappx; + } else { + resize(c, tx + m->gappx, ty + m->gappx, m->ww - 2 * (c->bw + m->gappx), th - 2 * (c->bw + m->gappx), 0); + if (th != m->wh) + ty += HEIGHT(c) + m->gappx; + } + } +} + +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; + if(n == 1){ + c = nexttiled(m->clients); + resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 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) - m->gappx; + resize(c, m->wx + mx + m->gappx, m->wy + my + m->gappx, mw - 2*(c->bw + m->gappx), + h - (2*c->bw) - m->gappx, 0); + my += HEIGHT(c) + m->gappx; + } else { + /* stack clients are stacked vertically */ + if ((i - m->nmaster) % 2 ) { + h = (m->wh - ety) / ( (1 + n - i) / 2) - m->gappx; + resize(c, m->wx + m->gappx, m->wy + ety + m->gappx, tw - 2*(c->bw + m->gappx), + h - (2*c->bw) - m->gappx, 0); + ety += HEIGHT(c) + m->gappx; + } else { + h = (m->wh - oty) / ((1 + n - i) / 2) - m->gappx; + resize(c, m->wx + mx + mw + m->gappx, m->wy + oty + m->gappx, + tw - 2*(c->bw + m->gappx), h - (2*c->bw) - m->gappx, 0); + oty += HEIGHT(c) + m->gappx; + } + } +} + +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; + if(n == 1){ + c = nexttiled(m->clients); + resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 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->gappx, m->wy + my + m->gappx, w - 2*(c->bw + m->gappx), + mh - 2*(c->bw + m->gappx), 0); + mx += WIDTH(c) + m->gappx; + } else { + /* stack clients are stacked horizontally */ + w = (m->ww - tx) / (n - i); + resize(c, m->wx + tx + m->gappx, m->wy + m->gappx, w - 2*(c->bw + m->gappx), + m->wh - 2*(c->bw + m->gappx), 0); + tx += WIDTH(c) + m->gappx; + } +} diff --git a/fibonacci.c b/fibonacci.c new file mode 100644 index 0000000..258b821 --- /dev/null +++ b/fibonacci.c _AT_@ -0,0 +1,71 @@ +void +fibonacci(Monitor *mon, int s) { + unsigned int i, n, nx, ny, nw, nh; + Client *c; + + for(n = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next), n++); + if(n == 0) + return; + if(n == 1){ + c = nexttiled(mon->clients); + resize(c, mon->wx, mon->wy, mon->ww - 2 * c->bw, mon->wh - 2 * c->bw, 0); + return; + } + + nx = mon->wx; + ny = 0; + nw = mon->ww; + nh = mon->wh; + + for(i = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next)) { + if((i % 2 && nh / 2 > 2 * c->bw) + || (!(i % 2) && nw / 2 > 2 * c->bw)) { + if(i < n - 1) { + if(i % 2) + nh /= 2; + else + nw /= 2; + if((i % 4) == 2 && !s) + nx += nw; + else if((i % 4) == 3 && !s) + ny += nh; + } + if((i % 4) == 0) { + if(s) + ny += nh; + else + ny -= nh; + } + else if((i % 4) == 1) + nx += nw; + else if((i % 4) == 2) + ny += nh; + else if((i % 4) == 3) { + if(s) + nx += nw; + else + nx -= nw; + } + if(i == 0) + { + if(n != 1) + nw = mon->ww * mon->mfact; + ny = mon->wy; + } + else if(i == 1) + nw = mon->ww - nw; + i++; + } + resize(c, nx + mon->gappx, ny + mon->gappx, nw - 2 * (c->bw + mon->gappx), nh - 2 * (c->bw + mon->gappx), False); + } +} + +void +dwindle(Monitor *mon) { + fibonacci(mon, 1); +} + +void +spiral(Monitor *mon) { + fibonacci(mon, 0); +} diff --git a/gaplessgrid.c b/gaplessgrid.c new file mode 100644 index 0000000..f7d623c --- /dev/null +++ b/gaplessgrid.c _AT_@ -0,0 +1,40 @@ +void +gaplessgrid(Monitor *m) { + unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch; + Client *c; + + for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) ; + if(n == 0) + return; + if(n == 1){ + c = nexttiled(m->clients); + resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0); + return; + } + + /* grid dimensions */ + for(cols = 0; cols <= n/2; cols++) + if(cols*cols >= n) + break; + if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */ + cols = 2; + rows = n/cols; + + /* window geometries */ + cw = cols ? m->ww / cols : m->ww; + cn = 0; /* current column number */ + rn = 0; /* current row number */ + for(i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) { + if(i/rows + 1 > cols - n%cols) + rows = n/cols + 1; + ch = rows ? m->wh / rows : m->wh; + cx = m->wx + cn*cw; + cy = m->wy + rn*ch; + resize(c, cx + m->gappx, cy + m->gappx, cw - 2 * (c->bw + m->gappx), ch - 2 * (c->bw + m->gappx), False); + rn++; + if(rn >= rows) { + rn = 0; + cn++; + } + } +} -- 2.21.0Received on Wed Apr 10 2019 - 03:17:45 CEST
This archive was generated by hypermail 2.3.0 : Wed Apr 10 2019 - 05:48:23 CEST