#include <dirent.h>
#include <getopt.h>
-#include "util.h"
-#include "send.h"
+#include "osd.h"
static int check_mode;
+static int check_every;
static int warn_threshold = 600;
static int total_full, total_capa, discharge_rate;
static int ac_online;
static unsigned int present_mask, charge_mask, discharge_mask;
+static unsigned int last_charge_mask, last_discharge_mask;
+static int last_ac_online = -1;
+
static char *parse_line(char *line)
{
char *t = strchr(line, '\n');
osd_send(msg);
}
+static void show_if_warn(void)
+{
+ if (discharge_mask && discharge_time < warn_threshold ||
+ last_ac_online >= 0 && (
+ charge_mask != last_charge_mask ||
+ discharge_mask != last_discharge_mask ||
+ ac_online != last_ac_online))
+ show();
+
+ last_charge_mask = charge_mask;
+ last_discharge_mask = discharge_mask;
+ last_ac_online = ac_online;
+}
+
static void NONRET
usage(void)
{
\n\
Options:\n\
-c, --check\t\tDisplay status only if battery is low\n\
+-e, --check-every=<sec>\tRun on background and check every <sec> seconds\n\
-w, --warn=<sec>\tBattery is low if less than <sec> seconds remain (default: 600)\n\
");
exit(1);
}
-static const char short_opts[] = "cw:";
+static const char short_opts[] = "ce:w:";
static const struct option long_opts[] = {
{ "check", no_argument, NULL, 'c' },
+ { "check-every", required_argument, NULL, 'e' },
{ "warn", required_argument, NULL, 'w' },
{ NULL, 0, NULL, 0 },
};
case 'c':
check_mode++;
break;
+ case 'e':
+ check_every = atoi(optarg);
+ break;
case 'w':
warn_threshold = atoi(optarg);
break;
if (optind < argc)
usage();
+ if (check_every)
+ {
+ osd_fork();
+ for (;;)
+ {
+ scan();
+ show_if_warn();
+ osd_wait(check_every);
+ }
+ }
+
scan();
- if (!check_mode || (discharge_mask && discharge_time < warn_threshold))
+ if (check_mode)
+ show_if_warn();
+ else
show();
return 0;