Index: gtkimcontextxim.c
===================================================================
RCS file: /cvs/gnome/gtk+/modules/input/gtkimcontextxim.c,v
retrieving revision 1.32.2.5
diff -u -p -r1.32.2.5 gtkimcontextxim.c
--- gtkimcontextxim.c	10 Jun 2003 18:25:25 -0000	1.32.2.5
+++ gtkimcontextxim.c	24 Jun 2003 23:28:46 -0000
@@ -524,15 +524,53 @@ reinitialize_ic (GtkIMContextXIM *contex
   context_xim->filter_key_release = FALSE;
 }
 
+static void status_window_free (StatusWindow *status_window);
+
+static void
+gtk_im_context_track_client_window (GtkWidget *widget,
+				    GtkWidget *old_widget)
+{
+  GtkWidget *toplevel;  
+  GSList *tmp_list;
+  StatusWindow *status_window;
+  GtkIMContextXIM *context_xim;
+
+  toplevel = gtk_widget_get_toplevel (old_widget);
+  context_xim = g_object_get_data (G_OBJECT (toplevel), "gtk-im-xim-context");
+
+  if (context_xim)
+    {
+      GdkWindow *client_window = widget->window;
+      set_ic_client_window (context_xim, client_window);
+    }
+  for (tmp_list = status_windows; tmp_list; tmp_list = tmp_list->next)
+    {
+      status_window = tmp_list->data;
+      if (status_window->toplevel == toplevel)
+	{
+	  status_window_free (status_window);
+	  break;
+	}
+    }
+}
+
 static void
 set_ic_client_window (GtkIMContextXIM *context_xim,
 		      GdkWindow       *client_window)
 {
+  GtkWidget *client_window_gtk;
+
   reinitialize_ic (context_xim);
   if (context_xim->client_window)
     {
       context_xim->im_info->ics = g_slist_remove (context_xim->im_info->ics, context_xim);
       context_xim->im_info = NULL;
+
+      gdk_window_get_user_data (context_xim->client_window,
+				(gpointer *)&client_window_gtk);
+      g_signal_handlers_disconnect_by_func (client_window_gtk,
+					    gtk_im_context_track_client_window,
+					    NULL);
     }
   
   context_xim->client_window = client_window;
@@ -541,6 +579,12 @@ set_ic_client_window (GtkIMContextXIM *c
     {
       context_xim->im_info = get_im (context_xim->client_window, context_xim->locale);
       context_xim->im_info->ics = g_slist_prepend (context_xim->im_info->ics, context_xim);
+
+      gdk_window_get_user_data (context_xim->client_window,
+				(gpointer *)&client_window_gtk);
+      g_signal_connect (client_window_gtk, "hierarchy_changed",
+			G_CALLBACK (gtk_im_context_track_client_window),
+			NULL);
     }
 }
 
@@ -1332,6 +1376,8 @@ status_window_get (GtkIMContextXIM *cont
   gdk_window_get_user_data (toplevel_gdk, (gpointer *)&toplevel);
   if (!toplevel)
     return NULL;
+
+  g_object_set_data (G_OBJECT (toplevel), "gtk-im-xim-context", context_xim);
 
   status_window = g_object_get_data (G_OBJECT (toplevel), "gtk-im-xim-status-window");
   if (status_window)
