#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;
osd_send(msg);
}
+static void show_if_warn(void)
+{
+ if (discharge_mask && discharge_time < warn_threshold)
+ show();
+}
+
static void NONRET
usage(void)
{
\n\
Options:\n\
-c, --check\t\tDisplay status only if battery is low\n\
--w, --warn=<sec>\tBattery is low if less than <sec> seconds remain\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;