3

I'm trying to create a simple notification in gnome that will execute some code when clicked. The code I have below compiles and runs, but clicking on the notification bubble doesn't do anything. All the code samples I've found indicate that this should work.

#include <stdlib.h>
#include <stdio.h>

#include <libnotify/notify.h>

void action(NotifyNotification *n, gchar *action, gpointer data) {
    system("gnome-terminal &");
}

int main(int argc, char **argv) {

    gtk_init(&argc, &argv);

    notify_init("MyApp");

    NotifyNotification *notification;
    notification = notify_notification_new("mynotification", "Hello", NULL, NULL);

    notify_notification_add_action(notification, "DoAction", "default",
            (NotifyActionCallback)action, NULL, NULL);

    notify_notification_show(notification, NULL);

    pause();

}

To compile:

gcc main.c `pkg-config --cflags --libs libnotify`

I'm on RHEL 6.4, gnome 2.82.2. Other apps (e.g. firefox "Downloads completed") are able to create notifications that perform an action when clicked; I'm just not doing it right somehow.

1 Answers1

3

Had the same issue. Apparently you will have to use the GTK loop by either calling gtk_main or one of the equivalent functions instead of using pause/sleep or other non gtk blocking functions.

Roeften
  • 416
  • 3
  • 7