diff --git a/TODO b/TODO index 73d0898..5ec4066 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,6 @@ -1. Show remaining time to the next timer (using SIGUSR1) -2. Add #ifdef to make libnotify an optional dependency -3. Add more support for non-libnotify such as echo(1) -4. Pause and continue the timer +1. Add #ifdef to make libnotify an optional dependency +2. Add more support for non-libnotify such as echo(1) +3. Pause and continue the timer Misc ---- diff --git a/spt.c b/spt.c index b8ecd61..9143ec1 100644 --- a/spt.c +++ b/spt.c @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -21,10 +22,13 @@ typedef struct { #include "config.h" +static int i, timecount; + /* function declarations */ static void die(const char *errstr, ...); static void spawn(char *); static void notify_send(char *); +static void remaining_time(int); static void usage(void); /* functions implementations */ @@ -75,6 +79,21 @@ notify_send(char *cmt) spawn(notifyext); } +void +remaining_time(int sigint) +{ + char remainingtext[17]; + if (signal(SIGUSR1, SIG_IGN) != SIG_IGN) { + signal(SIGUSR1, remaining_time); + } + + snprintf(remainingtext, 17, "Remaining: %02d:%02d\n", + (timers[i].tmr - timecount) / 60, + (timers[i].tmr - timecount) % 60); + + notify_send(remainingtext); +} + void usage(void) { @@ -84,8 +103,6 @@ usage(void) int main(int argc, char *argv[]) { - int i = 0; - ARGBEGIN { case 'e': notifyext = EARGF(usage()); @@ -101,9 +118,17 @@ main(int argc, char *argv[]) break; } ARGEND; + if (signal(SIGUSR1, SIG_IGN) != SIG_IGN) { + signal(SIGUSR1, remaining_time); + } + run: notify_send(timers[i].cmt); - sleep(timers[i].tmr); + + for (timecount = 0; timecount < timers[i].tmr; timecount++) { + sleep(1); + } + i + 1 >= LEN(timers) ? i = 0 : i++; /* i infinal loop */ goto run;