*** generic/tkEvent.c.orig	Fri Aug 13 19:52:12 1999
--- generic/tkEvent.c	Sun Jan 16 17:43:03 2000
***************
*** 14,23 ****
--- 14,40 ----
   * RCS: @(#) $Id: tkEvent.c,v 1.5 1999/08/13 17:52:12 redman Exp $
   */
  
+ #define reserved188 tcl_MainLoop
+ #define reserved284 tcl_SetMainLoop
+ 
  #include "tkPort.h"
  #include "tkInt.h"
  #include <signal.h>
  
+ #ifndef USE_TCL_STUBS
+ extern TclStubs tclStubs;
+ #define tclStubsPtr (&tclStubs)
+ #endif
+ 
+ /*
+  * Make sure that Tcl_MainLoop always references the stub pointer, not
+  * the real function.
+  */
+ #undef Tcl_MainLoop
+ #define Tcl_MainLoop ((void (*) _ANSI_ARGS_((void))) ((tclStubsPtr)->tcl_MainLoop))
+ #undef Tcl_SetMainLoop
+ #define Tcl_SetMainLoop ((void (*) _ANSI_ARGS_((VOID *))) ((tclStubsPtr)->tcl_SetMainLoop))
+ 
  /*
   * There's a potential problem if a handler is deleted while it's
   * current (i.e. its procedure is executing), since Tk_HandleEvent
***************
*** 636,641 ****
--- 653,670 ----
      }
  
  #ifdef TK_USE_INPUT_METHODS
+ #ifdef I18N_IMPROVE
+       /*
+        * No need to create an input context for each and every window.
+        *
+        * Futhermore, XFilterEvent() should be called just after the
+        * event is fetched, since some IM server have protocol bugs that
+        * causes Tk freezing, so events EXCEPT THE INPUT METHODS THINGS
+        * should only be queued into Tcl event queue.
+        *
+        *		m-hirano
+        */
+ #else
      /*
       * Pass the event to the input method(s), if there are any, and
       * discard the event if the input method(s) insist.  Create the
***************
*** 656,661 ****
--- 685,691 ----
      if (XFilterEvent(eventPtr, None)) {
          goto done;
      }
+ #endif /* I18N_IMPROVE */
  #endif /* TK_USE_INPUT_METHODS */
  
      /*
***************
*** 909,914 ****
--- 939,955 ----
  	}
      }
  
+ #if defined(TK_USE_INPUT_METHODS) && defined(I18N_IMPROVE)
+     if (eventPtr->type == KeyPress && eventPtr->xkey.keycode == 0) {
+         /*
+          * No doubt this is a composed message from IM server.
+          * Tk can handle KeyPress event with zero keycode value 
+          * if state of the event is zero.
+          */
+         eventPtr->xkey.state = 0;
+     }
+ #endif /* TK_USE_INPUT_METHODS && I18N_IMPROVE */
+ 
      if ((dispPtr->delayedMotionPtr != NULL) && (position == TCL_QUEUE_TAIL)) {
  	if ((eventPtr->type == MotionNotify) && (eventPtr->xmotion.window
  		== dispPtr->delayedMotionPtr->event.xmotion.window)) {
***************
*** 1095,1103 ****
--- 1136,1154 ----
   *--------------------------------------------------------------
   */
  
+ #ifndef USE_TCL_STUBS
+ extern TclStubs tclStubs;
+ #   define Tcl_MainLoop tclStubs.tcl_MainLoop
+ #endif
+ 
  void
  Tk_MainLoop()
  {
+     if (Tcl_MainLoop) {
+ 	Tcl_SetMainLoop(Tk_GetNumMainWindows);
+ 	Tcl_MainLoop();
+ 	return;
+     }
      while (Tk_GetNumMainWindows() > 0) {
  	Tcl_DoOneEvent(0);
      }
