diff options
| author | Douglas Rumbaugh <doug@douglasrumbaugh.com> | 2021-12-25 13:29:52 -0500 |
|---|---|---|
| committer | Douglas Rumbaugh <doug@douglasrumbaugh.com> | 2021-12-25 13:29:52 -0500 |
| commit | 1eb83d40737d44c07ae5f61134f73d08e5150c9b (patch) | |
| tree | 295954aa5aa89cfbc94167b30d2e2c691333f9fe | |
| parent | 5784018c18d5af4e8fa1bca7975547fb02dda873 (diff) | |
| download | dwm-1eb83d40737d44c07ae5f61134f73d08e5150c9b.tar.gz | |
Applied status2d with xrdb patch
https://dwm.suckless.org/patches/status2d/
For color support in the status bar. Had to tweak the xrdb patch a
bit to make it work with the xresources patch already applied.
Currently had a bug where an unprintable character is shown at the
beginning of the status bar when a symbol is present.
| -rw-r--r-- | config.def.h | 50 | ||||
| -rw-r--r-- | dwm.c | 131 |
2 files changed, 172 insertions, 9 deletions
diff --git a/config.def.h b/config.def.h index 631874d..caac1a9 100644 --- a/config.def.h +++ b/config.def.h @@ -26,6 +26,40 @@ static char normfgcolor[] = "#bbbbbb"; static char selfgcolor[] = "#eeeeee"; static char selbordercolor[] = "#005577"; static char selbgcolor[] = "#005577"; +static char termcol0[] = "#000000"; /* black */ +static char termcol1[] = "#ff0000"; /* red */ +static char termcol2[] = "#33ff00"; /* green */ +static char termcol3[] = "#ff0099"; /* yellow */ +static char termcol4[] = "#0066ff"; /* blue */ +static char termcol5[] = "#cc00ff"; /* magenta */ +static char termcol6[] = "#00ffff"; /* cyan */ +static char termcol7[] = "#d0d0d0"; /* white */ +static char termcol8[] = "#808080"; /* black */ +static char termcol9[] = "#ff0000"; /* red */ +static char termcol10[] = "#33ff00"; /* green */ +static char termcol11[] = "#ff0099"; /* yellow */ +static char termcol12[] = "#0066ff"; /* blue */ +static char termcol13[] = "#cc00ff"; /* magenta */ +static char termcol14[] = "#00ffff"; /* cyan */ +static char termcol15[] = "#ffffff"; /* white */ +static char *termcolor[] = { + termcol0, + termcol1, + termcol2, + termcol3, + termcol4, + termcol5, + termcol6, + termcol7, + termcol8, + termcol9, + termcol10, + termcol11, + termcol12, + termcol13, + termcol14, + termcol15, +}; static char *colors[][3] = { /* fg bg border */ [SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor }, @@ -132,6 +166,22 @@ ResourcePref resources[] = { { "nmaster", INTEGER, &nmaster }, { "resizehints", INTEGER, &resizehints }, { "mfact", FLOAT, &mfact }, + { "color0", STRING, &termcol0}, + { "color1", STRING, &termcol1}, + { "color2", STRING, &termcol2}, + { "color3", STRING, &termcol3}, + { "color4", STRING, &termcol4}, + { "color5", STRING, &termcol5}, + { "color6", STRING, &termcol6}, + { "color7", STRING, &termcol7}, + { "color8", STRING, &termcol8}, + { "color9", STRING, &termcol9}, + { "color10", STRING, &termcol10}, + { "color11", STRING, &termcol11}, + { "color12", STRING, &termcol12}, + { "color13", STRING, &termcol13}, + { "color14", STRING, &termcol14}, + { "color15", STRING, &termcol15}, }; @@ -194,6 +194,7 @@ static void detachstack(Client *c); static Monitor *dirtomon(int dir); static void drawbar(Monitor *m); static void drawbars(void); +static int drawstatusbar(Monitor *m, int bh, char* text); static void enternotify(XEvent *e); static void expose(XEvent *e); static void focus(Client *c); @@ -280,7 +281,7 @@ static pid_t winpid(Window w); /* variables */ static const char broken[] = "broken"; -static char stext[256]; +static char stext[1024]; static int statusw; static int statussig; static pid_t statuspid = -1; @@ -603,7 +604,7 @@ cleanup(void) cleanupmon(mons); for (i = 0; i < CurLast; i++) drw_cur_free(drw, cursor[i]); - for (i = 0; i < LENGTH(colors); i++) + for (i = 0; i < LENGTH(colors) + 1; i++) free(scheme[i]); XDestroyWindow(dpy, wmcheckwin); drw_free(drw); @@ -818,6 +819,120 @@ dirtomon(int dir) return m; } +int +drawstatusbar(Monitor *m, int bh, char* stext) { + int ret, i, w, x, len; + short isCode = 0; + char *text; + char *p; + + len = strlen(stext) + 1 ; + if (!(text = (char*) malloc(sizeof(char)*len))) + die("malloc"); + p = text; + memcpy(text, stext, len); + + /* compute width of the status text */ + w = 0; + i = -1; + while (text[++i]) { + if (text[i] == '^') { + if (!isCode) { + isCode = 1; + text[i] = '\0'; + w += TEXTW(text, statusfontindex) - lrpad; + text[i] = '^'; + if (text[++i] == 'f') + w += atoi(text + ++i); + } else { + isCode = 0; + text = text + i + 1; + i = -1; + } + } + } + if (!isCode) + w += TEXTW(text, statusfontindex) - lrpad; + else + isCode = 0; + text = p; + + w += 2; /* 1px padding on both sides */ + ret = x = m->ww - w; + + drw_setscheme(drw, scheme[LENGTH(colors)]); + drw->scheme[ColFg] = scheme[SchemeNorm][ColFg]; + drw->scheme[ColBg] = scheme[SchemeNorm][ColBg]; + drw_rect(drw, x, 0, w, bh, 1, 1); + x++; + + /* process status text */ + i = -1; + while (text[++i]) { + if (text[i] == '^' && !isCode) { + isCode = 1; + + text[i] = '\0'; + w = TEXTW(text, statusfontindex) - lrpad; + drw_text(drw, x, 0, w, bh, 0, text, 0, statusfontindex); + + x += w; + + /* process code */ + while (text[++i] != '^') { + if (text[i] == 'c') { + char buf[8]; + memcpy(buf, (char*)text+i+1, 7); + buf[7] = '\0'; + drw_clr_create(drw, &drw->scheme[ColFg], buf); + i += 7; + } else if (text[i] == 'b') { + char buf[8]; + memcpy(buf, (char*)text+i+1, 7); + buf[7] = '\0'; + drw_clr_create(drw, &drw->scheme[ColBg], buf); + i += 7; + } else if (text[i] == 'C') { + int c = atoi(text + ++i); + drw_clr_create(drw, &drw->scheme[ColFg], termcolor[c]); + } else if (text[i] == 'B') { + int c = atoi(text + ++i); + drw_clr_create(drw, &drw->scheme[ColBg], termcolor[c]); + } else if (text[i] == 'd') { + drw->scheme[ColFg] = scheme[SchemeNorm][ColFg]; + drw->scheme[ColBg] = scheme[SchemeNorm][ColBg]; + } else if (text[i] == 'r') { + int rx = atoi(text + ++i); + while (text[++i] != ','); + int ry = atoi(text + ++i); + while (text[++i] != ','); + int rw = atoi(text + ++i); + while (text[++i] != ','); + int rh = atoi(text + ++i); + + drw_rect(drw, rx + x, ry, rw, rh, 1, 0); + } else if (text[i] == 'f') { + x += atoi(text + ++i); + } + } + + text = text + i + 1; + i=-1; + isCode = 0; + } + } + + if (!isCode) { + w = TEXTW(text, statusfontindex) - lrpad; + drw_text(drw, x, 0, w, bh, 0, text, 0, statusfontindex); + } + + drw_setscheme(drw, scheme[SchemeNorm]); + free(p); + + return ret; +} + void drawbar(Monitor *m) { @@ -833,22 +948,19 @@ drawbar(Monitor *m) /* draw status first so it can be overdrawn by tags later */ if (m == selmon) { /* status is only drawn on selected monitor */ char *text, *s, ch; - drw_setscheme(drw, scheme[SchemeNorm]); x = 0; for (text = s = stext; *s; s++) { if ((unsigned char)(*s) < ' ') { ch = *s; *s = '\0'; - tw = TEXTW(text, statusfontindex) - lrpad; - drw_text(drw, m->ww - statusw + x, 0, tw, bh, 0, text, 0, statusfontindex); + tw = m->ww - drawstatusbar(m, bh, stext); x += tw; *s = ch; text = s + 1; } } - tw = TEXTW(stext, statusfontindex) - lrpad + 2; /* 2px right padding */ - drw_text(drw, m->ww - statusw + x, 0, tw, bh, 0, text, 0, statusfontindex); - tw = statusw; + + tw = m->ww - drawstatusbar(m, bh, stext); } for (c = m->clients; c; c = c->next) { @@ -1742,7 +1854,8 @@ setup(void) cursor[CurResize] = drw_cur_create(drw, XC_sizing); cursor[CurMove] = drw_cur_create(drw, XC_fleur); /* init appearance */ - scheme = ecalloc(LENGTH(colors), sizeof(Clr *)); + scheme = ecalloc(LENGTH(colors) + 1, sizeof(Clr *)); + scheme[LENGTH(colors)] = drw_scm_create(drw, colors[0], 3); for (i = 0; i < LENGTH(colors); i++) scheme[i] = drw_scm_create(drw, colors[i], 3); /* init bars */ |