diff options
author | John Ankarstr\xf6m <john@ankarstrom.se> | 2021-06-01 22:40:35 +0200 |
---|---|---|
committer | John Ankarstr\xf6m <john@ankarstrom.se> | 2021-06-01 22:40:35 +0200 |
commit | 725ff16645465cee0e552155e8eac2545896f714 (patch) | |
tree | 44154b5c7aa26417617e6b7d4d9e70f9000015d9 | |
parent | 7a7fcb66b8589b26194e36f6d0461a73b8f6a3f9 (diff) | |
download | xbattext-725ff16645465cee0e552155e8eac2545896f714.tar.gz |
Implement 'chargeFontlist', 'chargeForeground', fix alert bug
I also removed unnecessary checks on the pixel values.
Turns out they're set to zero when undefined, which is black.
-rw-r--r-- | xbattext.c | 56 |
1 files changed, 32 insertions, 24 deletions
@@ -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); |