aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarstr\xf6m <john@ankarstrom.se>2021-06-02 13:57:47 +0200
committerJohn Ankarstr\xf6m <john@ankarstrom.se>2021-06-02 13:57:47 +0200
commit5b99d5b1e5ae7da67aba3e249949add50a9dae04 (patch)
tree32ce8b23bc8f86b256c65a0cb91322a5c139e62c
parent61ef399092ee4f27629eb39da8c75054de4e8fcf (diff)
downloadxbattext-5b99d5b1e5ae7da67aba3e249949add50a9dae04.tar.gz
Fix charge check
-rw-r--r--Makefile3
-rw-r--r--xbattext.c21
2 files changed, 20 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 8fc4469..527c197 100644
--- a/Makefile
+++ b/Makefile
@@ -6,3 +6,6 @@ xbattext: xbattext.c
install: xbattext
install xbattext /usr/local/bin
+
+upload: xbattext.c
+ scp xbattext.c root@ankarstrom.se:/var/www/img/htdocs/xbattext.c
diff --git a/xbattext.c b/xbattext.c
index 0b26321..1457896 100644
--- a/xbattext.c
+++ b/xbattext.c
@@ -34,7 +34,7 @@
#include <Xm/Label.h>
/* interval in seconds */
-#define INTERVAL 15
+#define INTERVAL 10
/* low battery level */
#define ALERT 30
@@ -68,7 +68,7 @@ static XtResource res_opts[] = {
/* application state */
Arg wargs[10];
char *s;
-int apmfd, alert;
+int apmfd, alert, charge;
struct apm_power_info info;
Widget toplevel, label;
XmFontList font_list;
@@ -105,6 +105,7 @@ main(int argc, char* argv[])
XmNlabel, "",
NULL);
alert = 0;
+ charge = 0;
update(NULL, &timer);
XtRealizeWidget(toplevel);
@@ -138,7 +139,8 @@ update(XtPointer client_data, XtIntervalId *t)
i = 0;
XtSetArg(wargs[i], XmNlabelString, xms); i++;
- if (info.ac_state == APM_AC_ON) {
+ if (!charge && info.ac_state == APM_AC_ON) {
+ charge = 1;
XtSetArg(wargs[i], XtNforeground, res.charge_foreground);
i++;
if (res.charge_font_list != NULL) {
@@ -148,7 +150,7 @@ update(XtPointer client_data, XtIntervalId *t)
XtSetArg(wargs[i], XmNfontList, res.font_list);
i++;
}
- goto set;
+ goto set; /* skip alert */
}
#ifdef ALERT
@@ -171,6 +173,17 @@ update(XtPointer client_data, XtIntervalId *t)
}
#endif
+ if (charge && info.ac_state != APM_AC_ON) {
+ charge = 0;
+ if (i > 1) goto set; /* skip if alert already set */
+ XtSetArg(wargs[i], XtNforeground, res.foreground);
+ i++;
+ if (res.font_list != NULL) {
+ XtSetArg(wargs[i], XmNfontList, res.font_list);
+ i++;
+ }
+ }
+
set: XtSetValues(label, wargs, i);
XmStringFree(xms);