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=c0810eaad93ce286a9a88097e0573c351acdf23b;hp=4dd74a79b7cdd0d3655471bbd0f9ba7dc1b065d7;hb=50227f5a203c93a5a13ef093de45352e0c68169e;hpb=b4e0eab2fc31a2b65988f149c065aa4992c08820 diff --git a/cprogs/xacpi-simple.c b/cprogs/xacpi-simple.c index 4dd74a7..c0810ea 100644 --- a/cprogs/xacpi-simple.c +++ b/cprogs/xacpi-simple.c @@ -1,3 +1,9 @@ +/* todo + power vs current + Full + old way of doing alarm +*/ + /* * display outputs, per line: * @@ -6,14 +12,34 @@ * 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] * ... darkgreen ... no batteries present + * ... yellow ... error * * [1] battery must be quite badly degraded */ +/* + * Copyright (C) 2004 Ian Jackson + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 3, + * or (at your option) any later version. + * + * This is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this file; if not, consult the Free Software + * Foundation's website at www.fsf.org, or the GNU Project website at + * www.gnu.org. + */ #include #include @@ -23,17 +49,24 @@ #include #include #include +#include +#include #include #include #include #include +#include +#include #define TOP 60 #define BOTTOM 3600 -#define TIMEOUT 5000 /* milliseconds */ +#define TIMEOUT 5000 /* milliseconds */ +#define TIMEOUT_ONERROR 3333 /* milliseconds */ + +static const char program_name[]= "xacpi-simple"; /*---------- general utility stuff and declarations ----------*/ @@ -43,55 +76,104 @@ static void fail(const char *m) { } static void badusage(void) { fail("bad usage"); } -#define CHGST_DISCHARGING 0 /* Reflects order in E(state,charging_state) */ -#define CHGST_CHARGING 1 /* in fields table. Also, much code assumes */ -#define CHGST_CHARGED 2 /* exactly these three possible states. */ +typedef uint64_t value; +#define VAL_NOTFOUND (~(value)0) -/*---------- structure of and results from /proc/acpi/battery/... ----------*/ -/* variables thisbat_... are the results from readbattery(); - * if readbattery() succeeds they are all valid and not VAL_NOTFOUND +typedef struct fileinfo fileinfo; +typedef int parser(const fileinfo*); + +static parser parse_uevent, parse_separate; + +struct fileinfo { + const char *filename; + parser *parse; + const void *extra; +}; + +/*---------- structure of and results from /sys/class/power/... ----------*/ +/* variables this_... are the results from readbattery(); + * if readbattery() succeeds the appropriate ones are all valid + * and not VAL_NOTFOUND */ typedef struct batinfo_field { - const char *file; const char *label; - unsigned long *valuep; - const char *unit; + value *valuep; const char *enumarray[10]; } batinfo_field; -#define QUANTITY_FIELDS \ - QF(info, design_capacity, "mWh") \ - QF(info, last_full_capacity, "mWh") \ - QF(state, present_rate, "mW") \ - QF(state, remaining_capacity, "mWh") \ - QF(alarm, alarm, "mWh") - -#define QF(f,l,u) static unsigned long thisbat_##f##_##l; - QUANTITY_FIELDS -#undef QF - -static unsigned long thisbat_alarm_present, thisbat_info_present; -static unsigned long thisbat_state_present, thisbat_state_charging_state; - -#define VAL_NOTFOUND (~0UL) - -static const batinfo_field fields[]= { -#define E(f,l) #f, #l, &thisbat_##f##_##l, 0 -#define QF(f,l,u) { #f, #l, &thisbat_##f##_##l, u }, - { E(alarm, present), { "no", "yes" } }, - { E(info, present), { "no", "yes" } }, - { E(state,present), { "no", "yes" } }, - { E(state,charging_state), { "discharging", "charging", "charged" } }, - QUANTITY_FIELDS /* take care re charging_state values order - */ - { 0 } /* if you must change it, search for CHGST_... */ -#undef E -#undef QF +#define BAT_QTYS(_) \ + _(design_capacity, ENERGY, CHARGE, FULL_DESIGN ) \ + _(last_full_capacity, ENERGY, CHARGE, FULL ) \ + _(remaining_capacity, ENERGY, CHARGE, NOW ) \ + _(present_rate, POWER, CURRENT, NOW ) + /* ENERGY [mWh]; POWER [mW]; CHARGE [uAh]; CURRENT [uA] */ + +#define UEVENT_QTY_CHARGE(f,lle,llc,lr) \ + _(f##_energy, BATTERY, lle##_##lr ) \ + _(f##_charge, BATTERY, llc##_##lr ) + +#define UEVENT_QUANTITY_FIELDS(_) \ + BAT_QTYS(UEVENT_QTY_CHARGE) \ + _(present, BATTERY, PRESENT ) /* boolean */ \ + _(online, MAINS, ONLINE ) /* boolean */ + +#define UEVENT_ENUM_FIELDS(_) \ + _(state, BATTERY, STATUS, "Discharging","Charging","Full","Unknown" ) \ + _(type, BOTH, TYPE, "Mains", "Battery" ) + +#define CHGST_DISCHARGING 0 /* Reflects order in _(state,...) above */ +#define CHGST_CHARGING 1 /* Also, much code assumes exactly */ +#define CHGST_CHARGED 2 /* these three possible states. */ +#define CHGST_UNKNOWN 3 /* these three possible states. */ +#define CHGST_ERROR 8 /* Except that this one is an extra bit. */ + +#define TYPE_MAINS 0 /* Reflects order in _(type,...) above */ +#define TYPE_BATTERY 1 /* Also, much code assumes exactly these two */ +#define TYPE_BOTH 100 /* Except this is a magic invalid value. */ + +#define SEPARATE_QUANTITY_FIELDS(_) \ + _(alarm, BATTERY, "alarm", "0", "1") + +#define ALL_FIELDS(_) \ + UEVENT_QUANTITY_FIELDS(_) \ + UEVENT_ENUM_FIELDS(_) \ + SEPARATE_QUANTITY_FIELDS(_) + +#define ALL_QUANTITY_FIELDS(_) \ + UEVENT_QUANTITY_FIELDS(_) \ + SEPARATE_QUANTITY_FIELDS(_) + +#define ALL_VARS(_) \ + ALL_FIELDS(_) \ + BAT_QTYS(_) + +#define F_VAR(f,...) \ +static value this_##f; +ALL_VARS(F_VAR) + +#define Q_FLD(f,t,l) { "POWER_SUPPLY_" #l, &this_##f }, +#define E_FLD(f,t,l,vl...) { "POWER_SUPPLY_" #l, &this_##f, { vl } }, + +static const batinfo_field uevent_fields[]= { + UEVENT_QUANTITY_FIELDS(Q_FLD) + UEVENT_ENUM_FIELDS(E_FLD) + { 0 } }; -static const char *files[]= { "info", "state", "alarm" }; +#define S_FLD(f,t,fn,vl...) \ +static const batinfo_field bif_##f = { 0, &this_##f, { vl } }; + SEPARATE_QUANTITY_FIELDS(S_FLD) + +#define S_FILE(f,t,fn,vl...) { fn, parse_separate, &bif_##f }, + +static const fileinfo files[]= { + { "uevent", parse_uevent, uevent_fields }, + SEPARATE_QUANTITY_FIELDS(S_FILE) + { 0 } +}; -/*---------- parsing of one battery in /proc/acpi/battery/... ----------*/ +/*---------- parsing of one thingx in /sys/class/power/... ----------*/ /* variables private to the parser and its error handlers */ static char batlinebuf[1000]; @@ -102,50 +184,111 @@ static const char *batlinevalue; static int batfailf(const char *why) { if (batlinevalue) { - fprintf(stderr,"battery/%s/%s: %s value `%s': %s\n", + fprintf(stderr,"%s/%s: %s value `%s': %s\n", batdirname,batfilename, batlinebuf,batlinevalue,why); } else { - fprintf(stderr,"battery/%s/%s: %s: `%s'\n", + fprintf(stderr,"%s/%s: %s: `%s'\n", batdirname,batfilename, why, batlinebuf); } return -1; } +static int batfailc(const char *why) { + fprintf(stderr,"%s/%s: %s\n", + batdirname,batfilename, why); + return -1; +} + static int batfaile(const char *syscall, const char *target) { - fprintf(stderr,"battery/%s: failed to %s %s: %s\n", + fprintf(stderr,"%s: failed to %s %s: %s\n", batdirname ? batdirname : "*", syscall, target, strerror(errno)); return -1; } -static void chdir_base(void) { +static int chdir_base(void) { int r; - r= chdir("/proc/acpi/battery"); - if (r) batfaile("chdir","/proc/acpi/battery"); + r= chdir("/sys/class/power_supply"); + if (r) return batfaile("chdir","/sys/class/power_supply"); + + return 0; } static void tidybattery(void) { if (batfile) { fclose(batfile); batfile=0; } - if (batdirname) { chdir_base(); batdirname=0; } } -static int readbattery(void) { /* 0=>ok, -1=>couldn't */ +static int parse_value(const fileinfo *cfile, const batinfo_field *field) { + if (*field->valuep != VAL_NOTFOUND) + return batfailf("value specified multiple times"); + + if (!field->enumarray[0]) { + + char *ep; + *field->valuep= strtoull(batlinevalue,&ep,10); + if (*ep) + batfailf("value number syntax incorrect"); + + } else { + + const char *const *enumsearch; + for (*field->valuep=0, enumsearch=field->enumarray; + *enumsearch && strcmp(*enumsearch,batlinevalue); + (*field->valuep)++, enumsearch++); + if (!*enumsearch) + batfailf("unknown enum value"); + + } + return 0; +} + +static int parse_separate(const fileinfo *cfile) { + batlinevalue = batlinebuf; + return parse_value(cfile, cfile->extra); +} + +static int parse_uevent(const fileinfo *cfile) { + char *equals= strchr(batlinebuf,'='); + if (!equals) + return batfailf("line without a equals"); + *equals= 0; + batlinevalue = equals+1; + const batinfo_field *field; - const char *const *cfilename, *const *enumsearch; - char *colon, *ep, *sr, *p; - int r, l, missing; + for (field=cfile->extra; field->label; field++) { + if (!strcmp(field->label,batlinebuf)) + goto found; + } + return 0; + + found: + return parse_value(cfile, field); +} + +static int readbattery(void) { /* 0=>ok, -1=>couldn't */ + const fileinfo *cfile; + char *sr; + int r, l; + + r= chdir_base(); + if (r) return r; + r= chdir(batdirname); if (r) return batfaile("chdir",batdirname); - for (field=fields; field->file; field++) - *field->valuep= VAL_NOTFOUND; +#define V_NOTFOUND(f,...) \ + this_##f = VAL_NOTFOUND; +ALL_VARS(V_NOTFOUND) - for (cfilename=files; - (batfilename= *cfilename); - cfilename++) { + for (cfile=files; + (batfilename= cfile->filename); + cfile++) { batfile= fopen(batfilename,"r"); - if (!batfile) return batfaile("open",batfilename); + if (!batfile) { + if (errno == ENOENT) continue; + return batfaile("open",batfilename); + } for (;;) { batlinevalue= 0; @@ -158,70 +301,30 @@ static int readbattery(void) { /* 0=>ok, -1=>couldn't */ if (batlinebuf[l-1] != '\n') return batfailf("line too long"); batlinebuf[l-1]= 0; - colon= strchr(batlinebuf,':'); - if (!colon) - return batfailf("line without a colon"); - *colon= 0; - - for (p=batlinebuf; pfile; field++) { - if (!strcmp(field->file,batfilename) && - !strcmp(field->label,batlinebuf)) - goto label_interesting; - } - continue; - - label_interesting: - for (batlinevalue= colon+1; - *batlinevalue && isspace((unsigned char)*batlinevalue); - batlinevalue++); - - if (field->unit) { - - *field->valuep= strtoul(batlinevalue,&ep,10); - if (ep==batlinevalue || *ep!=' ') - batfailf("value number syntax incorrect"); - if (strcmp(ep+1,field->unit)) batfailf("incorrect unit"); - - } else { - - for (*field->valuep=0, enumsearch=field->enumarray; - *enumsearch && strcmp(*enumsearch,batlinevalue); - (*field->valuep)++, enumsearch++); - if (!*enumsearch) - batfailf("unknown enum value"); - } + if (cfile->parse(cfile)) + return -1; } fclose(batfile); batfile= 0; } - r= chdir(".."); - if (r) return batfaile("chdir",".."); - batdirname= 0; + int needsfields_MAINS = this_type == TYPE_MAINS; + int needsfields_BATTERY = this_type == TYPE_BATTERY; + int needsfields_BOTH = 1; - if (!(thisbat_alarm_present==0 || - thisbat_info_present==0 || - thisbat_state_present==0)) { - if (thisbat_alarm_present == VAL_NOTFOUND) - thisbat_alarm_present= 1; - - for (field=fields, missing=0; - field->file; - field++) { - if (*field->valuep == VAL_NOTFOUND) { - fprintf(stderr,"battery/%s/%s: %s: not found\n", - batdirname, field->file,field->label); - missing++; - } - } - if (missing) return -1; + int missing = 0; + +#define V_NEEDED(f,t,...) \ + if (needsfields_##t && this_##f == VAL_NOTFOUND) { \ + fprintf(stderr,"%s: %s: not found\n", \ + batdirname, #f); \ + missing++; \ } +ALL_FIELDS(V_NEEDED) + + if (missing) return -1; return 0; } @@ -229,28 +332,29 @@ static int readbattery(void) { /* 0=>ok, -1=>couldn't */ /*---------- data collection and analysis ----------*/ /* These next three variables are the results of the charging state */ -static unsigned charging_state_mask; /* 1u<d_name[0]==0 || de->d_name[0]=='.') continue; @@ -258,68 +362,161 @@ static void acquiredata(void) { r= readbattery(); tidybattery(); - if (r) continue; + if (r) { + bad: + charging_mask |= (1u << CHGST_ERROR); + break; + } + + if (this_type == TYPE_BATTERY) { + if (!this_present) + continue; - if (!thisbat_info_present || !thisbat_state_present) - continue; + charging_mask |= 1u << this_state; - charging_state_mask |= 1u << thisbat_state_charging_state; + if (this_state == CHGST_DISCHARGING) + /* negate it */ + total_present_rate -= 2.0 * thisbat_present_rate; -#define QF(f,l,u) \ - total_##f##_##l += thisbat_##f##_##l; - QUANTITY_FIELDS -#undef QF +#define QTY_ENERGY_SUPPLIED(f,...) this_##f##_energy != V_NOTFOUND && +#define QTY_ENERGY_USE(f,...) this_##f = this_##f##_energy; +#define QTY_CHARGE_SUPPLIED(f,...) this_##f##_charge != V_NOTFOUND && +#define QTY_CHARGE_USE(f,...) this_##f = this_##f##_charge; - if (thisbat_state_charging_state == CHGST_DISCHARGING) - /* negate it */ - total_state_present_rate -= 2.0 * thisbat_state_present_rate; + if (BAT_QTYS(QTY_ENERGY_SUPPLIED) 1) { + BAT_QTYS(QTY_ENERGY_USE); + } else if (BAT_QTYS(QTY_CHARGE_SUPPLIED) 1) { + BAT_QTYS(QTY_CHARGE_USE); + } else { + return batfailc("neither complete set of energy nor charge"); + } + } + +#define Q_TOTALISE(f,t,...) \ + if (thisbat_type == TYPE_##t) \ + total_##f += thisbat_##f; +ALL_QUANTITY_FIELDS(Q_TOTALISE) } closedir(di); - if (total_info_design_capacity < 0.5) - total_info_design_capacity= 1.0; + if (total_design_capacity < 0.5) + total_design_capacity= 1.0; - if (total_info_last_full_capacity < total_state_remaining_capacity) - total_info_last_full_capacity= total_state_remaining_capacity; - if (total_info_design_capacity < total_info_last_full_capacity) - total_info_design_capacity= total_info_last_full_capacity; + if (total_last_full_capacity < total_remaining_capacity) + total_last_full_capacity= total_remaining_capacity; + if (total_design_capacity < total_last_full_capacity) + total_design_capacity= total_last_full_capacity; - alarm_level= - (total_state_remaining_capacity < total_alarm_alarm && - !(charging_state_mask & 1u << CHGST_CHARGING)); + alarm_level= total_alarm && (charging_mask & 1u << CHGST_DISCHARGING); - nondegraded_norm= total_info_last_full_capacity / total_info_design_capacity; - fill_norm= total_state_remaining_capacity / total_info_design_capacity; - ratepersec_norm= total_state_present_rate - / (3600.0 * total_info_design_capacity); + nondegraded_norm= total_last_full_capacity / total_design_capacity; + fill_norm= total_remaining_capacity / total_design_capacity; + ratepersec_norm= total_present_rate + / (3600.0 * total_design_capacity); } static void initacquire(void) { - chdir_base(); } -/*---------- display ----------*/ +/*---------- argument parsing ----------*/ #define COLOURS \ - C(dimgrey) \ - C(blue) \ - C(black) \ - C(red) \ - C(green) \ - C(cyan) \ - C(grey) \ - C(darkgreen) \ - C(white) \ + 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) \ GC(remain) \ GC(white) \ GC(empty) +static XrmDatabase xrm; static Display *disp; +static int screen; + +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 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; +} + +static void more_resources(const char *str, const char *why) { + XrmDatabase more; + + if (!str) return; + + more= XrmGetStringDatabase((char*)str); + if (!more) fail(why); + XrmCombineDatabase(more,&xrm,0); +} + +static void parseargs(int argc, char **argv) { + Screen *screenscreen; + + XrmInitialize(); + + XrmParseCommand(&xrm, (XrmOptionDescRec*)optiontable, + sizeof(optiontable)/sizeof(*optiontable), + program_name, &argc, argv); + + if (argc>1) badusage(); + + disp= XOpenDisplay(getresource("display")); + if (!disp) fail("could not open display"); + + screen= DefaultScreen(disp); + + screenscreen= ScreenOfDisplay(disp,screen); + if (!screenscreen) fail("screenofdisplay"); + more_resources(XScreenResourceString(screenscreen), "screen resources"); + more_resources(XResourceManagerString(disp), "display resources"); + more_resources(defaultresources, "default resources"); +} + +/*---------- display ----------*/ + static Window win; static int width, height; static Colormap cmap; -static int screen; static unsigned long lastbackground; typedef struct { @@ -327,7 +524,7 @@ typedef struct { 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 @@ -335,7 +532,7 @@ typedef struct { static void refresh(void); -#define CHGMASK_CHG_DIS (1u<=nondegraded_norm)); + ((charging_mask & (1u<=nondegraded_norm)); if (then <= 0.0) then= 0.0; else if (then >= nondegraded_norm) then= nondegraded_norm; @@ -424,9 +628,13 @@ static void initgc(Gcstate *gc_r) { 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); @@ -434,16 +642,37 @@ static void colour(unsigned long *pix_r, const char *name) { *pix_r= xc.pixel; } -static void initgraphics(void) { - int r; +static void initgraphics(int argc, char **argv) { + int xwmgr, r; + const char *geom_string; + XSizeHints *normal_hints; + XWMHints *wm_hints; + XClassHint *class_hint; + int pos_x, pos_y, gravity; + char *program_name_silly; - disp= XOpenDisplay(0); if (!disp) fail("could not open display"); + program_name_silly= (char*)program_name; - screen= DefaultScreen(disp); - win= XCreateSimpleWindow(disp,DefaultRootWindow(disp),0,0,100,20,0,0,0); + normal_hints= XAllocSizeHints(); + wm_hints= XAllocWMHints(); + class_hint= XAllocClassHint(); + + if (!normal_hints || !wm_hints || !class_hint) + fail("could not alloc hint(s)"); + + geom_string= getresource("geometry"); + + xwmgr= XWMGeometry(disp,screen, geom_string,"128x32", 0, + normal_hints, + &pos_x, &pos_y, + &width, &height, + &gravity); + + win= XCreateSimpleWindow(disp,DefaultRootWindow(disp), + 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 @@ -453,6 +682,24 @@ static void initgraphics(void) { if (!r) fail("init set background"); lastbackground= pix_dimgrey; + normal_hints->flags= PWinGravity; + normal_hints->win_gravity= gravity; + normal_hints->x= pos_x; + normal_hints->y= pos_y; + normal_hints->width= width; + normal_hints->height= height; + if ((xwmgr & XValue) || (xwmgr & YValue)) + normal_hints->flags |= USPosition; + + wm_hints->flags= InputHint; + wm_hints->input= False; + + class_hint->res_name= program_name_silly; + class_hint->res_class= program_name_silly; + + XmbSetWMProperties(disp,win, program_name,program_name, + argv,argc, normal_hints, wm_hints, class_hint); + XSelectInput(disp,win, ExposureMask|StructureNotifyMask); XMapWindow(disp,win); } @@ -464,15 +711,21 @@ static void refresh(void) { static void newgeometry(void) { int dummy; + unsigned int udummy, gotwidth, gotheight; Window dummyw; - XGetGeometry(disp,win, &dummyw,&dummy,&dummy, &width,&height, &dummy,&dummy); + XGetGeometry(disp,win, &dummyw,&dummy,&dummy, &gotwidth,&gotheight, + &udummy,&udummy); + assert(gotwidth < INT_MAX); + assert(gotheight < INT_MAX); + width = gotwidth; + height = gotheight; } static void eventloop(void) { XEvent ev; struct pollfd pfd; - int r; + int r, timeout; newgeometry(); refresh(); @@ -483,7 +736,8 @@ static void eventloop(void) { pfd.fd= ConnectionNumber(disp); pfd.events= POLLIN|POLLERR; - r= poll(&pfd,1,TIMEOUT); + timeout= !(charging_mask & (1u << CHGST_ERROR)) ? TIMEOUT : TIMEOUT_ONERROR; + r= poll(&pfd,1,timeout); if (r==-1 && errno!=EINTR) failr("poll",errno); while (XPending(disp)) { @@ -498,12 +752,10 @@ static void eventloop(void) { } } -int main(int argc, const char *const *argv) { - if (!argv[0] || argv[1]) - badusage(); - +int main(int argc, char **argv) { + parseargs(argc,argv); initacquire(); - initgraphics(); + initgraphics(argc,argv); eventloop(); return 0; }