Created
April 21, 2015 17:46
-
-
Save holomorph/d99905acf73a2c44c061 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this is broken | |
diff --git a/config.def.h b/config.def.h | |
index eaae8f3..6f150cf 100644 | |
--- a/config.def.h | |
+++ b/config.def.h | |
@@ -7,12 +7,12 @@ static const char *fonts[] = { | |
"WenQuanYi Micro Hei:size=10.5", | |
}; | |
static const char dmenufont[] = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*"; | |
-static const char normbordercolor[] = "#444444"; | |
-static const char normbgcolor[] = "#222222"; | |
-static const char normfgcolor[] = "#bbbbbb"; | |
-static const char selbordercolor[] = "#005577"; | |
-static const char selbgcolor[] = "#005577"; | |
-static const char selfgcolor[] = "#eeeeee"; | |
+static const char schemes[NUMSCHEMES][ColLast][8] = { | |
+ /* border background foreground */ | |
+ { "#444444", "#222222", "#bbbbbb" }, /* 1 = normal */ | |
+ { "#005577", "#005577", "#eeeeee" }, /* 2 = selected */ | |
+ { "#aa4444", "#222222", "#aa4444" }, /* 3 = urgent */ | |
+}; | |
static const unsigned int borderpx = 1; /* border pixel of windows */ | |
static const unsigned int snap = 32; /* snap pixel */ | |
static const Bool showbar = True; /* False means no bar */ | |
@@ -56,7 +56,7 @@ static const Layout layouts[] = { | |
/* commands */ | |
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ | |
-static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL }; | |
+static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", schemes[0][ColBG], "-nf", schemes[0][ColFG], "-sb", schemes[1][ColBG], "-sf", schemes[1][ColFG], NULL }; | |
static const char *termcmd[] = { "st", NULL }; | |
static Key keys[] = { | |
diff --git a/drw.c b/drw.c | |
index eb3b3c3..8e36470 100644 | |
--- a/drw.c | |
+++ b/drw.c | |
@@ -203,12 +203,12 @@ drw_setscheme(Drw *drw, ClrScheme *scheme) { | |
} | |
void | |
-drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert) { | |
+drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty) { | |
int dx; | |
if(!drw || !drw->fontcount || !drw->scheme) | |
return; | |
- XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->bg->pix : drw->scheme->fg->pix); | |
+ XSetForeground(drw->dpy, drw->gc, drw->scheme->fg->pix); | |
dx = (drw->fonts[0]->ascent + drw->fonts[0]->descent + 2) / 4; | |
if(filled) | |
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x+1, y+1, dx+1, dx+1); | |
@@ -217,7 +217,7 @@ drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int | |
} | |
int | |
-drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int invert) { | |
+drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int pad) { | |
char buf[1024]; | |
int tx, ty, th; | |
Extnts tex; | |
@@ -242,7 +242,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *tex | |
if (!drw || !drw->scheme) { | |
return 0; | |
} else if (render) { | |
- XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->fg->pix : drw->scheme->bg->pix); | |
+ XSetForeground(drw->dpy, drw->gc, drw->scheme->bg->pix); | |
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); | |
} | |
@@ -294,10 +294,10 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *tex | |
for(i = len; i && i > len - 3; buf[--i] = '.'); | |
if (render) { | |
- th = curfont->ascent + curfont->descent; | |
+ th = pad ? (curfont->ascent + curfont->descent) : 0; | |
ty = y + (h / 2) - (th / 2) + curfont->ascent; | |
tx = x + (h / 2); | |
- XftDrawStringUtf8(d, invert ? &drw->scheme->bg->rgb : &drw->scheme->fg->rgb, curfont->xfont, tx, ty, (XftChar8 *)buf, len); | |
+ XftDrawStringUtf8(d, &drw->scheme->fg->rgb, curfont->xfont, tx, ty, (XftChar8 *)buf, len); | |
} | |
x += tex.w; | |
@@ -373,11 +373,23 @@ drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) { | |
void | |
drw_font_getexts(Fnt *font, const char *text, unsigned int len, Extnts *tex) { | |
+ /* remove non-printing color codes before calculating width */ | |
+ char *ptr = (char *) text; | |
+ unsigned int i, ibuf; | |
+ char buf[len + 1]; | |
XGlyphInfo ext; | |
+ for(i = 0, ibuf = 0; *ptr && i < len; i++, ptr++) { | |
+ if(!(*ptr <= NUMSCHEMES && *ptr > 0)) { | |
+ buf[ibuf] = *ptr; | |
+ ibuf++; | |
+ } | |
+ } | |
+ buf[ibuf] = 0; | |
+ | |
if(!font || !text) | |
return; | |
- XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext); | |
+ XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)buf, ibuf, &ext); | |
tex->h = font->h; | |
tex->w = ext.xOff; | |
} | |
diff --git a/drw.h b/drw.h | |
index 536171b..855b4e9 100644 | |
--- a/drw.h | |
+++ b/drw.h | |
@@ -1,6 +1,8 @@ | |
/* See LICENSE file for copyright and license details. */ | |
#define DRW_FONT_CACHE_SIZE 32 | |
+#define NUMSCHEMES 3 | |
+ | |
typedef struct { | |
unsigned long pix; | |
XftColor rgb; | |
@@ -67,8 +69,8 @@ void drw_setfont(Drw *drw, Fnt *font); | |
void drw_setscheme(Drw *drw, ClrScheme *scheme); | |
/* Drawing functions */ | |
-void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert); | |
-int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int invert); | |
+void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty); | |
+int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int pad); | |
/* Map functions */ | |
void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h); | |
diff --git a/dwm.c b/dwm.c | |
index 169adcb..a8fd1c0 100644 | |
--- a/dwm.c | |
+++ b/dwm.c | |
@@ -60,6 +60,7 @@ | |
/* enums */ | |
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ | |
enum { SchemeNorm, SchemeSel, SchemeLast }; /* color schemes */ | |
+enum { ColBorder, ColBG, ColFG, ColLast }; /* scheme elements */ | |
enum { NetSupported, NetWMName, NetWMState, | |
NetWMFullscreen, NetActiveWindow, NetWMWindowType, | |
NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */ | |
@@ -164,6 +165,7 @@ static void detachstack(Client *c); | |
static Monitor *dirtomon(int dir); | |
static void drawbar(Monitor *m); | |
static void drawbars(void); | |
+static void drawcoloredtext(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text); | |
static void enternotify(XEvent *e); | |
static void expose(XEvent *e); | |
static void focus(Client *c); | |
@@ -261,7 +263,7 @@ static void (*handler[LASTEvent]) (XEvent *) = { | |
static Atom wmatom[WMLast], netatom[NetLast]; | |
static Bool running = True; | |
static Cur *cursor[CurLast]; | |
-static ClrScheme scheme[SchemeLast]; | |
+static ClrScheme scheme[NUMSCHEMES]; | |
static Display *dpy; | |
static Drw *drw; | |
static Monitor *mons, *selmon; | |
@@ -690,6 +692,32 @@ dirtomon(int dir) { | |
} | |
void | |
+drawcoloredtext(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text) { | |
+ char *buf = (char *)text, *ptr = buf, c = 1; | |
+ ClrScheme col = scheme[SchemeNorm]; | |
+ int i, ox = x; | |
+ | |
+ while(*ptr) { | |
+ for(i = 0; *ptr < 0 || *ptr > NUMSCHEMES; i++, ptr++); | |
+ if(!*ptr) break; | |
+ c = *ptr; | |
+ *ptr = 0; | |
+ if(i) { | |
+ w = selmon->ww - x; | |
+ drw_setscheme(drw, &col); | |
+ drw_text(drw, x, 0, w, bh, buf, 1); | |
+ x += drw_font_getexts_width(drw->fonts[0], buf, i); | |
+ } | |
+ *ptr = c; | |
+ col = scheme[c - 1]; | |
+ buf = ++ptr; | |
+ } | |
+ drw_setscheme(drw, &col); | |
+ drw_text(drw, x, 0, w, bh, buf, 1); | |
+ x = ox; | |
+} | |
+ | |
+void | |
drawbar(Monitor *m) { | |
int x, xx, w; | |
unsigned int i, occ = 0, urg = 0; | |
@@ -703,15 +731,15 @@ drawbar(Monitor *m) { | |
x = 0; | |
for(i = 0; i < LENGTH(tags); i++) { | |
w = TEXTW(tags[i]); | |
- drw_setscheme(drw, m->tagset[m->seltags] & 1 << i ? &scheme[SchemeSel] : &scheme[SchemeNorm]); | |
- drw_text(drw, x, 0, w, bh, tags[i], urg & 1 << i); | |
+ drw_setscheme(drw, &scheme[(m->tagset[m->seltags] & 1 << i) ? 1 : (urg & 1 << i ? 2:0)]); | |
+ drw_text(drw, x, 0, w, bh, tags[i], 1); | |
drw_rect(drw, x, 0, w, bh, m == selmon && selmon->sel && selmon->sel->tags & 1 << i, | |
- occ & 1 << i, urg & 1 << i); | |
+ occ & 1 << i); | |
x += w; | |
} | |
w = blw = TEXTW(m->ltsymbol); | |
drw_setscheme(drw, &scheme[SchemeNorm]); | |
- drw_text(drw, x, 0, w, bh, m->ltsymbol, 0); | |
+ drw_text(drw, x, 0, w, bh, m->ltsymbol, 1); | |
x += w; | |
xx = x; | |
if(m == selmon) { /* status is only drawn on selected monitor */ | |
@@ -721,16 +749,16 @@ drawbar(Monitor *m) { | |
x = xx; | |
w = m->ww - xx; | |
} | |
- drw_text(drw, x, 0, w, bh, stext, 0); | |
+ drawcoloredtext(drw, x, 0, w, bh, stext); | |
} | |
else | |
x = m->ww; | |
if((w = x - xx) > bh) { | |
x = xx; | |
if(m->sel) { | |
- drw_setscheme(drw, m == selmon ? &scheme[SchemeSel] : &scheme[SchemeNorm]); | |
- drw_text(drw, x, 0, w, bh, m->sel->name, 0); | |
- drw_rect(drw, x, 0, w, bh, m->sel->isfixed, m->sel->isfloating, 0); | |
+ drw_setscheme(drw, &scheme[m == selmon ? SchemeSel : SchemeNorm]); | |
+ drw_text(drw, x, 0, w, bh, m->sel->name, 1); | |
+ drw_rect(drw, x, 0, w, bh, m->sel->isfixed, m->sel->isfloating); | |
} | |
else { | |
drw_setscheme(drw, &scheme[SchemeNorm]); | |
@@ -1531,12 +1559,11 @@ setup(void) { | |
cursor[CurResize] = drw_cur_create(drw, XC_sizing); | |
cursor[CurMove] = drw_cur_create(drw, XC_fleur); | |
/* init appearance */ | |
- scheme[SchemeNorm].border = drw_clr_create(drw, normbordercolor); | |
- scheme[SchemeNorm].bg = drw_clr_create(drw, normbgcolor); | |
- scheme[SchemeNorm].fg = drw_clr_create(drw, normfgcolor); | |
- scheme[SchemeSel].border = drw_clr_create(drw, selbordercolor); | |
- scheme[SchemeSel].bg = drw_clr_create(drw, selbgcolor); | |
- scheme[SchemeSel].fg = drw_clr_create(drw, selfgcolor); | |
+ for(int i = 0; i < NUMSCHEMES; i++) { | |
+ scheme[i].border = drw_clr_create(drw, schemes[i][ColBorder]); | |
+ scheme[i].bg = drw_clr_create(drw, schemes[i][ColBG]); | |
+ scheme[i].fg = drw_clr_create(drw, schemes[i][ColFG]); | |
+ } | |
/* init bars */ | |
updatebars(); | |
updatestatus(); | |
@@ -1957,8 +1984,11 @@ updatewmhints(Client *c) { | |
wmh->flags &= ~XUrgencyHint; | |
XSetWMHints(dpy, c->win, wmh); | |
} | |
- else | |
+ else { | |
c->isurgent = (wmh->flags & XUrgencyHint) ? True : False; | |
+ if(c->isurgent) | |
+ XSetWindowBorder(dpy, c->win, scheme[SchemeLast].border->pix); | |
+ } | |
if(wmh->flags & InputHint) | |
c->neverfocus = !wmh->input; | |
else |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment