From 5b99d5b1e5ae7da67aba3e249949add50a9dae04 Mon Sep 17 00:00:00 2001 From: "John Ankarstr\\xf6m" Date: Wed, 2 Jun 2021 13:57:47 +0200 Subject: Fix charge check --- Makefile | 3 +++ xbattext.c | 21 +++++++++++++++++---- 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 /* 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); -- cgit v1.2.3