On Tue, Nov 20, 2001 at 04:22:30PM -0200, Ademar de Souza Reis Jr. wrote:
> Hi there.
> 
> Why XFree treats accents utilization differently?
> 
> Let me try to explain:
> 
> If I press "'" and "t" on the console, I get "'t", but if I press it on an
> xterm (or any other X application), I get *nothing*.
> 
> So, to write "can't", I have to press: "can' t" in XFree. This is very
> weird.
> 
> I'm sure there's a way to change it. Anyone knows how? (patch, config, etc?)
> 

Paulo Cesar sent me a patch to "correct" this. It's attached, and works
fine.

Thanks
   - Ademar

-- 
Ademar de Souza Reis Jr.
Conectiva S/A - http://www.conectiva.com.br

iEmacs is the best editor ^[0cwVIM^[:wq!

^[:wq!
Index: xc/lib/X11/IMWrap.c
===================================================================
RCS file: /opt/XFree86/xc/lib/X11/IMWrap.c,v
retrieving revision 3.6
diff -u -r3.6 IMWrap.c
--- xc/lib/X11/IMWrap.c 1998/12/20 11:56:55     3.6
+++ xc/lib/X11/IMWrap.c 2000/10/02 13:21:05
@@ -122,10 +122,13 @@
     char       *res_class;
 {
     XLCd       lcd = _XOpenLC( (char *)NULL );
+    XIM                im;
 
     if( !lcd )
        return( (XIM)NULL );
-    return (*lcd->methods->open_im) (lcd, display, rdb, res_name, res_class);
+    if ((im = (*lcd->methods->open_im) (lcd, display, rdb, res_name, res_class)) != 
+NULL)
+       display->dk_info->client_i18n = 1;
+    return im;
 }
 
 /*
Index: xc/lib/X11/KeyBind.c
===================================================================
RCS file: /opt/XFree86/xc/lib/X11/KeyBind.c,v
retrieving revision 1.3
diff -u -r1.3 KeyBind.c
--- xc/lib/X11/KeyBind.c        2000/01/31 14:40:58     1.3
+++ xc/lib/X11/KeyBind.c        2000/10/02 14:15:42
@@ -39,13 +39,10 @@
 #include <X11/keysymdef.h>
 #include <stdio.h>
 
-#include "XKBlib.h"
+#include "Ximint.h"
+#include "XlcPublic.h"
+#include "Xlcint.h"
 
-#ifdef USE_OWN_COMPOSE
-#include "imComp.h"
-
-#endif
-
 #ifdef XKB
 #define        XKeycodeToKeysym        _XKeycodeToKeysym
 #define        XKeysymToKeycode        _XKeysymToKeycode
@@ -528,6 +525,9 @@
     buffer[0] = c;
     return 1;
 }
+
+#define KEY_CODE_PROCESSED     0x1000
+#define KEY_CODE_COMPOSED      0x2000  
   
 /*ARGSUSED*/
 int
@@ -540,82 +540,119 @@
 {
     unsigned int modifiers;
     KeySym symbol;
-
-    if (! _XTranslateKey(event->display, event->keycode, event->state,
-                 &modifiers, &symbol))
+    Display *dpy = event->display;
+    DefTree *p, *pspace;
+    XLCd lcd = _XlcCurrentLC();
+
+    if (!keysym)
+       keysym = &symbol;
+
+    if (!dpy->dk_info->client_i18n) {
+       if (event->keycode & KEY_CODE_PROCESSED) {
+           *keysym = NoSymbol;
+           return 0;
+       }
+       if ((event->keycode & KEY_CODE_COMPOSED) && ((p = dpy->dk_info->composed) != 
+NULL)) {
+           int len;
+           *keysym = p->ks;
+           if (p->mb!='\0') {
+               len = strlen(p->mb);
+               if (len > nbytes) len = nbytes;
+               memcpy(buffer,p->mb,len);
+           } else {
+               len = _XTranslateKeySym(dpy,*keysym,event->state,
+                                       buffer,nbytes,
+                                       NULL);
+           }
+           return len;
+       }                  
+    }  
+
+ 
+     if (! _XTranslateKey(event->display, event->keycode, event->state,
+                 &modifiers, keysym))
        return 0;
 
-#ifdef USE_OWN_COMPOSE
-    if ( status ) {
-       static int been_here= 0;
-       if ( !been_here ) {
-           XimCompInitTables();
-           been_here = 1;
-       }
-       if ( !XimCompLegalStatus(status) ) {
-           status->compose_ptr = NULL;
-           status->chars_matched = 0;
-       }
-       if ( ((status->chars_matched>0)&&(status->compose_ptr!=NULL)) || 
-               XimCompIsComposeKey(symbol,event->keycode,status) ) {
-           XimCompRtrn rtrn;
-           switch (XimCompProcessSym(status,symbol,&rtrn)) {
-               case XIM_COMP_IGNORE:
-                   break;
-               case XIM_COMP_IN_PROGRESS:
-                   if ( keysym!=NULL )
-                       *keysym = NoSymbol;
-                   return 0;
-               case XIM_COMP_FAIL:
-               {
-                   int n = 0, len= 0;
-                   for (n=len=0;rtrn.sym[n]!=XK_VoidSymbol;n++) {
-                       if ( nbytes-len > 0 ) {
-                           len+= _XTranslateKeySym(event->display,rtrn.sym[n],
-                                                       event->state,
-                                                       buffer+len,nbytes-len);
-                       }
-                   }
-                   if ( keysym!=NULL ) {
-                       if ( n==1 )     *keysym = rtrn.sym[0];
-                       else            *keysym = NoSymbol;
-                   }
-                   return len;
-               }
-               case XIM_COMP_SUCCEED:
-               {
-                   int len,n = 0;
-
-                   symbol = rtrn.matchSym;
-                   if ( keysym!=NULL ) *keysym = symbol;
-                   if ( rtrn.str[0]!='\0' ) {
-                       strncpy(buffer,rtrn.str,nbytes-1);
-                       buffer[nbytes-1]= '\0';
-                       len = strlen(buffer);
-                   }
-                   else {
-                       len = _XTranslateKeySym(event->display,symbol,
-                                                       event->state,
-                                                       buffer,nbytes);
-                   }
-                   for (n=0;rtrn.sym[n]!=XK_VoidSymbol;n++) {
-                       if ( nbytes-len > 0 ) {
-                           len+= _XTranslateKeySym(event->display,rtrn.sym[n],
-                                                       event->state,
-                                                       buffer+len,nbytes-len);
-                       }
-                   }
-                   return len;
-               }
-           }
+    /* Now we have are ready for return, and we are going to do some
+       post-processing to collapse several keysyms into a composed
+       string. */
+
+    if (!(dpy->dk_info->client_i18n || dpy->dk_info->top)) {
+       FILE *fp;
+       char *name;
+
+       name = _XlcFileName(lcd, COMPOSE_FILE);
+       if (name == (char *)NULL)
+           goto dead_keys_failure;
+
+       fp = fopen(name, "r");
+       if (fp == (FILE *)NULL)
+           goto dead_keys_failure;
+       (void)_XimParseStringFile(fp, &dpy->dk_info->top);
+       fclose(fp);
+       dpy->dk_info->status = dpy->dk_info->top;
+       goto dead_keys_ok;
+dead_keys_failure:
+       dpy->dk_info->client_i18n = 1;
+dead_keys_ok:
+       if (name)
+           Xfree (name);
+    }
+    if ((dpy->dk_info->top == NULL) || (event->type != KeyPress) ||
+       IsModifierKey(*keysym))
+       goto no_compose_fallthrough;
+
+    pspace = NULL;
+    for (p = dpy->dk_info->status; p; p = p->next) {
+       if ((event->state & p->modifier_mask) == p->modifier) {
+           if (*keysym == p->keysym)
+               break;
+           if (XK_space == p->keysym)
+               pspace = p;
        }
     }
-#endif
+    if (!p && pspace) {
+       XPutBackEvent(dpy, (XEvent *)event);
+       p = pspace;
+    }
+    if (p) { /* Matched */
+       if (p->succession) { /* Intermediate */
+           dpy->dk_info->status = p->succession;
+           dpy->dk_info->composed = NULL;
+           *keysym = NoSymbol;
+           event->keycode |= KEY_CODE_PROCESSED;
+           return 0;
+       } else { /* Terminate (reached to leaf) */
+           int len, n = 0;
+
+           /* initialize internal state for next key sequence */
+           dpy->dk_info->composed = p;
+           dpy->dk_info->status = dpy->dk_info->top;
+           event->keycode |= KEY_CODE_COMPOSED;
+           return _XLookupString (event, buffer, nbytes, keysym, status);
+       }
+    } else { /* Unmatched */
+       dpy->dk_info->composed = NULL;
+       if (dpy->dk_info->status == dpy->dk_info->top) {
+       /* OK : not matched at top node */
+           goto no_compose_fallthrough;
+       } else {
+           /* Error (Sequence Unmatch occured) */
+           /* initialize internal state for next key sequence */
+           dpy->dk_info->status = dpy->dk_info->top;
+
+           /* eat up erroneous keysyms, when we can do nothing else. */
+           event->keycode |= KEY_CODE_PROCESSED;
+           *keysym = NoSymbol;
+           return 0;
+       }
+    }
 
     if (keysym)
        *keysym = symbol;
+no_compose_fallthrough:
     /* arguable whether to use (event->state & ~modifiers) here */
-    return _XTranslateKeySym(event->display, symbol, event->state,
+    return _XTranslateKeySym(event->display, *keysym, event->state,
                             buffer, nbytes);
 }
 
Index: xc/lib/X11/OpenDis.c
===================================================================
RCS file: /opt/XFree86/xc/lib/X11/OpenDis.c,v
retrieving revision 3.7
diff -u -r3.7 OpenDis.c
--- xc/lib/X11/OpenDis.c        2000/06/16 01:50:18     3.7
+++ xc/lib/X11/OpenDis.c        2000/10/02 14:01:58
@@ -25,6 +25,7 @@
 #define NEED_REPLIES
 #define NEED_EVENTS
 #include "Xlibint.h"
+#include "Ximint.h"
 #include <X11/Xtrans.h>
 #include <X11/Xatom.h>
 #include "bigreqstr.h"
@@ -236,6 +237,14 @@
        dpy->flushes            = NULL;
        dpy->xcmisc_opcode      = 0;
        dpy->xkb_info           = NULL;
+       if ((dpy->dk_info = (struct _XDead_keys_info *)Xcalloc
+            (1,sizeof(struct _XDead_keys_info))) == NULL) {
+           Xfree(dpy);
+           return(NULL);
+       }
+       dpy->dk_info->client_i18n = 0;
+       dpy->dk_info->top = dpy->dk_info->status =
+           dpy->dk_info->composed = NULL;
 
 /*
  * Setup other information in this display structure.
Index: xc/lib/X11/Xlibint.h
===================================================================
RCS file: /opt/XFree86/xc/lib/X11/Xlibint.h,v
retrieving revision 3.15
diff -u -r3.15 Xlibint.h
--- xc/lib/X11/Xlibint.h        2000/02/08 17:18:43     3.15
+++ xc/lib/X11/Xlibint.h        2000/10/02 14:03:09
@@ -61,6 +61,12 @@
     XGCValues values;  /* shadow structure of values */
 };
 
+struct _DefTree;
+struct _XDead_keys_info {
+       int client_i18n;
+       struct _DefTree *top, *status, *composed;
+};
+
 struct _XDisplay
 {
        XExtData *ext_data;     /* hook for extension to hang data */
@@ -183,6 +189,7 @@
        int xcmisc_opcode;      /* major opcode for XC-MISC */
        struct _XkbInfoRec *xkb_info; /* XKB info */
        struct _XtransConnInfo *trans_conn; /* transport connection object */
+       struct _XDead_keys_info *dk_info;
 };
 
 #define XAllocIDs(dpy,ids,n) (*(dpy)->idlist_alloc)(dpy,ids,n)
Index: xc/lib/X11/imLcFlt.c
===================================================================
RCS file: /opt/XFree86/xc/lib/X11/imLcFlt.c,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 imLcFlt.c
--- xc/lib/X11/imLcFlt.c        1996/01/03 06:58:36     1.1.1.3
+++ xc/lib/X11/imLcFlt.c        2000/10/02 14:08:13
@@ -46,7 +46,7 @@
     Xic                 ic = (Xic)client_data;
     KeySym      keysym;
     static char         buf[256];
-    DefTree    *p;
+    DefTree    *p, *pspace;
 
     if(   (ev->type != KeyPress)
        || (ev->xkey.keycode == 0)
@@ -58,11 +58,17 @@
     if(IsModifierKey(keysym))
        return (False);
 
-    for(p = ic->private.local.context; p; p = p->next) {
-       if(((ev->xkey.state & p->modifier_mask) == p->modifier) &&
-           (keysym == p->keysym)) {
-           break;
+    for(pspace = NULL, p = ic->private.local.context; p; p = p->next) {
+       if ((ev->xkey.state & p->modifier_mask) == p->modifier) {
+           if (keysym == p->keysym)
+               break;
+           if (XK_space == p->keysym)
+               pspace = p;
        }
+    }
+    if (!p && pspace) {
+       XPutBackEvent (d, ev);
+       p = pspace;
     }
 
     if(p) { /* Matched */

Reply via email to