Index: gok/callbacks.c
===================================================================
RCS file: /cvs/gnome/gok/gok/callbacks.c,v
retrieving revision 1.41
diff -u -p -r1.41 callbacks.c
--- gok/callbacks.c	23 Jul 2003 09:22:13 -0000	1.41
+++ gok/callbacks.c	23 Jul 2003 09:45:16 -0000
@@ -106,6 +106,8 @@ gok_discard_focus_filter (GdkXEvent *xev
   XEvent *xev = (XEvent *)xevent;	
   GList *list, *l;
   gint n_mapped;
+  GtkWindow *window;
+  gboolean has_focus;
 
   if (xev->xany.type == ClientMessage &&
       (Atom) xev->xclient.data.l[0] == gdk_x11_atom_to_xatom (
@@ -113,13 +115,21 @@ gok_discard_focus_filter (GdkXEvent *xev
     {
       list = gtk_window_list_toplevels ();
       n_mapped = 0;
+      has_focus = FALSE;
       for (l = list; l; l = l->next)
         {
           if (GTK_WIDGET_MAPPED (GTK_WIDGET (l->data)))
-            n_mapped++;
+            {
+              n_mapped++;
+              window = GTK_WINDOW (l->data);
+              if (window->has_focus)
+                has_focus = TRUE;
+            }
         }
       if (n_mapped <= 1)
         XSetInputFocus (xev->xany.display, PointerRoot, RevertToPointerRoot, CurrentTime);
+      else if (!has_focus)
+        XSetInputFocus (xev->xany.display, GDK_WINDOW_XID (GTK_WIDGET (window)->window), RevertToPointerRoot, CurrentTime);
 
       g_list_free (list);
       return GDK_FILTER_REMOVE;
