dwm

Kris's build of dwm
git clone git clone https://git.krisyotam.com/krisyotam/dwm.git
Log | Files | Refs | README | LICENSE

nametag.c (1569B)


      1 void
      2 nametag(const Arg *arg)
      3 {
      4 	char *p, name[MAX_TAGLEN];
      5 	FILE *f;
      6 	int i, group;
      7 	int tagindex;
      8 	Monitor *m = selmon;
      9 	#if BAR_ALTTAGSDECORATION_PATCH
     10 	Client *c;
     11 	int occ = 0;
     12 
     13 	for (c = m->clients; c; c = c->next)
     14 		occ |= c->tags == 255 ? 0 : c->tags;
     15 	#endif // BAR_ALTTAGSDECORATION_PATCH
     16 
     17 	errno = 0; // popen(3p) says on failure it "may" set errno
     18 	if (!(f = popen(NAMETAG_COMMAND, "r"))) {
     19 		fprintf(stderr, "dwm: popen command failed%s%s\n", errno ? ": " : "", errno ? strerror(errno) : "");
     20 		return;
     21 	}
     22 
     23 	if (!(p = fgets(name, MAX_TAGLEN, f)) && (i = errno) && ferror(f))
     24 		fprintf(stderr, "dwm: fgets failed: %s\n", strerror(i));
     25 
     26 	pclose(f);
     27 
     28 	if (!p)
     29 		return;
     30 	if ((p = strchr(name, '\n')))
     31 		*p = '\0';
     32 
     33 	for (i = 0; i < NUMTAGS; i++) {
     34 		if (m->tagset[m->seltags] & (1 << i)) {
     35 
     36 		 	tagindex = i + NUMTAGS * m->num;
     37 			if (tagindex >= LENGTH(tagicons[DEFAULT_TAGS]))
     38 				tagindex = tagindex % LENGTH(tagicons[DEFAULT_TAGS]);
     39 
     40 			#if BAR_ALTTAGSDECORATION_PATCH
     41 			if (occ & 1 << i)
     42 				group = ALT_TAGS_DECORATION;
     43 			else
     44 			#endif // BAR_ALTTAGSDECORATION_PATCH
     45 			#if BAR_ALTERNATIVE_TAGS_PATCH
     46 			if (m->alttag)
     47 				group = ALTERNATIVE_TAGS;
     48 			else
     49 			#endif // BAR_ALTERNATIVE_TAGS_PATCH
     50 			group = DEFAULT_TAGS;
     51 
     52 			#if NAMETAG_PREPEND_PATCH
     53 			if (snprintf(tagicons[group][i], MAX_TAGLEN, NAMETAG_FORMAT, i+1, name) < 0)
     54 				fprintf(stderr, "nametag: if statement to avoid -Wformat-truncation= warnings\n");
     55 			#else
     56 			snprintf(tagicons[group][i], MAX_TAGLEN, NAMETAG_FORMAT, name);
     57 			#endif // NAMETAG_PREPEND_PATCH
     58 		}
     59 	}
     60 	drawbars();
     61 }