#include <gtk/gtk.h>

static unsigned s_click_count = 0;

static void
on_button_a_clicked (GtkButton *button, gpointer user_data)
{
  GApplication *application = G_APPLICATION (user_data);

  GNotification *notification = g_notification_new ("You clicked on Button A!");

  ++s_click_count;
  char *body = g_strdup_printf("You have clicked %u times.", s_click_count);
  g_notification_set_body (notification, body);
  g_free(body);

  g_application_send_notification (application, "test-a", notification);
  g_object_unref (notification);
}

static void
on_button_b_clicked (GtkButton *button, gpointer user_data)
{
  GApplication *application = G_APPLICATION (user_data);

  GNotification *notification = g_notification_new ("You clicked on Button B!");

  ++s_click_count;
  char *body = g_strdup_printf("You have clicked %u times.", s_click_count);
  g_notification_set_body (notification, body);
  g_free(body);

  g_application_send_notification (application, "test-b", notification);
  g_object_unref (notification);
}

static void
on_application_activate (GApplication *application, gpointer user_data)
{
  GtkWidget *button_a = gtk_button_new_with_label ("Button A");
  g_signal_connect (G_OBJECT (button_a), "clicked",
                    G_CALLBACK (&on_button_a_clicked), application);

  GtkWidget *button_b = gtk_button_new_with_label ("Button B");
  g_signal_connect (G_OBJECT (button_b), "clicked",
                    G_CALLBACK (&on_button_b_clicked), application);

  GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
  gtk_container_add (GTK_CONTAINER (box), button_a);
  gtk_container_add (GTK_CONTAINER (box), button_b);

  GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (window), 12);
  gtk_container_add (GTK_CONTAINER (window), box);
  gtk_widget_show_all (window);

  gtk_application_add_window (GTK_APPLICATION (application), GTK_WINDOW (window) );
}

int main(int argc, char **argv)
{
  /* N.B. gnome-shell needs an installed .desktop file with same basename as: */
  GtkApplication *application = gtk_application_new ("org.djb.test", /* <this */
                                                     G_APPLICATION_FLAGS_NONE);
  g_signal_connect (G_OBJECT (application), "activate",
                    G_CALLBACK (&on_application_activate), NULL);

  int result = g_application_run (G_APPLICATION (application), argc, argv);
}
