From 0db52b38d8ef1d95a127f93cd31354b3b3d28c46 Mon Sep 17 00:00:00 2001 From: Anas Elgarhy Date: Thu, 28 Apr 2022 00:22:25 +0200 Subject: [PATCH] =?UTF-8?q?Add=20gridlayout=20patch=20=F0=9F=99=8B?= =?UTF-8?q?=F0=9F=8F=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.def.h | 3 +++ config.def.h.orig | 5 +++++ config.def.h.rej | 10 ++++++++++ config.h | 2 ++ layouts.c | 27 +++++++++++++++++++++++++++ 5 files changed, 47 insertions(+) create mode 100644 config.def.h.rej create mode 100644 layouts.c diff --git a/config.def.h b/config.def.h index 938c4ae..eb638a8 100644 --- a/config.def.h +++ b/config.def.h @@ -47,11 +47,13 @@ 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 const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */ +#include "layouts.c" static const Layout layouts[] = { /* symbol arrange function */ { "[]=", tile }, /* first entry is default */ { "><>", NULL }, /* no layout function means floating behavior */ { "[M]", monocle }, + { "HHH", grid }, }; /* key definitions */ @@ -90,6 +92,7 @@ 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_g, setlayout, {.v = &layouts[3]} }, { MODKEY|ShiftMask, XK_f, fullscreen, {0} }, { MODKEY, XK_space, setlayout, {0} }, { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, diff --git a/config.def.h.orig b/config.def.h.orig index bc7740c..938c4ae 100644 --- a/config.def.h.orig +++ b/config.def.h.orig @@ -23,6 +23,11 @@ static const char *colors[][3] = { [SchemeSel] = { col_gray4, col_cyan, col_cyan }, }; +static const char *const autostart[] = { + "st", NULL, + NULL /* terminate */ +}; + /* tagging */ static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; diff --git a/config.def.h.rej b/config.def.h.rej new file mode 100644 index 0000000..f4ac42c --- /dev/null +++ b/config.def.h.rej @@ -0,0 +1,10 @@ +--- config.def.h ++++ config.def.h +@@ -78,6 +80,7 @@ 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_g, setlayout, {.v = &layouts[3]} }, + { MODKEY, XK_space, setlayout, {0} }, + { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, + { MODKEY, XK_0, view, {.ui = ~0 } }, diff --git a/config.h b/config.h index 2c5d652..e3ba142 100644 --- a/config.h +++ b/config.h @@ -64,6 +64,7 @@ static const Layout layouts[] = { { "[]=", tile }, /* first entry is default */ { "><>", NULL }, /* no layout function means floating behavior */ { "[M]", monocle }, + { "HHH", grid }, }; /* key definitions */ @@ -135,6 +136,7 @@ static Key keys[] = { { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, // Monocle layout { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, + { MODKEY, XK_g, setlayout, {.v = &layouts[3]} }, { MODKEY|ShiftMask, XK_space, setlayout, {0} }, { MODKEY|ShiftMask, XK_f, togglefloating, {0} }, diff --git a/layouts.c b/layouts.c new file mode 100644 index 0000000..d26acf3 --- /dev/null +++ b/layouts.c @@ -0,0 +1,27 @@ +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++; + } +}