Index: gtk+/modules/input/gtkimcontextxim.c
===================================================================
RCS file: /sgnome/cvsroots/sun-gnome/gtk+/modules/input/gtkimcontextxim.c,v
retrieving revision 1.6
diff -u -p -r1.6 gtkimcontextxim.c
--- gtk+/modules/input/gtkimcontextxim.c	19 Nov 2002 14:04:53 -0000	1.6
+++ gtk+/modules/input/gtkimcontextxim.c	26 Nov 2002 03:07:04 -0000
@@ -517,6 +517,7 @@ gtk_im_context_xim_filter_keypress (GtkI
 {
   GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
   XIC ic = gtk_im_context_xim_get_ic (context_xim);
+  GdkWindow *root_window = gdk_screen_get_root_window (gdk_drawable_get_screen (event->window));
   gchar static_buffer[256];
   gchar *buffer = static_buffer;
   gint buffer_size = sizeof(static_buffer) - 1;
@@ -524,7 +525,6 @@ gtk_im_context_xim_filter_keypress (GtkI
   KeySym keysym;
   Status status;
   gboolean result = FALSE;
-  GdkWindow *root_window = gdk_screen_get_root_window (gdk_drawable_get_screen (event->window));
 
   XKeyPressedEvent xevent;
 
@@ -545,9 +545,6 @@ gtk_im_context_xim_filter_keypress (GtkI
   xevent.keycode = event->hardware_keycode;
   xevent.same_screen = True;
   
-  if (XFilterEvent ((XEvent *)&xevent, GDK_DRAWABLE_XID (context_xim->client_window)))
-    return TRUE;
-  
  again:
   if (ic)
     num_bytes = XmbLookupString (ic, &xevent, buffer, buffer_size, &keysym, &status);
@@ -593,6 +590,41 @@ gtk_im_context_xim_filter_keypress (GtkI
   return result;
 }
 
+static gboolean
+gtk_im_context_xim_key_snooper (GtkWidget *grab_widget,
+				GdkEventKey *event,
+				gpointer func_data)
+{
+  GtkIMContext *context = (GtkIMContext*)func_data;
+  GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
+  GdkWindow *root_window = gdk_screen_get_root_window (gdk_drawable_get_screen (event->window));
+
+  XKeyPressedEvent xevent;
+
+  if (event->type == GDK_KEY_RELEASE && !context_xim->filter_key_release)
+    return FALSE;
+
+  xevent.type = (event->type == GDK_KEY_PRESS) ? KeyPress : KeyRelease;
+  xevent.serial = 0;		/* hope it doesn't matter */
+  xevent.send_event = event->send_event;
+  xevent.display = GDK_DRAWABLE_XDISPLAY (event->window);
+  xevent.window = GDK_DRAWABLE_XID (event->window);
+  xevent.root = GDK_DRAWABLE_XID (root_window);
+  xevent.subwindow = xevent.window;
+  xevent.time = event->time;
+  xevent.x = xevent.x_root = 0;
+  xevent.y = xevent.y_root = 0;
+  xevent.state = event->state;
+  xevent.keycode = event->hardware_keycode;
+  xevent.same_screen = True;
+  
+  if (XFilterEvent ((XEvent *)&xevent, GDK_DRAWABLE_XID (context_xim->client_window)))
+    return TRUE;
+  return FALSE;
+}
+
+static guint snooper_id = 0;
+
 static void
 gtk_im_context_xim_focus_in (GtkIMContext *context)
 {
@@ -602,6 +634,13 @@ gtk_im_context_xim_focus_in (GtkIMContex
   if (!ic)
     return;
 
+  if (snooper_id != 0)
+    {
+      gtk_key_snooper_remove (snooper_id);
+      snooper_id = 0;
+    }
+  snooper_id = gtk_key_snooper_install (gtk_im_context_xim_key_snooper,
+					context);
   XSetICFocus (ic);
 
   status_window_show (context_xim);
@@ -617,6 +656,12 @@ gtk_im_context_xim_focus_out (GtkIMConte
 
   if (!ic)
     return;
+
+  if (snooper_id != 0)
+    {
+      gtk_key_snooper_remove (snooper_id);
+      snooper_id = 0;
+    }
 
   XUnsetICFocus (ic);
 
