aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-11-17 13:32:17 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-11-17 13:32:17 +0100
commitf80198ef92177996c5dc5c6e0487f1ce9e180e63 (patch)
tree36292bb4ce86d4caa9772b805b2d66464da5ac8c
parentRemoved bloat (diff)
downloaddwm-f80198ef92177996c5dc5c6e0487f1ce9e180e63.tar.gz
dwm-f80198ef92177996c5dc5c6e0487f1ce9e180e63.tar.bz2
dwm-f80198ef92177996c5dc5c6e0487f1ce9e180e63.tar.xz
dwm-f80198ef92177996c5dc5c6e0487f1ce9e180e63.tar.zst
dwm-f80198ef92177996c5dc5c6e0487f1ce9e180e63.zip
Added centeredmaster patch
-rw-r--r--README1
-rw-r--r--README.org1
-rw-r--r--config.h14
-rw-r--r--dwm.c105
4 files changed, 116 insertions, 5 deletions
diff --git a/README b/README
index 2b403f8..0bffd1f 100644
--- a/README
+++ b/README
@@ -55,6 +55,7 @@ List of patches in use:
- alwayscenter
- alwaysfullscreen
- attachasideandbelow
+ - centeredmaster
- fibonacci
- focusonclick
- nmaster
diff --git a/README.org b/README.org
index 72a7979..82a6fb5 100644
--- a/README.org
+++ b/README.org
@@ -52,6 +52,7 @@ List of patches in use:
- /alwayscenter/
- /alwaysfullscreen/
- /attachasideandbelow/
+- /centeredmaster/
- /fibonacci/
- /focusonclick/
- /nmaster/
diff --git a/config.h b/config.h
index b257e45..a8aff8d 100644
--- a/config.h
+++ b/config.h
@@ -48,6 +48,8 @@ static const Layout layouts[] = {
/* symbol arrange function */
{ "-|=", ntile },
{ "-|-", nbstack },
+ { "|M|", centeredmaster },
+ { ">M>", centeredfloatingmaster },
{ "[\\]", dwindle },
{ "[@]", spiral },
{ "[]=", tile }, /* first entry is default */
@@ -114,11 +116,13 @@ static Key keys[] = {
{ MODKEY, XK_q, killclient, {0} },
{ MODKEY, XK_s, setlayout, {.v = &layouts[0]} }, /* nbtile */
{ MODKEY|ShiftMask, XK_s, setlayout, {.v = &layouts[1]} }, /* nbstack */
- { MODKEY, XK_t, setlayout, {.v = &layouts[2]} }, /* dwindle */
- { MODKEY|ShiftMask, XK_t, setlayout, {.v = &layouts[3]} }, /* spiral */
- { MODKEY, XK_v, setlayout, {.v = &layouts[4]} }, /* tile */
- { MODKEY, XK_f, setlayout, {.v = &layouts[5]} }, /* monocle */
- { MODKEY, XK_n, setlayout, {.v = &layouts[6]} }, /* floating */
+ { MODKEY, XK_c, setlayout, {.v = &layouts[2]} }, /* centeredmaster */
+ { MODKEY|ShiftMask, XK_c, setlayout, {.v = &layouts[3]} }, /* centeredfloatingmaster */
+ { MODKEY, XK_t, setlayout, {.v = &layouts[4]} }, /* dwindle */
+ { MODKEY|ShiftMask, XK_t, setlayout, {.v = &layouts[5]} }, /* spiral */
+ { MODKEY, XK_v, setlayout, {.v = &layouts[6]} }, /* tile */
+ { MODKEY, XK_f, setlayout, {.v = &layouts[7]} }, /* monocle */
+ { MODKEY, XK_n, setlayout, {.v = &layouts[8]} }, /* floating */
{ MODKEY|ShiftMask, XK_space, setlayout, {0} },
{ MODKEY, XK_space, togglefloating, {0} },
{ MODKEY|ShiftMask, XK_f, togglefullscr, {0} },
diff --git a/dwm.c b/dwm.c
index e595075..0b9cc8c 100644
--- a/dwm.c
+++ b/dwm.c
@@ -248,6 +248,8 @@ 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);
/* variables */
static const char broken[] = "broken";
@@ -2453,3 +2455,106 @@ 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);
+ }
+ }
+}
+
+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);
+ }
+}