dwm

[fork] dynamic window manager
Log | Files | Refs | README | LICENSE

commit 384317e87e9c0f3676bec5af5e916de3765eb5c3
parent 29bc023ee9641b86680139e87bea671f4c8aed75
Author: Hayden Hamilton <hayden@haydenvh.com>
Date:   Mon,  2 Mar 2020 16:30:55 +0000

centredmaster - not redone yet

Diffstat:
D.dwm.c.swp | 0
Mconfig.h | 4++++
Mdwm.c | 105+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 109 insertions(+), 0 deletions(-)

diff --git a/.dwm.c.swp b/.dwm.c.swp Binary files differ. diff --git a/config.h b/config.h @@ -39,6 +39,8 @@ static const Layout layouts[] = { { "[M]", monocle }, { "[@]", spiral }, { "[#=-]", dwindle }, + { "[SMS]", centeredmaster }, + { "[\\M/]", centeredfloatingmaster }, }; /* key definitions */ @@ -136,6 +138,8 @@ static Key keys[] = { { MODKEY|AltMask, XK_2, setlayout, {.v = &layouts[1]} }, { MODKEY|AltMask, XK_3, setlayout, {.v = &layouts[3]} }, { MODKEY|AltMask, XK_4, setlayout, {.v = &layouts[4]} }, + { MODKEY|AltMask, XK_5, setlayout, {.v = &layouts[5]} }, + { MODKEY|AltMask, XK_6, setlayout, {.v = &layouts[6]} }, { MODKEY|AltMask, XK_0, setlayout, {.v = &layouts[2]} }, /* Tags */ TAGKEYS( XK_1, 0) diff --git a/dwm.c b/dwm.c @@ -244,6 +244,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); static void self_restart(const Arg *arg); static char *get_dwm_path(void); static void spiral(Monitor *mon); @@ -2239,3 +2241,106 @@ self_restart(const Arg *arg) { execv(argv[0], argv); } + +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); + } +}