commit: 02caf5e2a81c9c4c60b22b8afa64a2489fd7fb3f
parent: 0f9884e6be0248a391de3c9ca9b6e73d25a911ab
author: Chris Noxz <chris@noxz.tech>
date: Fri, 11 Jun 2021 21:21:40 +0200
Implement some various changes
* simplify gaps
* set nmaster min = 1
* add bounds to nmaster
* add gaps to tile layout
* change tile to use columns instead of rows in master
2 files changed, 61 insertions(+), 42 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -60,7 +60,7 @@ static const Rule rules[] = { NULL
/* layout(s) */
static float mfact = 0.55; /* factor of master area size [0.05..0.95] */
-static int nmaster = 0; /* number of clients in master area */
+static int nmaster = 1; /* number of clients in master area */
static int resizehints = 0; /* 1 means respect size hints in tiled resizals */
static const Layout layouts[] = {
diff --git a/dwm.c b/dwm.c
@@ -196,6 +196,7 @@ static void focusin(XEvent *e);
static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg);
static Atom getatomprop(Client *c, Atom prop);
+static void getgap(Monitor *m, unsigned int n, unsigned int *g, unsigned int r, unsigned int c);
static int getrootptr(int *x, int *y);
static long getstate(Window w);
static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
@@ -1156,7 +1157,7 @@ incgaps(const Arg *arg)
void
incnmaster(const Arg *arg)
{
- selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 0);
+ selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 1);
arrange(selmon);
}
@@ -1977,42 +1978,71 @@ tagmon(const Arg *arg)
sendmon(selmon->sel, dirtomon(arg->i));
}
+void
+getgap(Monitor *m, unsigned int n, unsigned int *g, unsigned int r, unsigned int c)
+{
+ /* check if gaps are to large */
+ if (m->gap > m->wh / (r + 1))
+ m->gap = m->wh / (r + 1);
+ if (m->gap > m->ww / (c + 1))
+ m->gap = m->ww / (c + 1);
+
+ /* set gap if used */
+ *g = (m->pertag->enablegaps[m->pertag->curtag] && n > 1) ? m->gap : 0;
+}
+
void
tile(Monitor *m)
{
- unsigned int i, n, h, mw, my, ty;
+ unsigned int n, ri = 0, ci = 0; /* counters */
+ unsigned int cx, cy, cw, ch, cg; /* client geometry */
+ unsigned int uw = 0, uh = 0; /* utilization trackers */
+ unsigned int cols, rows, mw = m->ww;
Client *c;
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
if (n == 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++)
- 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);
- if (my + HEIGHT(c) < m->wh)
- my += HEIGHT(c);
+ cols = m->nmaster = MAX(MIN(m->nmaster, n), 1);
+ rows = n - cols;
+
+ getgap(m, n, &cg, rows, MAX(3, cols));
+
+ if (n > cols)
+ mw = cols ? mw * (double)MAX(2, cols) / (double)MAX(3, cols + 1) : 0;
+
+ /* define initials */
+ cy = m->wy + cg;
+ ch = m->wh - 2*cg;
+ uw = cx = cw = 0;
+
+ for (c = nexttiled(m->clients); c; c = nexttiled(c->next), ci++) {
+ if (ci == cols) {
+ cx = m->wx + uw + cg;
+ cw = m->ww - cx - cg;
+ }
+ if (ci < cols) {
+ cx = m->wx + uw + cg;
+ cw = ((mw - 2*cg) - uw - (cg * (cols - ci - 1))) / (cols - ci);
+ uw += cw + cg;
} 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);
- if (ty + HEIGHT(c) < m->wh)
- ty += HEIGHT(c);
+ cy = m->wy + uh + cg;
+ ch = ((m->wh - 2*cg) - uh - (cg * (rows - ri - 1))) / (rows - ri);
+ uh += ch + cg;
+ ri++;
}
+ resize(c, cx, cy, cw - (2*c->bw), ch - (2*c->bw), 0);
+ }
}
void
nrowgrid(Monitor *m)
{
unsigned int n, ri = 0, ci = 0; /* counters */
- unsigned int cx, cy, cw, ch; /* client geometry */
- unsigned int oh, ov, ih, iv; /* gaps */
+ unsigned int cx, cy, cw, ch, cg; /* client geometry */
unsigned int uw = 0, uh = 0, uc = 0; /* utilization trackers */
- unsigned int cols, rows = m->nmaster + 1;
+ unsigned int cols, rows;
Client *c;
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
@@ -2020,29 +2050,18 @@ nrowgrid(Monitor *m)
return;
/* calculate rows and cols, never allow empty rows */
+ rows = m->nmaster = MAX(MIN(m->nmaster, n), 1);
if (n < rows)
rows = n;
cols = n / rows;
- /* check if gaps are to large */
- if (m->gap > m->wh / (rows + 1))
- m->gap = m->wh / (rows + 1);
- if (m->gap > m->ww / (cols + 1))
- m->gap = m->ww / (cols + 1);
-
- /* get gaps */
- if (selmon->pertag->enablegaps[selmon->pertag->curtag] && n > 1) {
- oh = m->gap; /* outer horizontal */
- ov = m->gap; /* outer vertical */
- ih = m->gap; /* inner horizontal */
- iv = m->gap; /* inner vertical */
- } else { oh = ov = ih = iv = 0; }
+ getgap(m, n, &cg, rows, cols);
/* define first row */
uc = cols;
- cy = m->wy + oh;
- ch = (m->wh - 2*oh - (ih * (rows - 1))) / rows;
- uh = ch + ih;
+ cy = m->wy + cg;
+ ch = (m->wh - 2*cg - (cg * (rows - 1))) / rows;
+ uh = ch + cg;
for (c = nexttiled(m->clients); c; c = nexttiled(c->next), ci++) {
if (ci == cols) {
@@ -2053,14 +2072,14 @@ nrowgrid(Monitor *m)
/* next row */
cols = (n - uc) / (rows - ri);
uc += cols;
- cy = m->wy + uh + oh;
- ch = ((m->wh - 2*oh) - uh - (ih * (rows - ri - 1))) / (rows - ri);
- uh += ch + ih;
+ cy = m->wy + uh + cg;
+ ch = ((m->wh - 2*cg) - uh - (cg * (rows - ri - 1))) / (rows - ri);
+ uh += ch + cg;
}
- cx = m->wx + uw + ov;
- cw = ((m->ww - 2*ov) - uw - (iv * (cols - ci - 1))) / (cols - ci);
- uw += cw + iv;
+ cx = m->wx + uw + cg;
+ cw = ((m->ww - 2*cg) - uw - (cg * (cols - ci - 1))) / (cols - ci);
+ uw += cw + cg;
resize(c, cx, cy, cw - (2*c->bw), ch - (2*c->bw), 0);
}