summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe <rbo@gmx.us>2025-03-02 16:05:28 +0100
committerJoe <rbo@gmx.us>2025-03-02 16:05:28 +0100
commit84f95ad65ad25f5fa43298fc74ab4a9c4e42fca7 (patch)
tree860d7649e4f7c559544c1ab6f761820de082380b
parentbstacked (diff)
downloaddwl-84f95ad65ad25f5fa43298fc74ab4a9c4e42fca7.tar.gz
dwl-84f95ad65ad25f5fa43298fc74ab4a9c4e42fca7.tar.bz2
dwl-84f95ad65ad25f5fa43298fc74ab4a9c4e42fca7.tar.xz
dwl-84f95ad65ad25f5fa43298fc74ab4a9c4e42fca7.tar.zst
dwl-84f95ad65ad25f5fa43298fc74ab4a9c4e42fca7.zip
centered
-rw-r--r--config.def.h8
-rw-r--r--dwl.c63
-rw-r--r--patches/applied/centeredmaster.patch135
3 files changed, 203 insertions, 3 deletions
diff --git a/config.def.h b/config.def.h
index 03661dc..3835a10 100644
--- a/config.def.h
+++ b/config.def.h
@@ -121,6 +121,7 @@ static const Layout layouts[] = {
{ "[]=", tile },
{ "TTT", bstack },
{ "===", bstackhoriz },
+ { "|M|", centeredmaster },
{ "###", gaplessgrid },
{ "[M]", monocle },
{ "><>", NULL }, /* no layout function means floating behavior */
@@ -267,9 +268,10 @@ static const Key keys[] = {
{ MODKEY, XKB_KEY_z, setlayout, {.v = &layouts[0]} },
{ MODKEY, XKB_KEY_x, setlayout, {.v = &layouts[1]} },
{ MODKEY|SHIFT, XKB_KEY_X, setlayout, {.v = &layouts[2]} },
- { MODKEY, XKB_KEY_v, setlayout, {.v = &layouts[3]} },
- { MODKEY, XKB_KEY_m, setlayout, {.v = &layouts[4]} },
- { MODKEY, XKB_KEY_n, setlayout, {.v = &layouts[5]} },
+ { MODKEY, XKB_KEY_c, setlayout, {.v = &layouts[3]} },
+ { MODKEY, XKB_KEY_v, setlayout, {.v = &layouts[4]} },
+ { MODKEY, XKB_KEY_m, setlayout, {.v = &layouts[5]} },
+ { MODKEY, XKB_KEY_n, setlayout, {.v = &layouts[6]} },
{ MODKEY|SHIFT, XKB_KEY_space, setlayout, {0} },
{ MODKEY, XKB_KEY_space, togglefloating, {0} },
{ MODKEY, XKB_KEY_f, togglefullscreen, {0} },
diff --git a/dwl.c b/dwl.c
index 42f44c8..1f29d50 100644
--- a/dwl.c
+++ b/dwl.c
@@ -303,6 +303,7 @@ static void bufdataend(struct wlr_buffer *buffer);
static Buffer *bufmon(Monitor *m);
static void bufrelease(struct wl_listener *listener, void *data);
static void buttonpress(struct wl_listener *listener, void *data);
+static void centeredmaster(Monitor *m);
static void chvt(const Arg *arg);
static void checkidleinhibitor(struct wlr_surface *exclude);
static void cleanup(void);
@@ -991,6 +992,68 @@ buttonpress(struct wl_listener *listener, void *data)
}
void
+centeredmaster(Monitor *m)
+{
+ int i, n, h, mw, mx, my, oty, ety, tw;
+ Client *c;
+
+ n = 0;
+ wl_list_for_each(c, &clients, link)
+ if (VISIBLEON(c, m) && !c->isfloating && !c->isfullscreen)
+ n++;
+ if (n == 0)
+ return;
+
+ /* initialize areas */
+ mw = m->w.width;
+ mx = 0;
+ my = 0;
+ tw = mw;
+
+ if (n > m->nmaster) {
+ /* go mfact box in the center if more than nmaster clients */
+ mw = m->nmaster ? (int)roundf(m->w.width * m->mfact) : 0;
+ tw = m->w.width - mw;
+
+ if (n - m->nmaster > 1) {
+ /* only one client */
+ mx = (m->w.width - mw) / 2;
+ tw = (m->w.width - mw) / 2;
+ }
+ }
+
+ i = 0;
+ oty = 0;
+ ety = 0;
+ wl_list_for_each(c, &clients, link) {
+ if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
+ continue;
+ if (i < m->nmaster) {
+ /* nmaster clients are stacked vertically, in the center
+ * of the screen */
+ h = (m->w.height - my) / (MIN(n, m->nmaster) - i);
+ resize(c, (struct wlr_box){.x = m->w.x + mx, .y = m->w.y + my, .width = mw,
+ .height = h}, 0);
+ my += c->geom.height;
+ } else {
+ /* stack clients are stacked vertically */
+ if ((i - m->nmaster) % 2) {
+ h = (m->w.height - ety) / ( (1 + n - i) / 2);
+ resize(c, (struct wlr_box){.x = m->w.x, .y = m->w.y + ety, .width = tw,
+ .height = h}, 0);
+ ety += c->geom.height;
+ } else {
+ h = (m->w.height - oty) / ((1 + n - i) / 2);
+ resize(c, (struct wlr_box){.x = m->w.x + mx + mw, .y = m->w.y + oty, .width = tw,
+ .height = h}, 0);
+ oty += c->geom.height;
+ }
+ }
+ i++;
+ }
+}
+
+void
chvt(const Arg *arg)
{
wlr_session_change_vt(session, arg->ui);
diff --git a/patches/applied/centeredmaster.patch b/patches/applied/centeredmaster.patch
new file mode 100644
index 0000000..c29bd5f
--- /dev/null
+++ b/patches/applied/centeredmaster.patch
@@ -0,0 +1,135 @@
+From b1ca46930756b59c1ebba0b8c7871b85ff84f62f Mon Sep 17 00:00:00 2001
+From: Nikita Ivanov <nikita.vyach.ivanov@gmail.com>
+Date: Sat, 8 Feb 2025 16:10:25 +0100
+Subject: [PATCH] Add centeredmaster layout
+
+This is a port of centeredmaster patch for dwm:
+ https://dwm.suckless.org/patches/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]+[c].
+
+With one and two clients in master respectively this results in:
+
++------------------------------+ +------------------------------+
+|+--------++--------++--------+| |+--------++--------++--------+|
+|| || || || || || || ||
+|| || || || || || M1 || ||
+|| || || || || || || ||
+|| S2 || M || S1 || || |+--------+| ||
+|| || || || || |+--------+| ||
+|| || || || || || || ||
+|| || || || || || M2 || ||
+|| || || || || || || ||
+|+--------++--------++--------+| |+--------++--------++--------+|
++------------------------------+ +------------------------------+
+---
+ config.def.h | 2 ++
+ dwl.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 65 insertions(+)
+
+diff --git a/config.def.h b/config.def.h
+index 22d2171..9a3b0c5 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -34,6 +34,7 @@ static const Layout layouts[] = {
+ { "[]=", tile },
+ { "><>", NULL }, /* no layout function means floating behavior */
+ { "[M]", monocle },
++ { "|M|", centeredmaster },
+ };
+
+ /* monitors */
+@@ -139,6 +140,7 @@ static const Key keys[] = {
+ { MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} },
+ { MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} },
+ { MODKEY, XKB_KEY_m, setlayout, {.v = &layouts[2]} },
++ { MODKEY, XKB_KEY_c, setlayout, {.v = &layouts[3]} },
+ { MODKEY, XKB_KEY_space, setlayout, {0} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} },
+ { MODKEY, XKB_KEY_e, togglefullscreen, {0} },
+diff --git a/dwl.c b/dwl.c
+index def2562..c2456dd 100644
+--- a/dwl.c
++++ b/dwl.c
+@@ -251,6 +251,7 @@ static void arrangelayer(Monitor *m, struct wl_list *list,
+ static void arrangelayers(Monitor *m);
+ static void axisnotify(struct wl_listener *listener, void *data);
+ static void buttonpress(struct wl_listener *listener, void *data);
++static void centeredmaster(Monitor *m);
+ static void chvt(const Arg *arg);
+ static void checkidleinhibitor(struct wlr_surface *exclude);
+ static void cleanup(void);
+@@ -649,6 +650,68 @@ buttonpress(struct wl_listener *listener, void *data)
+ event->time_msec, event->button, event->state);
+ }
+
++void
++centeredmaster(Monitor *m)
++{
++ int i, n, h, mw, mx, my, oty, ety, tw;
++ Client *c;
++
++ n = 0;
++ wl_list_for_each(c, &clients, link)
++ if (VISIBLEON(c, m) && !c->isfloating && !c->isfullscreen)
++ n++;
++ if (n == 0)
++ return;
++
++ /* initialize areas */
++ mw = m->w.width;
++ mx = 0;
++ my = 0;
++ tw = mw;
++
++ if (n > m->nmaster) {
++ /* go mfact box in the center if more than nmaster clients */
++ mw = m->nmaster ? (int)roundf(m->w.width * m->mfact) : 0;
++ tw = m->w.width - mw;
++
++ if (n - m->nmaster > 1) {
++ /* only one client */
++ mx = (m->w.width - mw) / 2;
++ tw = (m->w.width - mw) / 2;
++ }
++ }
++
++ i = 0;
++ oty = 0;
++ ety = 0;
++ wl_list_for_each(c, &clients, link) {
++ if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
++ continue;
++ if (i < m->nmaster) {
++ /* nmaster clients are stacked vertically, in the center
++ * of the screen */
++ h = (m->w.height - my) / (MIN(n, m->nmaster) - i);
++ resize(c, (struct wlr_box){.x = m->w.x + mx, .y = m->w.y + my, .width = mw,
++ .height = h}, 0);
++ my += c->geom.height;
++ } else {
++ /* stack clients are stacked vertically */
++ if ((i - m->nmaster) % 2) {
++ h = (m->w.height - ety) / ( (1 + n - i) / 2);
++ resize(c, (struct wlr_box){.x = m->w.x, .y = m->w.y + ety, .width = tw,
++ .height = h}, 0);
++ ety += c->geom.height;
++ } else {
++ h = (m->w.height - oty) / ((1 + n - i) / 2);
++ resize(c, (struct wlr_box){.x = m->w.x + mx + mw, .y = m->w.y + oty, .width = tw,
++ .height = h}, 0);
++ oty += c->geom.height;
++ }
++ }
++ i++;
++ }
++}
++
+ void
+ chvt(const Arg *arg)
+ {
+--
+2.48.1
+