Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nullscm/89cd68de63d22681a589466ffbc579e3 to your computer and use it in GitHub Desktop.
Save nullscm/89cd68de63d22681a589466ffbc579e3 to your computer and use it in GitHub Desktop.
gaplessgrid.patch
diff --git a/dwl.c b/dwl.c
index a2a0b692..d3a5d651 100644
--- a/dwl.c
+++ b/dwl.c
@@ -240,6 +240,7 @@ static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg);
static void fullscreennotify(struct wl_listener *listener, void *data);
static Client *focustop(Monitor *m);
+static void gaplessgrid(Monitor *m);
static void incnmaster(const Arg *arg);
static void inputdevice(struct wl_listener *listener, void *data);
static int keybinding(uint32_t mods, xkb_keysym_t sym);
@@ -1166,6 +1167,50 @@ focustop(Monitor *m)
return NULL;
}
+void
+gaplessgrid(Monitor *m) {
+ unsigned int n = 0, i = 0, ch, cw, cn, rn, rows, cols;
+ Client *c;
+
+ wl_list_for_each(c, &clients, link)
+ if (VISIBLEON(c, m) && !c->isfloating)
+ 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->w.width / cols : m->w.width;
+ cn = 0; /* current column number */
+ rn = 0; /* current row number */
+ wl_list_for_each(c, &clients, link) {
+ unsigned int cx, cy;
+ if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
+ continue;
+
+ if ((i / rows + 1) > (cols - n % cols))
+ rows = n / cols + 1;
+ ch = rows ? m->w.height / rows : m->w.height;
+ cx = m->w.x + cn * cw;
+ cy = m->w.y + rn * ch;
+ resize(c, cx, cy, cw, ch, 0);
+ rn++;
+ if (rn >= rows) {
+ rn = 0;
+ cn++;
+ }
+ i++;
+ }
+}
+
void
incnmaster(const Arg *arg)
{
From fc45fd2adeec56f9a2a7287db8b9f74f7c9ff38b Mon Sep 17 00:00:00 2001
From: Vladislav Nepogodin <nepogodin.vlad@gmail.com>
Date: Tue, 27 Jul 2021 22:50:29 +0400
Subject: [PATCH 2/2] Cleanup
---
dwl.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/dwl.c b/dwl.c
index d3a5d651..f9f8b42c 100644
--- a/dwl.c
+++ b/dwl.c
@@ -1168,7 +1168,8 @@ focustop(Monitor *m)
}
void
-gaplessgrid(Monitor *m) {
+gaplessgrid(Monitor *m)
+{
unsigned int n = 0, i = 0, ch, cw, cn, rn, rows, cols;
Client *c;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment