From f7f8b4038409dda87fd840242d5949f26e8beb0b Mon Sep 17 00:00:00 2001 From: "John Ankarstr\\xf6m" Date: Tue, 1 Jun 2021 21:00:23 +0200 Subject: Fix color change bug I forgot to change the 4 to a 6 (strlen("black")+1). --- xbattext.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'xbattext.c') diff --git a/xbattext.c b/xbattext.c index e1d2fbe..efa7aa4 100644 --- a/xbattext.c +++ b/xbattext.c @@ -29,7 +29,7 @@ #include /* interval in seconds */ -#define INTERVAL 30 +#define INTERVAL 15 /* low battery level */ #define ALERT 30 @@ -98,22 +98,29 @@ update(XtPointer client_data, XtIntervalId *t) /* put battery status into label */ sprintf(s, "%d%%", info.battery_life); str = XmStringCreate(s, XmFONTLIST_DEFAULT_TAG); - XtSetArg(wargs[0], XmNlabelString, str); - XtSetValues(label, wargs, 1); - XmStringFree(str); - /* change color if low battery */ #ifdef ALERT if (!alert && info.battery_life < ALERT) { XtVaSetValues(label, - XtVaTypedArg, XmNforeground, XmRString, "red", 4); + XmNlabelString, str, + XtVaTypedArg, XtNforeground, XtRString, "red", 4, + NULL); alert = 1; - } else if (alert && info.battery_life >= ALERT) { + } + else if (alert && info.battery_life > ALERT) { XtVaSetValues(label, - XtVaTypedArg, XmNforeground, XmRString, "black", 4); + XmNlabelString, str, + XtVaTypedArg, XtNforeground, XtRString, "black", 6, + NULL); alert = 0; } + else #endif + XtVaSetValues(label, + XmNlabelString, str, + NULL); + + XmStringFree(str); /* add new timer */ end: timer = XtAppAddTimeOut(app_context, INTERVAL * 1000, update, toplevel); -- cgit v1.2.3