X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=blobdiff_plain;f=cprogs%2Fxacpi-simple.c;h=f2ba491d93adbc41d8773eedf77b4564f90ece13;hp=9d67c37bbbe7ba69b1e287853645afb05bc7f112;hb=6f9f49dbd62f0889fbbbbc249d1ae33f4e91269e;hpb=ff6c7766afc520c1248e4abedff7a8ba474ea024 diff --git a/cprogs/xacpi-simple.c b/cprogs/xacpi-simple.c index 9d67c37..f2ba491 100644 --- a/cprogs/xacpi-simple.c +++ b/cprogs/xacpi-simple.c @@ -1,16 +1,16 @@ /* * display outputs, per line: * - * Remaining: | Empty: | Degraded: - * blue | black | dimgrey discharging - * green | black | dimgrey charging - * cyan | black | dimgrey charged - * grey | black | dimgrey charging&discharching! - * darkcyan | black | dimgrey none of the above - * blue | red | dimgrey discharging - low! - * green | red | dimgrey charging - low - * cyan | red | dimgrey charged - low [1] - * grey | red | dimgrey charging&discharching, low [1] + * Remaining: | Empty: | Degraded: + * blue | black | dimgrey discharging + * green | black | dimgrey charging + * cyan | black | dimgrey charged + * grey | black | dimgrey charging&discharching! + * lightgrey | black | dimgrey none of the above + * blue | red | dimgrey discharging - low! + * green | red | dimgrey charging - low + * cyan | red | dimgrey charged - low [1] + * grey | red | dimgrey charging&discharching, low [1] * ... darkgreen ... no batteries present * ... yellow ... error * @@ -153,7 +153,6 @@ typedef struct batinfo_field { #define ALL_PLAIN_ACCUMULATE_FIELDS(_) \ UEVENT_ESSENTIAL_QUANTITY_FIELDS(_) \ - UEVENT_ENUM_FIELDS(_) \ SEPARATE_QUANTITY_FIELDS(_) #define ALL_ACCUMULATE_FIELDS(_) \ @@ -358,13 +357,15 @@ static double total_##f; ALL_ACCUMULATE_FIELDS(Q_VAR) static void acquiredata(void) { - DIR *di; + DIR *di = 0; struct dirent *de; int r; charging_mask= 0; alarmed = 0; + if (debug) printf("\n"); + #define Q_ZERO(f,t,...) \ total_##f= 0; ALL_ACCUMULATE_FIELDS(Q_ZERO) @@ -426,9 +427,11 @@ ALL_PLAIN_ACCUMULATE_FIELDS(Q_ACCUMULATE_PLAIN) } - closedir(di); + if (di) closedir(di); - printf("TOTAL:\n"); + if (debug) { + printf("TOTAL:\n"); + printf(" %-30s = %#20x\n", "mask", charging_mask); #define T_PRINT(f,...) \ printf(" %-30s = %20.6f\n", #f, total_##f); BAT_QTYS(T_PRINT,,,) @@ -464,17 +467,17 @@ static void initacquire(void) { /*---------- argument parsing ----------*/ #define COLOURS \ - C(blue, discharging) \ - C(green, charging) \ - C(cyan, charged) \ - C(darkcyan, notcharging) \ - C(grey, confusing) \ - C(black, normal) \ - C(red, low) \ - C(dimgrey, degraded) \ - C(darkgreen, absent) \ - C(yellow, error) \ - C(white, equilibrium) \ + C(blue, discharging) \ + C(green, charging) \ + C(cyan, charged) \ + C(lightgrey, notcharging) \ + 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) @@ -573,7 +576,7 @@ typedef struct { unsigned long lastfg; } Gcstate; -#define C(c,u) static unsigned long pix_##c; +#define C(c,u) static unsigned long pix_##u; #define GC(g) static Gcstate gc_##g; COLOURS #undef C @@ -619,23 +622,23 @@ static void show(void) { int i, leftmost_lit, leftmost_nondeg, beyond, first_beyond; if (!charging_mask) - return show_solid(pix_darkgreen); + return show_solid(pix_absent); if (charging_mask & (1u << CHGST_ERROR)) - return show_solid(pix_yellow); + return show_solid(pix_error); - setbackground(pix_dimgrey); + setbackground(pix_degraded); XClearWindow(disp,win); setforeground(&gc_remain, !(charging_mask & CHGMASK_CHG_DIS) ? (~charging_mask & (1u << CHGST_CHARGED) ? - pix_darkcyan : pix_cyan) : - !(~charging_mask & CHGMASK_CHG_DIS) ? pix_grey : + pix_notcharging : pix_charged) : + !(~charging_mask & CHGMASK_CHG_DIS) ? pix_confusing : charging_mask & (1u<lastfg= gcv.foreground= pix_white; + gc_r->lastfg= gcv.foreground= pix_equilibrium; gc_r->gc= XCreateGC(disp,win, GCFunction|GCLineWidth|GCForeground, &gcv); } @@ -721,15 +724,15 @@ static void initgraphics(int argc, char **argv) { pos_x,pos_y,width,height,0,0,0); cmap= DefaultColormap(disp,screen); -#define C(c,u) colour(&pix_##c, #u "Color"); +#define C(c,u) colour(&pix_##u, #u "Color"); #define GC(g) initgc(&gc_##g); COLOURS #undef C #undef GC - r= XSetWindowBackground(disp,win,pix_dimgrey); + r= XSetWindowBackground(disp,win,pix_degraded); if (!r) fail("init set background"); - lastbackground= pix_dimgrey; + lastbackground= pix_degraded; normal_hints->flags= PWinGravity; normal_hints->win_gravity= gravity; @@ -760,15 +763,9 @@ static void refresh(void) { static void newgeometry(void) { int dummy; - unsigned int udummy, gotwidth, gotheight; Window dummyw; - XGetGeometry(disp,win, &dummyw,&dummy,&dummy, &gotwidth,&gotheight, - &udummy,&udummy); - assert(gotwidth < INT_MAX); - assert(gotheight < INT_MAX); - width = gotwidth; - height = gotheight; + XGetGeometry(disp,win, &dummyw,&dummy,&dummy, &width,&height, &dummy,&dummy); } static void eventloop(void) {