summaryrefslogtreecommitdiffhomepage
path: root/patch/bar_powerline_status.c
diff options
context:
space:
mode:
authorbakkeby <[email protected]>2020-07-19 16:57:30 +0200
committerbakkeby <[email protected]>2020-07-19 16:57:30 +0200
commit023aa218e4a0f7614bf59db88942c4f66f560410 (patch)
tree776d6a5aac6ec4d4e17070a82cd9b88723c870e3 /patch/bar_powerline_status.c
parent23c0e9450f19e50c46a577e626e059e673ba1499 (diff)
downloaddwm-flexipatch-023aa218e4a0f7614bf59db88942c4f66f560410.tar.gz
dwm-flexipatch-023aa218e4a0f7614bf59db88942c4f66f560410.zip
Adding powerline patch
Diffstat (limited to 'patch/bar_powerline_status.c')
-rw-r--r--patch/bar_powerline_status.c121
1 files changed, 121 insertions, 0 deletions
diff --git a/patch/bar_powerline_status.c b/patch/bar_powerline_status.c
new file mode 100644
index 0000000..3e2ee6a
--- /dev/null
+++ b/patch/bar_powerline_status.c
@@ -0,0 +1,121 @@
+static Clr **statusscheme;
+
+int
+width_pwrl_status(Bar *bar, BarWidthArg *a)
+{
+ #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, BarWidthArg *a)
+{
+ #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, BarDrawArg *a)
+{
+ #if BAR_STATUSCMD_PATCH
+ return drawpowerlinestatus(a->x + a->w, rawstext);
+ #else
+ return drawpowerlinestatus(a->x + a->w, stext);
+ #endif // BAR_STATUSCMD_PATCH
+}
+
+#if BAR_EXTRASTATUS_PATCH
+int
+draw_pwrl_status_es(Bar *bar, BarDrawArg *a)
+{
+ #if BAR_STATUSCMD_PATCH
+ return drawpowerlinestatus(a->x + a->w, rawestext);
+ #else
+ return drawpowerlinestatus(a->x + a->w, estext);
+ #endif // BAR_STATUSCMD_PATCH
+}
+#endif // BAR_EXTRASTATUS_PATCH
+
+int
+click_pwrl_status(Bar *bar, Arg *arg, BarClickArg *a)
+{
+ 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)
+{
+ 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, 0, plw, bh, bp == '\\' || bp == '>' ? 1 : 0, bp == '<' ? 0 : 1);
+ x -= plw;
+ }
+
+ drw_setscheme(drw, nxtscheme);
+ w = TEXTW(bs+2);
+ drw_text(drw, x - w, 0, w, bh, lrpad / 2, bs+2, 0);
+ x -= w;
+
+ bp = *bs;
+ *bs = 0;
+ prevscheme = nxtscheme;
+ }
+ }
+ if (bp != '|') {
+ drw_settrans(drw, prevscheme, scheme[SchemeNorm]);
+ drw_arrow(drw, x - plw, 0, plw, bh, bp == '\\' || bp == '>' ? 1 : 0, bp == '<' ? 0 : 1);
+ drw_rect(drw, x - 2 * plw, 0, plw, bh, 1, 1);
+ x -= plw * 2;
+ }
+
+ return xpos - x;
+} \ No newline at end of file