1
0
Fork 0

Updated statuscolors patch

This commit is contained in:
Aaron Lindsay 2017-02-05 11:38:00 -05:00 committed by Aaron Lindsay
parent 6d52535803
commit 10ea1a380b
3 changed files with 50 additions and 2 deletions

44
drw.c
View File

@ -247,6 +247,50 @@ drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int
XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1);
}
int
drw_get_width(Drw *drw, int numcolors, const char *text)
{
int i;
int w = drw_text(drw, 0, 0, 0, 0, 0, text, 0);
for (i = 0; i < strlen(text); i++)
if (text[i] > 0 && text[i] <= numcolors)
/* we found a color code
* drw_text counted it as a normal character and added one character's width
* we aren't going to render this character, so we remove one character's width */
w -= drw->fonts->xfont->max_advance_width;
return w;
}
int
drw_color_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert, int numcolors, Clr **scheme)
{
int render = x || y || w || h;
char *buf = (char*)text, *ptr = buf, c = 1;
int i;
if (!drw || (render && !drw->scheme) || !text || !drw->fonts)
return 0;
while (*ptr) {
for (i = 0; *ptr < 0 || *ptr > numcolors; i++, ptr++);
if (!*ptr)
break;
c = *ptr;
*ptr = 0;
if (i) {
unsigned int sw = drw_fontset_getwidth(drw, buf);
x = drw_text(drw, x, y, sw, h, lpad, buf, invert);
}
*ptr = c;
drw_setscheme(drw, scheme[c-1]);
buf = ++ptr;
}
return drw_text(drw, x, y, w, h, lpad, buf, invert);
}
int
drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert)
{

4
drw.h
View File

@ -55,3 +55,7 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned in
/* Map functions */
void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h);
/* Drawing color text functions */
int drw_get_width(Drw *drw, int numcolors, const char *text);
int drw_color_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert, int numcolors, Clr **scheme);

4
dwm.c
View File

@ -704,8 +704,8 @@ drawbar(Monitor *m)
/* draw status first so it can be overdrawn by tags later */
if (m == selmon) { /* status is only drawn on selected monitor */
drw_setscheme(drw, scheme[SchemeNorm]);
sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
drw_text(drw, m->ww - sw, 0, sw, bh, 0, stext, 0);
sw = drw_get_width(drw, LENGTH(colors), stext) + 2; /*2px right padding */
drw_color_text(drw, m->ww - sw, 0, sw, bh, 0, stext, 0, LENGTH(colors), scheme);
}
for (c = m->clients; c; c = c->next) {