DWM: only display workspaces with windows in them (in the status bar)

08-14  Source: Network gathering  Views:3 

I was wondering if anyone either had a patch or had a few hints about the source in order to accomplish displaying only those workspaces with windows on them. I am willing to edit the source (dwm.c) but have no idea where to start.
Look at drawbar(), in this code block (line 664 in the current hg tip version of the file):
for(i = 0; i < LENGTH(tags); i++) {
dc.w = TEXTW(tags[i]);
col = m->tagset[m->seltags] & 1 << i ? dc.sel : dc.norm;
drawtext(tags[i], col, urg & 1 << i);
drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
occ & 1 << i, urg & 1 << i, col);
dc.x += dc.w;
The drawtext() and drawsquare() calls are what write the names. The variable "occ", which is computed in the block right above, tells which tags are occupied, in the format of one bit per tag. It shouldn't be too hard to skip the appropriate ones.
What looks harder is keeping the width of the tag display correct - if you just skip some names, there will be a gap big enough to fit the missing ones between the tag name list and the layout indicator.
The other thing worth mentioning is that the names of empty tags are useful if you want to retag windows, or switch tags, with the mouse.
Related articles