JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
applied Gottox' ClkTagBar patch
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index fcdab10..a5a9de2 100644 (file)
--- a/dwm.c
+++ b/dwm.c
 #define MOUSEMASK       (BUTTONMASK|PointerMotionMask)
 #define TAGMASK         ((int)((1LL << LENGTH(tags)) - 1))
 #define TEXTW(x)        (textnw(x, strlen(x)) + dc.font.height)
+#define ISVISIBLE(x)    (x->tags & tagset[seltags])
 
 /* enums */
 enum { CurNormal, CurResize, CurMove, CurLast };        /* cursor */
 enum { ColBorder, ColFG, ColBG, ColLast };              /* color */
 enum { NetSupported, NetWMName, NetLast };              /* EWMH atoms */
 enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */
-enum { ClkLtSymbol = 64, ClkStatusText, ClkWinTitle,
+enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
        ClkClientWin, ClkRootWin, ClkLast };             /* clicks */
 
 /* typedefs */
@@ -89,7 +90,7 @@ struct Client {
        int basew, baseh, incw, inch, maxw, maxh, minw, minh;
        int bw, oldbw;
        uint tags;
-       Bool isbanned, isfixed, isfloating, isurgent;
+       Bool isfixed, isfloating, isurgent;
        Client *next;
        Client *snext;
        Window win;
@@ -273,14 +274,13 @@ arrange(void) {
        Client *c;
 
        for(c = clients; c; c = c->next)
-               if(c->tags & tagset[seltags]) { /* is visible */
-                       c->isbanned = False;
+               if(ISVISIBLE(c)) {
+                       XMoveWindow(dpy, c->win, c->x, c->y);
                        if(!lt[sellt]->arrange || c->isfloating)
                                resize(c, c->x, c->y, c->w, c->h, True);
                }
-               else if(!c->isbanned) {
+               else {
                        XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
-                       c->isbanned = True;
                }
 
        focus(NULL);
@@ -304,17 +304,18 @@ attachstack(Client *c) {
 void
 buttonpress(XEvent *e) {
        uint i, x, click;
+       Arg arg = {0};
        Client *c;
        XButtonPressedEvent *ev = &e->xbutton;
 
        click = ClkRootWin;
        if(ev->window == barwin) {
-               i = x = 0;
-               do
+               for(i = x = 0; ev->x >= x && ++i < LENGTH(tags); i++)
                        x += TEXTW(tags[i]);
-               while(ev->x >= x && ++i < LENGTH(tags));
-               if(i < LENGTH(tags))
-                       click = i;
+               if(i < LENGTH(tags)) {
+                       click = ClkTagBar;
+                       arg.ui = 1 << i;
+               }
                else if(ev->x < x + blw)
                        click = ClkLtSymbol;
                else if(ev->x > wx + ww - TEXTW(stext))
@@ -330,7 +331,7 @@ buttonpress(XEvent *e) {
        for(i = 0; i < LENGTH(buttons); i++)
                if(click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
                   && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
-                       buttons[i].func(&buttons[i].arg);
+                       buttons[i].func(click == ClkTagBar ? &arg : &buttons[i].arg);
 }
 
 void
@@ -428,7 +429,7 @@ configurerequest(XEvent *e) {
                                c->y = sy + (sh / 2 - c->h / 2); /* center in y direction */
                        if((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight)))
                                configure(c);
-                       if(!c->isbanned)
+                       if(ISVISIBLE(c))
                                XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
                }
                else
@@ -605,8 +606,8 @@ expose(XEvent *e) {
 
 void
 focus(Client *c) {
-       if(!c || c->isbanned)
-               for(c = stack; c && c->isbanned; c = c->snext);
+       if(!c || !ISVISIBLE(c))
+               for(c = stack; c && !ISVISIBLE(c); c = c->snext);
        if(sel && sel != c) {
                grabbuttons(sel, False);
                XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]);
@@ -639,17 +640,17 @@ focusstack(const Arg *arg) {
        if(!sel)
                return;
        if (arg->i > 0) {
-               for(c = sel->next; c && c->isbanned; c = c->next);
+               for(c = sel->next; c && !ISVISIBLE(c); c = c->next);
                if(!c)
-                       for(c = clients; c && c->isbanned; c = c->next);
+                       for(c = clients; c && !ISVISIBLE(c); c = c->next);
        }
        else {
                for(i = clients; i != sel; i = i->next)
-                       if (!i->isbanned)
+                       if(ISVISIBLE(i))
                                c = i;
                if(!c)
                        for(; i; i = i->next)
-                               if (!i->isbanned)
+                               if(ISVISIBLE(i))
                                        c = i;
        }
        if(c) {
@@ -1018,7 +1019,7 @@ movemouse(const Arg *arg) {
 
 Client *
 nexttiled(Client *c) {
-       for(; c && (c->isfloating || c->isbanned); c = c->next);
+       for(; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);
        return c;
 }
 
@@ -1113,7 +1114,7 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
                h = bh;
        if(w < bh)
                w = bh;
-       if(!c->isbanned || c->x != x || c->y != y || c->w != w || c->h != h) {
+       if(c->x != x || c->y != y || c->w != w || c->h != h) {
                c->x = wc.x = x;
                c->y = wc.y = y;
                c->w = wc.width = w;
@@ -1189,7 +1190,7 @@ restack(void) {
                wc.stack_mode = Below;
                wc.sibling = barwin;
                for(c = stack; c; c = c->snext)
-                       if(!c->isfloating && !c->isbanned) {
+                       if(!c->isfloating && ISVISIBLE(c)) {
                                XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
                                wc.sibling = c->win;
                        }
@@ -1295,8 +1296,9 @@ setclientstate(Client *c, long state) {
 
 void
 setlayout(const Arg *arg) {
-       sellt ^= 1;
-       if(arg && arg->v && arg->v != lt[sellt])
+       if(!arg || !arg->v || arg->v != lt[sellt])
+               sellt ^= 1;
+       if(arg && arg->v)
                lt[sellt] = (Layout *)arg->v;
        if(sel)
                arrange();