#include <gtk/gtk.h>

static void
button_clicked (GtkWidget *widget, GtkWidget *parent)
{
  GtkWidget *child;
  GtkWidget *button;

  child = g_object_connect (gtk_widget_new (gtk_window_get_type (),
                                            "type", GTK_WINDOW_TOPLEVEL,
                                            "title", "Child Window",
                                            "modal", TRUE,
                                            "user_data", NULL,
                                            "destroy-with-parent", TRUE,
                                            NULL),
                            "signal::destroy", gtk_widget_destroy, NULL,
                            NULL);
  button = g_object_connect (gtk_widget_new (gtk_button_get_type (),
                                             "GtkButton::label", "Create Child",
                                             "GtkWidget::parent", child,
                                             NULL),
                             "signal::clicked", button_clicked, child,
                             NULL);

  gtk_window_set_transient_for (GTK_WINDOW (child), GTK_WINDOW (parent));  
  gtk_widget_show_all (child);
}

void
create_main_window ()
{
  GtkWidget *window;
  GtkWidget *button;

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Parent Window");
  gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);

  window = g_object_connect (gtk_widget_new (gtk_window_get_type (),
                                             "type", GTK_WINDOW_TOPLEVEL,
                                             "user_data", NULL,
                                             "title", "Parent Window",
                                             NULL),
                             "signal::destroy", gtk_main_quit, NULL,
                             NULL);
  button = g_object_connect (gtk_widget_new (gtk_button_get_type (),
                                             "GtkButton::label", "Create Child",
                                             "GtkWidget::parent", window,
                                             NULL),
                             "signal::clicked", button_clicked, window,
                             NULL);
  gtk_widget_show_all (window);
}

int main (int argc, char **argv)
{
  gtk_init (&argc, &argv);

  create_main_window ();
  gtk_main ();

  return 0;
}
