
#include <gtk/gtk.h>

static GtkWidget *window;

static gboolean show_dialog (const gchar *name)
{
    GtkWidget *dialog = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
    gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
    gtk_window_set_title (GTK_WINDOW (dialog), name);
    gtk_window_set_default_size (GTK_WINDOW (dialog), 320, 240);
    gtk_widget_show_now (dialog);
    gdk_window_focus (dialog->window, GDK_CURRENT_TIME);
    return FALSE;
}

static gboolean key_event (GtkWidget *widget, GdkEventKey *event, gpointer user_data)
{
    show_dialog ("First dialog");
    while (gtk_events_pending ()) gtk_main_iteration ();
    show_dialog ("Second dialog");
    return FALSE;
}

int main (int argc, char **argv)
{
    GtkWidget *vbox, *entry;
    gtk_init (&argc, &argv);
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    vbox = gtk_vbox_new (FALSE, 0);
    entry = gtk_entry_new ();
    gtk_entry_set_editable (GTK_ENTRY (entry), TRUE);
    gtk_container_add (GTK_CONTAINER (vbox), entry);
    gtk_container_add (GTK_CONTAINER (window), vbox);
    g_signal_connect (G_OBJECT (window), "destroy",
                      G_CALLBACK (gtk_main_quit), NULL);
    g_signal_connect (G_OBJECT (window), "key-press-event",
                      G_CALLBACK (key_event), NULL);
    gtk_widget_show_all (window);
    gtk_main ();
    return 0;
}

