#include <X11/Xlib.h>
#include <X11/Xutil.h>
+#include <X11/Xresource.h>
#define TOP 60
#define BOTTOM 3600
chdir_base();
}
-/*---------- display ----------*/
+/*---------- argument parsing ----------*/
#define COLOURS \
- C(dimgrey) \
- C(blue) \
- C(black) \
- C(red) \
- C(green) \
- C(cyan) \
- C(grey) \
- C(darkgreen) \
- C(yellow) \
- C(white) \
+ C(blue, discharging) \
+ C(green, charging) \
+ C(cyan, charged) \
+ C(grey, confusing) \
+ C(black, normal) \
+ C(red, low) \
+ C(dimgrey, degraded) \
+ C(darkgreen, absent) \
+ C(yellow, error) \
+ C(white, equilibrium) \
GC(remain) \
GC(white) \
GC(empty)
+static XrmDatabase xrm;
+
+static const char defaultresources[]=
+#define GC(g)
+#define C(c,u) \
+ "*" #u "Color: " #c "\n"
+ COLOURS
+#undef GC
+#undef C
+ ;
+
+#define S(s) ((char*)(s))
+static const XrmOptionDescRec optiontable[]= {
+ { S("-display"), S("*display"), XrmoptionSepArg },
+ { S("-geometry"), S("*geometry"), XrmoptionSepArg },
+#define GC(g)
+#define C(c,u) \
+ { S("-" #u "Color"), S("*" #u "Color"), XrmoptionSepArg }, \
+ { S("-" #u "Colour"), S("*" #u "Color"), XrmoptionSepArg },
+ COLOURS
+#undef GC
+#undef C
+};
+
+static void parseargs(int argc, char **argv) {
+ XrmInitialize();
+
+ xrm= XrmGetStringDatabase((char*)defaultresources);
+ if (!xrm) fail("xrmgetstringdatabase");
+
+ XrmParseCommand(&xrm, (XrmOptionDescRec*)optiontable,
+ sizeof(optiontable)/sizeof(*optiontable),
+ program_name, &argc, argv);
+
+ /* if (argc>0) badusage();*/
+}
+
+static const char *getresource(const char *want) {
+ char name_buf[256], class_buf[256];
+ XrmValue val;
+ char *rep_type_dummy;
+ int r;
+
+ assert(strlen(want) < 128);
+ sprintf(name_buf,"xacpi-simple.%s",want);
+ sprintf(class_buf,"Xacpi-Simple.%s",want);
+
+ r= XrmGetResource(xrm, name_buf,class_buf, &rep_type_dummy, &val);
+ if (!r) return 0;
+
+ return val.addr;
+}
+
+/*---------- display ----------*/
+
static Display *disp;
static Window win;
static int width, height;
unsigned long lastfg;
} Gcstate;
-#define C(c) static unsigned long pix_##c;
+#define C(c,u) static unsigned long pix_##c;
#define GC(g) static Gcstate gc_##g;
COLOURS
#undef C
gc_r->gc= XCreateGC(disp,win, GCFunction|GCLineWidth|GCForeground, &gcv);
}
-static void colour(unsigned long *pix_r, const char *name) {
+static void colour(unsigned long *pix_r, const char *whichcolour) {
XColor xc;
+ const char *name;
Status st;
+
+ name= getresource(whichcolour);
+ if (!name) fail("get colour resource");
st= XAllocNamedColor(disp,cmap,name,&xc,&xc);
if (!st) fail(name);
program_name_silly= (char*)program_name;
- disp= XOpenDisplay(0);
+ disp= XOpenDisplay(getresource("display"));
if (!disp) fail("could not open display");
screen= DefaultScreen(disp);
if (!normal_hints || !wm_hints || !class_hint)
fail("could not alloc hint(s)");
- geom_string= argc>=2 ? argv[1] : 0;
+ geom_string= getresource("geometry");
r= XWMGeometry(disp,screen, geom_string,"128x32", 0,
normal_hints,
pos_x,pos_y,width,height,0,0,0);
cmap= DefaultColormap(disp,screen);
-#define C(c) colour(&pix_##c, #c);
+#define C(c,u) colour(&pix_##c, #u "Color");
#define GC(g) initgc(&gc_##g);
COLOURS
#undef C
}
int main(int argc, char **argv) {
- if (argc<1 || argc>2)
- badusage();
-
+ parseargs(argc,argv);
initacquire();
initgraphics(argc,argv);
eventloop();