dwm

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

bar_powerline_status.c (2745B)


      1 static Clr **statusscheme;
      2 
      3 int
      4 width_pwrl_status(Bar *bar, BarArg *a)
      5 {
      6 	#if BAR_STATUSCMD_PATCH
      7 	return widthpowerlinestatus(rawstext);
      8 	#else
      9 	return widthpowerlinestatus(stext);
     10 	#endif // BAR_STATUSCMD_PATCH
     11 }
     12 
     13 #if BAR_EXTRASTATUS_PATCH
     14 int
     15 width_pwrl_status_es(Bar *bar, BarArg *a)
     16 {
     17 	#if BAR_STATUSCMD_PATCH
     18 	return widthpowerlinestatus(rawestext);
     19 	#else
     20 	return widthpowerlinestatus(estext);
     21 	#endif // BAR_STATUSCMD_PATCH
     22 }
     23 #endif // BAR_EXTRASTATUS_PATCH
     24 
     25 int
     26 draw_pwrl_status(Bar *bar, BarArg *a)
     27 {
     28 	#if BAR_STATUSCMD_PATCH
     29 	return drawpowerlinestatus(a->x + a->w, rawstext, a);
     30 	#else
     31 	return drawpowerlinestatus(a->x + a->w, stext, a);
     32 	#endif // BAR_STATUSCMD_PATCH
     33 }
     34 
     35 #if BAR_EXTRASTATUS_PATCH
     36 int
     37 draw_pwrl_status_es(Bar *bar, BarArg *a)
     38 {
     39 	#if BAR_STATUSCMD_PATCH
     40 	return drawpowerlinestatus(a->x + a->w, rawestext, a);
     41 	#else
     42 	return drawpowerlinestatus(a->x + a->w, estext, a);
     43 	#endif // BAR_STATUSCMD_PATCH
     44 }
     45 #endif // BAR_EXTRASTATUS_PATCH
     46 
     47 int
     48 click_pwrl_status(Bar *bar, Arg *arg, BarArg *a)
     49 {
     50 	return ClkStatusText;
     51 }
     52 
     53 int
     54 widthpowerlinestatus(char *stext)
     55 {
     56 	char status[512];
     57 	int w = 0, i, n = strlen(stext);
     58 	int plw = drw->fonts->h / 2 + 1;
     59 	char *bs, bp = '|';
     60 	strcpy(status, stext);
     61 
     62 	for (i = n, bs = &status[n-1]; i >= 0; i--, bs--) {
     63 		if (*bs == '<' || *bs == '/' || *bs == '\\' || *bs == '>' || *bs == '|') { /* block start */
     64 			if (bp != '|')
     65 				w += plw;
     66 			w += TEXTW(bs+2);
     67 			bp = *bs;
     68 			*bs = 0;
     69 		}
     70 	}
     71 	if (bp != '|')
     72 		w += plw * 2;
     73 
     74 	return w;
     75 }
     76 
     77 int
     78 drawpowerlinestatus(int xpos, char *stext, BarArg *barg)
     79 {
     80 	char status[512];
     81 	int i, n = strlen(stext), cn = 0;
     82 	int x = xpos, w = 0;
     83 	int plw = drw->fonts->h / 2 + 1;
     84 	char *bs, bp = '|';
     85 	Clr *prevscheme = statusscheme[0], *nxtscheme;
     86 	strcpy(status, stext);
     87 
     88 	for (i = n, bs = &status[n-1]; i >= 0; i--, bs--) {
     89 		if (*bs == '<' || *bs == '/' || *bs == '\\' || *bs == '>' || *bs == '|') { /* block start */
     90 			cn = ((int) *(bs+1)) - 1;
     91 
     92 			if (cn < LENGTH(statuscolors)) {
     93 				drw_settrans(drw, prevscheme, (nxtscheme = statusscheme[cn]));
     94 			} else {
     95 				drw_settrans(drw, prevscheme, (nxtscheme = statusscheme[0]));
     96 			}
     97 
     98 			if (bp != '|') {
     99 				drw_arrow(drw, x - plw, barg->y, plw, barg->h, bp == '\\' || bp == '>' ? 1 : 0, bp == '<' ? 0 : 1);
    100 				x -= plw;
    101 			}
    102 
    103 			drw_setscheme(drw, nxtscheme);
    104 			w = TEXTW(bs+2);
    105 			drw_text(drw, x - w, barg->y, w, barg->h, lrpad / 2, bs+2, 0, False);
    106 			x -= w;
    107 
    108 			bp = *bs;
    109 			*bs = 0;
    110 			prevscheme = nxtscheme;
    111 		}
    112 	}
    113 	if (bp != '|') {
    114 		drw_settrans(drw, prevscheme, scheme[SchemeNorm]);
    115 		drw_arrow(drw, x - plw, barg->y, plw, barg->h, bp == '\\' || bp == '>' ? 1 : 0, bp == '<' ? 0 : 1);
    116 		drw_rect(drw, x - 2 * plw, barg->y, plw, barg->h, 1, 1);
    117 		x -= plw * 2;
    118 	}
    119 
    120 	return xpos - x;
    121 }
    122