commit a04f9e13e4c07bb0054867dc5f72525ac3a59e0f
parent b3668b59d447a4bfa87cf18f688d76c979dd399e
Author: sin <sin@2f30.org>
Date: Sun, 19 Apr 2015 13:55:14 +0100
Blink bar below 5%
Diffstat:
3 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -6,7 +6,7 @@ char *colors[] = {
};
unsigned int thickness = 2; /* 2 pixels by default */
-time_t pollinterval = 5; /* poll battery state every 5 seconds */
int placement = BOTTOM; /* set to TOP if you want a top placement */
int maxcap = 100; /* maximum battery capacity */
int raise = 0; /* set to 1 if you want the bar to be raised on top of other windows */
+int critical = 5; /* start blinking below 5% */
diff --git a/xbattmon.1 b/xbattmon.1
@@ -7,7 +7,6 @@
.Sh SYNOPSIS
.Nm xbattmon
.Op Fl c Ar capacity
-.Op Fl i Ar interval
.Op Fl p Ar bottom | top | left | right
.Op Fl t Ar thickness
.Op Fl v
@@ -21,8 +20,6 @@ a bar thickness of 2 pixels and a bottom placement.
.Bl -tag -width Ds
.It Fl c Ar capacity
Set the maximum battery capacity.
-.It Fl i Ar interval
-Set the battery poll interval in seconds.
.It Fl p Ar bottom | top | left | right
Set the bar placement.
.It Fl t Ar thickness
diff --git a/xbattmon.c b/xbattmon.c
@@ -45,6 +45,8 @@ unsigned int barwidth;
unsigned int barheight;
int state; /* AC_ON or AC_OFF */
int batcap; /* 0 if completely discharged or `maxcap' if completely charged */
+int timeout;
+int blinkon;
#include "config.h"
@@ -136,6 +138,8 @@ setup(void)
errx(1, "cannot allocate color resources");
cmap[i] = color.pixel;
}
+
+ critical = critical * maxcap / 100;
}
void
@@ -144,6 +148,14 @@ redraw(void)
int pos;
unsigned long done, left;
+ if (state == AC_OFF && batcap <= critical) {
+ timeout = 500;
+ blinkon = !blinkon;
+ } else {
+ timeout = 5000;
+ blinkon = 0;
+ }
+
if (placement == BOTTOM || placement == TOP)
pos = barwidth * batcap / maxcap;
else
@@ -153,7 +165,7 @@ redraw(void)
done = cmap[COLOR_BAT_CHARGED];
left = cmap[COLOR_BAT_LEFT2CHARGE];
} else {
- done = cmap[COLOR_BAT_LEFT2DRAIN];
+ done = cmap[blinkon == 0 ? COLOR_BAT_LEFT2DRAIN : COLOR_BAT_DRAINED];
left = cmap[COLOR_BAT_DRAINED];
}
@@ -256,7 +268,7 @@ loop(void)
while (1) {
pfd[0].fd = dpyfd;
pfd[0].events = POLLIN;
- switch (poll(pfd, 1, pollinterval * 1000)) {
+ switch (poll(pfd, 1, timeout)) {
case -1:
if (errno != EINTR)
err(1, "poll");
@@ -289,9 +301,8 @@ loop(void)
void
usage(void)
{
- fprintf(stderr, "usage: %s [-c capacity] [-i interval] [-p bottom | top | left | right] [-t thickness] [-v]\n", argv0);
+ fprintf(stderr, "usage: %s [-c capacity] [-p bottom | top | left | right] [-t thickness] [-v]\n", argv0);
fprintf(stderr, " -c\tspecify battery capacity\n");
- fprintf(stderr, " -i\tbattery poll interval in seconds\n");
fprintf(stderr, " -p\tbar placement\n");
fprintf(stderr, " -t\tbar thickness\n");
fprintf(stderr, " -v\tshow version\n");
@@ -311,12 +322,6 @@ main(int argc, char *argv[])
if (errstr)
errx(1, "%s: %s", arg, errstr);
break;
- case 'i':
- arg = EARGF(usage());
- pollinterval = strtonum(arg, 1, 60, &errstr);
- if (errstr)
- errx(1, "%s: %s", arg, errstr);
- break;
case 'p':
arg = EARGF(usage());
if (strcmp(arg, "bottom") == 0)