4 #include <sys/inotify.h>
5 #include <notification.h>
7 #include <libwlmessage.h>
13 void sigint_handler (int s)
15 inotify_rm_watch (fd, wd);
20 void display_notifications ()
22 notification_h noti = NULL;
23 notification_list_h notification_list = NULL;
24 notification_list_h get_list = NULL;
29 char *image_path = NULL;
31 notification_get_list (NOTIFICATION_TYPE_NOTI, -1, ¬ification_list);
32 if (notification_list) {
33 get_list = notification_list_get_head (notification_list);
35 noti = notification_list_get_data (get_list);
36 notification_get_pkgname (noti, &pkgname);
38 notification_get_application (noti, &pkgname);
39 notification_get_title (noti, &title, NULL);
40 notification_get_text (noti, NOTIFICATION_TEXT_TYPE_CONTENT, &content);
41 notification_get_image (noti, NOTIFICATION_IMAGE_TYPE_ICON, &image_path);
44 struct wlmessage *wlmessage = wlmessage_create ();
45 wlmessage_set_title (wlmessage, title);
46 wlmessage_set_icon (wlmessage, image_path);
47 wlmessage_set_message (wlmessage, content);
48 wlmessage_add_button (wlmessage, 0, "Ok");
49 if (wlmessage_show (wlmessage, NULL) < 0) {
50 wlmessage_destroy (wlmessage);
53 wlmessage_destroy (wlmessage);
55 fprintf(stderr, "\nNew Notification : %s\n", title);
56 fprintf(stderr, "Icon : %s\n", image_path);
57 fprintf(stderr, "Message : %s\n", content);
60 get_list = notification_list_remove(get_list, noti);
61 notification_delete(noti);
66 int main (int argc, char **argv)
70 /* display notifications once, so it stays useful without inotify */
71 display_notifications ();
75 fprintf (stderr, "ERROR: cannot initialize inotify\n");
76 fprintf (stderr, "Verify that your kernel integrates it\n");
80 signal (SIGINT, sigint_handler);
81 wd = inotify_add_watch (fd, "/usr/dbspace/.notification.db", IN_MODIFY);
83 read (fd, buffer, sizeof(buffer));
84 display_notifications ();