dwm

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 25c0493c8e6b196317ea4b4f331c4493680d16db
parent 9d0482a1856506ca51f9c90b60400aee05fba648
Author: AndrewLockVI <andrew@laack.co>
Date:   Sat, 15 Feb 2025 13:12:39 -0600

Patched with centermaster, updated bindings, and added columnar mode

Diffstat:
Mconfig.h | 13++++++++++---
Mdwm.c | 105+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 115 insertions(+), 3 deletions(-)

diff --git a/config.h b/config.h @@ -42,7 +42,8 @@ static const Layout layouts[] = { { "[]=", tile }, /* first entry is default */ //{ "><>", NULL }, /* no layout function means floating behavior */ //{ "[M]", monocle }, - { "|||", col }, + { "|||", col}, + { "|M|", centeredmaster} }; /* key definitions */ @@ -61,6 +62,7 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() static const char *dmenucmd[] = {"/home/andrew/bin/dmenu.sh", NULL}; +//static const char *endcmd[] = {"/home/andrew/bin/power.sh", NULL}; static const char *passcmd[] = {"/home/andrew/bin/pass.sh", NULL}; static const char *tmuxcmd[] = {"/home/andrew/bin/tmux.sh", NULL}; static const char *searchcmd[] = {"/home/andrew/bin/search.sh", NULL}; @@ -74,6 +76,7 @@ static const char *termcmd[] = { "st", NULL }; static const Key keys[] = { /* modifier key function argument */ { MODKEY, XK_o, spawn, {.v = dmenucmd } }, + //{ MODKEY, XK_e, spawn, {.v = endcmd } }, { MODKEY, XK_p, spawn, {.v = passcmd } }, { MODKEY, XK_t, spawn, {.v = tmuxcmd } }, { MODKEY, XK_s, spawn, {.v = searchcmd } }, @@ -92,8 +95,8 @@ static const Key keys[] = { { MODKEY|ShiftMask, XK_s, spawn, {.v = suspendcmd } }, - //{ MODKEY, XK_h, setmfact, {.f = -0.05} }, - //{ MODKEY, XK_l, setmfact, {.f = +0.05} }, + { MODKEY, XK_Left, setmfact, {.f = -0.05} }, + { MODKEY, XK_Right, setmfact, {.f = +0.05} }, { MODKEY|ShiftMask, XK_Return, zoom, {0} }, @@ -122,6 +125,10 @@ static const Key keys[] = { { MODKEY|ShiftMask, XK_v, setlayout, {.v = &layouts[0]} }, // columnar mode { MODKEY|ShiftMask, XK_h, setlayout, {.v = &layouts[1]} }, + + // centered master + { MODKEY|ShiftMask, XK_c, setlayout, {.v = &layouts[2]} }, + //{ MODKEY, XK_space, setlayout, {0} }, //{ MODKEY|ShiftMask, XK_space, togglefloating, {0} }, diff --git a/dwm.c b/dwm.c @@ -233,6 +233,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"; @@ -2189,3 +2191,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); + } +}