1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX team.
9 * ====================================================== */
14 // This part is the full blown Input Method manager for X11R5 and up.
15 // For the plain-and-old-X11R4 version, see later.
18 #include <X11/Xutil.h>
19 #include <X11/keysym.h>
31 XComposeStatus compose_status= {0, 0};
33 // This is called after the main LyX window has been created
34 void InitLyXLookup(Display * display, Window window)
38 // This part could be done before opening display
39 setlocale(LC_CTYPE, "");
40 if (!XSupportsLocale()) {
42 << "InitLyXLookup: X does not support this locale."
46 if (!XSetLocaleModifiers("")) {
47 lyxerr[Debug::KEY] << "InitLyXLookup: Could not set modifiers "
48 "for this locale." << endl;
52 // This part will have to be done for each frame
53 xim = XOpenIM (display, 0, 0, 0);
55 xic = XCreateIC(xim, XNInputStyle,
56 XIMPreeditNothing | XIMStatusNothing,
57 XNClientWindow, window,
58 XNFocusWindow, window,
62 lyxerr[Debug::KEY] << "InitLyXLookup: could not create "
63 "an input context" << endl;
69 lyxerr[Debug::KEY] << "InitLyXLookup: could not open "
70 "an input method." << endl;
75 bool isDeadEvent(XEvent * event,
76 char * buffer_return, int bytes_buffer,
77 KeySym * keysym_return)
79 XLookupString(&event->xkey, buffer_return,
80 bytes_buffer, keysym_return,
82 // Can this be done safely in any other way?
83 // This is all the dead keys I know of in X11R6.1
86 || *keysym_return == XK_dead_grave
89 || *keysym_return == XK_dead_acute
91 #ifdef XK_dead_circumflex
92 || *keysym_return == XK_dead_circumflex
95 || *keysym_return == XK_dead_tilde
98 || *keysym_return == XK_dead_macron
101 || *keysym_return == XK_dead_breve
103 #ifdef XK_dead_abovedot
104 || *keysym_return == XK_dead_abovedot
106 #ifdef XK_dead_diaeresis
107 || *keysym_return == XK_dead_diaeresis
109 #ifdef XK_dead_abovering
110 || *keysym_return == XK_dead_abovering
112 #ifdef XK_dead_doubleacute
113 || *keysym_return == XK_dead_doubleacute
116 || *keysym_return == XK_dead_caron
118 #ifdef XK_dead_cedilla
119 || *keysym_return == XK_dead_cedilla
121 #ifdef XK_dead_ogonek
122 || *keysym_return == XK_dead_ogonek
125 || *keysym_return == XK_dead_iota
127 #ifdef XK_dead_voiced_sound
128 || *keysym_return == XK_dead_voiced_sound
130 #ifdef XK_dead_semivoiced_sound
131 || *keysym_return == XK_dead_semivoiced_sound
133 #ifdef XK_dead_belowdot
134 || *keysym_return == XK_dead_belowdot
142 // This is called instead of XLookupString()
143 int LyXLookupString(XEvent * event,
144 char * buffer_return, int bytes_buffer,
145 KeySym * keysym_return)
149 if (isDeadEvent(event, buffer_return, bytes_buffer,
153 if (XFilterEvent (event, None)) {
154 //lyxerr <<"XFilterEvent");
155 *keysym_return = NoSymbol;
158 if (event->type != KeyPress)
159 lyxerr << "LyXLookupString: wrong event type"
160 << event->type << endl;
161 Status status_return;
163 result = XmbLookupString(xic, &event->xkey, buffer_return,
164 bytes_buffer, keysym_return,
166 switch(status_return) {
168 //lyxerr <<"XLookupBoth");
171 //lyxerr <<"XLookupChars");
172 *keysym_return = NoSymbol;
175 //lyxerr <<"XLookupKeySym");
179 //lyxerr <<"default");
180 *keysym_return = NoSymbol;
185 result = XLookupString(&event->xkey, buffer_return,
186 bytes_buffer, keysym_return,
192 // This is called after the main window has been destroyed
193 void CloseLyXLookup()
196 lyxerr[Debug::KEY] << "CloseLyXLookup: destroying input context"
205 #else // We do not have XOpenIM, so we stick with normal XLookupString
207 #include <X11/Xlib.h>
208 #include <X11/Xutil.h>
210 XComposeStatus compose_status= {0, 0};
212 // This is called after the main LyX window has been created
213 void InitLyXLookup(Display *, Window )
218 // This is called instead of XLookupString(). I this particular case,
219 // this *is* XLookupString...
220 int LyXLookupString(XEvent * event,
221 char * buffer_return, int bytes_buffer,
222 KeySym * keysym_return)
224 return XLookupString(&event->xkey, buffer_return,
225 bytes_buffer, keysym_return,
229 // This is called after the main window has been destroyed
230 void CloseLyXLookup()
235 #endif // HAVE_XOPENIM