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>
29 XComposeStatus compose_status= {0, 0};
31 // This is called after the main LyX window has been created
32 void InitLyXLookup(Display * display, Window window)
36 // This part could be done before opening display
37 setlocale(LC_CTYPE, "");
38 if (!XSupportsLocale()) {
40 << "InitLyXLookup: X does not support this locale."
44 if (!XSetLocaleModifiers("")) {
45 lyxerr[Debug::KEY] << "InitLyXLookup: Could not set modifiers "
46 "for this locale." << endl;
50 // This part will have to be done for each frame
51 xim = XOpenIM (display, 0, 0, 0);
53 xic = XCreateIC(xim, XNInputStyle,
54 XIMPreeditNothing | XIMStatusNothing,
55 XNClientWindow, window,
56 XNFocusWindow, window,
60 lyxerr[Debug::KEY] << "InitLyXLookup: could not create "
61 "an input context" << endl;
67 lyxerr[Debug::KEY] << "InitLyXLookup: could not open "
68 "an input method." << endl;
73 bool isDeadEvent(XEvent * event,
74 char * buffer_return, int bytes_buffer,
75 KeySym * keysym_return)
77 XLookupString(&event->xkey, buffer_return,
78 bytes_buffer, keysym_return,
80 // Can this be done safely in any other way?
81 // This is all the dead keys I know of in X11R6.1
84 || *keysym_return == XK_dead_grave
87 || *keysym_return == XK_dead_acute
89 #ifdef XK_dead_circumflex
90 || *keysym_return == XK_dead_circumflex
93 || *keysym_return == XK_dead_tilde
96 || *keysym_return == XK_dead_macron
99 || *keysym_return == XK_dead_breve
101 #ifdef XK_dead_abovedot
102 || *keysym_return == XK_dead_abovedot
104 #ifdef XK_dead_diaeresis
105 || *keysym_return == XK_dead_diaeresis
107 #ifdef XK_dead_abovering
108 || *keysym_return == XK_dead_abovering
110 #ifdef XK_dead_doubleacute
111 || *keysym_return == XK_dead_doubleacute
114 || *keysym_return == XK_dead_caron
116 #ifdef XK_dead_cedilla
117 || *keysym_return == XK_dead_cedilla
119 #ifdef XK_dead_ogonek
120 || *keysym_return == XK_dead_ogonek
123 || *keysym_return == XK_dead_iota
125 #ifdef XK_dead_voiced_sound
126 || *keysym_return == XK_dead_voiced_sound
128 #ifdef XK_dead_semivoiced_sound
129 || *keysym_return == XK_dead_semivoiced_sound
131 #ifdef XK_dead_belowdot
132 || *keysym_return == XK_dead_belowdot
140 // This is called instead of XLookupString()
141 int LyXLookupString(XEvent * event,
142 char * buffer_return, int bytes_buffer,
143 KeySym * keysym_return)
147 if (isDeadEvent(event, buffer_return, bytes_buffer,
151 if (XFilterEvent (event, None)) {
152 //lyxerr <<"XFilterEvent");
153 *keysym_return = NoSymbol;
156 if (event->type != KeyPress)
157 lyxerr << "LyXLookupString: wrong event type"
158 << event->type << endl;
159 Status status_return;
161 result = XmbLookupString(xic, &event->xkey, buffer_return,
162 bytes_buffer, keysym_return,
164 switch(status_return) {
166 //lyxerr <<"XLookupBoth");
169 //lyxerr <<"XLookupChars");
170 *keysym_return = NoSymbol;
173 //lyxerr <<"XLookupKeySym");
177 //lyxerr <<"default");
178 *keysym_return = NoSymbol;
183 result = XLookupString(&event->xkey, buffer_return,
184 bytes_buffer, keysym_return,
190 // This is called after the main window has been destroyed
191 void CloseLyXLookup()
194 lyxerr[Debug::KEY] << "CloseLyXLookup: destroying input context"
203 #else // We do not have XOpenIM, so we stick with normal XLookupString
205 #include <X11/Xlib.h>
206 #include <X11/Xutil.h>
208 XComposeStatus compose_status= {0, 0};
210 // This is called after the main LyX window has been created
211 void InitLyXLookup(Display *, Window )
216 // This is called instead of XLookupString(). I this particular case,
217 // this *is* XLookupString...
218 int LyXLookupString(XEvent * event,
219 char * buffer_return, int bytes_buffer,
220 KeySym * keysym_return)
222 return XLookupString(&event->xkey, buffer_return,
223 bytes_buffer, keysym_return,
227 // This is called after the main window has been destroyed
228 void CloseLyXLookup()
233 #endif // HAVE_XOPENIM