Hi all,

Thanks to the very good advices I received from Jukka Salmi a most annoying 
bug has been fixed (about changing views while in grid mode), and also the 
patch is now smaller by 11 SLOC (has only 44 SLOC).

The new patch is attached.

Cheers,
Alex
diff -Naur --exclude='.hg*' dwm-tip/config.default.h 
dwm-tip-gridmode/config.default.h
--- dwm-tip/config.default.h    2007-01-31 00:12:46.000000000 +0200
+++ dwm-tip-gridmode/config.default.h   2007-02-05 10:37:38.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-tip-gridmode/draw.c
--- dwm-tip/draw.c      2007-01-31 00:12:46.000000000 +0200
+++ dwm-tip-gridmode/draw.c     2007-02-05 10:38:14.000000000 +0200
@@ -111,7 +111,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-tip-gridmode/dwm.h
--- dwm-tip/dwm.h       2007-02-02 12:47:36.000000000 +0200
+++ dwm-tip-gridmode/dwm.h      2007-02-05 10:38:52.000000000 +0200
@@ -144,6 +144,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-tip-gridmode/view.c
--- dwm-tip/view.c      2007-02-02 12:49:14.000000000 +0200
+++ dwm-tip-gridmode/view.c     2007-02-05 10:41:31.000000000 +0200
@@ -118,6 +118,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 - 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 + dc.h;
+                       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;
    
@@ -216,6 +257,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