Added more layouts to DWM

This commit is contained in:
Clay Gomera 2022-07-20 16:43:10 -04:00
parent 498f6f3e1f
commit fd998f361a
5 changed files with 199 additions and 12 deletions

View file

@ -38,7 +38,7 @@ static const unsigned int alphas[][3] = {
}; };
/* |||--- TAG NAMES ---||| */ /* |||--- TAG NAMES ---||| */
static const char *tags[] = { "edt", "exp", "web", "cht", "msc", "gms", "vrt", "wrk", "msc" }; static const char *tags[] = { "dev", "exp", "web", "cht", "msc", "gms", "vrt", "wrk", "msc" };
/* |||--- RULES ---||| */ /* |||--- RULES ---||| */
static const Rule rules[] = { static const Rule rules[] = {
@ -65,12 +65,19 @@ static const int nmaster = 1; /* number of clients in master area */
static const int resizehints = 0; /* 1 means respect size hints in tiled resizals */ static const int resizehints = 0; /* 1 means respect size hints in tiled resizals */
static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */ static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
#include "grid.c" #include "grid.c"
#include "tcl.c"
#include "fbc.c"
#include "tlwide.c"
static const Layout layouts[] = { static const Layout layouts[] = {
/* symbol arrange function */ /* symbol arrange function */
{ "[]=", tile }, /* first entry is default */ { "[]=", tile }, /* first entry is default */
{ "><>", NULL }, /* no layout function means floating behavior */ { "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle }, { "[M]", monocle },
{ "HHH", grid }, { "HHH", grid },
{ "|||", tcl },
{ "[@]", spiral },
{ "[\\]", dwindle },
{ "[][]=", tilewide },
{ NULL, NULL }, { NULL, NULL },
}; };
@ -125,8 +132,8 @@ static Keychord keychords[] = {
{1, {{MODKEY, XK_j}}, focusstack, {.i = +1 } }, {1, {{MODKEY, XK_j}}, focusstack, {.i = +1 } },
{1, {{MODKEY, XK_k}}, focusstack, {.i = -1 } }, {1, {{MODKEY, XK_k}}, focusstack, {.i = -1 } },
/* Increase and decrease master windows count */ /* Increase and decrease master windows count */
{1, {{MODKEY, XK_i}}, incnmaster, {.i = +1 } }, {1, {{MODKEY, XK_equal}}, incnmaster, {.i = +1 } },
{1, {{MODKEY, XK_d}}, incnmaster, {.i = -1 } }, {1, {{MODKEY, XK_minus}}, incnmaster, {.i = -1 } },
/* Increase and decrease master window size */ /* Increase and decrease master window size */
{1, {{MODKEY, XK_h}}, setmfact, {.f = -0.05} }, {1, {{MODKEY, XK_h}}, setmfact, {.f = -0.05} },
{1, {{MODKEY, XK_l}}, setmfact, {.f = +0.05} }, {1, {{MODKEY, XK_l}}, setmfact, {.f = +0.05} },
@ -143,6 +150,14 @@ static Keychord keychords[] = {
{1, {{MODKEY, XK_m}}, setlayout, {.v = &layouts[2]} }, {1, {{MODKEY, XK_m}}, setlayout, {.v = &layouts[2]} },
/* Switch to grid layout */ /* Switch to grid layout */
{1, {{MODKEY, XK_g}}, setlayout, {.v = &layouts[3]} }, {1, {{MODKEY, XK_g}}, setlayout, {.v = &layouts[3]} },
/* Switch to three column layout */
{1, {{MODKEY, XK_c}}, setlayout, {.v = &layouts[4]} },
/* Switch to fibonacci spiral layout */
{1, {{MODKEY, XK_s}}, setlayout, {.v = &layouts[5]} },
/* Switch to fibonacci dwindle layout */
{1, {{MODKEY, XK_d}}, setlayout, {.v = &layouts[6]} },
/* Switch to tilewide layout */
{1, {{MODKEY, XK_w}}, setlayout, {.v = &layouts[7]} },
/* Toggle floating mode */ /* Toggle floating mode */
{1, {{MODKEY|ShiftMask, XK_f}}, togglefloating, {0} }, {1, {{MODKEY|ShiftMask, XK_f}}, togglefloating, {0} },
/* Toggle fullscreen mode */ /* Toggle fullscreen mode */
@ -206,23 +221,23 @@ static Keychord keychords[] = {
/* MISC PROGRAMS launched with emacs-style keychords SUPER + m (app) followed by "key" */ /* MISC PROGRAMS launched with emacs-style keychords SUPER + m (app) followed by "key" */
/* System monitor btop */ /* System monitor btop */
{2, {{MODKEY, XK_s}, {0, XK_b}}, spawn, SHCMD("alacritty -t misc --class misc,misc -e btop") }, {2, {{MODKEY, XK_z}, {0, XK_b}}, spawn, SHCMD("alacritty -t misc --class misc,misc -e btop") },
/* System monitor htop */ /* System monitor htop */
{2, {{MODKEY, XK_s}, {0, XK_h}}, spawn, SHCMD("alacritty -t misc --class misc,misc -e htop") }, {2, {{MODKEY, XK_z}, {0, XK_h}}, spawn, SHCMD("alacritty -t misc --class misc,misc -e htop") },
/* Pulse mixer */ /* Pulse mixer */
{2, {{MODKEY, XK_s}, {0, XK_p}}, spawn, SHCMD("alacritty -t misc --class misc,misc -e pulsemixer") }, {2, {{MODKEY, XK_z}, {0, XK_p}}, spawn, SHCMD("alacritty -t misc --class misc,misc -e pulsemixer") },
/* Alsa mixer */ /* Alsa mixer */
{2, {{MODKEY, XK_s}, {0, XK_m}}, spawn, SHCMD("alacritty -t misc --class misc,misc -e alsamixer") }, {2, {{MODKEY, XK_z}, {0, XK_m}}, spawn, SHCMD("alacritty -t misc --class misc,misc -e alsamixer") },
/* Rss reader */ /* Rss reader */
{2, {{MODKEY, XK_s}, {0, XK_n}}, spawn, SHCMD("alacritty -t misc --class misc,misc -e newsboat") }, {2, {{MODKEY, XK_z}, {0, XK_n}}, spawn, SHCMD("alacritty -t misc --class misc,misc -e newsboat") },
/* Ytfzf */ /* Ytfzf */
{2, {{MODKEY, XK_s}, {0, XK_y}}, spawn, SHCMD("alacritty -t misc --class misc,misc -e ytfzf -flst") }, {2, {{MODKEY, XK_z}, {0, XK_y}}, spawn, SHCMD("alacritty -t misc --class misc,misc -e ytfzf -flst") },
/* Ani-cli */ /* Ani-cli */
{2, {{MODKEY, XK_s}, {0, XK_a}}, spawn, SHCMD("alacritty -t misc --class misc,misc -e ani-cli") }, {2, {{MODKEY, XK_z}, {0, XK_a}}, spawn, SHCMD("alacritty -t misc --class misc,misc -e ani-cli") },
/* Flix-cli */ /* Flix-cli */
{2, {{MODKEY, XK_s}, {0, XK_f}}, spawn, SHCMD("alacritty -t misc --class misc,misc -e flix-cli") }, {2, {{MODKEY, XK_z}, {0, XK_f}}, spawn, SHCMD("alacritty -t misc --class misc,misc -e flix-cli") },
/* Castero */ /* Castero */
{2, {{MODKEY, XK_s}, {0, XK_c}}, spawn, SHCMD("alacritty -t misc --class misc,misc -e castero") }, {2, {{MODKEY, XK_z}, {0, XK_c}}, spawn, SHCMD("alacritty -t misc --class misc,misc -e castero") },
/* DMENU PROMPTS launched with emacs-style keychords SUPER + p (prompt) followed by "key" */ /* DMENU PROMPTS launched with emacs-style keychords SUPER + p (prompt) followed by "key" */
/* dmenu */ /* dmenu */

View file

@ -1909,6 +1909,10 @@ togglefloating(const Arg *arg)
if (selmon->sel->isfloating) if (selmon->sel->isfloating)
resize(selmon->sel, selmon->sel->x, selmon->sel->y, resize(selmon->sel, selmon->sel->x, selmon->sel->y,
selmon->sel->w, selmon->sel->h, 0); selmon->sel->w, selmon->sel->h, 0);
selmon->sel->x = selmon->sel->mon->mx + (selmon->sel->mon->mw - WIDTH(selmon->sel)) / 2;
selmon->sel->y = selmon->sel->mon->my + (selmon->sel->mon->mh - HEIGHT(selmon->sel)) / 2;
arrange(selmon); arrange(selmon);
} }

View file

@ -0,0 +1,66 @@
void
fibonacci(Monitor *mon, int s) {
unsigned int i, n, nx, ny, nw, nh;
Client *c;
for(n = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next), n++);
if(n == 0)
return;
nx = mon->wx;
ny = 0;
nw = mon->ww;
nh = mon->wh;
for(i = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next)) {
if((i % 2 && nh / 2 > 2 * c->bw)
|| (!(i % 2) && nw / 2 > 2 * c->bw)) {
if(i < n - 1) {
if(i % 2)
nh /= 2;
else
nw /= 2;
if((i % 4) == 2 && !s)
nx += nw;
else if((i % 4) == 3 && !s)
ny += nh;
}
if((i % 4) == 0) {
if(s)
ny += nh;
else
ny -= nh;
}
else if((i % 4) == 1)
nx += nw;
else if((i % 4) == 2)
ny += nh;
else if((i % 4) == 3) {
if(s)
nx += nw;
else
nx -= nw;
}
if(i == 0)
{
if(n != 1)
nw = mon->ww * mon->mfact;
ny = mon->wy;
}
else if(i == 1)
nw = mon->ww - nw;
i++;
}
resize(c, nx, ny, nw - 2 * c->bw, nh - 2 * c->bw, False);
}
}
void
dwindle(Monitor *mon) {
fibonacci(mon, 1);
}
void
spiral(Monitor *mon) {
fibonacci(mon, 0);
}

View file

@ -0,0 +1,75 @@
void
tcl(Monitor * m)
{
int x, y, h, w, mw, sw, bdw;
unsigned int i, n;
Client * c;
for (n = 0, c = nexttiled(m->clients); c;
c = nexttiled(c->next), n++);
if (n == 0)
return;
c = nexttiled(m->clients);
mw = m->mfact * m->ww;
sw = (m->ww - mw) / 2;
bdw = (2 * c->bw);
resize(c,
n < 3 ? m->wx : m->wx + sw,
m->wy,
n == 1 ? m->ww - bdw : mw - bdw,
m->wh - bdw,
False);
if (--n == 0)
return;
w = (m->ww - mw) / ((n > 1) + 1);
c = nexttiled(c->next);
if (n > 1)
{
x = m->wx + ((n > 1) ? mw + sw : mw);
y = m->wy;
h = m->wh / (n / 2);
if (h < bh)
h = m->wh;
for (i = 0; c && i < n / 2; c = nexttiled(c->next), i++)
{
resize(c,
x,
y,
w - bdw,
(i + 1 == n / 2) ? m->wy + m->wh - y - bdw : h - bdw,
False);
if (h != m->wh)
y = c->y + HEIGHT(c);
}
}
x = (n + 1 / 2) == 1 ? mw : m->wx;
y = m->wy;
h = m->wh / ((n + 1) / 2);
if (h < bh)
h = m->wh;
for (i = 0; c; c = nexttiled(c->next), i++)
{
resize(c,
x,
y,
(i + 1 == (n + 1) / 2) ? w - bdw : w - bdw,
(i + 1 == (n + 1) / 2) ? m->wy + m->wh - y - bdw : h - bdw,
False);
if (h != m->wh)
y = c->y + HEIGHT(c);
}
}

View file

@ -0,0 +1,27 @@
void
tilewide(Monitor *m)
{
unsigned int i, n, w, h, mw, mx, ty;
Client *c;
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
if (n == 0)
return;
if (n > m->nmaster)
mw = m->nmaster ? m->ww * m->mfact : 0;
else
mw = m->ww;
for (i = mx = ty = 0, c = nexttiled(m->clients); c;
c = nexttiled(c->next), i++)
if (i < m->nmaster) {
w = (mw - mx) / (MIN(n, m->nmaster) - i);
resize(c, m->wx + mx, m->wy, w - (2*c->bw), (m->wh - ty) - (2*c->bw), 0);
if (mx + WIDTH(c) < m->ww)
mx += WIDTH(c);
} else {
h = (m->wh - ty) / (n - i);
resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0);
if (ty + HEIGHT(c) < m->wh)
ty += HEIGHT(c);
}
}