*
* [1] battery must be quite badly degraded
*/
+/*
+ * Copyright (C) 2004 Ian Jackson <ian@davenant.greenend.org.uk>
+ *
+ * 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 <stdio.h>
#include <assert.h>
typedef struct batinfo_field {
const char *file;
const char *label;
+ const char *acpi_label;
+ double acpi_conversion_factor;
unsigned long *valuep;
const char *unit;
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 QUANTITY_FIELDS \
+ QF(info, design_capacity, "mWh", energy_full_design, 1e-3) \
+ QF(info, last_full_capacity, "mWh", energy_full, 1e-3) \
+ QF(state, present_rate, "mW", power_now, 1e-3) \
+ QF(state, remaining_capacity, "mWh", energy_now, 1e-3) \
+ QF(alarm, alarm, "mWh", alarm, 1e-3)
-#define QF(f,l,u) static unsigned long thisbat_##f##_##l;
+#define QF(f,l,u,a,ac) static unsigned long thisbat_##f##_##l;
QUANTITY_FIELDS
#undef QF
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(alarm, present), 0,0, { "no", "yes" } },
+ { E(info, present), 0,0, { "no", "yes" } },
+ { E(state,present), 0,0, { "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_... */
}
if (!(thisbat_alarm_present==0 ||
- thisbat_info_present==0 ||
- thisbat_state_present==0)) {
+ thisbat_state_present==0 || thisbat_info_present==0)) {
if (thisbat_alarm_present == VAL_NOTFOUND)
thisbat_alarm_present= 1;
GC(empty)
static XrmDatabase xrm;
+static Display *disp;
+static int screen;
static const char defaultresources[]=
#define GC(g)
#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;
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 Display *disp;
static Window win;
static int width, height;
static Colormap cmap;
-static int screen;
static unsigned long lastbackground;
typedef struct {
}
static void initgraphics(int argc, char **argv) {
- int r;
+ int xwmgr, r;
const char *geom_string;
XSizeHints *normal_hints;
XWMHints *wm_hints;
program_name_silly= (char*)program_name;
- disp= XOpenDisplay(getresource("display"));
- if (!disp) fail("could not open display");
-
- screen= DefaultScreen(disp);
-
normal_hints= XAllocSizeHints();
wm_hints= XAllocWMHints();
class_hint= XAllocClassHint();
geom_string= getresource("geometry");
- r= XWMGeometry(disp,screen, geom_string,"128x32", 0,
+ xwmgr= XWMGeometry(disp,screen, geom_string,"128x32", 0,
normal_hints,
&pos_x, &pos_y,
&width, &height,
normal_hints->y= pos_y;
normal_hints->width= width;
normal_hints->height= height;
- if (geom_string) normal_hints->flags |= USPosition;
+ if ((xwmgr & XValue) || (xwmgr & YValue))
+ normal_hints->flags |= USPosition;
wm_hints->flags= InputHint;
wm_hints->input= False;