dwm-flexipatch/patch/bar_powerline_status.c

121 lines
2.7 KiB
C
Raw Normal View History

2020-07-19 14:57:30 +00:00
static Clr **statusscheme;
int
width_pwrl_status(Bar *bar, BarArg *a)
2020-07-19 14:57:30 +00:00
{
#if BAR_STATUSCMD_PATCH
return widthpowerlinestatus(rawstext);
#else
return widthpowerlinestatus(stext);
#endif // BAR_STATUSCMD_PATCH
}
#if BAR_EXTRASTATUS_PATCH
int
width_pwrl_status_es(Bar *bar, BarArg *a)
2020-07-19 14:57:30 +00:00
{
#if BAR_STATUSCMD_PATCH
return widthpowerlinestatus(rawestext);
#else
return widthpowerlinestatus(estext);
#endif // BAR_STATUSCMD_PATCH
}
#endif // BAR_EXTRASTATUS_PATCH
int
draw_pwrl_status(Bar *bar, BarArg *a)
2020-07-19 14:57:30 +00:00
{
#if BAR_STATUSCMD_PATCH
return drawpowerlinestatus(a->x + a->w, rawstext, a);
2020-07-19 14:57:30 +00:00
#else
return drawpowerlinestatus(a->x + a->w, stext, a);
2020-07-19 14:57:30 +00:00
#endif // BAR_STATUSCMD_PATCH
}
#if BAR_EXTRASTATUS_PATCH
int
draw_pwrl_status_es(Bar *bar, BarArg *a)
2020-07-19 14:57:30 +00:00
{
#if BAR_STATUSCMD_PATCH
return drawpowerlinestatus(a->x + a->w, rawestext, a);
2020-07-19 14:57:30 +00:00
#else
return drawpowerlinestatus(a->x + a->w, estext, a);
2020-07-19 14:57:30 +00:00
#endif // BAR_STATUSCMD_PATCH
}
#endif // BAR_EXTRASTATUS_PATCH
int
click_pwrl_status(Bar *bar, Arg *arg, BarArg *a)
2020-07-19 14:57:30 +00:00
{
return ClkStatusText;
}
int
widthpowerlinestatus(char *stext)
{
char status[512];
int w = 0, i, n = strlen(stext);
int plw = drw->fonts->h / 2 + 1;
char *bs, bp = '|';
strcpy(status, stext);
for (i = n, bs = &status[n-1]; i >= 0; i--, bs--) {
if (*bs == '<' || *bs == '/' || *bs == '\\' || *bs == '>' || *bs == '|') { /* block start */
if (bp != '|')
w += plw;
w += TEXTW(bs+2);
bp = *bs;
*bs = 0;
}
}
if (bp != '|')
w += plw * 2;
return w;
}
int
drawpowerlinestatus(int xpos, char *stext, BarArg *barg)
2020-07-19 14:57:30 +00:00
{
char status[512];
int i, n = strlen(stext), cn = 0;
int x = xpos, w = 0;
int plw = drw->fonts->h / 2 + 1;
char *bs, bp = '|';
Clr *prevscheme = statusscheme[0], *nxtscheme;
strcpy(status, stext);
for (i = n, bs = &status[n-1]; i >= 0; i--, bs--) {
if (*bs == '<' || *bs == '/' || *bs == '\\' || *bs == '>' || *bs == '|') { /* block start */
cn = ((int) *(bs+1)) - 1;
if (cn < LENGTH(statuscolors)) {
drw_settrans(drw, prevscheme, (nxtscheme = statusscheme[cn]));
} else {
drw_settrans(drw, prevscheme, (nxtscheme = statusscheme[0]));
}
if (bp != '|') {
drw_arrow(drw, x - plw, barg->y, plw, barg->h, bp == '\\' || bp == '>' ? 1 : 0, bp == '<' ? 0 : 1);
2020-07-19 14:57:30 +00:00
x -= plw;
}
drw_setscheme(drw, nxtscheme);
w = TEXTW(bs+2);
drw_text(drw, x - w, barg->y, w, barg->h, lrpad / 2, bs+2, 0, False);
2020-07-19 14:57:30 +00:00
x -= w;
bp = *bs;
*bs = 0;
prevscheme = nxtscheme;
}
}
if (bp != '|') {
drw_settrans(drw, prevscheme, scheme[SchemeNorm]);
drw_arrow(drw, x - plw, barg->y, plw, barg->h, bp == '\\' || bp == '>' ? 1 : 0, bp == '<' ? 0 : 1);
drw_rect(drw, x - 2 * plw, barg->y, plw, barg->h, 1, 1);
2020-07-19 14:57:30 +00:00
x -= plw * 2;
}
return xpos - x;
}