aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xbattext.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/xbattext.c b/xbattext.c
index fd41aa3..c34f997 100644
--- a/xbattext.c
+++ b/xbattext.c
@@ -16,6 +16,8 @@
* xbattext*foreground = normal text color
* xbattext*alertFontList = font when battery is low
* xbattext*alertForeground = text color when battery is low
+ * xbattext*chargeFontList = font when charging
+ * xbattext*chargeForeground = text color when charging
*
* Set their values in ~/.Xdefaults to customize xbattext.
*
@@ -43,18 +45,24 @@ void update(XtPointer, XtIntervalId *);
struct _res {
XmFontList font_list;
XmFontList alert_font_list;
+ XmFontList charge_font_list;
Pixel foreground;
Pixel alert_foreground;
+ Pixel charge_foreground;
} res;
static XtResource res_opts[] = {
{"fontList", "FontList", XmRFontList, sizeof(XmFontList),
XtOffset(struct _res*, font_list), XtRImmediate, (caddr_t)NULL},
- {"foreground", "foreground", XmRPixel, sizeof(Pixel),
- XtOffset(struct _res*, foreground), XtRImmediate, (caddr_t)NULL},
{"alertFontList", "AlertFontList", XmRFontList, sizeof(XmFontList),
XtOffset(struct _res*, alert_font_list), XtRImmediate, (caddr_t)NULL},
+ {"chargeFontList", "ChargeFontList", XmRFontList, sizeof(XmFontList),
+ XtOffset(struct _res*, charge_font_list), XtRImmediate, (caddr_t)NULL},
+ {"foreground", "foreground", XmRPixel, sizeof(Pixel),
+ XtOffset(struct _res*, foreground), XtRImmediate, (caddr_t)NULL},
{"alertForeground", "AlertForeground", XmRPixel, sizeof(Pixel),
XtOffset(struct _res*, alert_foreground), XtRImmediate, (caddr_t)NULL},
+ {"chargeForeground", "ChargeForeground", XmRPixel, sizeof(Pixel),
+ XtOffset(struct _res*, charge_foreground), XtRImmediate, (caddr_t)NULL},
};
/* application state */
@@ -64,7 +72,7 @@ int apmfd, alert;
struct apm_power_info info;
Widget toplevel, label;
XmFontList font_list;
-XmString str;
+XmString xms;
XtAppContext app_context;
XtIntervalId timer = 0;
@@ -125,43 +133,43 @@ update(XtPointer client_data, XtIntervalId *t)
/* put battery status into label */
sprintf(s, "%d%%", info.battery_life);
- str = XmStringCreate(s, XmFONTLIST_DEFAULT_TAG);
+ xms = XmStringCreate(s, XmFONTLIST_DEFAULT_TAG);
i = 0;
+ XtSetArg(wargs[i], XmNlabelString, xms); i++;
+
+ if (info.battery_state == APM_BATT_CHARGING) {
+ XtSetArg(wargs[i], XtNforeground, res.charge_foreground);
+ i++;
+ if (res.charge_font_list != NULL) {
+ XtSetArg(wargs[i], XmNfontList, res.charge_font_list);
+ i++;
+ }
+ goto set;
+ }
+
#ifdef ALERT
if (!alert && info.battery_life < ALERT) {
alert = 1;
- XtSetArg(wargs[i], XmNlabelString, str); i++;
- if (res.alert_foreground != -1) {
- XtSetArg(wargs[i], XtNforeground, res.alert_foreground);
- i++;
- }
+ XtSetArg(wargs[i], XtNforeground, res.alert_foreground);
+ i++;
if (res.alert_font_list != NULL) {
XtSetArg(wargs[i], XmNfontList, res.alert_font_list);
i++;
}
- XtSetValues(label, wargs, i);
- }
- else if (alert && info.battery_life >= ALERT) {
- alert = 1;
- XtSetArg(wargs[i], XmNlabelString, str); i++;
- if (res.foreground != -1) {
- XtSetArg(wargs[i], XtNforeground, res.foreground);
- i++;
- }
+ } else if (alert && info.battery_life >= ALERT) {
+ alert = 0;
+ XtSetArg(wargs[i], XtNforeground, res.foreground);
+ i++;
if (res.font_list != NULL) {
XtSetArg(wargs[i], XmNfontList, res.font_list);
i++;
}
- XtSetValues(label, wargs, i);
}
- else
#endif
- XtVaSetValues(label,
- XmNlabelString, str,
- NULL);
- XmStringFree(str);
+set: XtSetValues(label, wargs, i);
+ XmStringFree(xms);
/* add new timer */
end: timer = XtAppAddTimeOut(app_context, INTERVAL * 1000, update, toplevel);