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 fa5fdea..d71bb58 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -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;
@@ -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 */
@@ -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;
@@ -1690,8 +1687,6 @@ updategeom(void) {
        if(XineramaIsActive(dpy))
                info = XineramaQueryScreens(dpy, &n);
 #endif /* XINERAMA */
-       if(n > LENGTH(monsyms))
-               n = LENGTH(monsyms);
        /* allocate monitor(s) for the new geometry setup */
        for(i = 0; i < n; i++) {
                if(!(m = (Monitor *)malloc(sizeof(Monitor))))