Index: sqUnixX11.c
===================================================================
RCS file: /cvsroot/squeak/squeak/platforms/unix/vm-display-X11/sqUnixX11.c,v
retrieving revision 1.15
diff -c -r1.15 sqUnixX11.c
*** sqUnixX11.c	3 Apr 2004 21:48:57 -0000	1.15
--- sqUnixX11.c	8 Oct 2004 10:03:30 -0000
***************
*** 1024,1044 ****
  }
  
  
! int recode(int charCode)
  {
!   if (charCode >= 128)
!     {
!       unsigned char buf[32];
!       unsigned char out[32];
!       buf[0]= charCode;
!       if (convertChars((char *)buf, 1, uxXWinEncoding,
! 		       (char *)out, sizeof(out),
! 		       sqTextEncoding, 0, 1))
! 	charCode= out[0];
! #    if defined(DEBUG_EVENTS)
!       fprintf(stderr, "  8-bit: %d=%02x [%c->%c]\n", charCode, charCode,
! 	      (char *)uxXWinEncoding, (char *)sqTextEncoding);
! #    endif
      }
    return charCode;
  }
--- 1024,1044 ----
  }
  
  
! int recode(char *buffer, int count)
  {
!   unsigned char out[32];
!   int charCode= -1;
!   int resLength= 0;
!   resLength= convertChars(buffer, count, uxXWinEncoding,
!                           (char *)out, sizeof(out),
!                           sqTextEncoding, 0, 1);
!   if (resLength > 0)
!     {
!       charCode= out[0]; /* only single-byte chars for now*/
! #     if defined(DEBUG_EVENTS)
!       fprintf(stderr, "  8-bit: %d=%02x [%s->%s]\n", charCode, charCode,
!               (char *)uxXWinEncoding, (char *)sqTextEncoding);
! #     endif
      }
    return charCode;
  }
***************
*** 1050,1071 ****
    static XIM im= 0;
    static XIC ic= 0;
    static int lastKey= -1;
  
    if (!initialised)
      {
        initialised= 1;
        if (!setlocale(LC_CTYPE, ""))
! 	{
! 	  fprintf(stderr, "setlocale() failed (check values of LC_CTYPE, LANG and LC_ALL)\n");
! 	  goto revertInput;
! 	}
        if (!(im= XOpenIM(stDisplay, 0, 0, 0)))
! 	{
! 	  fprintf(stderr, "XOpenIM() failed\n");
! 	  goto revertInput;
! 	}
        else
! 	{
  	  if (!(ic= XCreateIC(im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
  			      XNClientWindow, stWindow, 0)))
  	    {
--- 1050,1080 ----
    static XIM im= 0;
    static XIC ic= 0;
    static int lastKey= -1;
+   const char *xLocale= 0;
  
    if (!initialised)
      {
        initialised= 1;
        if (!setlocale(LC_CTYPE, ""))
!       {
!         fprintf(stderr, "setlocale() failed (check values of LC_CTYPE, LANG and LC_ALL)\n");
!         goto revertInput;
!       }
        if (!(im= XOpenIM(stDisplay, 0, 0, 0)))
!       {
!         fprintf(stderr, "XOpenIM() failed\n");
!         goto revertInput;
!       }
        else
!       {
! 		xLocale = XLocaleOfIM(im);
! 		if (strstr(xLocale, "UTF-8") || strstr(xLocale, "UTF8"))
!           {
!             setEncoding(&uxXWinEncoding, "UTF-8");
!             textEncodingUTF8 = 1;
!             /* TODO set other encodings to utf8, too? */
!           }
! 			
  	  if (!(ic= XCreateIC(im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
  			      XNClientWindow, stWindow, 0)))
  	    {
***************
*** 1081,1087 ****
  	      mask |= xwa.your_event_mask;
  	      XSelectInput(stDisplay, stWindow, mask);
  	    }
! 	}
      }
  
    if (KeyPress != xevt->type)
--- 1090,1096 ----
  	      mask |= xwa.your_event_mask;
  	      XSelectInput(stDisplay, stWindow, mask);
  	    }
! 	  }
      }
  
    if (KeyPress != xevt->type)
***************
*** 1096,1113 ****
  #endif
  
    {
!     unsigned char string[128];	/* way too much */
      KeySym symbolic;
      Status status;
      int count= XmbLookupString(ic, (XKeyPressedEvent *)xevt,
  			       string, sizeof(string), &symbolic, &status);
      switch (status)
        {
        case XLookupNone:		/* still composing */
! #	 if defined(DEBUG_CONV)
! 	fprintf(stderr, "x2sqKey XLookupNone\n");
! #	 endif
! 	return -1;
  
        case XLookupChars:
  #	 if defined(DEBUG_CONV)
--- 1105,1127 ----
  #endif
  
    {
!     unsigned char string[8];
      KeySym symbolic;
      Status status;
      int count= XmbLookupString(ic, (XKeyPressedEvent *)xevt,
  			       string, sizeof(string), &symbolic, &status);
      switch (status)
        {
+       case XBufferOverflow:
+ #	    if defined(DEBUG_CONV)
+         fprintf(stderr, "buffer overflow in XmbLookupString: %i", count);
+ #	    endif
+         return -1;
        case XLookupNone:		/* still composing */
! #	  if defined(DEBUG_CONV)
!         fprintf(stderr, "x2sqKey XLookupNone\n");
! #	  endif
! 	    return -1;
  
        case XLookupChars:
  #	 if defined(DEBUG_CONV)
***************
*** 1117,1123 ****
  #	 if defined(DEBUG_CONV)
  	fprintf(stderr, "x2sqKey XLookupBoth count %d\n", count);
  #	 endif
! 	lastKey= (count ? recode(string[0]) : -1);
  #	 if defined(DEBUG_CONV)
  	fprintf(stderr, "x2sqKey == %d\n", lastKey);
  #	 endif
--- 1131,1137 ----
  #	 if defined(DEBUG_CONV)
  	fprintf(stderr, "x2sqKey XLookupBoth count %d\n", count);
  #	 endif
! 	lastKey= (count ? recode(string, count) : -1);
  #	 if defined(DEBUG_CONV)
  	fprintf(stderr, "x2sqKey == %d\n", lastKey);
  #	 endif
***************
*** 1171,1177 ****
        modifierState= charCode >> 8;
        charCode &= 0xff;
      }
!   return recode(charCode);
  }
  
  
--- 1185,1191 ----
        modifierState= charCode >> 8;
        charCode &= 0xff;
      }
!   return recode((char *)buf, nConv);
  }
  
  
