From 7629d9537aadfc6e7553165683d0f8a70b3ce747 Mon Sep 17 00:00:00 2001 From: speedie Date: Mon, 5 Dec 2022 20:30:07 +0100 Subject: [PATCH] statuscmd compatibility with powerline --- bar/statusbar-powerline.c | 61 +++++++++++++++++++++++++++++++-------- bar/statusbar-powerline.h | 1 + 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/bar/statusbar-powerline.c b/bar/statusbar-powerline.c index 264f6b7..1ffcfa1 100644 --- a/bar/statusbar-powerline.c +++ b/bar/statusbar-powerline.c @@ -1,21 +1,56 @@ -static Clr **powerlinescheme; +int +click_status_pwl(Bar *bar, Arg *arg, BarClickArg *a) +{ + if (selmon->hidestatus) { + return 0; + } else { + return click_status_text(arg, a->rel_x, rawstext); + } +} + +int +click_status_text_pwl(Arg *arg, int rel_x, char *text) +{ + int dpad = drw->font->h; + int i = -1; + int x = dpad / 2 - (TEXTW("_") - lrpad); + char ch; + clickstatusn = 0; + while (text[++i]) { + if ((unsigned char)text[i] < ' ') { + ch = text[i]; + text[i] = '\0'; + x += textlength(text) + dpad; + text[i] = ch; + text += i+1; + i = -1; + if (x >= rel_x) + break; + if (ch <= LENGTH(clickstatuss)) + clickstatusn = ch; + } + } + return ClkStatusText; +} int width_status_pwl(Bar *bar, BarWidthArg *a) { - return widthpowerlinestatus(rawstext); + if (selmon->hidestatus) { + return 0; + } else { + return widthpowerlinestatus(rawstext); + } } int draw_status_pwl(Bar *bar, BarDrawArg *a) { - return drawpowerlinestatus(a->x + a->w, rawstext); -} - -int -click_status_pwl(Bar *bar, Arg *arg, BarClickArg *a) -{ - return ClkStatusText; + if (selmon->hidestatus) { + return 0; + } else { + return drawpowerlinestatus(a->x + a->w, rawstext); + } } int @@ -55,11 +90,13 @@ drawpowerlinestatus(int xpos, char *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; + int offset = 3; + cn = *(bs + offset - 1) - 1; if (cn < LENGTH(powerlinecolors)) { drw_settrans(drw, prevscheme, (nxtscheme = powerlinescheme[cn])); } else { + offset--; drw_settrans(drw, prevscheme, (nxtscheme = powerlinescheme[0])); } @@ -70,8 +107,8 @@ drawpowerlinestatus(int xpos, char *stext) } drw_setscheme(drw, nxtscheme); - w = TEXTW(bs+2); - drw_text(drw, x - w, 0, w, bh, lrpad / 2, bs+2, 0, False); + w = TEXTW(bs+offset); + drw_text(drw, x - w, 0, w, bh, lrpad / 2, bs+offset, 0, False); x -= w; bp = *bs; diff --git a/bar/statusbar-powerline.h b/bar/statusbar-powerline.h index ed5a400..8742bf4 100644 --- a/bar/statusbar-powerline.h +++ b/bar/statusbar-powerline.h @@ -1,5 +1,6 @@ static int width_status_pwl(Bar *bar, BarWidthArg *a); static int draw_status_pwl(Bar *bar, BarDrawArg *a); static int click_status_pwl(Bar *bar, Arg *arg, BarClickArg *a); +static int click_status_text_pwl(Arg *arg, int rel_x, char *text); static int drawpowerlinestatus(int x, char *stext); static int widthpowerlinestatus(char *stext);