From efb13be2db2ff7a497a7d06b5cd7ae6c4b9cb684 Mon Sep 17 00:00:00 2001 From: Immanuel Onyeka Date: Sun, 7 Mar 2021 20:13:11 -0500 Subject: [PATCH] Move nrowgrid function --- TODO | 3 +-- config.h | 15 ++++++++------- dwm.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ layouts.c | 27 --------------------------- movestack.c | 3 +++ 5 files changed, 66 insertions(+), 36 deletions(-) delete mode 100644 layouts.c diff --git a/TODO b/TODO index ae3253e..a2cbd21 100644 --- a/TODO +++ b/TODO @@ -8,8 +8,6 @@ fullgaps (might be shortcuts) awesomebar: hidewindow() function crashes dwm and tag background color is weird maybe manage hidden windows with dmenu use dmenu for selecting and focusing window -undo fullgaps and add useless gaps instead for more generality -add patch for moving slave windows correct tag colors hide border of nonfocused windows or make transparent @@ -28,3 +26,4 @@ specified from known directories and used in dmenu), and pointing to specific file to update it's position (ctrlp hook script should be possible) add shortcut for focusing master add scratchpad that opens in a special session +maybe make width and height of outer gaps equal diff --git a/config.h b/config.h index 814f7d8..bbb87fa 100644 --- a/config.h +++ b/config.h @@ -5,13 +5,13 @@ static const char *fonts[] = { "SauceCodePro NF:size=10" }; static const char dmenufont[] = "SauceCodePro NF:size=10"; -static const char normbordercolor[] = "#444444"; +static const char normbordercolor[] = "#000000"; static const char normbgcolor[] = "#222222"; static const char normfgcolor[] = "#bbbbbb"; -static const char selbordercolor[] = "#333544"; +static const char selbordercolor[] = "#ffffff"; static const char selbgcolor[] = "#005577"; static const char selfgcolor[] = "#eeeeee"; -static const unsigned int borderpx = 5; /* border pixel of windows */ +static const unsigned int borderpx = 2; /* border pixel of windows */ static const Gap default_gap = {.ogap = 10, .isgap = 1, .realgap = 10, .gappx = 10}; static const unsigned int snap = 32; /* snap pixel */ static const int showbar = 0; /* 0 means no bar */ @@ -36,7 +36,7 @@ static const int nmaster = 1; /* number of clients in master area */ static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ static int attachbelow = 1; /* 1 means attach after the currently active window */ -#include "layouts.c" +#define FORCE_VSPLIT 1 static const Layout layouts[] = { /* symbol arrange function */ { "|M|", centeredmaster }, @@ -44,7 +44,7 @@ static const Layout layouts[] = { { "[M]", monocle }, { "[]=", tile }, /* first entry is default */ { "><>", NULL }, /* no layout function means floating behavior */ - { "HHH", grid }, + { "###", nrowgrid }, }; /* key definitions */ @@ -62,8 +62,9 @@ static const Layout layouts[] = { static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL }; static const char *termcmd[] = { "st", NULL }; -static const char scratchpadname[] = "scratchpad"; -static const char *scratchpadcmd[] = { "st", "-t", scratchpadname, "-g", "120x34", NULL }; +static const char scratchpadname[] = "Scratchpad"; +static const char *scratchpadcmd[] = { "st", "-t", scratchpadname, + "-g", "120x34", "-e", "tmux", "new-session", "-As", "scratchpad", NULL}; #include "movestack.c" static Key keys[] = { diff --git a/dwm.c b/dwm.c index f53dbb6..89ffbc5 100644 --- a/dwm.c +++ b/dwm.c @@ -209,6 +209,7 @@ static void maprequest(XEvent *e); static void monocle(Monitor *m); static void motionnotify(XEvent *e); static void movemouse(const Arg *arg); +static void nrowgrid(Monitor *m); static Client *nexttiled(Client *c); static void pop(Client *); static void propertynotify(XEvent *e); @@ -2662,3 +2663,56 @@ focusmaster(const Arg *arg) if (c) focus(c); } + +void +nrowgrid(Monitor *m) +{ + unsigned int n = 0, i = 0, ri = 0, ci = 0; /* counters */ + unsigned int cx, cy, cw, ch; /* client geometry */ + unsigned int uw = 0, uh = 0, uc = 0; /* utilization trackers */ + unsigned int cols, rows = m->nmaster + 1; + Client *c; + + /* count clients */ + for (c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); + + /* nothing to do here */ + if (n == 0) + return; + + /* force 2 clients to always split vertically */ + if (FORCE_VSPLIT && n == 2) + rows = 1; + + /* never allow empty rows */ + if (n < rows) + rows = n; + + /* define first row */ + cols = n / rows; + uc = cols; + cy = m->wy; + ch = m->wh / rows; + uh = ch; + + for (c = nexttiled(m->clients); c; c = nexttiled(c->next), i++, ci++) { + if (ci == cols) { + uw = 0; + ci = 0; + ri++; + + /* next row */ + cols = (n - uc) / (rows - ri); + uc += cols; + cy = m->wy + uh; + ch = (m->wh - uh) / (rows - ri); + uh += ch; + } + + cx = m->wx + uw; + cw = (m->ww - uw) / (cols - ci); + uw += cw; + + resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, 0); + } +} diff --git a/layouts.c b/layouts.c deleted file mode 100644 index d26acf3..0000000 --- a/layouts.c +++ /dev/null @@ -1,27 +0,0 @@ -void -grid(Monitor *m) { - unsigned int i, n, cx, cy, cw, ch, aw, ah, cols, rows; - Client *c; - - for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) - n++; - - /* grid dimensions */ - for(rows = 0; rows <= n/2; rows++) - if(rows*rows >= n) - break; - cols = (rows && (rows - 1) * rows >= n) ? rows - 1 : rows; - - /* window geoms (cell height/width) */ - ch = m->wh / (rows ? rows : 1); - cw = m->ww / (cols ? cols : 1); - for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) { - cx = m->wx + (i / rows) * cw; - cy = m->wy + (i % rows) * ch; - /* adjust height/width of last row/column's windows */ - ah = ((i + 1) % rows == 0) ? m->wh - ch * rows : 0; - aw = (i >= rows * (cols - 1)) ? m->ww - cw * cols : 0; - resize(c, cx, cy, cw - 2 * c->bw + aw, ch - 2 * c->bw + ah, False); - i++; - } -} diff --git a/movestack.c b/movestack.c index c040462..19e37f2 100644 --- a/movestack.c +++ b/movestack.c @@ -27,10 +27,13 @@ movestack(const Arg *arg) { pc = i; } + /* printf("%s", c->name); */ /* swap c and selmon->sel selmon->clients in the selmon->clients list */ if(c && c != selmon->sel) { Client *temp = selmon->sel->next==c?selmon->sel:selmon->sel->next; + /* Client *temp = selmon->sel; */ selmon->sel->next = c->next==selmon->sel?c:c->next; + /* selmon->sel->next = c->next; */ c->next = temp; if(p && p != c)