aboutsummaryrefslogtreecommitdiff
path: root/c/timer
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-12-10 00:39:16 +0100
committerThomas Voss <mail@thomasvoss.com> 2023-12-10 00:39:37 +0100
commit03f8544691a8de9f77a803fd8cd2eeadb919ec03 (patch)
tree4d3431d678b892cb057af72a982ac73d313d60f9 /c/timer
Genesis commit
Diffstat (limited to 'c/timer')
-rw-r--r--c/timer/.gitignore1
-rw-r--r--c/timer/Makefile11
-rw-r--r--c/timer/main.c48
3 files changed, 60 insertions, 0 deletions
diff --git a/c/timer/.gitignore b/c/timer/.gitignore
new file mode 100644
index 0000000..fe84f2c
--- /dev/null
+++ b/c/timer/.gitignore
@@ -0,0 +1 @@
+timer
diff --git a/c/timer/Makefile b/c/timer/Makefile
new file mode 100644
index 0000000..410dc79
--- /dev/null
+++ b/c/timer/Makefile
@@ -0,0 +1,11 @@
+include ../base.mk
+
+CFLAGS := $(CFLAGS) $(shell pkg-config --cflags libnotify) -D_ISOC99_SOURCE
+LDLIBS = $(shell pkg-config --libs libnotify)
+
+all: timer
+timer: main.c
+ $(CC) $(CFLAGS) $(LDLIBS) -o $@ $<
+
+clean:
+ rm -f timer
diff --git a/c/timer/main.c b/c/timer/main.c
new file mode 100644
index 0000000..751cbca
--- /dev/null
+++ b/c/timer/main.c
@@ -0,0 +1,48 @@
+#include <err.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <libnotify/notify.h>
+
+#define die(...) err(EXIT_FAILURE, __VA_ARGS__)
+#define diex(...) errx(EXIT_FAILURE, __VA_ARGS__)
+
+static char buf[128];
+
+int
+main(int argc, char **argv)
+{
+ char *endptr;
+ long secs;
+
+ if (argc != 3) {
+ fprintf(stderr, "Usage: %s secs body\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ errno = 0;
+ secs = strtol(argv[1], &endptr, 10);
+ if (errno)
+ die("strtol: %s", argv[1]);
+ if (endptr == argv[1] || *endptr)
+ diex("Invalid integer: %s", argv[1]);
+
+ snprintf(buf, sizeof(buf), "%ld Second%s Elapsed", secs,
+ secs == 1 ? "" : "s");
+
+ notify_init("TIMER");
+ NotifyNotification *n =
+ notify_notification_new(buf, argv[2], "dialog-information");
+
+ notify_notification_set_timeout(n, 5000);
+ while ((secs = sleep(secs)))
+ sleep(secs);
+ if (!notify_notification_show(n, NULL))
+ diex("Failed to send notification");
+
+ g_object_unref(G_OBJECT(n));
+ notify_uninit();
+ return EXIT_SUCCESS;
+}