123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- diff -up dwm/drw.c dwm-statuscolors/drw.c
- --- dwm/drw.c 2015-11-08 15:39:37.000000000 -0700
- +++ dwm-statuscolors/drw.c 2015-11-28 15:42:28.534399525 -0700
- @@ -206,6 +206,68 @@ drw_setscheme(Drw *drw, ClrScheme *schem
- drw->scheme = scheme;
- }
-
- +int
- +drw_get_width(Drw *drw, int numcolors, const char *text)
- +{
- + int i;
- + Fnt *curfont = drw->fonts[0];
- + int w = drw_text(drw, 0, 0, 0, 0, text, 0) + curfont->h;
- +
- + 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 -= curfont->xfont->max_advance_width;
- +
- + if (i == 0 || i + 1 == strlen(text)) {
- + /* we're on the first or the last character of the string
- + * drw_text already added one character's height (divided by 2) as padding to the beginning and end
- + * we don't want to double this padding, so we skip this character */
- + continue;
- + }
- +
- + if (text[i - 1] > 0 && text[i - 1] <= numcolors) {
- + /* the previous character was also a color code
- + * we already added padding in the previous iteration
- + * we don't want to double this padding, so we skip this character */
- + continue;
- + }
- +
- + /* we are somewhere in the middle of the string and the color has changed
- + * we want to add one character's height (divided by 2) as padding to the end of the previous colored text
- + * and to the beginning of the new colored text */
- + w += curfont->h;
- + }
- + }
- +
- + return w;
- +}
- +
- +void
- +drw_colored_text(Drw *drw, ClrScheme *scheme, int numcolors, int x, int y, unsigned int w, unsigned int h, char *text)
- +{
- + if (!drw || !drw->fontcount || !drw->scheme)
- + return;
- +
- + char *buf = text, *ptr = buf, c = 1;
- + int i;
- +
- + while (*ptr) {
- + for (i = 0; *ptr < 0 || *ptr > numcolors; i++, ptr++);
- + if (!*ptr)
- + break;
- + c = *ptr;
- + *ptr = 0;
- + if (i)
- + x = drw_text(drw, x, y, w, h, buf, 0) + drw->fonts[0]->h;
- + *ptr = c;
- + drw_setscheme(drw, &scheme[c-1]);
- + buf = ++ptr;
- + }
- + drw_text(drw, x, y, w, h, buf, 0);
- +}
- +
- void
- drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert)
- {
- diff -up dwm/drw.h dwm-statuscolors/drw.h
- --- dwm/drw.h 2015-11-08 15:39:37.000000000 -0700
- +++ dwm-statuscolors/drw.h 2015-11-28 15:39:44.427726312 -0700
- @@ -67,6 +67,8 @@ void drw_setfont(Drw *, Fnt *);
- void drw_setscheme(Drw *, ClrScheme *);
-
- /* Drawing functions */
- +int drw_get_width(Drw *, int, const char *);
- +void drw_colored_text(Drw *, ClrScheme *, int, int, int, unsigned int, unsigned int, char *);
- void drw_rect(Drw *, int, int, unsigned int, unsigned int, int, int, int);
- int drw_text(Drw *, int, int, unsigned int, unsigned int, const char *, int);
-
- diff -up dwm/dwm.c dwm-statuscolors/dwm.c
- --- dwm/dwm.c 2015-11-08 15:39:37.000000000 -0700
- +++ dwm-statuscolors/dwm.c 2015-11-28 15:45:32.134406853 -0700
- @@ -51,6 +51,7 @@
- * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
- #define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
- #define LENGTH(X) (sizeof X / sizeof X[0])
- +#define MAXCOLORS 9
- #define MOUSEMASK (BUTTONMASK|PointerMotionMask)
- #define WIDTH(X) ((X)->w + 2 * (X)->bw)
- #define HEIGHT(X) ((X)->h + 2 * (X)->bw)
- @@ -261,7 +262,7 @@ static void (*handler[LASTEvent]) (XEven
- static Atom wmatom[WMLast], netatom[NetLast];
- static int running = 1;
- static Cur *cursor[CurLast];
- -static ClrScheme scheme[SchemeLast];
- +static ClrScheme scheme[MAXCOLORS];
- static Display *dpy;
- static Drw *drw;
- static Monitor *mons, *selmon;
- @@ -718,35 +719,35 @@ 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], 0);
- drw_rect(drw, x + 1, 1, dx, dx, m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
- - occ & 1 << i, urg & 1 << i);
- + occ & 1 << i, 0);
- x += w;
- }
- w = blw = TEXTW(m->ltsymbol);
- - drw_setscheme(drw, &scheme[SchemeNorm]);
- + drw_setscheme(drw, &scheme[0]);
- drw_text(drw, x, 0, w, bh, m->ltsymbol, 0);
- x += w;
- xx = x;
- if (m == selmon) { /* status is only drawn on selected monitor */
- - w = TEXTW(stext);
- + w = drw_get_width(drw, NUMCOLORS, stext);
- x = m->ww - w;
- if (x < xx) {
- x = xx;
- w = m->ww - xx;
- }
- - drw_text(drw, x, 0, w, bh, stext, 0);
- + drw_colored_text(drw, scheme, NUMCOLORS, 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_setscheme(drw, &scheme[m == selmon ? 1 : 0]);
- drw_text(drw, x, 0, w, bh, m->sel->name, 0);
- drw_rect(drw, x + 1, 1, dx, dx, m->sel->isfixed, m->sel->isfloating, 0);
- } else {
- - drw_setscheme(drw, &scheme[SchemeNorm]);
- + drw_setscheme(drw, &scheme[0]);
- drw_rect(drw, x, 0, w, bh, 1, 0, 1);
- }
- }
- @@ -807,7 +808,7 @@ focus(Client *c)
- detachstack(c);
- attachstack(c);
- grabbuttons(c, 1);
- - XSetWindowBorder(dpy, c->win, scheme[SchemeSel].border->pix);
- + XSetWindowBorder(dpy, c->win, scheme[1].border->pix);
- setfocus(c);
- } else {
- XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
- @@ -1065,7 +1066,7 @@ manage(Window w, XWindowAttributes *wa)
-
- wc.border_width = c->bw;
- XConfigureWindow(dpy, w, CWBorderWidth, &wc);
- - XSetWindowBorder(dpy, w, scheme[SchemeNorm].border->pix);
- + XSetWindowBorder(dpy, w, scheme[0].border->pix);
- configure(c); /* propagates border_width, if size doesn't change */
- updatewindowtype(c);
- updatesizehints(c);
- @@ -1580,12 +1581,12 @@ 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 < NUMCOLORS; i++){
- + scheme[i].border = drw_clr_create(drw, colors[i][0]);
- + scheme[i].fg = drw_clr_create(drw, colors[i][1]);
- + scheme[i].bg = drw_clr_create(drw, colors[i][2]);
- + }
- +
- /* init bars */
- updatebars();
- updatestatus();
- @@ -1745,7 +1746,7 @@ unfocus(Client *c, int setfocus)
- if (!c)
- return;
- grabbuttons(c, 0);
- - XSetWindowBorder(dpy, c->win, scheme[SchemeNorm].border->pix);
- + XSetWindowBorder(dpy, c->win, scheme[0].border->pix);
- if (setfocus) {
- XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
- XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
|