Hi all,

Attached is the grid mode patch for dwm 4.3
As always :-) many thanks to Jukka Salmi for his valuable and
much appreciated suggestions.

Cheers,
Alex
diff -Naur --exclude='.hg*' dwm-tip/config.default.h 
dwm-gridmode/config.default.h
--- dwm-tip/config.default.h    2007-07-15 11:52:46.000000000 +0300
+++ dwm-gridmode/config.default.h       2007-07-15 12:05:26.000000000 +0300
@@ -30,6 +30,7 @@
        /* symbol               function */ \
        { "[]=",                tile }, /* first entry is default */ \
        { "><>",                floating }, \
+       { "+++",                grid }, \
 };
 #define MASTERWIDTH            600             /* master width per thousand */
 #define NMASTER                        1               /* clients in master 
area */
diff -Naur --exclude='.hg*' dwm-tip/layout.c dwm-gridmode/layout.c
--- dwm-tip/layout.c    2007-07-15 11:52:46.000000000 +0300
+++ dwm-gridmode/layout.c       2007-07-15 12:37:28.000000000 +0300
@@ -12,6 +12,44 @@
 static unsigned int nmaster = NMASTER;
 
 static void
+grid(void) {
+       unsigned int i, n, cx, cy, cw, ch, aw, ah, cols, rows;
+       Client *c;
+
+       for(n = 0, c = nexttiled(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 = wah / (rows ? rows : 1);
+       cw = waw / (cols ? cols : 1);
+
+       for(i = 0, c = clients; c; c = c->next)
+               if(isvisible(c)) {
+                       unban(c);
+                       if(c->isfloating)
+                               continue;
+                       c->ismax = False;
+                       cx = (i / rows) * cw;
+                       cy = (i % rows) * ch + (bpos == BarTop ? bh : 0); // 
bh? adjust
+                       /* adjust height/width of last row/column's windows */ 
+                       ah = ((i + 1) % rows == 0) ? wah - ch * rows : 0;
+                       aw = (i >= rows * (cols - 1)) ? waw - cw * cols : 0;
+                       resize(c, cx, cy, cw - 2 * c->border + aw, ch - 2 * 
c->border + ah, False);
+                       i++;
+               }
+               else
+            ban(c);
+       focus(NULL);
+       restack();
+}
+
+static void
 tile(void) {
        unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
        Client *c;

Reply via email to