diff --git a/config.def.h b/config.def.h index 8fd5d4a..0f67f44 100644 --- a/config.def.h +++ b/config.def.h @@ -12,6 +12,7 @@ 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 */ static const Bool topbar = True; /* False means bottom bar */ +static const char invert_delim[] = "*"; /* Character to use to switch between norm/sel drawing in statusbar */ /* tagging */ static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; diff --git a/dwm.c b/dwm.c index d9443da..92059b5 100644 --- a/dwm.c +++ b/dwm.c @@ -180,6 +180,7 @@ static void drawbar(Monitor *m); static void drawbars(void); static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); static void drawtext(const char *text, unsigned long col[ColLast], Bool invert); +static void drawstatus(const char *text); static void enternotify(XEvent *e); static void expose(XEvent *e); static void focus(Client *c); @@ -740,7 +741,7 @@ drawbar(Monitor *m) { dc.x = x; dc.w = m->ww - x; } - drawtext(stext, dc.norm, False); + drawstatus(stext); } else dc.x = m->ww; @@ -806,6 +807,46 @@ drawtext(const char *text, unsigned long col[ColLast], Bool invert) { } void +drawstatus(const char *text) { + int len = strlen(text); + int i, x, y, h; + char inv_d = invert_delim[0]; + Bool invert = False; + char buff[256] = ""; + char full_buff[256] = ""; + + h = dc.font.ascent + dc.font.descent; + y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; + x = dc.x + (h/2); + + XSetForeground(dpy, dc.gc, (invert?dc.sel:dc.norm)[ColBG]); + XFillRectangle(dpy, dc.drawable, dc.gc, dc.x, dc.y, dc.w, dc.h); + + for (i = 0; i < len; i++) { + x += (text[i] == inv_d) * textnw(" ", 1); + } + + for (i = 0; i <= len; i++) { + if (text[i] == inv_d || text[i] == '\0') { + XSetForeground(dpy, dc.gc, (invert?dc.sel:dc.norm)[ColFG]); + + if(dc.font.set) + XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, + x, y, buff, strlen(buff)); + else + XDrawString(dpy, dc.drawable, dc.gc, x, y, buff, strlen(buff)); + + x += textnw(buff, strlen(buff)); + invert = !invert; + strcpy(buff, "\0"); + } else { + strncat(buff, &(text)[i], 1); + strncat(full_buff, &(text)[i], 1); + } + } +} + +void enternotify(XEvent *e) { Client *c; Monitor *m;