| 1 |
#include <libnotify/notify.h> |
|---|
| 2 |
#include <stdio.h> |
|---|
| 3 |
#include <unistd.h> |
|---|
| 4 |
#include <glib.h> |
|---|
| 5 |
#include <gtk/gtk.h> |
|---|
| 6 |
|
|---|
| 7 |
static int count = 0; |
|---|
| 8 |
|
|---|
| 9 |
static void |
|---|
| 10 |
on_exposed(GtkWidget *widget, GdkEventExpose *ev, void *user_data) |
|---|
| 11 |
{ |
|---|
| 12 |
NotifyNotification *n = NOTIFY_NOTIFICATION(user_data); |
|---|
| 13 |
|
|---|
| 14 |
g_signal_handlers_disconnect_by_func(widget, on_exposed, user_data); |
|---|
| 15 |
|
|---|
| 16 |
notify_notification_show(n, NULL); |
|---|
| 17 |
} |
|---|
| 18 |
|
|---|
| 19 |
static void |
|---|
| 20 |
on_clicked(GtkButton *button, void *user_data) |
|---|
| 21 |
{ |
|---|
| 22 |
gchar *buf; |
|---|
| 23 |
NotifyNotification *n = NOTIFY_NOTIFICATION(user_data); |
|---|
| 24 |
|
|---|
| 25 |
count++; |
|---|
| 26 |
buf = g_strdup_printf("You clicked the button %i times", count); |
|---|
| 27 |
notify_notification_update(n, "Widget Attachment Test", buf, NULL); |
|---|
| 28 |
g_free(buf); |
|---|
| 29 |
|
|---|
| 30 |
notify_notification_show(n, NULL); |
|---|
| 31 |
} |
|---|
| 32 |
|
|---|
| 33 |
int |
|---|
| 34 |
main(int argc, char *argv[]) |
|---|
| 35 |
{ |
|---|
| 36 |
NotifyNotification *n; |
|---|
| 37 |
GtkWidget *window; |
|---|
| 38 |
GtkWidget *button; |
|---|
| 39 |
|
|---|
| 40 |
gtk_init(&argc, &argv); |
|---|
| 41 |
notify_init("Replace Test"); |
|---|
| 42 |
|
|---|
| 43 |
window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
|---|
| 44 |
g_signal_connect(G_OBJECT(window), "delete_event", |
|---|
| 45 |
G_CALLBACK(gtk_main_quit), NULL); |
|---|
| 46 |
|
|---|
| 47 |
button = gtk_button_new_with_label("click here to change notification"); |
|---|
| 48 |
gtk_container_add(GTK_CONTAINER(window), button); |
|---|
| 49 |
|
|---|
| 50 |
gtk_widget_show_all(window); |
|---|
| 51 |
|
|---|
| 52 |
n = notify_notification_new("Widget Attachment Test", |
|---|
| 53 |
"Button has not been clicked yet", |
|---|
| 54 |
NULL, //no icon |
|---|
| 55 |
button); //attach to button |
|---|
| 56 |
|
|---|
| 57 |
notify_notification_set_timeout(n, 0); //don't timeout |
|---|
| 58 |
|
|---|
| 59 |
g_signal_connect(G_OBJECT(button), "clicked", |
|---|
| 60 |
G_CALLBACK(on_clicked), n); |
|---|
| 61 |
g_signal_connect_after(G_OBJECT(button), "expose-event", |
|---|
| 62 |
G_CALLBACK(on_exposed), n); |
|---|
| 63 |
|
|---|
| 64 |
gtk_main(); |
|---|
| 65 |
|
|---|
| 66 |
return 0; |
|---|
| 67 |
} |
|---|