Hi all,

Attached is the grid mode patch updated for for dwm-3.5
The only enhancement is that it honours TOPBAR setting.

Cheers,
Alex
diff -Naur --exclude='.hg*' dwm-tip/config.default.h 
dwm-gridmode/config.default.h
--- dwm-tip/config.default.h    2007-02-14 12:55:38.000000000 +0200
+++ dwm-gridmode/config.default.h       2007-02-14 13:07:01.000000000 +0200
@@ -9,6 +9,7 @@
 #define DEFMODE                        dotile          /* dofloat */
 #define FLOATSYMBOL            "><>"
 #define TILESYMBOL             "[]="
+#define GRIDSYMBOL             "[-]"
 
 #define FONT                   "-*-fixed-medium-r-normal-*-13-*-*-*-*-*-*-*"
 #define NORMBORDERCOLOR                "#dddddd"
diff -Naur --exclude='.hg*' dwm-tip/draw.c dwm-gridmode/draw.c
--- dwm-tip/draw.c      2007-02-05 18:31:44.000000000 +0200
+++ dwm-gridmode/draw.c 2007-02-14 13:07:20.000000000 +0200
@@ -101,7 +101,7 @@
                dc.x += dc.w;
        }
        dc.w = bmw;
-       drawtext(arrange == dofloat ? FLOATSYMBOL : TILESYMBOL, dc.norm, False, 
False);
+       drawtext(arrange == dofloat ? FLOATSYMBOL : (arrange == dogrid ? 
GRIDSYMBOL : TILESYMBOL), dc.norm, False, False);
        x = dc.x + dc.w;
        dc.w = textw(stext);
        dc.x = sw - dc.w;
diff -Naur --exclude='.hg*' dwm-tip/dwm.h dwm-gridmode/dwm.h
--- dwm-tip/dwm.h       2007-02-07 17:34:08.000000000 +0200
+++ dwm-gridmode/dwm.h  2007-02-14 13:07:32.000000000 +0200
@@ -142,6 +142,7 @@
 extern void detach(Client *c);                 /* detaches c from global 
client list */
 extern void dofloat(void);                     /* arranges all windows 
floating */
 extern void dotile(void);                      /* arranges all windows tiled */
+extern void dogrid(void);                      /* arranges all windows in a 
grid */
 extern void focusnext(Arg *arg);               /* focuses next visible client, 
arg is ignored  */
 extern void focusprev(Arg *arg);               /* focuses previous visible 
client, arg is ignored */
 extern void incnmaster(Arg *arg);              /* increments nmaster with 
arg's index value */
diff -Naur --exclude='.hg*' dwm-tip/view.c dwm-gridmode/view.c
--- dwm-tip/view.c      2007-02-14 12:55:38.000000000 +0200
+++ dwm-gridmode/view.c 2007-02-14 13:08:39.000000000 +0200
@@ -117,6 +117,47 @@
 }
 
 void
+dogrid(void) {
+       unsigned int i, n, tw, th, cols, rows;
+       Client *c;
+
+       for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
+               n++;
+
+       for(rows = 0; rows <= n/2; rows++)
+               if(rows*rows >= n)
+                       break;
+    cols = (rows && (rows - 1) * rows >= n) ? rows - 1 : rows;
+
+       if (n > 0) {
+               th = (sh - dc.h) / rows;
+               tw = sw / cols;
+       }
+
+       for(i = 0, c = clients; c; c = c->next)
+               if(isvisible(c)) {
+                       if(c->isfloat) {
+                               resize(c, True);
+                               continue;
+                       }
+                       c->ismax = False;
+                       c->x = (i / rows) * tw;
+                       c->y = (i % rows) * th + (TOPBAR ? dc.h : 0);
+                       c->w = tw - 2 * BORDERPX;
+                       c->h = th - 2 * BORDERPX;
+                       resize(c, False);
+                       i++;
+               }
+               else
+                       XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
+       if(!sel || !isvisible(sel)) {
+               for(c = stack; c && !isvisible(c); c = c->snext);
+               focus(c);
+       }
+       restack();
+}
+
+void
 focusnext(Arg *arg) {
        Client *c;
    
@@ -214,7 +255,8 @@
 
 void
 togglemode(Arg *arg) {
-       arrange = (arrange == dofloat) ? dotile : dofloat;
+       arrange = (arrange == dofloat) ? 
+               dotile : (arrange == dotile) ? dogrid : dofloat;
        if(sel)
                arrange();
        else

Reply via email to