imLcFlt.c revision 1ab64890
1/* $Xorg: imLcFlt.c,v 1.3 2000/08/17 19:45:13 cpqbld Exp $ */
2/******************************************************************
3
4              Copyright 1992 by Fuji Xerox Co., Ltd.
5              Copyright 1992, 1994 by FUJITSU LIMITED
6
7Permission to use, copy, modify, distribute, and sell this software
8and its documentation for any purpose is hereby granted without fee,
9provided that the above copyright notice appear in all copies and
10that both that copyright notice and this permission notice appear
11in supporting documentation, and that the name of Fuji Xerox,
12FUJITSU LIMITED not be used in advertising or publicity pertaining
13to distribution of the software without specific, written prior
14permission. Fuji Xerox, FUJITSU LIMITED make no representations
15about the suitability of this software for any purpose.
16It is provided "as is" without express or implied warranty.
17
18FUJI XEROX, FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH
19REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
20MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJI XEROX,
21FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
22DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
23OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
24TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
25PERFORMANCE OF THIS SOFTWARE.
26
27  Author   : Kazunori Nishihara	Fuji Xerox
28  Modifier : Takashi Fujiwara   FUJITSU LIMITED
29                                fujiwara@a80.tech.yk.fujitsu.co.jp
30
31******************************************************************/
32
33#define NEED_EVENTS
34#ifdef HAVE_CONFIG_H
35#include <config.h>
36#endif
37#include "Xlibint.h"
38#include <X11/keysym.h>
39#include "Xlcint.h"
40#include "Ximint.h"
41
42Bool
43_XimLocalFilter(d, w, ev, client_data)
44    Display	*d;
45    Window	 w;
46    XEvent	*ev;
47    XPointer	 client_data;
48{
49    Xic		 ic = (Xic)client_data;
50    KeySym	 keysym;
51    static char	 buf[256];
52    DefTree	*b = ic->private.local.base.tree;
53    DTIndex	 t;
54
55    if(ev->xkey.keycode == 0)
56	return (False);
57
58    XLookupString((XKeyEvent *)ev, buf, sizeof(buf), &keysym, NULL);
59
60    if(IsModifierKey(keysym))
61	return (False);
62
63    if(keysym >= XK_braille_dot_1 && keysym <= XK_braille_dot_8) {
64	if(ev->type == KeyPress) {
65	    ic->private.local.brl_pressed |=
66		1<<(keysym-XK_braille_dot_1);
67	} else {
68	    if(!ic->private.local.brl_committing
69		    || ev->xkey.time - ic->private.local.brl_release_start > 300) {
70	    	ic->private.local.brl_committing = ic->private.local.brl_pressed;
71		ic->private.local.brl_release_start = ev->xkey.time;
72	    }
73	    ic->private.local.brl_pressed &= ~(1<<(keysym-XK_braille_dot_1));
74	    if(!ic->private.local.brl_pressed) {
75		if(ic->private.local.brl_committing) {
76		    ic->private.local.brl_committed =
77			ic->private.local.brl_committing;
78		    ic->private.local.composed = 0;
79		    ev->type = KeyPress;
80		    ev->xkey.keycode = 0;
81		    _XPutBackEvent(d, ev);
82		}
83	    }
84	}
85	return(True);
86    }
87
88    if(   (ev->type != KeyPress)
89       || (((Xim)ic->core.im)->private.local.top == 0 ) )
90	return(False);
91
92    for(t = ic->private.local.context; t; t = b[t].next) {
93	if(((ev->xkey.state & b[t].modifier_mask) == b[t].modifier) &&
94	   (keysym == b[t].keysym))
95	    break;
96    }
97
98    if(t) { /* Matched */
99	if(b[t].succession) { /* Intermediate */
100	    ic->private.local.context = b[t].succession;
101	    return(True);
102	} else { /* Terminate (reached to leaf) */
103	    ic->private.local.composed = t;
104	    ic->private.local.brl_committed = 0;
105	    /* return back to client KeyPressEvent keycode == 0 */
106	    ev->xkey.keycode = 0;
107	    _XPutBackEvent(d, ev);
108	    /* initialize internal state for next key sequence */
109	    ic->private.local.context = ((Xim)ic->core.im)->private.local.top;
110	    return(True);
111	}
112    } else { /* Unmatched */
113	if(ic->private.local.context == ((Xim)ic->core.im)->private.local.top) {
114	    return(False);
115	}
116	/* Error (Sequence Unmatch occured) */
117	/* initialize internal state for next key sequence */
118	ic->private.local.context = ((Xim)ic->core.im)->private.local.top;
119	return(True);
120    }
121}
122