Notifications now wait in a 'queue' and get displayed one after another, add handling of 2 more signals for clean exit

This commit is contained in:
Samuel Dudik 2020-08-14 20:19:17 +02:00
parent b41b280509
commit e1df67a0fe
3 changed files with 15 additions and 9 deletions

View file

@ -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

17
herbe.c
View file

@ -6,6 +6,8 @@
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <fcntl.h>
#include <semaphore.h>
#include "config.h" #include "config.h"
@ -75,9 +77,8 @@ int main(int argc, char *argv[])
die("Usage: %s body", argv[0]); die("Usage: %s body", argv[0]);
signal(SIGALRM, expire); signal(SIGALRM, expire);
signal(SIGTERM, expire);
if (duration != 0) signal(SIGINT, expire);
alarm(duration);
display = XOpenDisplay(0); display = XOpenDisplay(0);
@ -150,6 +151,12 @@ int main(int argc, char *argv[])
XMapWindow(display, window); XMapWindow(display, window);
sem_t *mutex = sem_open("/herbe", O_CREAT, 0644, 1);
sem_wait(mutex);
if (duration != 0)
alarm(duration);
while (1) while (1)
{ {
XEvent event; XEvent event;
@ -165,6 +172,10 @@ int main(int argc, char *argv[])
break; break;
} }
sem_post(mutex);
sem_close(mutex);
sem_unlink("/herbe");
for (int i = 0; i < num_of_lines; i++) for (int i = 0; i < num_of_lines; i++)
free(words[i]); free(words[i]);

View file

@ -1,5 +1,5 @@
default: 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 install: default
cp herbe /usr/local/bin cp herbe /usr/local/bin