JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
added client number printing right of layout symbol
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index b089fe9..d71bb58 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -66,7 +66,7 @@ typedef union {
        int i;
        unsigned int ui;
        float f;
-       void *v;
+       const void *v;
 } Arg;
 
 typedef struct {
@@ -123,7 +123,7 @@ typedef struct {
 struct Monitor {
        int screen_number;
        float mfact;
-       int by, btx;          /* bar geometry */
+       int by;               /* bar geometry */
        int mx, my, mw, mh;   /* screen size */
        int wx, wy, ww, wh;   /* window area  */
        unsigned int seltags;
@@ -136,7 +136,7 @@ struct Monitor {
        Client *stack;
        Monitor *next;
        Window barwin;
-       Layout *lt[2];
+       const Layout *lt[2];
 };
 
 typedef struct {
@@ -236,7 +236,7 @@ static int xerrorstart(Display *dpy, XErrorEvent *ee);
 static void zoom(const Arg *arg);
 
 /* variables */
-static char stext[256];
+static char stext[256], ntext[8];
 static int screen;
 static int sw, sh;           /* X display screen geometry x, y, width, height */
 static int bh, blw = 0;      /* bar geometry */
@@ -275,7 +275,7 @@ struct NumTags { char limitexceeded[sizeof(unsigned int) * 8 < LENGTH(tags) ? -1
 void
 applyrules(Client *c) {
        unsigned int i;
-       Rule *r;
+       const Rule *r;
        XClassHint ch = { 0 };
 
        /* rule matching */
@@ -409,9 +409,8 @@ buttonpress(XEvent *e) {
                selmon = m;
                focus(NULL);
        }
-       if(ev->window == selmon->barwin && ev->x >= selmon->btx) {
-               i = 0;
-               x = selmon->btx;
+       if(ev->window == selmon->barwin) {
+               i = x = 0;
                do
                        x += TEXTW(tags[i]);
                while(ev->x >= x && ++i < LENGTH(tags));
@@ -642,22 +641,18 @@ dirtomon(int dir) {
 void
 drawbar(Monitor *m) {
        int x;
-       unsigned int i, occ = 0, urg = 0;
+       unsigned int i, n = 0, occ = 0, urg = 0;
        unsigned long *col;
        Client *c;
 
        for(c = m->clients; c; c = c->next) {
+               if(ISVISIBLE(c))
+                       n++;
                occ |= c->tags;
                if(c->isurgent)
                        urg |= c->tags;
        }
        dc.x = 0;
-       if(mons->next) { /* more than a single monitor */
-               dc.w = TEXTW(monsyms[m->screen_number]);
-               drawtext(monsyms[m->screen_number], selmon == m ? dc.sel : dc.norm, False);
-               dc.x += dc.w;
-       }
-       m->btx = dc.x;
        for(i = 0; i < LENGTH(tags); i++) {
                dc.w = TEXTW(tags[i]);
                col = m->tagset[m->seltags] & 1 << i ? dc.sel : dc.norm;
@@ -669,10 +664,12 @@ drawbar(Monitor *m) {
        if(blw > 0) {
                dc.w = blw;
                drawtext(m->lt[m->sellt]->symbol, dc.norm, False);
-               x = dc.x + dc.w;
+               dc.x += dc.w;
        }
-       else
-               x = dc.x;
+       snprintf(ntext, sizeof ntext, "%u", n);
+       dc.w = TEXTW(ntext);
+       drawtext(ntext, dc.norm, False);
+       x = (dc.x += dc.w);
        if(m == selmon) { /* status is only drawn on selected monitor */
                dc.w = TEXTW(stext);
                dc.x = m->ww - dc.w;
@@ -1329,7 +1326,6 @@ restack(Monitor *m) {
                                wc.sibling = c->win;
                        }
        }
-       XLowerWindow(dpy, m->barwin);
        XSync(dpy, False);
        while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
 }
@@ -1727,8 +1723,8 @@ updategeom(void) {
                m->sellt = 0;
                m->tagset[0] = m->tagset[1] = 1;
                m->mfact = mfact;
-               m->showbar = SHOWBAR;
-               m->topbar = TOPBAR;
+               m->showbar = showbar;
+               m->topbar = topbar;
                m->lt[0] = &layouts[0];
                m->lt[1] = &layouts[1 % LENGTH(layouts)];
                updatebarpos(m);