diff --git a/demos/gtk-demo/assistant.c b/demos/gtk-demo/assistant.c
index b461171..2f6fc8a 100644
--- a/demos/gtk-demo/assistant.c
+++ b/demos/gtk-demo/assistant.c
@@ -173,6 +173,8 @@ do_assistant (GtkWidget *do_widget)
       gtk_window_set_screen (GTK_WINDOW (assistant),
                              gtk_widget_get_screen (do_widget));
 
+      gtk_window_set_transient_for (GTK_WINDOW (assistant), GTK_WINDOW (do_widget));
+
       create_page1 (assistant);
       create_page2 (assistant);
       create_page3 (assistant);
diff --git a/demos/gtk-demo/builder.c b/demos/gtk-demo/builder.c
index c4f03fe..af902eb 100644
--- a/demos/gtk-demo/builder.c
+++ b/demos/gtk-demo/builder.c
@@ -52,6 +52,8 @@ do_builder (GtkWidget *do_widget)
       window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
+
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
       toolbar = GTK_WIDGET (gtk_builder_get_object (builder, "toolbar1"));
diff --git a/demos/gtk-demo/button_box.c b/demos/gtk-demo/button_box.c
index 18e7970..3928293 100644
--- a/demos/gtk-demo/button_box.c
+++ b/demos/gtk-demo/button_box.c
@@ -58,6 +58,8 @@ do_button_box (GtkWidget *do_widget)
                            gtk_widget_get_screen (do_widget));
     gtk_window_set_title (GTK_WINDOW (window), "Button Boxes");
 
+    gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
+
     g_signal_connect (window, "destroy",
                       G_CALLBACK (gtk_widget_destroyed),
                       &window);
diff --git a/demos/gtk-demo/changedisplay.c b/demos/gtk-demo/changedisplay.c
index 7525d8a..a9e3b22 100644
--- a/demos/gtk-demo/changedisplay.c
+++ b/demos/gtk-demo/changedisplay.c
@@ -532,6 +532,7 @@ do_changedisplay (GtkWidget *do_widget)
                                             _("_Close"),  GTK_RESPONSE_CLOSE,
                                             "Change",         GTK_RESPONSE_OK,
                                             NULL);
+      gtk_window_set_transient_for (GTK_WINDOW (info->window), GTK_WINDOW (do_widget));
 
       gtk_window_set_default_size (GTK_WINDOW (info->window), 300, 400);
 
diff --git a/demos/gtk-demo/clipboard.c b/demos/gtk-demo/clipboard.c
index 378a77f..a0c3b96 100644
--- a/demos/gtk-demo/clipboard.c
+++ b/demos/gtk-demo/clipboard.c
@@ -214,6 +214,7 @@ do_clipboard (GtkWidget *do_widget)
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Clipboard demo");
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
 
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
diff --git a/demos/gtk-demo/colorsel.c b/demos/gtk-demo/colorsel.c
index 8f0cc18..f96b167 100644
--- a/demos/gtk-demo/colorsel.c
+++ b/demos/gtk-demo/colorsel.c
@@ -74,6 +74,7 @@ do_colorsel (GtkWidget *do_widget)
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Color Chooser");
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
 
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
diff --git a/demos/gtk-demo/combobox.c b/demos/gtk-demo/combobox.c
index f78ee82..0293ad3 100644
--- a/demos/gtk-demo/combobox.c
+++ b/demos/gtk-demo/combobox.c
@@ -319,6 +319,7 @@ do_combobox (GtkWidget *do_widget)
     gtk_window_set_screen (GTK_WINDOW (window),
                            gtk_widget_get_screen (do_widget));
     gtk_window_set_title (GTK_WINDOW (window), "Combo boxes");
+    gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
 
     g_signal_connect (window, "destroy",
                       G_CALLBACK (gtk_widget_destroyed),
diff --git a/demos/gtk-demo/css_accordion.c b/demos/gtk-demo/css_accordion.c
index df5e14b..42dfb88 100644
--- a/demos/gtk-demo/css_accordion.c
+++ b/demos/gtk-demo/css_accordion.c
@@ -30,6 +30,7 @@ do_css_accordion (GtkWidget *do_widget)
       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
       gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
       gtk_window_set_default_size (GTK_WINDOW (window), 600, 300);
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
       
diff --git a/demos/gtk-demo/dialog.c b/demos/gtk-demo/dialog.c
index 209fd6d..cbd7990 100644
--- a/demos/gtk-demo/dialog.c
+++ b/demos/gtk-demo/dialog.c
@@ -110,6 +110,7 @@ do_dialog (GtkWidget *do_widget)
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Dialogs");
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
 
       g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window);
       gtk_container_set_border_width (GTK_CONTAINER (window), 8);
diff --git a/demos/gtk-demo/drawingarea.c b/demos/gtk-demo/drawingarea.c
index c7bbcae..ee7cd93 100644
--- a/demos/gtk-demo/drawingarea.c
+++ b/demos/gtk-demo/drawingarea.c
@@ -211,6 +211,7 @@ do_drawingarea (GtkWidget *do_widget)
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Drawing Area");
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
 
       g_signal_connect (window, "destroy", G_CALLBACK (close_window), NULL);
 
diff --git a/demos/gtk-demo/editable_cells.c b/demos/gtk-demo/editable_cells.c
index 717bf50..05e307e 100644
--- a/demos/gtk-demo/editable_cells.c
+++ b/demos/gtk-demo/editable_cells.c
@@ -350,6 +350,7 @@ do_editable_cells (GtkWidget *do_widget)
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Shopping list");
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
       gtk_container_set_border_width (GTK_CONTAINER (window), 5);
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
diff --git a/demos/gtk-demo/event_axes.c b/demos/gtk-demo/event_axes.c
index 71db570..173c62b 100644
--- a/demos/gtk-demo/event_axes.c
+++ b/demos/gtk-demo/event_axes.c
@@ -385,6 +385,7 @@ do_event_axes (GtkWidget *toplevel)
     {
       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
       gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (toplevel));
 
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
diff --git a/demos/gtk-demo/flowbox.c b/demos/gtk-demo/flowbox.c
index 38ce3c0..8b48412 100644
--- a/demos/gtk-demo/flowbox.c
+++ b/demos/gtk-demo/flowbox.c
@@ -724,6 +724,7 @@ do_flowbox (GtkWidget *do_widget)
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Flow Box");
       gtk_window_set_default_size (GTK_WINDOW (window), 400, 600);
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
 
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed),
diff --git a/demos/gtk-demo/gestures.c b/demos/gtk-demo/gestures.c
index 9a414fc..0fc0417 100644
--- a/demos/gtk-demo/gestures.c
+++ b/demos/gtk-demo/gestures.c
@@ -140,6 +140,7 @@ do_gestures (GtkWidget *do_widget)
       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
       gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
       gtk_window_set_title (GTK_WINDOW (window), "Gestures demo");
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
 
diff --git a/demos/gtk-demo/glarea.c b/demos/gtk-demo/glarea.c
index 8ac5b37..90be322 100644
--- a/demos/gtk-demo/glarea.c
+++ b/demos/gtk-demo/glarea.c
@@ -139,6 +139,7 @@ create_glarea_window (GtkWidget *do_widget)
   gtk_window_set_screen (GTK_WINDOW (window), gtk_widget_get_screen (do_widget));
   gtk_window_set_title (GTK_WINDOW (window), "GtkGLArea - Golden Triangle");
   gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
+  gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
   gtk_container_set_border_width (GTK_CONTAINER (window), 12);
   g_signal_connect (window, "destroy", G_CALLBACK (close_window), NULL);
 
diff --git a/demos/gtk-demo/headerbar.c b/demos/gtk-demo/headerbar.c
index 64356c8..a83a547 100644
--- a/demos/gtk-demo/headerbar.c
+++ b/demos/gtk-demo/headerbar.c
@@ -25,6 +25,7 @@ do_headerbar (GtkWidget *do_widget)
     {
       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
       gtk_window_set_screen (GTK_WINDOW (window), gtk_widget_get_screen (do_widget));
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
       gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
diff --git a/demos/gtk-demo/hypertext.c b/demos/gtk-demo/hypertext.c
index 28a7522..e586a8f 100644
--- a/demos/gtk-demo/hypertext.c
+++ b/demos/gtk-demo/hypertext.c
@@ -247,6 +247,7 @@ do_hypertext (GtkWidget *do_widget)
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_default_size (GTK_WINDOW (window),
                                    450, 450);
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
 
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
diff --git a/demos/gtk-demo/iconview.c b/demos/gtk-demo/iconview.c
index a377146..9e83a3a 100644
--- a/demos/gtk-demo/iconview.c
+++ b/demos/gtk-demo/iconview.c
@@ -256,6 +256,7 @@ do_iconview (GtkWidget *do_widget)
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "GtkIconView demo");
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
 
       g_signal_connect (window, "destroy",
                         G_CALLBACK (close_window), NULL);
diff --git a/demos/gtk-demo/iconview_edit.c b/demos/gtk-demo/iconview_edit.c
index 25bc80f..2c3ab42 100644
--- a/demos/gtk-demo/iconview_edit.c
+++ b/demos/gtk-demo/iconview_edit.c
@@ -111,6 +111,7 @@ do_iconview_edit (GtkWidget *do_widget)
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Editing and Drag-and-Drop");
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
 
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
diff --git a/demos/gtk-demo/images.c b/demos/gtk-demo/images.c
index a36c8df..9ab6f5e 100644
--- a/demos/gtk-demo/images.c
+++ b/demos/gtk-demo/images.c
@@ -341,6 +341,7 @@ do_images (GtkWidget *do_widget)
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Images");
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
 
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
diff --git a/demos/gtk-demo/infobar.c b/demos/gtk-demo/infobar.c
index 2bee2d4..9fae59f 100644
--- a/demos/gtk-demo/infobar.c
+++ b/demos/gtk-demo/infobar.c
@@ -56,6 +56,7 @@ do_infobar (GtkWidget *do_widget)
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Info Bars");
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
 
       g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window);
       gtk_container_set_border_width (GTK_CONTAINER (window), 8);
diff --git a/demos/gtk-demo/links.c b/demos/gtk-demo/links.c
index fa3075d..3e65a1c 100644
--- a/demos/gtk-demo/links.c
+++ b/demos/gtk-demo/links.c
@@ -57,6 +57,7 @@ do_links (GtkWidget *do_widget)
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Links");
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
       gtk_container_set_border_width (GTK_CONTAINER (window), 12);
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
diff --git a/demos/gtk-demo/list_store.c b/demos/gtk-demo/list_store.c
index 580f07c..0a2d930 100644
--- a/demos/gtk-demo/list_store.c
+++ b/demos/gtk-demo/list_store.c
@@ -260,6 +260,7 @@ do_list_store (GtkWidget *do_widget)
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "GtkListStore demo");
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
 
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
diff --git a/demos/gtk-demo/listbox.c b/demos/gtk-demo/listbox.c
index 3941f2d..8bbd233 100644
--- a/demos/gtk-demo/listbox.c
+++ b/demos/gtk-demo/listbox.c
@@ -322,6 +322,7 @@ do_listbox (GtkWidget *do_widget)
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "List Box");
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
       gtk_window_set_default_size (GTK_WINDOW (window),
                                    400, 600);
 
diff --git a/demos/gtk-demo/main.c b/demos/gtk-demo/main.c
index c555136..099ff4d 100644
--- a/demos/gtk-demo/main.c
+++ b/demos/gtk-demo/main.c
@@ -137,7 +137,6 @@ run_example_for_row (GtkWidget    *window,
 
           if (gtk_widget_is_toplevel (demo))
             {
-              gtk_window_set_transient_for (GTK_WINDOW (demo), GTK_WINDOW (window));
               gtk_window_set_modal (GTK_WINDOW (demo), TRUE);
             }
 
diff --git a/demos/gtk-demo/menus.c b/demos/gtk-demo/menus.c
index 7fd9553..d099e24 100644
--- a/demos/gtk-demo/menus.c
+++ b/demos/gtk-demo/menus.c
@@ -100,6 +100,7 @@ do_menus (GtkWidget *do_widget)
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Menus");
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
       g_signal_connect (window, "destroy",
                         G_CALLBACK(gtk_widget_destroyed), &window);
 
diff --git a/demos/gtk-demo/offscreen_window.c b/demos/gtk-demo/offscreen_window.c
index 9109e27..92d2ee8 100644
--- a/demos/gtk-demo/offscreen_window.c
+++ b/demos/gtk-demo/offscreen_window.c
@@ -577,6 +577,7 @@ do_offscreen_window (GtkWidget *do_widget)
       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Rotated widget");
 
       g_signal_connect (window, "destroy",
diff --git a/demos/gtk-demo/offscreen_window2.c b/demos/gtk-demo/offscreen_window2.c
index b327f71..075a4a1 100644
--- a/demos/gtk-demo/offscreen_window2.c
+++ b/demos/gtk-demo/offscreen_window2.c
@@ -483,6 +483,7 @@ do_offscreen_window2 (GtkWidget *do_widget)
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Effects");
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
 
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
diff --git a/demos/gtk-demo/overlay.c b/demos/gtk-demo/overlay.c
index 60f419f..3e0b7d4 100644
--- a/demos/gtk-demo/overlay.c
+++ b/demos/gtk-demo/overlay.c
@@ -21,6 +21,7 @@ do_overlay (GtkWidget *do_widget)
       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
       gtk_window_set_default_size (GTK_WINDOW (window),
                                    450, 450);
 
diff --git a/demos/gtk-demo/panes.c b/demos/gtk-demo/panes.c
index 2811b36..6772945 100644
--- a/demos/gtk-demo/panes.c
+++ b/demos/gtk-demo/panes.c
@@ -137,6 +137,7 @@ do_panes (GtkWidget *do_widget)
       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
 
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
diff --git a/demos/gtk-demo/pickers.c b/demos/gtk-demo/pickers.c
index 46826b5..910185f 100644
--- a/demos/gtk-demo/pickers.c
+++ b/demos/gtk-demo/pickers.c
@@ -18,6 +18,7 @@ do_pickers (GtkWidget *do_widget)
     gtk_window_set_screen (GTK_WINDOW (window),
                            gtk_widget_get_screen (do_widget));
     gtk_window_set_title (GTK_WINDOW (window), "Pickers");
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
 
     g_signal_connect (window, "destroy",
                       G_CALLBACK (gtk_widget_destroyed),
diff --git a/demos/gtk-demo/pixbufs.c b/demos/gtk-demo/pixbufs.c
index d220b75..c37d87c 100644
--- a/demos/gtk-demo/pixbufs.c
+++ b/demos/gtk-demo/pixbufs.c
@@ -179,6 +179,7 @@ do_pixbufs (GtkWidget *do_widget)
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Pixbufs");
       gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
 
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
diff --git a/demos/gtk-demo/popover.c b/demos/gtk-demo/popover.c
index cb2c6b9..4731e93 100644
--- a/demos/gtk-demo/popover.c
+++ b/demos/gtk-demo/popover.c
@@ -138,6 +138,7 @@ do_popover (GtkWidget *do_widget)
   if (!window)
     {
       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
       box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 24);
       gtk_container_set_border_width (GTK_CONTAINER (box), 24);
       gtk_container_add (GTK_CONTAINER (window), box);
diff --git a/demos/gtk-demo/revealer.c b/demos/gtk-demo/revealer.c
index 703223a..361f4fc 100644
--- a/demos/gtk-demo/revealer.c
+++ b/demos/gtk-demo/revealer.c
@@ -76,6 +76,7 @@ do_revealer (GtkWidget *do_widget)
       window = GTK_WIDGET (gtk_builder_get_object (builder, "dialog1"));
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
       g_signal_connect (window, "response", G_CALLBACK (response_cb), NULL);
diff --git a/demos/gtk-demo/rotated_text.c b/demos/gtk-demo/rotated_text.c
index 8b4ecb2..27cd136 100644
--- a/demos/gtk-demo/rotated_text.c
+++ b/demos/gtk-demo/rotated_text.c
@@ -186,6 +186,7 @@ do_rotated_text (GtkWidget *do_widget)
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Rotated Text");
       gtk_window_set_default_size (GTK_WINDOW (window), 4 * RADIUS, 2 * RADIUS);
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
       g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window);
 
       box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
diff --git a/demos/gtk-demo/sidebar.c b/demos/gtk-demo/sidebar.c
index f135794..9917347 100644
--- a/demos/gtk-demo/sidebar.c
+++ b/demos/gtk-demo/sidebar.c
@@ -38,6 +38,7 @@ do_sidebar (GtkWidget *do_widget)
     {
       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
       gtk_window_set_resizable (GTK_WINDOW (window), TRUE);
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
       gtk_widget_set_size_request (window, 500, 350);
 
       header = gtk_header_bar_new ();
diff --git a/demos/gtk-demo/stack.c b/demos/gtk-demo/stack.c
index badcd99..674c308 100644
--- a/demos/gtk-demo/stack.c
+++ b/demos/gtk-demo/stack.c
@@ -29,6 +29,7 @@ do_stack (GtkWidget *do_widget)
       window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
     }
diff --git a/demos/gtk-demo/textscroll.c b/demos/gtk-demo/textscroll.c
index 90ae13b..6593af3 100644
--- a/demos/gtk-demo/textscroll.c
+++ b/demos/gtk-demo/textscroll.c
@@ -181,6 +181,7 @@ do_textscroll (GtkWidget *do_widget)
       GtkWidget *hbox;
 
       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
       gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
diff --git a/demos/gtk-demo/textview.c b/demos/gtk-demo/textview.c
index 9422759..0ace9a9 100644
--- a/demos/gtk-demo/textview.c
+++ b/demos/gtk-demo/textview.c
@@ -476,6 +476,7 @@ do_textview (GtkWidget *do_widget)
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_default_size (GTK_WINDOW (window),
                                    450, 450);
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
 
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
diff --git a/demos/gtk-demo/theming_style_classes.c b/demos/gtk-demo/theming_style_classes.c
index fa9cded..41e65e7 100644
--- a/demos/gtk-demo/theming_style_classes.c
+++ b/demos/gtk-demo/theming_style_classes.c
@@ -25,6 +25,7 @@ do_theming_style_classes (GtkWidget *do_widget)
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Style Classes");
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
       gtk_container_set_border_width (GTK_CONTAINER (window), 12);
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
diff --git a/demos/gtk-demo/toolpalette.c b/demos/gtk-demo/toolpalette.c
index f8d9573..95e1e77 100644
--- a/demos/gtk-demo/toolpalette.c
+++ b/demos/gtk-demo/toolpalette.c
@@ -440,6 +440,7 @@ do_toolpalette (GtkWidget *do_widget)
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Tool Palette");
       gtk_window_set_default_size (GTK_WINDOW (window), 200, 600);
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
 
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
diff --git a/demos/gtk-demo/transparent.c b/demos/gtk-demo/transparent.c
index c6e59c8..3623baa 100644
--- a/demos/gtk-demo/transparent.c
+++ b/demos/gtk-demo/transparent.c
@@ -198,6 +198,7 @@ do_transparent (GtkWidget *do_widget)
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_default_size (GTK_WINDOW (window),
                                    450, 450);
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
 
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
diff --git a/demos/gtk-demo/tree_store.c b/demos/gtk-demo/tree_store.c
index c51b946..bbdbe6a 100644
--- a/demos/gtk-demo/tree_store.c
+++ b/demos/gtk-demo/tree_store.c
@@ -399,6 +399,7 @@ do_tree_store (GtkWidget *do_widget)
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Card planning sheet");
+      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
       g_signal_connect (window, "destroy",
                         G_CALLBACK (gtk_widget_destroyed), &window);
 
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index 6862ca9..8edfd6e 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -1840,7 +1840,6 @@ gtk_menu_popdown (GtkMenu *menu)
   if (priv->toplevel)
     {
       gtk_widget_hide (priv->toplevel);
-      gtk_window_set_transient_for (GTK_WINDOW (priv->toplevel), NULL);
     }
 
   pointer = _gtk_menu_shell_get_grab_device (menu_shell);
@@ -1871,7 +1870,8 @@ gtk_menu_popdown (GtkMenu *menu)
         }
 
       /* gtk_menu_popdown is called each time a menu item is selected from
-       * a torn off menu. Only scroll back to the saved position if the
+       * a torn off menu. Only\
+        scroll back to the saved position if the
        * non-tearoff menu was popped down.
        */
       if (!priv->tearoff_active)
@@ -1879,7 +1879,10 @@ gtk_menu_popdown (GtkMenu *menu)
       priv->tearoff_active = TRUE;
     }
   else
-    gtk_widget_hide (GTK_WIDGET (menu));
+    {
+      gtk_widget_unrealize (GTK_WIDGET (menu));
+      gtk_widget_unrealize (priv->toplevel);
+    }
 
   menu_shell->priv->have_xgrab = FALSE;
 
@@ -2303,13 +2306,13 @@ gtk_menu_set_tearoff_state (GtkMenu  *menu,
 
               gtk_menu_update_title (menu);
 
-              gtk_widget_realize (priv->tearoff_window);
-
               toplevel = gtk_menu_get_toplevel (GTK_WIDGET (menu));
               if (toplevel != NULL)
                 gtk_window_set_transient_for (GTK_WINDOW (priv->tearoff_window),
                                               GTK_WINDOW (toplevel));
 
+              gtk_widget_realize (priv->tearoff_window);
+
               priv->tearoff_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
               gtk_container_add (GTK_CONTAINER (priv->tearoff_window),
                                  priv->tearoff_hbox);
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 241f8ed..8e60e4c 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -3094,6 +3094,9 @@ gtk_window_set_transient_for  (GtkWindow *window,
 
   priv = window->priv;
 
+  if (gtk_widget_get_realized (GTK_WIDGET (window)))
+    g_warning ("gtk_window_set_transient_for called on a realized window. This is discouraged.");
+
   if (priv->transient_parent)
     {
       if (gtk_widget_get_realized (GTK_WIDGET (window)) &&
