-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjokes.c
48 lines (39 loc) · 992 Bytes
/
jokes.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "jokes.h"
#include <libnotify/notify.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
int timeout = 600;
char *ptr;
if (argc >= 3 && strncmp(argv[1], "-t", 16) == 0)
timeout = 60 * strtol(argv[2], &ptr, 0);
pid_t id = fork();
if (id < 0) {
fprintf(stderr, "failed to fork\n");
exit(1);
}
else if (id == 0) {
while (1) {
char name[] = "jokesd";
notify_init(name);
notify_set_app_name("jokes");
NotifyNotification *joke;
char *random_joke = get_joke();
joke = notify_notification_new(
"dad jokez", random_joke,
"/home/daduser/.local/share/icons/jokesd/icon.png");
notify_notification_set_category(joke, "jokes");
notify_notification_set_timeout(joke, 5000);
notify_notification_set_urgency(joke,
NOTIFY_URGENCY_NORMAL);
GError *error = NULL;
notify_notification_show(joke, &error);
sleep(timeout);
}
}
else {
printf("pid: %d\n", id);
}
return 0;
}