*** unix/tkUnixEvent.c.orig	Fri Apr 16 03:51:46 1999
--- unix/tkUnixEvent.c	Sun Jan 16 17:43:02 2000
***************
*** 161,167 ****
          (void) XSync(dispPtr->display, False);
          (void) XCloseDisplay(dispPtr->display);
      }
!     
      ckfree((char *) dispPtr);
  }
  
--- 161,172 ----
          (void) XSync(dispPtr->display, False);
          (void) XCloseDisplay(dispPtr->display);
      }
! #ifdef I18N_IMPROVE
!     if (displayPtr->imEncoding != NULL) {
! 	Tcl_FreeEncoding(displayPtr->imEncoding);
!     }
! #endif /* I18N_IMPROVE */    
! 
      ckfree((char *) dispPtr);
  }
  
***************
*** 246,251 ****
--- 251,268 ----
  
      while (numFound > 0) {
  	XNextEvent(display, &event);
+ #ifdef I18N_IMPROVE
+ 	/*
+ 	 * To avoid Tk freezing by IM server's protocol bugs,
+ 	 * Re-check queued event after an event is filterd.
+ 	 *
+ 	 *	m-hirano
+ 	 */
+ 	if (XFilterEvent(&event, None) == True) {
+ 	    numFound = XEventsQueued(display, QueuedAlready);
+ 	    continue;
+ 	}
+ #endif /* I18N_IMPROVE */
  	Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
  	numFound--;
      }
