Display time & state for SIGUSR1

This commit is contained in:
Ivan Tham 2016-10-29 12:40:54 +08:00
parent 44395654d8
commit ba2d3922fa
2 changed files with 10 additions and 8 deletions

3
spt.1
View File

@ -14,9 +14,10 @@ is a simple timer that uses pomodoro technique with desktop notification to
double your efficiency.
.B spt
receives 2 signals:
.P
.RS
.B SIGUSR1()
\- show remaining time
\- show remaining time, state
.br
.B SIGUSR2()
\- play/pause the timer

15
spt.c
View File

@ -31,7 +31,7 @@ volatile static sig_atomic_t display, suspend;
static void die(const char *errstr, ...);
static void spawn(char *cmd, char *cmt);
static void notify_send(char *cmt);
static void display_time(int timecount);
static void display_state(int remaining, int suspend);
static void toggle_display(int sigint);
static void toggle_suspend(int sigint);
static void usage(void);
@ -80,13 +80,14 @@ notify_send(char *cmt)
}
void
display_time(int timecount)
display_state(int remaining, int suspend)
{
char buf[17];
char buf[22];
snprintf(buf, 17, "Remaining: %02d:%02d\n",
timecount / 60,
timecount % 60);
snprintf(buf, 22, "Remaining: %02d:%02d %s\n",
remaining / 60,
remaining % 60,
(suspend) ? "" : "");
notify_send(buf);
display = 0;
@ -155,7 +156,7 @@ main(int argc, char *argv[])
remaining.tv_nsec = 0;
while (remaining.tv_sec) {
if (display)
display_time(remaining.tv_sec);
display_state(remaining.tv_sec, suspend);
if (suspend)
sigsuspend(&emptymask);