> On 15 June 2010 18:04, v4hn <m...@v4hn.de> wrote:
> > dwm-5.8.2 $ cat ../dwm-5.8.2-bstack.diff \
> >                ../dwm-5.8.2-fibonacci.diff \
> >                ../dwm-5.8.2-gridmode.diff \
> >                ../dwm-5.8.2-monocle_count.diff \
> >                ../dwm-5.8.2-pertag_without_bar.diff | patch -p1
> >
> > Last but not least in my current setup I see no point of
> > one showbar flag for each tag, while I really like pertag.
> > So I hacked pertag, to keep one boolean showbar,
> > while layout and mfact are stored per tag.

Two more things:

- The pertag-patch for 5.8.2 contains a bug concerning adding
monitors after setup() - lts for that monitor will not be initialized
properly resulting in a segfault.
patch is attached.(with and without bar per tag)

- Since there are Monitor structs the exact definition of Monitor using pertag
requires knowledge about the number of tags(for there is an array
of LENGTH(tags)+1 layouts in there).
Because tags is defined in config.h, the definition of struct Monitor had to be
moved below `#include "config.h"` - this is ugly, but I can't see
any way around this.
Problem is, it became a habit for layout-patches to add an include above the
array of layouts, like:

> +#include "bstack.c"
> static const Layout layouts[] = {

But since layout algorithms dereference a Monitor pointer, the exact
definition of Monitor has to be given before, else compilation fails.

Are there any ideas on how to resolve this cyclic dependency?
It would be nice to have a unified way of writing layout patches imho.


v4hn
diff -U3 dwm-5.8.2/dwm.c dwm-5.8.2-pertag/dwm.c
--- dwm-5.8.2/dwm.c     2010-06-04 12:39:15.000000000 +0200
+++ dwm-5.8.2-pertag/dwm.c      2010-06-16 10:32:20.000000000 +0200
@@ -122,26 +122,6 @@
        void (*arrange)(Monitor *);
 } Layout;
 
-struct Monitor {
-       char ltsymbol[16];
-       float mfact;
-       int num;
-       int by;               /* bar geometry */
-       int mx, my, mw, mh;   /* screen size */
-       int wx, wy, ww, wh;   /* window area  */
-       unsigned int seltags;
-       unsigned int sellt;
-       unsigned int tagset[2];
-       Bool showbar;
-       Bool topbar;
-       Client *clients;
-       Client *sel;
-       Client *stack;
-       Monitor *next;
-       Window barwin;
-       const Layout *lt[2];
-};
-
 typedef struct {
        const char *class;
        const char *instance;
@@ -278,6 +258,31 @@
 /* configuration, allows nested code to access above variables */
 #include "config.h"
 
+struct Monitor {
+       char ltsymbol[16];
+       float mfact;
+       int num;
+       int by;               /* bar geometry */
+       int mx, my, mw, mh;   /* screen size */
+       int wx, wy, ww, wh;   /* window area  */
+       unsigned int seltags;
+       unsigned int sellt;
+       unsigned int tagset[2];
+       Bool showbar;
+       Bool topbar;
+       Client *clients;
+       Client *sel;
+       Client *stack;
+       Monitor *next;
+       Window barwin;
+       const Layout *lt[2];
+       int curtag;
+       int prevtag;
+       const Layout *lts[LENGTH(tags) + 1];
+       double mfacts[LENGTH(tags) + 1];
+       Bool showbars[LENGTH(tags) + 1];
+};
+
 /* compile-time check if all tags fit into an unsigned int bit array. */
 struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
 
@@ -611,15 +616,30 @@
 Monitor *
 createmon(void) {
        Monitor *m;
+       unsigned int i;
 
        if(!(m = (Monitor *)calloc(1, sizeof(Monitor))))
                die("fatal: could not malloc() %u bytes\n", sizeof(Monitor));
        m->tagset[0] = m->tagset[1] = 1;
+       /* init mfacts */
        m->mfact = mfact;
+       for(i=0; i < LENGTH(tags) + 1 ; i++) {
+               m->mfacts[i] = m->mfact;
+       }
+       /* init bars */
        m->showbar = showbar;
+       for(i=0; i < LENGTH(tags) + 1; i++) {
+               m->showbars[i] = m->showbar;
+       }
        m->topbar = topbar;
+       /* init layouts */
        m->lt[0] = &layouts[0];
        m->lt[1] = &layouts[1 % LENGTH(layouts)];
+       for(i=0; i < LENGTH(tags) + 1; i++) {
+               m->lts[i] = &layouts[0];
+       }
+       
+       m->curtag = m->prevtag = 1;
        strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
        return m;
 }
@@ -1494,7 +1514,7 @@
        if(!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
                selmon->sellt ^= 1;
        if(arg && arg->v)
-               selmon->lt[selmon->sellt] = (Layout *)arg->v;
+               selmon->lt[selmon->sellt] = selmon->lts[selmon->curtag] = 
(Layout *)arg->v;
        strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof 
selmon->ltsymbol);
        if(selmon->sel)
                arrange(selmon);
@@ -1512,7 +1532,7 @@
        f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
        if(f < 0.1 || f > 0.9)
                return;
-       selmon->mfact = f;
+       selmon->mfact = selmon->mfacts[selmon->curtag] = f;
        arrange(selmon);
 }
 
@@ -1666,7 +1686,7 @@
 
 void
 togglebar(const Arg *arg) {
-       selmon->showbar = !selmon->showbar;
+       selmon->showbar = selmon->showbars[selmon->curtag] = !selmon->showbar;
        updatebarpos(selmon);
        XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, 
selmon->ww, bh);
        arrange(selmon);
@@ -1686,12 +1706,27 @@
 void
 toggletag(const Arg *arg) {
        unsigned int newtags;
+       unsigned int i;
 
        if(!selmon->sel)
                return;
        newtags = selmon->sel->tags ^ (arg->ui & TAGMASK);
        if(newtags) {
                selmon->sel->tags = newtags;
+               if(newtags == ~0) {
+                       selmon->prevtag = selmon->curtag;
+                       selmon->curtag = 0;
+               }
+               if(!(newtags & 1 << (selmon->curtag - 1))) {
+                       selmon->prevtag = selmon->curtag;
+                       for (i=0; !(newtags & 1 << i); i++);
+                       selmon->curtag = i + 1;
+               }
+               selmon->sel->tags = newtags;
+               selmon->lt[selmon->sellt] = selmon->lts[selmon->curtag];
+               selmon->mfact = selmon->mfacts[selmon->curtag];
+               if (selmon->showbar != selmon->showbars[selmon->curtag])
+                       togglebar(NULL);
                arrange(selmon);
        }
 }
@@ -1959,11 +1994,29 @@
 
 void
 view(const Arg *arg) {
+       unsigned int i;
+
        if((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
                return;
        selmon->seltags ^= 1; /* toggle sel tagset */
-       if(arg->ui & TAGMASK)
+       if(arg->ui & TAGMASK) {
                selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
+               selmon->prevtag = selmon->curtag;
+               if(arg->ui == ~0)
+                       selmon->curtag = 0;
+               else {
+                       for (i=0; !(arg->ui & 1 << i); i++);
+                       selmon->curtag = i + 1;
+               }
+       } else {
+               selmon->prevtag= selmon->curtag ^ selmon->prevtag;
+               selmon->curtag^= selmon->prevtag;
+               selmon->prevtag= selmon->curtag ^ selmon->prevtag;
+       }
+       selmon->lt[selmon->sellt]= selmon->lts[selmon->curtag];
+       selmon->mfact = selmon->mfacts[selmon->curtag];
+       if(selmon->showbar != selmon->showbars[selmon->curtag])
+               togglebar(NULL);
        arrange(selmon);
 }
 
diff -rU3 dwm-5.8.2/dwm.c dwm-5.8.2-pertag_without_bar_fixed_multihead/dwm.c
--- dwm-5.8.2/dwm.c     2010-06-04 12:39:15.000000000 +0200
+++ dwm-5.8.2-pertag_without_bar_fixed_multihead/dwm.c  2010-06-16 
11:25:59.000000000 +0200
@@ -122,26 +122,6 @@
        void (*arrange)(Monitor *);
 } Layout;
 
-struct Monitor {
-       char ltsymbol[16];
-       float mfact;
-       int num;
-       int by;               /* bar geometry */
-       int mx, my, mw, mh;   /* screen size */
-       int wx, wy, ww, wh;   /* window area  */
-       unsigned int seltags;
-       unsigned int sellt;
-       unsigned int tagset[2];
-       Bool showbar;
-       Bool topbar;
-       Client *clients;
-       Client *sel;
-       Client *stack;
-       Monitor *next;
-       Window barwin;
-       const Layout *lt[2];
-};
-
 typedef struct {
        const char *class;
        const char *instance;
@@ -278,6 +258,30 @@
 /* configuration, allows nested code to access above variables */
 #include "config.h"
 
+struct Monitor {
+       char ltsymbol[16];
+       float mfact;
+       int num;
+       int by;               /* bar geometry */
+       int mx, my, mw, mh;   /* screen size */
+       int wx, wy, ww, wh;   /* window area  */
+       unsigned int seltags;
+       unsigned int sellt;
+       unsigned int tagset[2];
+       Bool showbar;
+       Bool topbar;
+       Client *clients;
+       Client *sel;
+       Client *stack;
+       Monitor *next;
+       Window barwin;
+       const Layout *lt[2];
+       int curtag;
+       int prevtag;
+       const Layout *lts[LENGTH(tags) + 1];
+       double mfacts[LENGTH(tags) + 1];
+};
+
 /* compile-time check if all tags fit into an unsigned int bit array. */
 struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
 
@@ -611,15 +615,27 @@
 Monitor *
 createmon(void) {
        Monitor *m;
+       unsigned int i;
 
        if(!(m = (Monitor *)calloc(1, sizeof(Monitor))))
                die("fatal: could not malloc() %u bytes\n", sizeof(Monitor));
        m->tagset[0] = m->tagset[1] = 1;
+       /* init mfacts */
        m->mfact = mfact;
+       for(i=0; i < LENGTH(tags) + 1 ; i++) {
+               m->mfacts[i] = m->mfact;
+       }
+       /* init bars */
        m->showbar = showbar;
        m->topbar = topbar;
+       /* init layouts */
        m->lt[0] = &layouts[0];
        m->lt[1] = &layouts[1 % LENGTH(layouts)];
+       for(i=0; i < LENGTH(tags) + 1; i++) {
+               m->lts[i] = &layouts[0];
+       }
+       
+       m->curtag = m->prevtag = 1;
        strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
        return m;
 }
@@ -1494,7 +1510,7 @@
        if(!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
                selmon->sellt ^= 1;
        if(arg && arg->v)
-               selmon->lt[selmon->sellt] = (Layout *)arg->v;
+               selmon->lt[selmon->sellt] = selmon->lts[selmon->curtag] = 
(Layout *)arg->v;
        strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof 
selmon->ltsymbol);
        if(selmon->sel)
                arrange(selmon);
@@ -1512,7 +1528,7 @@
        f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
        if(f < 0.1 || f > 0.9)
                return;
-       selmon->mfact = f;
+       selmon->mfact = selmon->mfacts[selmon->curtag] = f;
        arrange(selmon);
 }
 
@@ -1686,12 +1702,25 @@
 void
 toggletag(const Arg *arg) {
        unsigned int newtags;
+       unsigned int i;
 
        if(!selmon->sel)
                return;
        newtags = selmon->sel->tags ^ (arg->ui & TAGMASK);
        if(newtags) {
                selmon->sel->tags = newtags;
+               if(newtags == ~0) {
+                       selmon->prevtag = selmon->curtag;
+                       selmon->curtag = 0;
+               }
+               if(!(newtags & 1 << (selmon->curtag - 1))) {
+                       selmon->prevtag = selmon->curtag;
+                       for (i=0; !(newtags & 1 << i); i++);
+                       selmon->curtag = i + 1;
+               }
+               selmon->sel->tags = newtags;
+               selmon->lt[selmon->sellt] = selmon->lts[selmon->curtag];
+               selmon->mfact = selmon->mfacts[selmon->curtag];
                arrange(selmon);
        }
 }
@@ -1959,11 +1988,27 @@
 
 void
 view(const Arg *arg) {
+       unsigned int i;
+
        if((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
                return;
        selmon->seltags ^= 1; /* toggle sel tagset */
-       if(arg->ui & TAGMASK)
+       if(arg->ui & TAGMASK) {
                selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
+               selmon->prevtag = selmon->curtag;
+               if(arg->ui == ~0)
+                       selmon->curtag = 0;
+               else {
+                       for (i=0; !(arg->ui & 1 << i); i++);
+                       selmon->curtag = i + 1;
+               }
+       } else {
+               selmon->prevtag= selmon->curtag ^ selmon->prevtag;
+               selmon->curtag^= selmon->prevtag;
+               selmon->prevtag= selmon->curtag ^ selmon->prevtag;
+       }
+       selmon->lt[selmon->sellt]= selmon->lts[selmon->curtag];
+       selmon->mfact = selmon->mfacts[selmon->curtag];
        arrange(selmon);
 }
 

Attachment: pgpKrCk18H6s0.pgp
Description: PGP signature

Reply via email to