Notifications now wait in a 'queue' and get displayed one after another, add handling...
authorSamuel Dudik <redacted>
Fri, 14 Aug 2020 18:19:17 +0000 (20:19 +0200)
committerSamuel Dudik <redacted>
Fri, 14 Aug 2020 18:19:17 +0000 (20:19 +0200)
TODO.md [deleted file]
herbe.c
makefile

diff --git a/TODO.md b/TODO.md
deleted file mode 100644 (file)
index 78e9c08..0000000
--- a/TODO.md
+++ /dev/null
@@ -1,5 +0,0 @@
-* Handle multiple notifications at the same time
-* ~~Properly handle duration = 0~~
-* Keyboard shortcut to dismiss and accept notifications (also mouse)
-* ~~Properly print new lines~~
-* Refactor code
\ No newline at end of file
diff --git a/herbe.c b/herbe.c
index c8dc2798223be303d961169d0dafc604003c7d2b..f1b1ca90390cdda5520fe5dfcaa48f12204a456d 100644 (file)
--- a/herbe.c
+++ b/herbe.c
@@ -6,6 +6,8 @@
 #include <unistd.h>
 #include <string.h>
 #include <stdarg.h>
+#include <fcntl.h>
+#include <semaphore.h>
 
 #include "config.h"
 
@@ -75,9 +77,8 @@ int main(int argc, char *argv[])
                die("Usage: %s body", argv[0]);
 
        signal(SIGALRM, expire);
-
-       if (duration != 0)
-               alarm(duration);
+       signal(SIGTERM, expire);
+       signal(SIGINT, expire);
 
        display = XOpenDisplay(0);
 
@@ -150,6 +151,12 @@ int main(int argc, char *argv[])
 
        XMapWindow(display, window);
 
+       sem_t *mutex = sem_open("/herbe", O_CREAT, 0644, 1);
+       sem_wait(mutex);
+
+       if (duration != 0)
+               alarm(duration);
+
        while (1)
        {
                XEvent event;
@@ -165,6 +172,10 @@ int main(int argc, char *argv[])
                        break;
        }
 
+       sem_post(mutex);
+       sem_close(mutex);
+       sem_unlink("/herbe");
+
        for (int i = 0; i < num_of_lines; i++)
                free(words[i]);
 
index dd26b9a06f22adde29411752d999ee62c029cee7..dcc5639afb3b19520c90eff928690333a592ceeb 100644 (file)
--- a/makefile
+++ b/makefile
@@ -1,5 +1,5 @@
 default:
-       gcc herbe.c -Wall -Wextra -pedantic -lX11 -lXft -I/usr/include/freetype2 -lm -o herbe
+       gcc herbe.c -Wall -Wextra -pedantic -lX11 -lXft -I/usr/include/freetype2 -lm -pthread -o herbe
 
 install: default
        cp herbe /usr/local/bin