Index: gdk/win32/gdkevents-win32.c
===================================================================
--- gdk/win32/gdkevents-win32.c	(revision 18344)
+++ gdk/win32/gdkevents-win32.c	(working copy)
@@ -1,6 +1,7 @@
 /* GDK - The GIMP Drawing Kit
  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  * Copyright (C) 1998-2002 Tor Lillqvist
+ * Copyright (C) 2007 Cody Russell
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -3283,6 +3284,13 @@
 
       append_event (event);
 
+      impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
+
+      if (impl->transient_owner)
+	{
+	  SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
+	}
+
       return_val = TRUE;
       break;
 
Index: gdk/win32/gdkwindow-win32.c
===================================================================
--- gdk/win32/gdkwindow-win32.c	(revision 18344)
+++ gdk/win32/gdkwindow-win32.c	(working copy)
@@ -2,6 +2,7 @@
  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  * Copyright (C) 1998-2004 Tor Lillqvist
  * Copyright (C) 2001-2004 Hans Breuer
+ * Copyright (C) 2007 Cody Russell
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -155,6 +156,9 @@
   impl->hint_flags = 0;
   impl->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
   impl->extension_events_selected = FALSE;
+  impl->transient_owner = NULL;
+  impl->transient_children = NULL;
+  impl->num_transients = 0;
 }
 
 static void
@@ -868,16 +872,44 @@
 			       gboolean   foreign_destroy)
 {
   GdkWindowObject *private = (GdkWindowObject *)window;
+  GdkWindowImplWin32 *window_impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
+  GSList *tmp;
 
   g_return_if_fail (GDK_IS_WINDOW (window));
   
   GDK_NOTE (MISC, g_print ("_gdk_windowing_window_destroy: %p\n",
 			   GDK_WINDOW_HWND (window)));
 
+  g_print ("_gdk_windowing_window_destroy: %p\n", GDK_WINDOW_HWND (window));
+
   if (private->extension_events != 0)
     _gdk_input_window_destroy (window);
 
+  /* Remove all our transient children */
+  if (window_impl->num_transients)
+    {
+      tmp = window_impl->transient_children;
+      while (tmp != NULL)
+	{
+	  GdkWindow *child = tmp->data;
+	  GdkWindowImplWin32 *child_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (child)->impl);
 
+	  child_impl->transient_owner = NULL;
+	  tmp = g_slist_next (tmp);
+	  window_impl->num_transients--;
+	}
+      g_slist_free (window_impl->transient_children);
+      window_impl->transient_children = NULL;
+    }
+
+  /* Remove ourself from our transient owner */
+  g_print ("Remove our transient_owner if it exists..\n");
+  if (window_impl->transient_owner != NULL)
+    {
+      g_print ("set_transient_for (NULL)\n");
+      gdk_window_set_transient_for (window, NULL);
+    }
+
   if (!recursing && !foreign_destroy)
     {
       _gdk_win32_drawable_finish (private->impl);
@@ -885,6 +917,7 @@
       private->destroyed = TRUE;
       DestroyWindow (GDK_WINDOW_HWND (window));
     }
+
   gdk_win32_handle_table_remove (GDK_WINDOW_HWND (window));
 }
 
@@ -1956,30 +1989,75 @@
   /* XXX */
 }
 
-void          
+void
 gdk_window_set_transient_for (GdkWindow *window, 
 			      GdkWindow *parent)
 {
   HWND window_id, parent_id;
+  GSList *item;
+  GdkWindowImplWin32 *window_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
+  GdkWindowImplWin32 *parent_impl = NULL;
 
   g_return_if_fail (GDK_IS_WINDOW (window));
-  
+
+  window_id = GDK_WINDOW_HWND (window);
+  parent_id = parent != NULL ? GDK_WINDOW_HWND (parent) : NULL;
+
+  if (parent != NULL)
+    parent_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (parent)->impl);
+
+#if 0
   GDK_NOTE (MISC, g_print ("gdk_window_set_transient_for: %p: %p\n",
 			   GDK_WINDOW_HWND (window),
 			   GDK_WINDOW_HWND (parent)));
+#endif
 
-  if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (parent))
-    return;
+  if (GDK_WINDOW_DESTROYED (window) || parent && GDK_WINDOW_DESTROYED (parent))
+    {
+      if (GDK_WINDOW_DESTROYED (window))
+	GDK_NOTE (MISC, g_print ("... destroyed!\n"));
+      else
+	GDK_NOTE (MISC, g_print ("... owner destroyed!\n"));
 
+      return;
+    }
+
   if (((GdkWindowObject *) window)->window_type == GDK_WINDOW_CHILD)
     {
       GDK_NOTE (MISC, g_print ("... a child window!\n"));
       return;
     }
+
+  if (parent == NULL)
+    {
+      GdkWindowImplWin32 *trans_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window_impl->transient_owner)->impl);
+
+      if (trans_impl->transient_children != NULL)
+      {
+	item = g_slist_find (trans_impl->transient_children, window);
+	item->data = NULL;
+	trans_impl->transient_children = g_slist_delete_link (trans_impl->transient_children, item);
+	trans_impl->num_transients--;
+	if (!trans_impl->num_transients)
+	  trans_impl->transient_children = NULL;
+
+	g_print ("item removed, num_transients == %d\n", trans_impl->num_transients);
+      }
+
+      window_impl->transient_owner = NULL;
+    }
+  else
+    {
+      g_print ("parent != null\n");
+
+      parent_impl->transient_children = g_slist_append (parent_impl->transient_children, window);
+      parent_impl->num_transients++;
+
+      window_impl->transient_owner = parent;
+
+      g_print ("num_transients == %d\n", parent_impl->num_transients);
+    }
   
-  window_id = GDK_WINDOW_HWND (window);
-  parent_id = GDK_WINDOW_HWND (parent);
-
   /* This changes the *owner* of the window, despite the misleading
    * name. (Owner and parent are unrelated concepts.) At least that's
    * what people who seem to know what they talk about say on
@@ -3427,11 +3505,14 @@
 
   private->modal_hint = modal;
 
+#if 0
+  /* Not sure about this one.. */
   if (GDK_WINDOW_IS_MAPPED (window))
     API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), 
 			     modal ? HWND_TOPMOST : HWND_NOTOPMOST,
 			     0, 0, 0, 0,
 			     SWP_NOMOVE | SWP_NOSIZE));
+#endif
 }
 
 void
Index: gdk/win32/gdkwindow-win32.h
===================================================================
--- gdk/win32/gdkwindow-win32.h	(revision 18344)
+++ gdk/win32/gdkwindow-win32.h	(working copy)
@@ -86,6 +86,10 @@
   GdkWindowTypeHint type_hint;
 
   gboolean extension_events_selected;
+
+  GdkWindow *transient_owner;
+  GSList    *transient_children;
+  gint       num_transients;
 };
  
 struct _GdkWindowImplWin32Class 
