sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit d125c77a5dd36d381b8e37a42fcdea983d226ecc
parent b402daf061c0bfbe4d66f971a259e8e70251c00f
Author: FRIGN <dev@frign.de>
Date:   Tue, 19 Jul 2016 11:37:35 +0200

dwm centeredmaster patch: refactor

Diffstat:
Ddwm.suckless.org/patches/centeredmaster.c | 91-------------------------------------------------------------------------------
Mdwm.suckless.org/patches/centeredmaster.md | 157++++++++++++++++++++++++++++++++-----------------------------------------------
Adwm.suckless.org/patches/dwm-centeredmaster-20160719-56a31dc.diff | 142+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdwm.suckless.org/patches/dwm-centeredmaster-6.1.diff | 159++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------
4 files changed, 326 insertions(+), 223 deletions(-)

diff --git a/dwm.suckless.org/patches/centeredmaster.c b/dwm.suckless.org/patches/centeredmaster.c @@ -1,91 +0,0 @@ -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 @@ -1,94 +1,63 @@ -# centeredmaster - -## `centeredmaster` - -makes the nmaster area centered -on screen, using `mfact * monitor width & height`, with the stacked windows -distributed on left and right. - -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: - - +------------------------------+ - |+--------++--------++--------+| - || || || || - || +------------------+ || - || | | || - || | | || - || | M | || - || | | || - || +------------------+ || - || || || || - |+--------++--------++--------+| - +------------------------------+ - -With two clients in master: - - +------------------------------+ - |+--------++--------++--------+| - || || || || - || +--------++--------+ || - || | || | || - || | || | || - || | M1 || M2 | || - || | || | || - || +--------++--------+ || - || || || || - |+--------++--------++--------+| - +------------------------------+ - - -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-centeredmaster-6.1.diff](dwm-centeredmaster-6.1.diff) - 2015/11/21 - - -[jerome](http://blog.jardinmagique.info) <jerome@gcu.info> +centeredmaster +============== + +Description +----------- + +`centeredmaster` and `centeredfloatingmaster` are two stack layouts for dwm. + +`centeredmaster` centers the nmaster area on screen, using +`mfact * monitor width & height`, with the stacked windows +distributed to the left and right. + +With one and two clients in master respectively this results in: + + +------------------------------+ +------------------------------+ + |+--------++--------++--------+| |+--------++--------++--------+| + || || || || || || || || + || || || || || || M1 || || + || || || || || || || || + || S2 || M || S1 || || |+--------+| || + || || || || || |+--------+| || + || || || || || || || || + || || || || || || M2 || || + || || || || || || || || + |+--------++--------++--------+| |+--------++--------++--------+| + +------------------------------+ +------------------------------+ + +`centeredfloatingmaster` centers the nmaster area on screen, using +`mfact * monitor width & height` over a horizontally tiled `stack` area, +comparable to a scratchpad. + +With one and two clients in master respectively this results in: + + +------------------------------+ +------------------------------+ + |+--------++--------++--------+| |+--------++--------++--------+| + || || || || || || || || + || +------------------+ || || +--------++--------+ || + || | | || || | || | || + || | | || || | || | || + || | M | || || | M1 || M2 | || + || | | || || | || | || + || +------------------+ || || +--------++--------+ || + || || || || || || || || + |+--------++--------++--------+| |+--------++--------++--------+| + +------------------------------+ +------------------------------+ + +These stack layouts can be useful on large screens, where `monocle` or +`htile` might be either too large or forcing the user to type in a corner +of the screen. +They allow for instance to center the editor while being able to keep an +eye on background processes (logs, tests,...) + +Download +-------- + + * [dwm-centeredmaster-6.1.diff](dwm-centeredmaster-6.1.diff) + * [dwm-centeredmaster-20160719-56a31dc.diff](dwm-centeredmaster-20160719-56a31dc.diff) + +Authors +------- + + * [Jérôme Andrieux](http://blog.jardinmagique.info) - <jerome@gcu.info> + * Laslo Hunhold - <dev@frign.de> (6.1, git ports) diff --git a/dwm.suckless.org/patches/dwm-centeredmaster-20160719-56a31dc.diff b/dwm.suckless.org/patches/dwm-centeredmaster-20160719-56a31dc.diff @@ -0,0 +1,142 @@ +diff --git a/config.def.h b/config.def.h +index fd77a07..f025619 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -41,6 +41,8 @@ static const Layout layouts[] = { + { "[]=", tile }, /* first entry is default */ + { "><>", NULL }, /* no layout function means floating behavior */ + { "[M]", monocle }, ++ { "|M|", centeredmaster }, ++ { ">M>", centeredfloatingmaster }, + }; + + /* key definitions */ +@@ -76,6 +78,8 @@ static Key keys[] = { + { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, + { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, + { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, ++ { MODKEY, XK_u, setlayout, {.v = &layouts[3]} }, ++ { MODKEY, XK_o, setlayout, {.v = &layouts[4]} }, + { MODKEY, XK_space, setlayout, {0} }, + { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, + { MODKEY, XK_0, view, {.ui = ~0 } }, +diff --git a/dwm.c b/dwm.c +index b2bc9bd..9ecabae 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -234,6 +234,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"; +@@ -2138,3 +2140,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); ++ } ++} diff --git a/dwm.suckless.org/patches/dwm-centeredmaster-6.1.diff b/dwm.suckless.org/patches/dwm-centeredmaster-6.1.diff @@ -1,59 +1,142 @@ +diff --git a/config.def.h b/config.def.h +index 7054c06..527b214 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -39,6 +39,8 @@ static const Layout layouts[] = { + { "[]=", tile }, /* first entry is default */ + { "><>", NULL }, /* no layout function means floating behavior */ + { "[M]", monocle }, ++ { "|M|", centeredmaster }, ++ { ">M>", centeredfloatingmaster }, + }; + + /* key definitions */ +@@ -74,6 +76,8 @@ static Key keys[] = { + { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, + { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, + { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, ++ { MODKEY, XK_u, setlayout, {.v = &layouts[3]} }, ++ { MODKEY, XK_o, setlayout, {.v = &layouts[4]} }, + { MODKEY, XK_space, setlayout, {0} }, + { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, + { MODKEY, XK_0, view, {.ui = ~0 } }, diff --git a/dwm.c b/dwm.c -index 0362114..fa5ae4c 100644 +index 0362114..1e81412 100644 --- a/dwm.c +++ b/dwm.c -@@ -209,6 +209,7 @@ static void spawn(const Arg *arg); - static void tag(const Arg *arg); - static void tagmon(const Arg *arg); - static void tile(Monitor *); -+static void centeredmaster(Monitor *); - static void togglebar(const Arg *arg); - static void togglefloating(const Arg *arg); - static void toggletag(const Arg *arg); -@@ -1690,6 +1691,46 @@ tile(Monitor *m) - } +@@ -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); - void + /* variables */ + static const char broken[] = "broken"; +@@ -2139,3 +2141,106 @@ main(int argc, char *argv[]) + XCloseDisplay(dpy); + return EXIT_SUCCESS; + } ++ ++void +centeredmaster(Monitor *m) +{ -+ unsigned int i, n, w, mh, mw, mx, mxo, my, myo, tx; ++ 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) ++ /* 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 ++ /* 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; -+ mh = m->nmaster ? m->wh * 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 ++ /* go fullscreen if all clients are in the master area */ + mh = m->wh; + mw = m->ww; + mx = mxo = 0; -+ my = 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); -+ } ++ 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); ++ } +} -+ -+void - togglebar(const Arg *arg) - { - selmon->showbar = !selmon->showbar;