sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-taglabels-hide_vacant_tags_funcionality-6.2.diff (3390B)


      1 diff -pu dwm.hide_vacant_tags/config.def.h dwm.programtags+hidewithvacanttags/config.def.h
      2 --- dwm.hide_vacant_tags/config.def.h	2021-03-15 16:37:24.586622415 -0500
      3 +++ dwm.programtags+hidewithvacanttags/config.def.h	2021-03-15 16:32:37.586956549 -0500
      4 @@ -21,6 +21,10 @@ static const char *colors[][3]      = {
      5  /* tagging */
      6  static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
      7  
      8 +static const char ptagf[] = "[%s %s]";	/* format of a tag label */
      9 +static const char etagf[] = "[%s]";	/* format of an empty tag */
     10 +static const int lcaselbl = 0;		/* 1 means make tag label lowercase */	
     11 +
     12  static const Rule rules[] = {
     13  	/* xprop(1):
     14  	 *	WM_CLASS(STRING) = instance, class
     15 diff -pu dwm.hide_vacant_tags/dwm.c dwm.programtags+hidewithvacanttags/dwm.c
     16 --- dwm.hide_vacant_tags/dwm.c	2021-03-15 16:37:38.189939908 -0500
     17 +++ dwm.programtags+hidewithvacanttags/dwm.c	2021-03-15 16:32:23.693639390 -0500
     18 @@ -20,6 +20,7 @@
     19   *
     20   * To understand everything else, start reading main().
     21   */
     22 +#include <ctype.h> /* for making tab label lowercase, very tiny standard library */
     23  #include <errno.h>
     24  #include <locale.h>
     25  #include <signal.h>
     26 @@ -272,6 +273,8 @@ static Window root, wmcheckwin;
     27  /* configuration, allows nested code to access above variables */
     28  #include "config.h"
     29  
     30 +unsigned int tagw[LENGTH(tags)];
     31 +
     32  /* compile-time check if all tags fit into an unsigned int bit array. */
     33  struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
     34  
     35 @@ -438,7 +441,7 @@ buttonpress(XEvent *e)
     36  			/* do not reserve space for vacant tags */
     37  			if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
     38  				continue;
     39 -			x += TEXTW(tags[i]);
     40 +			x += tagw[i];
     41  		} while (ev->x >= x && ++i < LENGTH(tags));
     42  		if (i < LENGTH(tags)) {
     43  			click = ClkTagBar;
     44 @@ -706,6 +709,8 @@ drawbar(Monitor *m)
     45  	int boxw = drw->fonts->h / 6 + 2;
     46  	unsigned int i, occ = 0, urg = 0;
     47  	Client *c;
     48 +	char tagdisp[64];
     49 +	char *masterclientontag[LENGTH(tags)];
     50  
     51  	/* draw status first so it can be overdrawn by tags later */
     52  	if (m == selmon) { /* status is only drawn on selected monitor */
     53 @@ -714,10 +719,21 @@ drawbar(Monitor *m)
     54  		drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
     55  	}
     56  
     57 +	for (i = 0; i < LENGTH(tags); i++)
     58 +		masterclientontag[i] = NULL;
     59 +
     60  	for (c = m->clients; c; c = c->next) {
     61  		occ |= c->tags == 255 ? 0 : c->tags;
     62  		if (c->isurgent)
     63  			urg |= c->tags;
     64 +		for (i = 0; i < LENGTH(tags); i++)
     65 +			if (!masterclientontag[i] && c->tags & (1<<i)) {
     66 +				XClassHint ch = { NULL, NULL };
     67 +				XGetClassHint(dpy, c->win, &ch);
     68 +				masterclientontag[i] = ch.res_class;
     69 +				if (lcaselbl)
     70 +					masterclientontag[i][0] = tolower(masterclientontag[i][0]);
     71 +			}
     72  	}
     73  	x = 0;
     74  	for (i = 0; i < LENGTH(tags); i++) {
     75 @@ -725,9 +741,14 @@ drawbar(Monitor *m)
     76  		if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
     77  		continue;
     78  
     79 -		w = TEXTW(tags[i]);
     80 +		if (masterclientontag[i])
     81 +			snprintf(tagdisp, 64, ptagf, tags[i], masterclientontag[i]);
     82 +		else
     83 +			snprintf(tagdisp, 64, etagf, tags[i]);
     84 +		masterclientontag[i] = tagdisp;
     85 +		tagw[i] = w = TEXTW(masterclientontag[i]);
     86  		drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
     87 -		drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
     88 +		drw_text(drw, x, 0, w, bh, lrpad / 2, masterclientontag[i], urg & 1 << i);
     89  		x += w;
     90  	}
     91  	w = blw = TEXTW(m->ltsymbol);