[wiki] [sites] Update centered master patch || jeromenerf
 
commit 8785a283200fc4e0434e1e2735038df85734a983
Author: jeromenerf <jerome.andrieux_AT_af83.com>
Date:   Sun Nov 22 23:08:47 2015 +0100
    Update centered master patch
diff --git a/dwm.suckless.org/patches/centeredmaster.c b/dwm.suckless.org/patches/centeredmaster.c
new file mode 100644
index 0000000..3236912
--- /dev/null
+++ b/dwm.suckless.org/patches/centeredmaster.c
_AT_@ -0,0 +1,91 @@
+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), False);
+			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), False);
+			tx += WIDTH(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 verticaly, 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), False);
+			my += HEIGHT(c);
+		} else {
+      // Stack clients are stacked verticaly
+      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), False);
+        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), False);
+        oty += HEIGHT(c);
+      }
+		}
+}
diff --git a/dwm.suckless.org/patches/centeredmaster.md b/dwm.suckless.org/patches/centeredmaster.md
index b1b9e52..5c3b112 100644
--- a/dwm.suckless.org/patches/centeredmaster.md
+++ b/dwm.suckless.org/patches/centeredmaster.md
_AT_@ -1,19 +1,47 @@
 # centeredmaster
 
-`centeredmaster` layout patch makes the nmaster area centered
-on screen, using `mfact * monitor width & height`, over an
-horizontally tiled `stack` area, pretty much like
-a "scratchpad".
+## `centeredmaster` 
 
-I find it useful on large screens (say 1920px wide), where
-`monocle` or `htile` feels either too large or makes me type in
-a corner of the screen.
+makes the nmaster area centered
+on screen, using `mfact * monitor width & height`, with the stacked windows
+distributed on left and right.
 
-With `centeredmaster`, for instance, I can set my editor in the
-center, while keeping an eye on what's happening in the windows
-behind (logs, tests, ...).
+With one client in master:
 
+    +------------------------------+
+    |+--------++--------++--------+|
+    ||        ||        ||        ||
+    ||        ||        ||        ||
+    ||        ||        ||        ||
+    ||  S2    ||   M    ||   S1   ||
+    ||        ||        ||        ||
+    ||        ||        ||        ||
+    ||        ||        ||        ||
+    ||        ||        ||        ||
+    |+--------++--------++--------+|
+    +------------------------------+
 
+With two clients in master:
+
+    +------------------------------+
+    |+--------++--------++--------+|
+    ||        ||        ||        ||
+    ||        ||   M1   ||        ||
+    ||        ||        ||        ||
+    ||        |+--------+|        ||
+    ||        |+--------+|        ||
+    ||        ||        ||        ||
+    ||        ||   M2   ||        ||
+    ||        ||        ||        ||
+    |+--------++--------++--------+|
+    +------------------------------+
+
+## `centeredfloatingmaster` 
+
+makes the nmaster area centered
+on screen, using `mfact * monitor width & height`, over an
+horizontally tiled `stack` area, pretty much like
+a "scratchpad".
 
 With one client in master:
 
_AT_@ -46,8 +74,20 @@ With two clients in master:
     +------------------------------+
 
 
+I find it useful on large screens (say 1920px wide), where
+`monocle` or `htile` feels either too large or makes me type in
+a corner of the screen.
+
+With `centeredmaster`, for instance, I can set my editor in the
+center, while keeping an eye on what's happening in the windows
+behind (logs, tests, ...).
+
+
+
+
 ## Links
 
+* [centeredmaster.c](centeredmaster.c) - 2015/11/22
 * [dwm-6.1-centeredmaster.diff](dwm-6.1-centeredmaster.diff) - 2015/11/21
 
 
Received on Sun Nov 22 2015 - 23:14:19 CET
This archive was generated by hypermail 2.3.0
: Sun Nov 22 2015 - 23:24:11 CET