From 610362d2f38260ad2a06ffbd91d089ba738429e9 Mon Sep 17 00:00:00 2001
From: Ben Collerson <benc@benc.cc>
Date: Thu, 18 Jul 2024 11:03:46 +1000
Subject: [PATCH] singlemaster

---
 config.def.h |  8 +++-----
 dwl.c        | 49 ++++++++++++++++++++++---------------------------
 2 files changed, 25 insertions(+), 32 deletions(-)

diff --git a/config.def.h b/config.def.h
index 22d2171d..0ba9ddb8 100644
--- a/config.def.h
+++ b/config.def.h
@@ -43,12 +43,12 @@ static const Layout layouts[] = {
 */
 /* NOTE: ALWAYS add a fallback rule, even if you are completely sure it won't be used */
 static const MonitorRule monrules[] = {
-	/* name       mfact  nmaster scale layout       rotate/reflect                x    y */
+	/* name       mfact scale layout       rotate/reflect                x    y */
 	/* example of a HiDPI laptop monitor:
-	{ "eDP-1",    0.5f,  1,      2,    &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL,   -1,  -1 },
+	{ "eDP-1",    0.5f,  2,    &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL,   -1,  -1 },
 	*/
 	/* defaults */
-	{ NULL,       0.55f, 1,      1,    &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL,   -1,  -1 },
+	{ NULL,       0.55f, 1,    &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL,   -1,  -1 },
 };
 
 /* keyboard */
@@ -129,8 +129,6 @@ static const Key keys[] = {
 	{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return,     spawn,          {.v = termcmd} },
 	{ MODKEY,                    XKB_KEY_j,          focusstack,     {.i = +1} },
 	{ MODKEY,                    XKB_KEY_k,          focusstack,     {.i = -1} },
-	{ MODKEY,                    XKB_KEY_i,          incnmaster,     {.i = +1} },
-	{ MODKEY,                    XKB_KEY_d,          incnmaster,     {.i = -1} },
 	{ MODKEY,                    XKB_KEY_h,          setmfact,       {.f = -0.05f} },
 	{ MODKEY,                    XKB_KEY_l,          setmfact,       {.f = +0.05f} },
 	{ MODKEY,                    XKB_KEY_Return,     zoom,           {0} },
diff --git a/dwl.c b/dwl.c
index 145fd018..6a3c84a7 100644
--- a/dwl.c
+++ b/dwl.c
@@ -70,7 +70,6 @@
 
 /* macros */
 #define MAX(A, B)               ((A) > (B) ? (A) : (B))
-#define MIN(A, B)               ((A) < (B) ? (A) : (B))
 #define CLEANMASK(mask)         (mask & ~WLR_MODIFIER_CAPS)
 #define VISIBLEON(C, M)         ((M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags]))
 #define LENGTH(X)               (sizeof X / sizeof X[0])
@@ -204,7 +203,6 @@ struct Monitor {
 	uint32_t tagset[2];
 	float mfact;
 	int gamma_lut_changed;
-	int nmaster;
 	char ltsymbol[16];
 	int asleep;
 };
@@ -212,7 +210,6 @@ struct Monitor {
 typedef struct {
 	const char *name;
 	float mfact;
-	int nmaster;
 	float scale;
 	const Layout *lt;
 	enum wl_output_transform rr;
@@ -288,7 +285,6 @@ static void focusstack(const Arg *arg);
 static Client *focustop(Monitor *m);
 static void fullscreennotify(struct wl_listener *listener, void *data);
 static void handlesig(int signo);
-static void incnmaster(const Arg *arg);
 static void inputdevice(struct wl_listener *listener, void *data);
 static int keybinding(uint32_t mods, xkb_keysym_t sym);
 static void keypress(struct wl_listener *listener, void *data);
@@ -955,7 +951,6 @@ createmon(struct wl_listener *listener, void *data)
 			m->m.x = r->x;
 			m->m.y = r->y;
 			m->mfact = r->mfact;
-			m->nmaster = r->nmaster;
 			m->lt[0] = r->lt;
 			m->lt[1] = &layouts[LENGTH(layouts) > 1 && r->lt != &layouts[1]];
 			strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, LENGTH(m->ltsymbol));
@@ -1467,15 +1462,6 @@ handlesig(int signo)
 	}
 }
 
-void
-incnmaster(const Arg *arg)
-{
-	if (!arg || !selmon)
-		return;
-	selmon->nmaster = MAX(selmon->nmaster + arg->i, 0);
-	arrange(selmon);
-}
-
 void
 inputdevice(struct wl_listener *listener, void *data)
 {
@@ -2635,8 +2621,7 @@ tagmon(const Arg *arg)
 void
 tile(Monitor *m)
 {
-	unsigned int mw, my, ty;
-	int i, n = 0;
+	unsigned int i, n = 0, mw, ty;
 	Client *c;
 
 	wl_list_for_each(c, &clients, link)
@@ -2645,21 +2630,31 @@ tile(Monitor *m)
 	if (n == 0)
 		return;
 
-	if (n > m->nmaster)
-		mw = m->nmaster ? (int)roundf(m->w.width * m->mfact) : 0;
-	else
-		mw = m->w.width;
-	i = my = ty = 0;
+	mw = (n == 1) ? m->w.width : (int)roundf(m->w.width * m->mfact);
+	i = ty = 0;
 	wl_list_for_each(c, &clients, link) {
 		if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
 			continue;
-		if (i < m->nmaster) {
-			resize(c, (struct wlr_box){.x = m->w.x, .y = m->w.y + my, .width = mw,
-				.height = (m->w.height - my) / (MIN(n, m->nmaster) - i)}, 0);
-			my += c->geom.height;
+		if (i == 0) {
+			resize(
+				c,
+				(struct wlr_box){
+					.x = m->w.x,
+					.y = m->w.y,
+					.width = mw,
+					.height = (m->w.height)
+					},
+				0);
 		} else {
-			resize(c, (struct wlr_box){.x = m->w.x + mw, .y = m->w.y + ty,
-				.width = m->w.width - mw, .height = (m->w.height - ty) / (n - i)}, 0);
+			resize(
+				c,
+				(struct wlr_box){
+					.x = m->w.x + mw,
+					.y = m->w.y + ty,
+					.width = m->w.width - mw,
+					.height = (m->w.height - ty) / (n - i)
+					},
+				0);
 			ty += c->geom.height;
 		}
 		i++;
-- 
2.45.2

