Renamed package to ion1, and made it conflict with package 'ion'.
[ion1.git] / src / xic.c
blob58b48a31ca07a7c43050fbd4559388f64283d590
1 /*
2 * ion/xic.c
4 * Copyright (c) Tuomo Valkonen 1999-2001.
5 * See the included file LICENSE for details.
6 */
8 #include <ctype.h>
9 #include <string.h>
10 #include "common.h"
11 #include "global.h"
13 /*#define X_LOCALE*/
14 #include <X11/Xlocale.h>
17 static XIM input_method=NULL;
18 static XIMStyle input_style=(XIMPreeditNothing|XIMStatusNothing);
21 static void init_xlocale(void)
23 char *p;
24 int i;
25 XIM xim=NULL;
26 XIMStyles *xim_styles = NULL;
27 bool found=FALSE;
29 if((p=XSetLocaleModifiers(""))!=NULL && *p)
30 xim=XOpenIM(wglobal.dpy, NULL, NULL, NULL);
32 if(xim==NULL && (p=XSetLocaleModifiers("@im=none"))!=NULL && *p)
33 xim=XOpenIM(wglobal.dpy, NULL, NULL, NULL);
35 if(xim==NULL){
36 warn("Failed to open input method");
37 return;
40 if(XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL) || !xim_styles) {
41 warn("input method doesn't support any style");
42 XCloseIM(xim);
43 return;
46 for(i=0; (ushort)i<xim_styles->count_styles; i++){
47 if(input_style==xim_styles->supported_styles[i]){
48 found=TRUE;
49 break;
53 XFree(xim_styles);
55 if(!found){
56 warn("input method doesn't support my preedit type");
57 XCloseIM(xim);
58 return;
61 input_method=xim;
65 XIC create_xic(Window win)
67 static bool tried=FALSE;
68 XIC xic;
70 if(input_method==NULL && !tried){
71 init_xlocale();
72 tried=TRUE;
75 if(input_method==NULL)
76 return NULL;
78 xic=XCreateIC(input_method, XNInputStyle, input_style,
79 XNClientWindow, win, XNFocusWindow, win,
80 NULL);
82 if(xic==NULL)
83 warn("Failed to create input context");
85 return xic;