summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2024-03-02 11:05:58 -0500
committerMalfurious <m@lfurio.us>2024-03-05 21:04:47 -0500
commit72bcdd4d6be18975843637ad0a5e2f21de5fea82 (patch)
treef0ff5780a9b0e7f0d8649ccc3baaaea9486bbceb
parent2d0d68ce93d35a46029879addd567c89cc41597d (diff)
downloaddwm-72bcdd4d6be18975843637ad0a5e2f21de5fea82.tar.gz
dwm-72bcdd4d6be18975843637ad0a5e2f21de5fea82.zip
patch: centeredmaster
centeredmaster centers the nmaster area on screen, using mfact * monitor width & height, with the stacked windows distributed to the left and right. It can be selected with [Alt]+[u]. With one and two clients in master respectively this results in: +------------------------------+ +------------------------------+ |+--------++--------++--------+| |+--------++--------++--------+| || || || || || || || || || || || || || || M1 || || || || || || || || || || || S2 || M || S1 || || |+--------+| || || || || || || |+--------+| || || || || || || || || || || || || || || || M2 || || || || || || || || || || |+--------++--------++--------+| |+--------++--------++--------+| +------------------------------+ +------------------------------+ This layout can be useful on large screens, where monocle or htile might be either too large or forcing the user to type in a corner of the screen. It allows for instance to center the editor while being able to keep an eye on background processes (logs, tests, ...).
-rw-r--r--config.def.h2
-rw-r--r--dwm.c56
2 files changed, 58 insertions, 0 deletions
diff --git a/config.def.h b/config.def.h
index aae7682..62319e2 100644
--- a/config.def.h
+++ b/config.def.h
@@ -49,6 +49,7 @@ static const Layout layouts[] = {
{ "[]=", tile }, /* first entry is default */
{ "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle },
+ { "|M|", centeredmaster },
};
/* key definitions */
@@ -96,6 +97,7 @@ static const Key keys[] = {
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
+ { MODKEY, XK_u, setlayout, {.v = &layouts[3]} },
{ MODKEY, XK_comma, focusmon, {.i = -1 } },
{ MODKEY, XK_period, focusmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
diff --git a/dwm.c b/dwm.c
index d6391f5..b178c0e 100644
--- a/dwm.c
+++ b/dwm.c
@@ -241,6 +241,7 @@ static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void xinitvisual();
static void zoom(const Arg *arg);
+static void centeredmaster(Monitor *m);
/* variables */
static const char broken[] = "broken";
@@ -2280,3 +2281,58 @@ main(int argc, char *argv[])
XCloseDisplay(dpy);
return EXIT_SUCCESS;
}
+
+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);
+ }
+ }
+}