diff --git a/patch/bar_status2d.c b/patch/bar_status2d.c index 48bccdf..2e413c8 100644 --- a/patch/bar_status2d.c +++ b/patch/bar_status2d.c @@ -1,3 +1,26 @@ +#if BAR_STATUS2D_XRDB_TERMCOLORS_PATCH +static char termcol0[] = "#000000"; /* black */ +static char termcol1[] = "#ff0000"; /* red */ +static char termcol2[] = "#33ff00"; /* green */ +static char termcol3[] = "#ff0099"; /* yellow */ +static char termcol4[] = "#0066ff"; /* blue */ +static char termcol5[] = "#cc00ff"; /* magenta */ +static char termcol6[] = "#00ffff"; /* cyan */ +static char termcol7[] = "#d0d0d0"; /* white */ +static char termcol8[] = "#808080"; /* black */ +static char termcol9[] = "#ff0000"; /* red */ +static char termcol10[] = "#33ff00"; /* green */ +static char termcol11[] = "#ff0099"; /* yellow */ +static char termcol12[] = "#0066ff"; /* blue */ +static char termcol13[] = "#cc00ff"; /* magenta */ +static char termcol14[] = "#00ffff"; /* cyan */ +static char termcol15[] = "#ffffff"; /* white */ +static char *termcolor[] = { + termcol0, termcol1, termcol2, termcol3, termcol4, termcol5, termcol6, termcol7, + termcol8, termcol9, termcol10, termcol11, termcol12, termcol13, termcol14, termcol15, +}; +#endif // BAR_STATUS2D_XRDB_TERMCOLORS_PATCH + int width_status2d(Bar *bar, BarWidthArg *a) { @@ -123,6 +146,26 @@ drawstatusbar(int x, char* stext) drw_clr_create(drw, &drw->scheme[ColBg], buf); #endif // BAR_ALPHA_PATCH i += 7; + #if BAR_STATUS2D_XRDB_TERMCOLORS_PATCH + } else if (text[i] == 'C') { + int c = atoi(text + ++i) % 16; + #if BAR_ALPHA_PATCH && BAR_STATUS2D_NO_ALPHA_PATCH + drw_clr_create(drw, &drw->scheme[ColFg], termcolor[c], 0xff); + #elif BAR_ALPHA_PATCH + drw_clr_create(drw, &drw->scheme[ColFg], termcolor[c], alphas[SchemeNorm][ColBg]); + #else + drw_clr_create(drw, &drw->scheme[ColFg], termcolor[c]); + #endif // BAR_ALPHA_PATCH + } else if (text[i] == 'B') { + int c = atoi(text + ++i) % 16; + #if BAR_ALPHA_PATCH && BAR_STATUS2D_NO_ALPHA_PATCH + drw_clr_create(drw, &drw->scheme[ColBg], termcolor[c], 0xff); + #elif BAR_ALPHA_PATCH + drw_clr_create(drw, &drw->scheme[ColBg], termcolor[c], alphas[SchemeNorm][ColBg]); + #else + drw_clr_create(drw, &drw->scheme[ColBg], termcolor[c]); + #endif // BAR_ALPHA_PATCH + #endif // BAR_STATUS2D_XRDB_TERMCOLORS_PATCH } else if (text[i] == 'd') { drw->scheme[ColFg] = scheme[SchemeNorm][ColFg]; drw->scheme[ColBg] = scheme[SchemeNorm][ColBg]; diff --git a/patch/xrdb.c b/patch/xrdb.c index b1270d4..7718b49 100644 --- a/patch/xrdb.c +++ b/patch/xrdb.c @@ -83,6 +83,24 @@ loadxrdb() XRDB_LOAD_COLOR("dwm.selSPRLbgcolor", selSPRLbgcolor); XRDB_LOAD_COLOR("dwm.selfloatbgcolor", selfloatbgcolor); #endif // BAR_FLEXWINTITLE_PATCH + #if BAR_STATUS2D_XRDB_TERMCOLORS_PATCH + XRDB_LOAD_COLOR("color0", termcol0); + XRDB_LOAD_COLOR("color1", termcol1); + XRDB_LOAD_COLOR("color2", termcol2); + XRDB_LOAD_COLOR("color3", termcol3); + XRDB_LOAD_COLOR("color4", termcol4); + XRDB_LOAD_COLOR("color5", termcol5); + XRDB_LOAD_COLOR("color6", termcol6); + XRDB_LOAD_COLOR("color7", termcol7); + XRDB_LOAD_COLOR("color8", termcol8); + XRDB_LOAD_COLOR("color9", termcol9); + XRDB_LOAD_COLOR("color10", termcol10); + XRDB_LOAD_COLOR("color11", termcol11); + XRDB_LOAD_COLOR("color12", termcol12); + XRDB_LOAD_COLOR("color13", termcol13); + XRDB_LOAD_COLOR("color14", termcol14); + XRDB_LOAD_COLOR("color15", termcol15); + #endif // BAR_STATUS2D_XRDB_TERMCOLORS_PATCH } } } diff --git a/patches.def.h b/patches.def.h index e558d92..91bb480 100644 --- a/patches.def.h +++ b/patches.def.h @@ -105,6 +105,14 @@ /* Supplementary patch should you want to disable alpha for the status2d section */ #define BAR_STATUS2D_NO_ALPHA_PATCH 0 +/* Addition to the status2d patch that allows the use of terminal colors (color0 through color15) + * from xrdb in the status, allowing programs like pywal to change statusbar colors. + * This adds the C and B codes to use terminal foreground and background colors respectively. + * E.g. ^B5^ would use color5 as the background color. + * https://dwm.suckless.org/patches/status2d/ + */ +#define BAR_STATUS2D_XRDB_TERMCOLORS_PATCH 0 + /* The systray patch adds systray for the status bar. * https://dwm.suckless.org/patches/systray/ */