]> mj.ucw.cz Git - osdd.git/blobdiff - osd-batt.c
osd-mpc-volume: Fixed the parsing regex, volume=100% did not work :)
[osdd.git] / osd-batt.c
index 9d7a6ca132a2f019f3596f249c5ef960788b5b72..56bf5b916ed558164e3efd00548f14846552114a 100644 (file)
 #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;
@@ -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 <options>\n\
 \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   },
 };
@@ -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;