]> git.decadent.org.uk Git - ion3.git/blob - ioncore/xic.c
21339d633bfb547fa4afd9e86b86071c22f09bb9
[ion3.git] / ioncore / xic.c
1 /*
2  * ion/ioncore/xic.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2007. 
5  *
6  * Ion is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  */
11
12 #include <ctype.h>
13 #include <string.h>
14 #include "common.h"
15 #include "global.h"
16 #include "ioncore.h"
17
18
19 static XIM input_method=NULL;
20 static XIMStyle input_style=(XIMPreeditNothing|XIMStatusNothing);
21
22
23 void ioncore_init_xim(void)
24 {
25     char *p;
26     int i;
27     XIM xim=NULL;
28     XIMStyles *xim_styles = NULL;
29       bool found=FALSE;
30
31     if((p=XSetLocaleModifiers(""))!=NULL && *p)
32         xim=XOpenIM(ioncore_g.dpy, NULL, NULL, NULL);
33     
34     if(xim==NULL && (p=XSetLocaleModifiers("@im=none"))!=NULL && *p)
35         xim=XOpenIM(ioncore_g.dpy, NULL, NULL, NULL);
36
37     if(xim==NULL){
38         ioncore_warn_nolog(TR("Failed to open input method."));
39         return;
40     }
41     
42     if(XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL) || !xim_styles) {
43         ioncore_warn_nolog(TR("Input method doesn't support any style."));
44         XCloseIM(xim);
45         return;
46     }
47     
48     for(i=0; (ushort)i<xim_styles->count_styles; i++){
49         if(input_style==xim_styles->supported_styles[i]){
50             found=TRUE;
51             break;
52         }
53     }
54     
55     XFree(xim_styles);
56     
57     if(!found){
58         ioncore_warn_nolog(TR("input method doesn't support my preedit type."));
59         XCloseIM(xim);
60         return;
61     }
62
63     input_method=xim;    
64 }
65
66
67 XIC xwindow_create_xic(Window win)
68 {
69     /*static bool tried=FALSE;*/
70     XIC xic;
71     
72     /*
73     if(input_method==NULL && !tried){
74         init_xlocale();
75         tried=TRUE;
76     }*/
77     
78     if(input_method==NULL)
79         return NULL;
80     
81     xic=XCreateIC(input_method, XNInputStyle, input_style,
82                   XNClientWindow, win, XNFocusWindow, win,
83                   NULL);
84     
85     if(xic==NULL)
86         warn(TR("Failed to create input context."));
87
88     return xic;
89 }
90
91
92 bool window_create_xic(WWindow *wwin)
93 {
94     if(wwin->xic==NULL)
95         wwin->xic=xwindow_create_xic(wwin->win);
96     return (wwin->xic!=NULL);
97 }