--- gtk+/gdk/x11/gdkkeys-x11.c.orig	2004-03-09 01:23:54.219631680 -0500
+++ gtk+/gdk/x11/gdkkeys-x11.c	2004-03-09 02:15:58.119726680 -0500
@@ -383,29 +383,35 @@
 get_direction (GdkKeymapX11 *keymap_x11)
 {
   XkbDescRec *xkb = get_xkb (keymap_x11);
-  const char *name;
+  KeyCode code = xkb->min_key_code;
   XkbStateRec state_rec;
-  PangoDirection result;
-
   GdkDisplay *display = GDK_KEYMAP (keymap_x11)->display;
 
   XkbGetState (GDK_DISPLAY_XDISPLAY (display), XkbUseCoreKbd, &state_rec);
-  
-  if (xkb->names->groups[state_rec.locked_group] == None)
-    result = PANGO_DIRECTION_LTR;
-  else
+
+  /* We use an infinite loop here instead of 'for' since max_key_code
+   * is often the maximum value of KeyCode (=CARD8), and a for loop
+   *  ends up overflowing and running endlessly.
+   */
+  for (;;)
     {
-      name = gdk_x11_get_xatom_name_for_display (display, xkb->names->groups[state_rec.locked_group]);
+      int width = XkbKeyGroupsWidth(xkb, code);
+      int w;
+      for (w = 0; w < width; ++w)
+	{
+	  KeySym sym = XkbKeySymEntry(xkb, code, w,
+		  state_rec.locked_group);
 
-      if (g_ascii_strcasecmp (name, "arabic") == 0 ||
-	  g_ascii_strcasecmp (name, "hebrew") == 0 ||
-	  g_ascii_strcasecmp (name, "israelian") == 0)
-	result = PANGO_DIRECTION_RTL;
-      else
-	result = PANGO_DIRECTION_LTR;
+	  if (pango_unichar_direction(
+              gdk_keyval_to_unicode(sym)) == PANGO_DIRECTION_RTL)
+	    return PANGO_DIRECTION_RTL;
+	}
+      if (code == xkb->max_key_code)
+	break;
+      code++;
     }
     
-  return result;
+  return PANGO_DIRECTION_LTR;
 }
 
 void
@@ -467,7 +473,7 @@
     }
   else
 #endif /* HAVE_XKB */
-    return PANGO_DIRECTION_LTR;
+    return PANGO_DIRECTION_NEUTRAL;
 }
 
 /**
