From 976638aa52ca8695a08d80e90185b6bf4721349c Mon Sep 17 00:00:00 2001 From: BitHeaven Date: Fri, 31 May 2024 11:11:54 +0500 Subject: [PATCH] Add gaplessgrid patch --- config.def.h | 9 +++++---- config.h | 2 ++ dwm.c | 2 -- layouts.c | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/config.def.h b/config.def.h index 5362c8a..4adeb87 100644 --- a/config.def.h +++ b/config.def.h @@ -66,10 +66,11 @@ static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen win #include "layouts.c" static const Layout layouts[] = { - /* symbol arrange function */ - { "[]=", tile }, /* first entry is default */ - { "><>", NULL }, /* no layout function means floating behavior */ - { "[M]", monocle }, + /* symbol arrange function */ + { "###", gaplessgrid }, + { "[]=", tile }, + { "><>", NULL }, + { "[M]", monocle }, }; /* key definitions */ diff --git a/config.h b/config.h index 1507a8d..5362c8a 100644 --- a/config.h +++ b/config.h @@ -63,6 +63,8 @@ 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 */ diff --git a/dwm.c b/dwm.c index 41cd5a3..29db3b5 100644 --- a/dwm.c +++ b/dwm.c @@ -182,7 +182,6 @@ static void killclient(const Arg *arg); static void manage(Window w, XWindowAttributes *wa); static void mappingnotify(XEvent *e); static void maprequest(XEvent *e); -static void monocle(Monitor *m); static void motionnotify(XEvent *e); static void movemouse(const Arg *arg); static Client *nexttiled(Client *c); @@ -210,7 +209,6 @@ static void showhide(Client *c); static void spawn(const Arg *arg); static void tag(const Arg *arg); static void tagmon(const Arg *arg); -static void tile(Monitor *m); static void togglebar(const Arg *arg); static void togglefloating(const Arg *arg); static void togglefullscr(const Arg *arg); diff --git a/layouts.c b/layouts.c index 7865780..ae7e786 100644 --- a/layouts.c +++ b/layouts.c @@ -40,3 +40,40 @@ monocle(Monitor *m) for (c = nexttiled(m->clients); c; c = nexttiled(c->next)) resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0); } + +// TODO: Add gaps +void +gaplessgrid(Monitor *m) { + unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch; + Client *c; + + for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) ; + if(n == 0) + return; + + /* grid dimensions */ + for(cols = 0; cols <= n/2; cols++) + if(cols*cols >= n) + break; + if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */ + cols = 2; + rows = n/cols; + + /* window geometries */ + cw = cols ? m->ww / cols : m->ww; + cn = 0; /* current column number */ + rn = 0; /* current row number */ + for(i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) { + if(i/rows + 1 > cols - n%cols) + rows = n/cols + 1; + ch = rows ? m->wh / rows : m->wh; + cx = m->wx + cn*cw; + cy = m->wy + rn*ch; + resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False); + rn++; + if(rn >= rows) { + rn = 0; + cn++; + } + } +}