Index: gdk/win32/gdkevents-win32.c
===================================================================
--- gdk/win32/gdkevents-win32.c	(revision 17113)
+++ gdk/win32/gdkevents-win32.c	(working copy)
@@ -2155,6 +2155,7 @@
 
   gchar buf[256];
   gboolean return_val = FALSE;
+  gboolean set_focus = FALSE;
 
   int i;
 
@@ -2870,6 +2871,8 @@
        break;
 
     case WM_KILLFOCUS:
+      GDK_NOTE (EVENTS, g_print (" %p", (HWND) msg->wParam));
+
       if (p_grab_window != NULL && !GDK_WINDOW_DESTROYED (p_grab_window))
 	generate_grab_broken_event (p_grab_window, FALSE, NULL);
 
@@ -2879,6 +2882,8 @@
 
       /* fallthrough */
     case WM_SETFOCUS:
+      if (msg->message == WM_SETFOCUS)
+	GDK_NOTE (EVENTS, g_print (" %p", (HWND) msg->wParam));
       if (k_grab_window != NULL && !k_grab_owner_events)
 	break;
 
@@ -3348,7 +3353,10 @@
 
     case WM_DESTROY:
       if (window == current_window)
-	assign_object (&current_window, _gdk_root);
+	{
+	  assign_object (&current_window, _gdk_root);
+	  set_focus = TRUE;
+	}
 
       if (p_grab_window == window)
 	gdk_pointer_ungrab (msg->time);
@@ -3356,6 +3364,19 @@
       if (k_grab_window == window)
 	gdk_keyboard_ungrab (msg->time);
 
+      impl = GDK_WINDOW_IMPL_WIN32 (((GdkWindowObject *) window)->impl);
+      if (impl->transient_for != NULL)
+	{
+	  GDK_NOTE (EVENTS, g_print (" SetFocus(%p)", GDK_WINDOW_HWND (impl->transient_for)));
+	  SetLastError (0);
+	  if (set_focus)
+	    {
+	      if (SetFocus (GDK_WINDOW_HWND (impl->transient_for)) == NULL &&
+		  GetLastError () != 0)
+		WIN32_API_FAILED ("SetFocus");
+	    }
+	}
+
       if ((window != NULL) && (msg->hwnd != GetDesktopWindow ()))
 	gdk_window_destroy_notify (window);
 
Index: gdk/win32/gdkwindow-win32.c
===================================================================
--- gdk/win32/gdkwindow-win32.c	(revision 17113)
+++ gdk/win32/gdkwindow-win32.c	(working copy)
@@ -1,7 +1,8 @@
 /* GDK - The GIMP Drawing Kit
  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- * Copyright (C) 1998-2004 Tor Lillqvist
+ * Copyright (C) 1998-2006 Tor Lillqvist
  * Copyright (C) 2001-2004 Hans Breuer
+ * Copyright (C) 2005 Charles Reilly
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -806,7 +807,6 @@
   if (private->extension_events != 0)
     _gdk_input_window_destroy (window);
 
-
   if (!recursing && !foreign_destroy)
     {
       _gdk_win32_drawable_finish (private->impl);
@@ -1446,7 +1446,7 @@
 
       if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TEMP)
         API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), HWND_TOPMOST,
-	                         0, 0, 0, 0,
+				 0, 0, 0, 0,
 				 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE));
       else if (((GdkWindowObject *)window)->accept_focus)
         API_CALL (BringWindowToTop, (GDK_WINDOW_HWND (window)));
@@ -1748,13 +1748,24 @@
 			   GDK_WINDOW_HWND (parent)));
 
   if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (parent))
-    return;
+    {
+      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;
     }
+  else if (((GdkWindowObject *) window)->window_type == GDK_WINDOW_FOREIGN)
+    {
+      GDK_NOTE (MISC, g_print ("... a foreign window!\n"));
+      return;
+    }
   
   window_id = GDK_WINDOW_HWND (window);
   parent_id = GDK_WINDOW_HWND (parent);
@@ -1768,6 +1779,8 @@
   if (SetWindowLong (window_id, GWL_HWNDPARENT, (long) parent_id) == 0 &&
       GetLastError () != 0)
     WIN32_API_FAILED ("SetWindowLong");
+
+  ((GdkWindowImplWin32 *)((GdkWindowObject *)window)->impl)->transient_for = parent;
 }
 
 void
@@ -3206,11 +3219,13 @@
 
   private->modal_hint = modal;
 
-  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));
+  /* We used to call SetWindowPos() here if the window is mapped,
+   * setting the window to HWND_TOPMOST if modal and HWND_NOTOPMOST if
+   * not. That can't be right, can it? Just having a modal hint
+   * does not mean a window should be TOPMOST. It's transient-for that
+   * indicates a window should be on always top of another
+   * window. It's keep-above that corresponds to TOPMOST.
+   */
 }
 
 void
@@ -3239,15 +3254,6 @@
 
       SetWindowLong (GDK_WINDOW_HWND (window), GWL_HWNDPARENT,
 		     (long) GDK_WINDOW_HWND (owner));
-
-#if 0 /* Should we also turn off the minimize and maximize buttons? */
-      SetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE,
-		     GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE) & ~(WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_SYSMENU));
-      SetWindowPos (GDK_WINDOW_HWND (window), NULL,
-		    0, 0, 0, 0,
-		    SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE |
-		    SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER);
-#endif
     }
   else
     {
Index: gdk/win32/gdkwindow-win32.h
===================================================================
--- gdk/win32/gdkwindow-win32.h	(revision 17113)
+++ gdk/win32/gdkwindow-win32.h	(working copy)
@@ -86,6 +86,10 @@
   GdkWindowTypeHint type_hint;
 
   gboolean extension_events_selected;
+
+  GdkWindow *transient_for;
+
+  gboolean skips_taskbar;
 };
  
 struct _GdkWindowImplWin32Class 
