From fd998f361a70690e80fce148ea3b9e3bb2f7faf9 Mon Sep 17 00:00:00 2001 From: Clay Gomera Date: Wed, 20 Jul 2022 16:43:10 -0400 Subject: [PATCH] Added more layouts to DWM --- user/.config/suckless/dwm/config.def.h | 39 +++++++++----- user/.config/suckless/dwm/dwm.c | 4 ++ user/.config/suckless/dwm/fbc.c | 66 +++++++++++++++++++++++ user/.config/suckless/dwm/tcl.c | 75 ++++++++++++++++++++++++++ user/.config/suckless/dwm/tlwide.c | 27 ++++++++++ 5 files changed, 199 insertions(+), 12 deletions(-) create mode 100644 user/.config/suckless/dwm/fbc.c create mode 100644 user/.config/suckless/dwm/tcl.c create mode 100644 user/.config/suckless/dwm/tlwide.c diff --git a/user/.config/suckless/dwm/config.def.h b/user/.config/suckless/dwm/config.def.h index 145175a18..ff825e952 100644 --- a/user/.config/suckless/dwm/config.def.h +++ b/user/.config/suckless/dwm/config.def.h @@ -38,7 +38,7 @@ static const unsigned int alphas[][3] = { }; /* |||--- 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 ---||| */ 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 lockfullscreen = 1; /* 1 will force focus on the fullscreen window */ #include "grid.c" +#include "tcl.c" +#include "fbc.c" +#include "tlwide.c" static const Layout layouts[] = { /* symbol arrange function */ { "[]=", tile }, /* first entry is default */ { "><>", NULL }, /* no layout function means floating behavior */ { "[M]", monocle }, { "HHH", grid }, + { "|||", tcl }, + { "[@]", spiral }, + { "[\\]", dwindle }, + { "[][]=", tilewide }, { NULL, NULL }, }; @@ -125,8 +132,8 @@ static Keychord keychords[] = { {1, {{MODKEY, XK_j}}, focusstack, {.i = +1 } }, {1, {{MODKEY, XK_k}}, focusstack, {.i = -1 } }, /* Increase and decrease master windows count */ - {1, {{MODKEY, XK_i}}, incnmaster, {.i = +1 } }, - {1, {{MODKEY, XK_d}}, incnmaster, {.i = -1 } }, + {1, {{MODKEY, XK_equal}}, incnmaster, {.i = +1 } }, + {1, {{MODKEY, XK_minus}}, incnmaster, {.i = -1 } }, /* Increase and decrease master window size */ {1, {{MODKEY, XK_h}}, 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]} }, /* Switch to grid layout */ {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 */ {1, {{MODKEY|ShiftMask, XK_f}}, togglefloating, {0} }, /* Toggle fullscreen mode */ @@ -206,23 +221,23 @@ static Keychord keychords[] = { /* MISC PROGRAMS launched with emacs-style keychords SUPER + m (app) followed by "key" */ /* 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 */ - {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 */ - {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 */ - {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 */ - {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 */ - {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 */ - {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 */ - {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 */ - {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 */ diff --git a/user/.config/suckless/dwm/dwm.c b/user/.config/suckless/dwm/dwm.c index 0480d4a20..ccd171558 100644 --- a/user/.config/suckless/dwm/dwm.c +++ b/user/.config/suckless/dwm/dwm.c @@ -1909,6 +1909,10 @@ togglefloating(const Arg *arg) if (selmon->sel->isfloating) resize(selmon->sel, selmon->sel->x, selmon->sel->y, 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); } diff --git a/user/.config/suckless/dwm/fbc.c b/user/.config/suckless/dwm/fbc.c new file mode 100644 index 000000000..fce0a577b --- /dev/null +++ b/user/.config/suckless/dwm/fbc.c @@ -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); +} diff --git a/user/.config/suckless/dwm/tcl.c b/user/.config/suckless/dwm/tcl.c new file mode 100644 index 000000000..6bcf1cee0 --- /dev/null +++ b/user/.config/suckless/dwm/tcl.c @@ -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); + } +} + diff --git a/user/.config/suckless/dwm/tlwide.c b/user/.config/suckless/dwm/tlwide.c new file mode 100644 index 000000000..f850e6e16 --- /dev/null +++ b/user/.config/suckless/dwm/tlwide.c @@ -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); + } +}