2008/5/21, Premysl Hruby <[EMAIL PROTECTED]>:
> tagmask can be #define:
>
>  #define TAGMASK ((int)(1LL << (LENGTH(tags) + 1) - 1))
Thanks! Here's the updated patch

-- 
http://www.gnuffy.org - Real Community Distro
http://www.gnuffy.org/index.php/GnuEm - Gnuffy on Ipaq (Codename Peggy)
diff -r cd9fd0986555 config.def.h
--- a/config.def.h      Mon May 19 20:29:57 2008 +0100
+++ b/config.def.h      Wed May 21 11:23:38 2008 +0200
@@ -19,6 +19,7 @@
 Rule rules[] = {
        /* class      instance    title       tags ref      isfloating */
        { "Gimp",     NULL,       NULL,       NULL,         True },
+       { "Firefox",  NULL,       NULL,       1 << 8,       True },
 };
 
 /* layout(s) */
diff -r cd9fd0986555 dwm.c
--- a/dwm.c     Mon May 19 20:29:57 2008 +0100
+++ b/dwm.c     Wed May 21 11:23:38 2008 +0200
@@ -27,6 +27,7 @@
 #include <locale.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <limits.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -51,6 +52,7 @@
 #define LENGTH(x)       (sizeof x / sizeof x[0])
 #define MAXTAGLEN       16
 #define MOUSEMASK       (BUTTONMASK|PointerMotionMask)
+#define TAGMASK         ((int)(1LL << (LENGTH(tags) + 1) - 1))
 
 /* enums */
 enum { CurNormal, CurResize, CurMove, CurLast };        /* cursor */
@@ -68,7 +70,7 @@
        long flags;
        unsigned int bw, oldbw;
        Bool isbanned, isfixed, isfloating, isurgent;
-       Bool *tags;
+       unsigned int tags;
        Client *next;
        Client *prev;
        Client *snext;
@@ -107,7 +109,7 @@
        const char *class;
        const char *instance;
        const char *title;
-       const char *tag;
+       unsigned int tags;
        Bool isfloating;
 } Rule;
 
@@ -198,7 +200,7 @@
 int screen, sx, sy, sw, sh;
 int bx, by, bw, bh, blw, wx, wy, ww, wh;
 int mx, my, mw, mh, tx, ty, tw, th;
-int seltags = 0;
+unsigned int seltags = 0;
 int (*xerrorxlib)(Display *, XErrorEvent *);
 unsigned int numlockmask = 0;
 void (*handler[LASTEvent]) (XEvent *) = {
@@ -218,7 +220,7 @@
 Atom wmatom[WMLast], netatom[NetLast];
 Bool otherwm, readin;
 Bool running = True;
-Bool *tagset[2];
+unsigned int tagset[] = {1, 1}; /* after start, first tag is selected */
 Client *clients = NULL;
 Client *sel = NULL;
 Client *stack = NULL;
@@ -231,14 +233,12 @@
 
 /* configuration, allows nested code to access above variables */
 #include "config.h"
-#define TAGSZ (LENGTH(tags) * sizeof(Bool))
 
 /* function implementations */
 
 void
 applyrules(Client *c) {
        unsigned int i;
-       Bool matched = False;
        Rule *r;
        XClassHint ch = { 0 };
 
@@ -250,18 +250,15 @@
                && (!r->class || (ch.res_class && strstr(ch.res_class, 
r->class)))
                && (!r->instance || (ch.res_name && strstr(ch.res_name, 
r->instance)))) {
                        c->isfloating = r->isfloating;
-                       if(r->tag) {
-                               c->tags[idxoftag(r->tag)] = True;
-                               matched = True;
-                       }
+                       c->tags |= r->tags & TAGMASK;
                }
        }
        if(ch.res_class)
                XFree(ch.res_class);
        if(ch.res_name)
                XFree(ch.res_name);
-       if(!matched)
-               memcpy(c->tags, tagset[seltags], TAGSZ);
+       if(!c->tags)
+               c->tags = tagset[seltags];
 }
 
 void
@@ -313,7 +310,7 @@
 
        if(ev->window == barwin) {
                x = 0;
-               for(i = 0; i < LENGTH(tags); i++) {
+               for(i = 0; i < LENGTH(tags) && i < sizeof(int) * CHAR_BIT; i++) 
{
                        x += textw(tags[i]);
                        if(ev->x < x) {
                                if(ev->button == Button1) {
@@ -499,15 +496,15 @@
 
        dc.x = 0;
        for(c = stack; c && !isvisible(c); c = c->snext);
-       for(i = 0; i < LENGTH(tags); i++) {
+       for(i = 0; i < LENGTH(tags) && i < sizeof(int) * CHAR_BIT; i++) {
                dc.w = textw(tags[i]);
-               if(tagset[seltags][i]) {
+               if(tagset[seltags] & 1 << i) {
                        drawtext(tags[i], dc.sel, isurgent(i));
-                       drawsquare(c && c->tags[i], isoccupied(i), isurgent(i), 
dc.sel);
+                       drawsquare(c && c->tags & 1 << i, isoccupied(i), 
isurgent(i), dc.sel);
                }
                else {
                        drawtext(tags[i], dc.norm, isurgent(i));
-                       drawsquare(c && c->tags[i], isoccupied(i), isurgent(i), 
dc.norm);
+                       drawsquare(c && c->tags & 1 << i, isoccupied(i), 
isurgent(i), dc.norm);
                }
                dc.x += dc.w;
        }
@@ -861,7 +858,7 @@
        Client *c;
 
        for(c = clients; c; c = c->next)
-               if(c->tags[t])
+               if(c->tags & 1 << t)
                        return True;
        return False;
 }
@@ -886,19 +883,14 @@
        Client *c;
 
        for(c = clients; c; c = c->next)
-               if(c->isurgent && c->tags[t])
+               if(c->isurgent && c->tags & 1 << t)
                        return True;
        return False;
 }
 
 Bool
 isvisible(Client *c) {
-       unsigned int i;
-
-       for(i = 0; i < LENGTH(tags); i++)
-               if(c->tags[i] && tagset[seltags][i])
-                       return True;
-       return False;
+       return c->tags & tagset[seltags];
 }
 
 void
@@ -945,7 +937,6 @@
        XWindowChanges wc;
 
        c = emallocz(sizeof(Client));
-       c->tags = emallocz(TAGSZ);
        c->win = w;
 
        /* geometry */
@@ -980,7 +971,7 @@
        if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success))
                for(t = clients; t && t->win != trans; t = t->next);
        if(t)
-               memcpy(c->tags, t->tags, TAGSZ);
+               c->tags = t->tags;
        else
                applyrules(c);
        if(!c->isfloating)
@@ -1396,11 +1387,6 @@
        if(!dc.font.set)
                XSetFont(dpy, dc.gc, dc.font.xfont->fid);
 
-       /* init tags */
-       tagset[0] = emallocz(TAGSZ);
-       tagset[1] = emallocz(TAGSZ);
-       tagset[0][0] = tagset[1][0] = True;
-
        /* init bar */
        for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
                w = textw(layouts[i].symbol);
@@ -1460,14 +1446,11 @@
 
 void
 tag(const char *arg) {
-       unsigned int i;
-
        if(!sel)
                return;
-       for(i = 0; i < LENGTH(tags); i++)
-               sel->tags[i] = (arg == NULL);
-       sel->tags[idxoftag(arg)] = True;
+       sel->tags = arg ? 1 << MIN(idxoftag(arg), sizeof(int) * CHAR_BIT - 1) & 
TAGMASK : TAGMASK;
        arrange();
+
 }
 
 unsigned int
@@ -1575,27 +1558,25 @@
 
 void
 toggletag(const char *arg) {
-       unsigned int i, j;
+       int i;
 
        if(!sel)
                return;
        i = idxoftag(arg);
-       sel->tags[i] = !sel->tags[i];
-       for(j = 0; j < LENGTH(tags) && !sel->tags[j]; j++);
-       if(j == LENGTH(tags))
-               sel->tags[i] = True; /* at least one tag must be enabled */
+       if(sel->tags ^ 1 << i)
+               sel->tags ^= 1 << i;
        arrange();
 }
 
 void
 toggleview(const char *arg) {
-       unsigned int i, j;
+       int i;
 
+       if(!sel)
+               return;
        i = idxoftag(arg);
-       tagset[seltags][i] = !tagset[seltags][i];
-       for(j = 0; j < LENGTH(tags) && !tagset[seltags][j]; j++);
-       if(j == LENGTH(tags))
-               tagset[seltags][i] = True; /* at least one tag must be viewed */
+       if(sel->tags ^ 1 << i)
+               sel->tags ^= 1 << i;
        arrange();
 }
 
@@ -1622,7 +1603,6 @@
                focus(NULL);
        XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
        setclientstate(c, WithdrawnState);
-       free(c->tags);
        free(c);
        XSync(dpy, False);
        XSetErrorHandler(xerror);
@@ -1771,8 +1751,7 @@
 void
 view(const char *arg) {
        seltags ^= 1; /* toggle sel tagset */
-       memset(tagset[seltags], (NULL == arg), TAGSZ);
-       tagset[seltags][idxoftag(arg)] = True;
+       tagset[seltags] = arg ? 1 << MIN(idxoftag(arg), sizeof(int) * CHAR_BIT 
- 1) & TAGMASK : TAGMASK;
        arrange();
 }
 

Reply via email to