我正在尝试在gnome中创建一个简单的通知,当单击时将执行一些代码。下面的代码会编译并运行,但单击通知气泡不会执行任何操作。我找到的所有代码样本都表明这应该是可行的。
#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();
}要编译:
gcc main.c `pkg-config --cflags --libs libnotify`我在RHEL 6.4,gnome 2.82.2上。其他应用程序(例如firefox“下载完成”)也可以创建通知,在点击时执行操作;我只是不知何故做得不对。
发布于 2013-07-01 20:23:47
也有同样的问题。显然,您必须通过调用gtk_main或等效函数来使用GTK循环,而不是使用暂停/睡眠或其他非gtk阻塞函数。
https://stackoverflow.com/questions/17218995
复制相似问题