Another simple patch for anyone interested. Changes the way colors are
defined slighty, allowing you to create more color combinations. Then,
to color the status text from stdin you can simply use the color combo # as
follows:
echo -e "\x03 warning low battery" -- will be printed with the third color
combo
echo -e "\x04 danger will robinson" -- will be printed with the fourth color
combo
echo -e " normal text \x03 warning \x04 error \x01 normal again"
For example, my colors in config.h are:
#define NUMCOLORS 4
static const char colors[NUMCOLORS][ColLast][8] = {
// border foreground background
{ "#33", "#dd", "#33" }, // normal
{ "#88", "#ff", "#88" }, // selected
{ "#ff", "#00", "#00" }, // urgent/warning (black on yellow)
{ "#ff", "#ff", "#ff" }, // error (white on red)
// add more here
};
Which, coupled with my own status script results in things like the attached
image.
Hope someone else finds this handy, I let my battery die one too many
times because I never noticed how low it was...
Jeremy
diff -r f6c3491c41f1 config.def.h
--- a/config.def.h Sun Nov 16 13:22:24 2008 +
+++ b/config.def.h Thu Dec 04 13:29:50 2008 -0500
@@ -1,13 +1,16 @@
/* See LICENSE file for copyright and license details. */
/* appearance */
+#define NUMCOLORS 4
+static const char colors[NUMCOLORS][ColLast][8] = {
+ // border foreground background
+ { "#cc", "#00", "#cc" }, // normal
+ { "#0066ff", "#ff", "#0066ff" }, // selected
+ { "#0066ff", "#0066ff", "#ff" }, // urgent/warning
+ { "#ff", "#ff", "#ff" }, // error
+ // add more here
+};
static const char font[]=
"-*-terminus-medium-r-normal-*-14-*-*-*-*-*-*-*";
-static const char normbordercolor[] = "#cc";
-static const char normbgcolor[] = "#cc";
-static const char normfgcolor[] = "#00";
-static const char selbordercolor[] = "#0066ff";
-static const char selbgcolor[] = "#0066ff";
-static const char selfgcolor[] = "#ff";
static unsigned int borderpx= 1;/* border pixel of windows */
static unsigned int snap= 32; /* snap pixel */
static Bool showbar = True; /* False means no bar */
@@ -49,7 +52,7 @@
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
/* commands */
-static const char *dmenucmd[] = { "dmenu_run", "-fn", font, "-nb",
normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL };
+static const char *dmenucmd[] = { "dmenu_run", "-fn", font, "-nb",
colors[0][ColBG], "-nf", colors[0][ColFG], "-sb", colors[1][ColBG], "-sf",
colors[1][ColFG], NULL };
static const char *termcmd[] = { "uxterm", NULL };
static Key keys[] = {
diff -r f6c3491c41f1 dwm.c
--- a/dwm.c Sun Nov 16 13:22:24 2008 +
+++ b/dwm.c Thu Dec 04 13:29:50 2008 -0500
@@ -52,6 +52,7 @@
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAXTAGLEN 16
+#define MAXCOLORS 8
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
#define WIDTH(x)((x)->w + 2 * (x)->bw)
#define HEIGHT(x) ((x)->h + 2 * (x)->bw)
@@ -97,8 +98,7 @@
typedef struct {
int x, y, w, h;
- unsigned long norm[ColLast];
- unsigned long sel[ColLast];
+ unsigned long colors[MAXCOLORS][ColLast];
Drawable drawable;
GC gc;
struct {
@@ -147,8 +147,9 @@
static void detachstack(Client *c);
static void die(const char *errstr, ...);
static void drawbar(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 drawcoloredtext(char *text);
+static void drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]);
+static void drawtext(const char *text, unsigned long col[ColLast], Bool pad);
static void enternotify(XEvent *e);
static void expose(XEvent *e);
static void focus(Client *c);
@@ -506,14 +507,14 @@
dc.x = 0;
for(i = 0; i < LENGTH(tags); i++) {
dc.w = TEXTW(tags[i]);
- col = tagset[seltags] & 1 << i ? dc.sel : dc.norm;
- drawtext(tags[i], col, urg & 1 << i);
- drawsquare(sel && sel->tags & 1 << i, occ & 1 << i, urg & 1 <<
i, col);
+ col = dc.colors[ (tagset[seltags] & 1 << i ? 1 : (urg & 1 << i
? 2:0)) ];
+ drawtext(tags[i], col, True);
+ drawsquare(sel && tagset[seltags] & 1 << i, occ & 1 << i, col);
dc.x += dc.w;
}
if(blw > 0) {
dc.w = blw;
- drawtext(lt[sellt]->symbol, dc.norm, False);
+ drawtext(lt[sellt]->symbol, dc.colors[0], True);