IMs come in two flavors, front-end and back-end. Both types can use identical application programming interfaces, so you lose no generality by using back-end methods for our examples here.
To use an IM, follow these steps:
The syntax is
XIM XOpenIM(Display *dpy, XrmDataBase db, char *res_name, char *res_class);The res_name is the resource name of the application, res_class is the resource class, and db is the resource database that the input method should use for looking up resources private to itself. Any of these can be NULL. The fragment in Example 6-7 shows how easy it is to open an input method.
XIM im; im = XOpenIM(dpy, NULL, NULL, NULL); if (im == NULL) exit_with_error();XOpenIM() finds the IM appropriate for the current locale. If XSupportsLocale() has returned good status (see "Initialization for Xlib Programming") and XOpenIM() fails, something is amiss with the administration of the system.
XSetLocaleModifiers() determines configure locale modifiers. The local host X locale modifiers announcer (the XMODIFIERS environment variable) is appended to the modifier list to provide default values on the locale host. The modifier list argument is a null-terminated string containing zero or more concatenated expressions of this form:
@category=value
For example, if you want to connect Input Method Server xwnmo, set modifiers _XWNMO as follows:
Or, set environment variable XMODIFIERS to the stringXSetLocaleModifiers("@im=_XWNMO");
@im=_XWNMO
and execute
XSetLocaleModifiers("");
Note: The library routines are not prepared for the possibility of XSupportsLocale() succeeding and XOpenIM() failing, so it's up to application developers to deal with such an eventuality. (This circumstance could occur, for example, if the IM died after XSupportsLocale() was called.) This topic is under some debate in the MIT X consortium. If XSetLocaleModifiers() is wrong, XOpenIM() will fail. Most of the complexity associated with IM use comes from configuring an input context to work with the IM. Input contexts are discussed in "Input Contexts (ICs)".
To close an input method, call XCloseIM().