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