Compare commits

...

2 Commits

Author SHA1 Message Date
cb5e34f1b2 Add urgent and warning color schemes 2017-02-05 11:56:19 -05:00
edd94ca487 Updated statuscolors patch 2017-02-05 11:38:00 -05:00
4 changed files with 58 additions and 6 deletions

View File

@@ -14,10 +14,14 @@ static const char col_gray2[] = "#444444";
static const char col_gray3[] = "#bbbbbb";
static const char col_gray4[] = "#eeeeee";
static const char col_cyan[] = "#005577";
static const char col_red[] = "#dc322f";
static const char col_orange[] = "#cb4b16";
static const char *colors[][3] = {
/* fg bg border */
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
[SchemeSel] = { col_gray4, col_cyan, col_cyan },
/* fg bg border */
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
[SchemeSel] = { col_gray4, col_cyan, col_cyan },
[SchemeUrg] = { col_orange, col_gray1, col_gray2 },
[SchemeWarn] = { col_gray4, col_red, col_gray2 },
};
/* tagging */

44
drw.c
View File

@@ -234,6 +234,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, Scm *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, Scm *scheme);

6
dwm.c
View File

@@ -60,7 +60,7 @@
/* enums */
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
enum { SchemeNorm, SchemeSel }; /* color schemes */
enum { SchemeNorm, SchemeSel, SchemeUrg, SchemeWarn }; /* color schemes */
enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
NetWMFullscreen, NetActiveWindow, NetWMWindowType,
NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
@@ -702,8 +702,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) {