xbattmon

simple battery monitor for X
git clone git://git.2f30.org/xbattmon
Log | Files | Refs | README | LICENSE

commit 717451927241d6b6249c9f2caf25cfcffe9865d6
parent f59dca559a08c22a2091594ecdeb027af7168616
Author: sin <sin@2f30.org>
Date:   Fri, 31 Oct 2014 22:24:13 +0000

Just expose an array of colors to the user

Diffstat:
Mconfig.def.h | 13+++++--------
Mxbattmon.c | 16+++++++++-------
2 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -1,11 +1,8 @@ -struct { - char *name; - unsigned long pixel; -} colmap[] = { - [COLOR_BATT_CHARGED] = { "green", 0 }, - [COLOR_BATT_LEFT2CHARGE] = { "grey", 0 }, - [COLOR_BATT_DRAINED] = { "red", 0 }, - [COLOR_BATT_LEFT2DRAIN] = { "blue", 0 } +char *colors[] = { + [COLOR_BATT_CHARGED] = "green", + [COLOR_BATT_LEFT2CHARGE] = "grey", + [COLOR_BATT_DRAINED] = "red", + [COLOR_BATT_LEFT2DRAIN] = "blue" }; unsigned int thickness = 4; /* 4 pixels by default */ diff --git a/xbattmon.c b/xbattmon.c @@ -52,6 +52,8 @@ int howmuch; /* 0 if completely discharged or `maxcap' if completely charged * #include "config.h" +unsigned long cmap[LEN(colors)]; + void setup(void) { @@ -94,12 +96,12 @@ setup(void) gcbar = XCreateGC(dpy, winbar, 0, 0); - for (i = 0; i < LEN(colmap); i++) { + for (i = 0; i < LEN(colors); i++) { r = XAllocNamedColor(dpy, DefaultColormap(dpy, 0), - colmap[i].name, &color, &exact); + colors[i], &color, &exact); if (r == 0) errx(1, "cannot allocate color resources"); - colmap[i].pixel = color.pixel; + cmap[i] = color.pixel; } } @@ -111,15 +113,15 @@ redraw(void) pos = barwidth * howmuch / maxcap; switch (state) { case AC_ON: - XSetForeground(dpy, gcbar, colmap[COLOR_BATT_CHARGED].pixel); + XSetForeground(dpy, gcbar, cmap[COLOR_BATT_CHARGED]); XFillRectangle(dpy, winbar, gcbar, 0, 0, pos, thickness); - XSetForeground(dpy, gcbar, colmap[COLOR_BATT_LEFT2CHARGE].pixel); + XSetForeground(dpy, gcbar, cmap[COLOR_BATT_LEFT2CHARGE]); XFillRectangle(dpy, winbar, gcbar, pos, 0, barwidth, thickness); break; case AC_OFF: - XSetForeground(dpy, gcbar, colmap[COLOR_BATT_LEFT2DRAIN].pixel); + XSetForeground(dpy, gcbar, cmap[COLOR_BATT_LEFT2DRAIN]); XFillRectangle(dpy, winbar, gcbar, 0, 0, pos, thickness); - XSetForeground(dpy, gcbar, colmap[COLOR_BATT_DRAINED].pixel); + XSetForeground(dpy, gcbar, cmap[COLOR_BATT_DRAINED]); XFillRectangle(dpy, winbar, gcbar, pos, 0, barwidth, thickness); break; }