[wiki] [sites] [st][fix_ime] Fix st ime behavior || Ivan Tham

From: <git_AT_suckless.org>
Date: Sat, 02 Feb 2019 13:18:53 +0100

commit 0556853f906c938396d798f95cd4eaa287b7adf8
Author: Ivan Tham <pickfire_AT_riseup.net>
Date: Sat Feb 2 20:17:19 2019 +0800

    [st][fix_ime] Fix st ime behavior

diff --git a/st.suckless.org/patches/fix_ime/index.md b/st.suckless.org/patches/fix_ime/index.md
new file mode 100644
index 00000000..1c2dd755
--- /dev/null
+++ b/st.suckless.org/patches/fix_ime/index.md
_AT_@ -0,0 +1,22 @@
+Fix IME
+=======
+
+Description
+-----------
+Better Input Method Editor (IME) support. Features:
+
+* Over-the-spot pre-editing style, pre-edit data placed over insertion point
+* Restart IME without breaking st
+
+TODO:
+
+* Allow swapping input methods (E.g. ctrl + alt)
+* Automatically pickup IME if st started before IME
+
+Download
+--------
+* [st-ime-20190202-3be4cf1.diff](st-ime-20190202-3be4cf1.diff)
+
+Authors
+-------
+* Ivan Tham - <pickfire_AT_riseup.net>
diff --git a/st.suckless.org/patches/fix_ime/st-ime-20190202-3be4cf1.diff b/st.suckless.org/patches/fix_ime/st-ime-20190202-3be4cf1.diff
new file mode 100644
index 00000000..2458016a
--- /dev/null
+++ b/st.suckless.org/patches/fix_ime/st-ime-20190202-3be4cf1.diff
_AT_@ -0,0 +1,123 @@
+diff --git a/st.c b/st.c
+index b8e6077..cf8687e 100644
+--- a/st.c
++++ b/st.c
+_AT_@ -2594,6 +2594,7 @@ draw(void)
+ term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
+ term.ocx = cx, term.ocy = term.c.y;
+ xfinishdraw();
++ xximspot(term.ocx, term.ocy);
+ }
+
+ void
+diff --git a/win.h b/win.h
+index 31f327d..a6ef1b9 100644
+--- a/win.h
++++ b/win.h
+_AT_@ -36,3 +36,4 @@ void xsetmode(int, unsigned int);
+ void xsetpointermotion(int);
+ void xsetsel(char *);
+ int xstartdraw(void);
++void xximspot(int, int);
+diff --git a/x.c b/x.c
+index 0422421..714098f 100644
+--- a/x.c
++++ b/x.c
+_AT_@ -139,6 +139,9 @@ static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int);
+ static void xdrawglyph(Glyph, int, int);
+ static void xclear(int, int, int, int);
+ static int xgeommasktogravity(int);
++static void ximopen(Display *);
++static void ximinstantiate(Display *, XPointer, XPointer);
++static void ximdestroy(XIM, XPointer, XPointer);
+ static void xinit(int, int);
+ static void cresize(int, int);
+ static void xresize(int, int);
+_AT_@ -996,6 +999,46 @@ xunloadfonts(void)
+ xunloadfont(&dc.ibfont);
+ }
+
++void
++ximopen(Display *dpy)
++{
++ XIMCallback destroy = { .client_data = NULL, .callback = ximdestroy };
++
++ if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
++ XSetLocaleModifiers("_AT_im=local");
++ if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
++ XSetLocaleModifiers("_AT_im=");
++ if ((xw.xim = XOpenIM(xw.dpy,
++ NULL, NULL, NULL)) == NULL) {
++ die("XOpenIM failed. Could not open input"
++ " device.
");
++ }
++ }
++ }
++ if (XSetIMValues(xw.xim, XNDestroyCallback, &destroy, NULL) != NULL)
++ die("XSetIMValues failed. Could not set input method value.
");
++ xw.xic = XCreateIC(xw.xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
++ XNClientWindow, xw.win, XNFocusWindow, xw.win, NULL);
++ if (xw.xic == NULL)
++ die("XCreateIC failed. Could not obtain input method.
");
++}
++
++void
++ximinstantiate(Display *dpy, XPointer client, XPointer call)
++{
++ ximopen(dpy);
++ XUnregisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
++ ximinstantiate, NULL);
++}
++
++void
++ximdestroy(XIM xim, XPointer client, XPointer call)
++{
++ xw.xim = NULL;
++ XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
++ ximinstantiate, NULL);
++}
++
+ void
+ xinit(int cols, int rows)
+ {
+_AT_@ -1061,22 +1104,7 @@ xinit(int cols, int rows)
+ xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap);
+
+ /* input methods */
+- if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
+- XSetLocaleModifiers("_AT_im=local");
+- if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
+- XSetLocaleModifiers("_AT_im=");
+- if ((xw.xim = XOpenIM(xw.dpy,
+- NULL, NULL, NULL)) == NULL) {
+- die("XOpenIM failed. Could not open input"
+- " device.
");
+- }
+- }
+- }
+- xw.xic = XCreateIC(xw.xim, XNInputStyle, XIMPreeditNothing
+- | XIMStatusNothing, XNClientWindow, xw.win,
+- XNFocusWindow, xw.win, NULL);
+- if (xw.xic == NULL)
+- die("XCreateIC failed. Could not obtain input method.
");
++ ximopen(xw.dpy);
+
+ /* white cursor, black outline */
+ cursor = XCreateFontCursor(xw.dpy, mouseshape);
+_AT_@ -1554,6 +1582,16 @@ xfinishdraw(void)
+ defaultfg : defaultbg].pixel);
+ }
+
++void
++xximspot(int x, int y)
++{
++ XPoint spot = { borderpx + x * win.cw, borderpx + (y + 1) * win.ch };
++ XVaNestedList attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL);
++
++ XSetICValues(xw.xic, XNPreeditAttributes, attr, NULL);
++ XFree(attr);
++}
++
+ void
+ expose(XEvent *ev)
+ {
Received on Sat Feb 02 2019 - 13:18:53 CET

This archive was generated by hypermail 2.3.0 : Sat Feb 02 2019 - 13:24:26 CET