X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=osd-batt.c;h=56bf5b916ed558164e3efd00548f14846552114a;hb=c35777a78cc041672856c74cdaa478bc119c8c69;hp=df27bce8fd23bb060d19151670dfb6f8172f7afd;hpb=6b0069005ee1fc055a16983d675dc13db38170af;p=osdd.git diff --git a/osd-batt.c b/osd-batt.c index df27bce..56bf5b9 100644 --- a/osd-batt.c +++ b/osd-batt.c @@ -11,10 +11,10 @@ #include #include -#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; @@ -202,6 +202,12 @@ static void show(void) osd_send(msg); } +static void show_if_warn(void) +{ + if (discharge_mask && discharge_time < warn_threshold) + show(); +} + static void NONRET usage(void) { @@ -210,15 +216,17 @@ Usage: osd-batt \n\ \n\ Options:\n\ -c, --check\t\tDisplay status only if battery is low\n\ +-e, --check-every=\tRun on background and check every seconds\n\ -w, --warn=\tBattery is low if less than 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 }, }; @@ -232,6 +240,9 @@ int main(int argc, char **argv) case 'c': check_mode++; break; + case 'e': + check_every = atoi(optarg); + break; case 'w': warn_threshold = atoi(optarg); break; @@ -241,8 +252,21 @@ int main(int argc, char **argv) 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;