add patch: 007-centeredmaster

This commit is contained in:
altffour 2020-05-25 20:56:22 +03:00
parent 2b480b5562
commit 00574da349
No known key found for this signature in database
GPG Key ID: F37C0524D5295EA1
3 changed files with 223 additions and 2 deletions

View File

@ -47,6 +47,8 @@ static const Layout layouts[] = {
{ "[M]", monocle },
{ "TTT", bstack },
{ "===", bstackhoriz },
{ "|M|", centeredmaster },
{ ">M>", centeredfloatingmaster },
};
/* key definitions */
@ -83,8 +85,8 @@ static Key keys[] = {
{ MODKEY, XK_b, togglebar, {0} },
{ MODKEY, XK_j, focusstack, {.i = +1 } },
{ MODKEY, XK_k, focusstack, {.i = -1 } },
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
{ MODKEY, XK_greater,incnmaster, {.i = +1 } },
{ MODKEY, XK_less, incnmaster, {.i = -1 } },
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
{ MODKEY, XK_Return, zoom, {0} },
@ -95,6 +97,8 @@ static Key keys[] = {
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
{ MODKEY, XK_y, setlayout, {.v = &layouts[3]} },
{ MODKEY|ShiftMask, XK_y, setlayout, {.v = &layouts[4]} },
{ MODKEY, XK_i, setlayout, {.v = &layouts[5]} },
{ MODKEY|ShiftMask, XK_i, setlayout, {.v = &layouts[6]} },
{ MODKEY, XK_space, setlayout, {0} },
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
{ MODKEY, XK_0, view, {.ui = ~0 } },

102
dwm.c
View File

@ -246,6 +246,8 @@ static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void zoom(const Arg *arg);
static void bstack(Monitor *m);
static void bstackhoriz(Monitor *m);
static void centeredmaster(Monitor *m);
static void centeredfloatingmaster(Monitor *m);
/* variables */
static const char broken[] = "broken";
@ -2396,3 +2398,103 @@ bstackhoriz(Monitor *m) {
}
}
}
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);
}
}

View File

@ -0,0 +1,115 @@
--- dwm.c 2020-05-25 20:18:32.786733660 +0300
+++ dwm.c.orig 2020-05-25 20:11:57.780060152 +0300
@@ -246,8 +246,6 @@
static void zoom(const Arg *arg);
static void bstack(Monitor *m);
static void bstackhoriz(Monitor *m);
-static void centeredmaster(Monitor *m);
-static void centeredfloatingmaster(Monitor *m);
/* variables */
static const char broken[] = "broken";
@@ -2398,103 +2396,3 @@
}
}
}
-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);
- }
-}