Adding separate statuscolors bar module ref. #180

This commit is contained in:
bakkeby 2021-08-25 12:18:01 +02:00
parent c2e4fed918
commit 036421845f
6 changed files with 113 additions and 3 deletions

View File

@ -481,7 +481,11 @@ static const BarRule barrules[] = {
#if BAR_LTSYMBOL_PATCH
{ -1, 0, BAR_ALIGN_LEFT, width_ltsymbol, draw_ltsymbol, click_ltsymbol, "layout" },
#endif // BAR_LTSYMBOL_PATCH
#if BAR_STATUS2D_PATCH && BAR_STATUSCMD_PATCH
#if BAR_STATUSCOLORS_PATCH && BAR_STATUSCMD_PATCH
{ 'A', 0, BAR_ALIGN_RIGHT, width_statuscolors, draw_statuscolors, click_statuscmd, "statuscolors" },
#elif BAR_STATUSCOLORS_PATCH
{ 'A', 0, BAR_ALIGN_RIGHT, width_statuscolors, draw_statuscolors, click_statuscolors, "statuscolors" },
#elif BAR_STATUS2D_PATCH && BAR_STATUSCMD_PATCH
{ 'A', 0, BAR_ALIGN_RIGHT, width_status2d, draw_status2d, click_statuscmd, "status2d" },
#elif BAR_STATUS2D_PATCH
{ 'A', 0, BAR_ALIGN_RIGHT, width_status2d, draw_status2d, click_status2d, "status2d" },
@ -507,7 +511,11 @@ static const BarRule barrules[] = {
{ -1, 0, BAR_ALIGN_NONE, width_wintitle, draw_wintitle, click_wintitle, "wintitle" },
#endif // BAR_TABGROUPS_PATCH | BAR_AWESOMEBAR_PATCH | BAR_FANCYBAR_PATCH | BAR_WINTITLE_PATCH
#if BAR_EXTRASTATUS_PATCH
#if BAR_STATUS2D_PATCH && BAR_STATUSCMD_PATCH
#if BAR_STATUSCOLORS_PATCH && BAR_STATUSCMD_PATCH
{ 'A', 1, BAR_ALIGN_CENTER, width_statuscolors_es, draw_statuscolors_es, click_statuscmd_es, "statuscolors_es" },
#elif BAR_STATUSCOLORS_PATCH
{ 'A', 1, BAR_ALIGN_CENTER, width_statuscolors_es, draw_statuscolors_es, click_statuscolors, "statuscolors_es" },
#elif BAR_STATUS2D_PATCH && BAR_STATUSCMD_PATCH
{ 'A', 1, BAR_ALIGN_CENTER, width_status2d_es, draw_status2d_es, click_statuscmd_es, "status2d_es" },
#elif BAR_STATUS2D_PATCH
{ 'A', 1, BAR_ALIGN_CENTER, width_status2d_es, draw_status2d_es, click_status2d, "status2d_es" },

View File

@ -31,9 +31,13 @@ click_statuscmd_text(Arg *arg, int rel_x, char *text)
#endif // BAR_DWMBLOCKS_PATCH
while (text[++i]) {
if ((unsigned char)text[i] < ' ') {
#if BAR_STATUSCOLORS_PATCH
if (text[i] < 17)
continue;
#endif // BAR_STATUSCOLORS_PATCH
ch = text[i];
text[i] = '\0';
#if BAR_STATUS2D_PATCH && !BAR_BAR_STATUSCOLORS_PATCH
#if BAR_STATUS2D_PATCH && !BAR_STATUSCOLORS_PATCH
x += status2dtextlength(text);
#else
x += TEXTWM(text) - lrpad;

View File

@ -1,3 +1,55 @@
int
width_statuscolors(Bar *bar, BarArg *a)
{
#if BAR_STATUSCMD_PATCH
return textw_wosc(rawstext);
#else
return textw_wosc(stext);
#endif // BAR_STATUSCMD_PATCH
}
#if BAR_EXTRASTATUS_PATCH
int
width_statuscolors_es(Bar *bar, BarArg *a)
{
#if BAR_STATUSCMD_PATCH
return textw_wosc(rawestext);
#else
return textw_wosc(estext);
#endif // BAR_STATUSCMD_PATCH
}
#endif // BAR_EXTRASTATUS_PATCH
int
draw_statuscolors(Bar *bar, BarArg *a)
{
#if BAR_STATUSCMD_PATCH
return draw_wosc(bar, a, rawstext);
#else
return draw_wosc(bar, a, stext);
#endif // BAR_STATUSCMD_PATCH
}
#if BAR_EXTRASTATUS_PATCH
int
draw_statuscolors_es(Bar *bar, BarArg *a)
{
#if BAR_STATUSCMD_PATCH
return draw_wosc(bar, a, rawestext);
#else
return draw_wosc(bar, a, estext);
#endif // BAR_STATUSCMD_PATCH
}
#endif // BAR_EXTRASTATUS_PATCH
#if !BAR_STATUSCMD_PATCH
int
click_statuscolors(Bar *bar, Arg *arg, BarArg *a)
{
return ClkStatusText;
}
#endif // BAR_STATUSCMD_PATCH
int
textw_wosc(char *s)
{
@ -22,3 +74,29 @@ textw_wosc(char *s)
return sw;
}
int
draw_wosc(Bar *bar, BarArg *a, char *s)
{
char *ts = s;
char *tp = s;
int tx = 0;
char ctmp;
while (1) {
if ((unsigned int)*ts > LENGTH(colors)) {
ts++;
continue;
}
ctmp = *ts;
*ts = '\0';
drw_text(drw, a->x + tx, a->y, a->w - tx, a->h, 0, tp, 0, True);
tx += TEXTW(tp) - lrpad;
if (ctmp == '\0')
break;
drw_setscheme(drw, scheme[(unsigned int)(ctmp-1)]);
*ts = ctmp;
tp = ++ts;
}
return 1;
}

13
patch/bar_statuscolors.h Normal file
View File

@ -0,0 +1,13 @@
static int width_statuscolors(Bar *bar, BarArg *a);
#if BAR_EXTRASTATUS_PATCH
static int width_statuscolors_es(Bar *bar, BarArg *a);
#endif // BAR_EXTRASTATUS_PATCH
static int draw_statuscolors(Bar *bar, BarArg *a);
#if BAR_EXTRASTATUS_PATCH
static int draw_statuscolors_es(Bar *bar, BarArg *a);
#endif // BAR_EXTRASTATUS_PATCH
#if !BAR_STATUSCMD_PATCH
static int click_statuscolors(Bar *bar, Arg *arg, BarArg *a);
#endif // BAR_STATUSCMD_PATCH
static int textw_wosc(char *s);
static int draw_wosc(Bar *bar, BarArg *a, char *s);

View File

@ -44,6 +44,9 @@
#if BAR_STATUSCMD_PATCH
#include "bar_statuscmd.h"
#endif
#if BAR_STATUSCOLORS_PATCH
#include "bar_statuscolors.h"
#endif
#if BAR_WINICON_PATCH
#include "bar_winicon.h"
#endif

View File

@ -361,6 +361,10 @@
/* This patch enables colored text in the status bar. It changes the way colors are defined
* in config.h allowing multiple color combinations for use in the status script.
* This patch is incompatible with and takes precedence over the status2d patch.
*
* This patch is compatible with the statuscmd patch with the caveat that the first 16 markers
* are reserved for status colors restricting block signals to 17 through 31.
*
* https://dwm.suckless.org/patches/statuscolors/
*/
#define BAR_STATUSCOLORS_PATCH 0