/* gcc `pkg-config --cflags --libs gtk+-3.0` gtktest.c */

#include <gtk/gtk.h>

int 
main (int argc, char **argv)
{
  if (!gtk_parse_args (&argc, &argv))
    return 1;

  const char *display_name = gdk_get_display_arg_name();
  GdkDisplay *display = gdk_display_open(display_name);
  if (!display)
    return 1;

  gdk_display_manager_set_default_display (gdk_display_manager_get(), display);


  GtkWidget *win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (win, "destroy",
		    G_CALLBACK (gtk_main_quit), NULL);
  g_signal_connect (win, "delete-event",
                    G_CALLBACK (gtk_widget_destroy), NULL);

  GtkWidget *but = gtk_button_new_with_label ("Try to Exit");
  g_signal_connect_swapped (but, "clicked",
			    G_CALLBACK (gtk_widget_destroy), win);
  gtk_container_add (GTK_CONTAINER (win), but);

  /* Show the application window */
  gtk_widget_show_all (win);

  /* Enter the main event loop, and wait for user interaction */
  gtk_main ();

  gdk_display_close(display);
  /* The user lost interest */
  return 0;
}
