x: fix XIM handling (8888e3)

This commit is contained in:
bakkeby 2020-03-24 15:41:43 +01:00
parent 2e2d10eca6
commit baf5955e45
1 changed files with 45 additions and 25 deletions

62
x.c
View File

@ -173,9 +173,10 @@ static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int);
static void xdrawglyph(Glyph, int, int); static void xdrawglyph(Glyph, int, int);
static void xclear(int, int, int, int); static void xclear(int, int, int, int);
static int xgeommasktogravity(int); static int xgeommasktogravity(int);
static void ximopen(Display *); static int ximopen(Display *);
static void ximinstantiate(Display *, XPointer, XPointer); static void ximinstantiate(Display *, XPointer, XPointer);
static void ximdestroy(XIM, XPointer, XPointer); static void ximdestroy(XIM, XPointer, XPointer);
static int xicdestroy(XIC, XPointer, XPointer);
static void xinit(int, int); static void xinit(int, int);
static void cresize(int, int); static void cresize(int, int);
static void xresize(int, int); static void xresize(int, int);
@ -972,46 +973,59 @@ xgeommasktogravity(int mask)
return SouthEastGravity; return SouthEastGravity;
} }
void int
ximopen(Display *dpy) ximopen(Display *dpy)
{ {
XIMCallback destroy = { .client_data = NULL, .callback = ximdestroy }; XIMCallback imdestroy = { .client_data = NULL, .callback = ximdestroy };
XICCallback icdestroy = { .client_data = NULL, .callback = xicdestroy };
if ((xw.ime.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) { xw.ime.xim = XOpenIM(xw.dpy, NULL, NULL, NULL);
XSetLocaleModifiers("@im=local"); if (xw.ime.xim == NULL)
if ((xw.ime.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) { return 0;
XSetLocaleModifiers("@im=");
if ((xw.ime.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) if (XSetIMValues(xw.ime.xim, XNDestroyCallback, &imdestroy, NULL))
die("XOpenIM failed. Could not open input device.\n"); fprintf(stderr, "XSetIMValues: "
} "Could not set XNDestroyCallback.\n");
}
if (XSetIMValues(xw.ime.xim, XNDestroyCallback, &destroy, NULL) != NULL)
die("XSetIMValues failed. Could not set input method value.\n");
xw.ime.xic = XCreateIC(xw.ime.xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
XNClientWindow, xw.win, XNFocusWindow, xw.win, NULL);
if (xw.ime.xic == NULL)
die("XCreateIC failed. Could not obtain input method.\n");
xw.ime.spotlist = XVaCreateNestedList(0, XNSpotLocation, &xw.ime.spot, xw.ime.spotlist = XVaCreateNestedList(0, XNSpotLocation, &xw.ime.spot,
NULL); NULL);
if (xw.ime.xic == NULL) {
xw.ime.xic = XCreateIC(xw.ime.xim, XNInputStyle,
XIMPreeditNothing | XIMStatusNothing,
XNClientWindow, xw.win,
XNFocusWindow, xw.win,
XNDestroyCallback, &icdestroy,
NULL);
}
if (xw.ime.xic == NULL)
fprintf(stderr, "XCreateIC: Could not create input context.\n");
return 1;
} }
void void
ximinstantiate(Display *dpy, XPointer client, XPointer call) ximinstantiate(Display *dpy, XPointer client, XPointer call)
{ {
ximopen(dpy); if (ximopen(dpy))
XUnregisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL, XUnregisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
ximinstantiate, NULL); ximinstantiate, NULL);
XFree(xw.ime.spotlist);
} }
void void
ximdestroy(XIM xim, XPointer client, XPointer call) ximdestroy(XIM xim, XPointer client, XPointer call)
{ {
xw.ime.xim = NULL; xw.ime.xim = NULL;
xw.ime.xic = NULL;
XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL, XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
ximinstantiate, NULL); ximinstantiate, NULL);
XFree(xw.ime.spotlist);
}
int
xicdestroy(XIC xim, XPointer client, XPointer call)
{
xw.ime.xic = NULL;
return 1;
} }
int int
@ -1308,7 +1322,10 @@ xinit(int cols, int rows)
xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap); xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap);
/* input methods */ /* input methods */
ximopen(xw.dpy); if (!ximopen(xw.dpy)) {
XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
ximinstantiate, NULL);
}
/* white cursor, black outline */ /* white cursor, black outline */
#if HIDECURSOR_PATCH #if HIDECURSOR_PATCH
@ -2131,7 +2148,10 @@ kpress(XEvent *ev)
if (IS_SET(MODE_KBDLOCK)) if (IS_SET(MODE_KBDLOCK))
return; return;
if (xw.ime.xic)
len = XmbLookupString(xw.ime.xic, e, buf, sizeof buf, &ksym, &status); len = XmbLookupString(xw.ime.xic, e, buf, sizeof buf, &ksym, &status);
else
len = XLookupString(e, buf, sizeof buf, &ksym, NULL);
#if KEYBOARDSELECT_PATCH #if KEYBOARDSELECT_PATCH
if ( IS_SET(MODE_KBDSELECT) ) { if ( IS_SET(MODE_KBDSELECT) ) {
if ( match(XK_NO_MOD, e->state) || if ( match(XK_NO_MOD, e->state) ||