dwm

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

bar_taglabels.c (3271B)


      1 int
      2 width_taglabels(Bar *bar, BarArg *a)
      3 {
      4 	int w, i;
      5 	Client *c;
      6 	Monitor *m = bar->mon;
      7 	char *icon;
      8 	unsigned int occ = 0;
      9 
     10 	for (c = m->clients; c; c = c->next)
     11 		occ |= c->tags == 255 ? 0 : c->tags;
     12 
     13 	for (w = 0, i = 0; i < NUMTAGS; i++) {
     14 		m->taglabel[i][0] = '\0';
     15 		#if BAR_HIDEVACANTTAGS_PATCH
     16 		if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
     17 			continue;
     18 		#endif // BAR_HIDEVACANTTAGS_PATCH
     19 		icon = tagicon(m, i);
     20 		XClassHint ch = { NULL, NULL };
     21 		for (c = m->clients; c; c = c->next) {
     22 			if (c->tags & (1 << i)) {
     23 				XGetClassHint(dpy, c->win, &ch);
     24 				break;
     25 			}
     26 		}
     27 		if (ch.res_class) {
     28 			if (lcaselbl)
     29 				ch.res_class[0] = tolower(ch.res_class[0]);
     30 			snprintf(m->taglabel[i], 64, ptagf, icon, ch.res_class);
     31 		} else
     32 			snprintf(m->taglabel[i], 64, etagf, icon);
     33 
     34 		w += TEXTW(m->taglabel[i]);
     35 	}
     36 	return w;
     37 }
     38 
     39 int
     40 draw_taglabels(Bar *bar, BarArg *a)
     41 {
     42 	int invert = 0;
     43 	int w, x = a->x;
     44 	unsigned int i, occ = 0, urg = 0;
     45 	Client *c;
     46 	Monitor *m = bar->mon;
     47 
     48 	for (c = m->clients; c; c = c->next)
     49 		if (c->isurgent)
     50 			urg |= c->tags;
     51 
     52 	for (i = 0; i < NUMTAGS; i++) {
     53 		/* do not draw vacant tags */
     54 		if (!m->taglabel[i][0])
     55 			continue;
     56 		drw_setscheme(drw, scheme[
     57 			m->tagset[m->seltags] & 1 << i
     58 			? SchemeTagsSel
     59 			: urg & 1 << i
     60 			? SchemeUrg
     61 			: SchemeTagsNorm
     62 		]);
     63 		w = TEXTW(m->taglabel[i]);
     64 		drw_text(drw, x, a->y, w, a->h, lrpad / 2, m->taglabel[i], invert, False);
     65 		drawindicator(m, NULL, occ, x, a->y, w, a->h, i, -1, invert, tagindicatortype);
     66 		#if BAR_UNDERLINETAGS_PATCH
     67 		if (ulineall || m->tagset[m->seltags] & 1 << i)
     68 			drw_rect(drw, x + ulinepad, a->y + bh - ulinestroke - ulinevoffset, w - (ulinepad * 2), ulinestroke, 1, 0);
     69 		#endif // BAR_UNDERLINETAGS_PATCH
     70 		x += w;
     71 	}
     72 
     73 	return 1;
     74 }
     75 
     76 int
     77 click_taglabels(Bar *bar, Arg *arg, BarArg *a)
     78 {
     79 	int i = 0, x = lrpad / 2;
     80 	Monitor *m = bar->mon;
     81 
     82 	do {
     83 		if (!m->taglabel[i][0])
     84 			continue;
     85 		x += TEXTW(m->taglabel[i]);
     86 	} while (a->x >= x && ++i < NUMTAGS);
     87 	if (i < NUMTAGS) {
     88 		arg->ui = 1 << i;
     89 	}
     90 	#if BAR_TAGPREVIEW_PATCH
     91 	if (selmon->previewshow != 0) {
     92 		hidetagpreview(selmon);
     93 	}
     94 	#endif // BAR_TAGPREVIEW_PATCH
     95 	return ClkTagBar;
     96 }
     97 
     98 int
     99 hover_taglabels(Bar *bar, BarArg *a, XMotionEvent *ev)
    100 {
    101 	#if BAR_TAGPREVIEW_PATCH
    102 	int i = 0, x = lrpad / 2;
    103 	int px, py;
    104 	Monitor *m = bar->mon;
    105 	#if VANITYGAPS_PATCH
    106 	int ov = gappov;
    107 	int oh = gappoh;
    108 	#else
    109 	int ov = 0;
    110 	int oh = 0;
    111 	#endif // VANITYGAPS_PATCH
    112 
    113 	do {
    114 		if (!m->taglabel[i][0])
    115 			continue;
    116 		x += TEXTW(m->taglabel[i]);
    117 	} while (a->x >= x && ++i < NUMTAGS);
    118 
    119 	if (i < NUMTAGS) {
    120 		if ((i + 1) != selmon->previewshow && !(selmon->tagset[selmon->seltags] & 1 << i)) {
    121 			if (bar->by > m->my + m->mh / 2) // bottom bar
    122 				py = bar->by - m->mh / scalepreview - oh;
    123 			else // top bar
    124 				py = bar->by + bar->bh + oh;
    125 			px = bar->bx + ev->x - m->mw / scalepreview / 2;
    126 			if (px + m->mw / scalepreview > m->mx + m->mw)
    127 				px = m->wx + m->ww - m->mw / scalepreview - ov;
    128 			else if (px < bar->bx)
    129 				px = m->wx + ov;
    130 			selmon->previewshow = i + 1;
    131 			showtagpreview(i, px, py);
    132 		} else if (selmon->tagset[selmon->seltags] & 1 << i) {
    133 			hidetagpreview(selmon);
    134 		}
    135 	} else if (selmon->previewshow != 0) {
    136 		hidetagpreview(selmon);
    137 	}
    138 	#endif // BAR_TAGPREVIEW_PATCH
    139 
    140 	return 1;
    141 }