better Input Method Editor (IME) support (35f7db)

This commit is contained in:
bakkeby 2020-03-24 11:25:39 +01:00
parent 9f1a2db7c5
commit e7cfd5ae16
11 changed files with 56 additions and 93 deletions

View File

@ -56,6 +56,7 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the
- [fixime](https://st.suckless.org/patches/fix_ime/) - [fixime](https://st.suckless.org/patches/fix_ime/)
- adds better Input Method Editor (IME) support - adds better Input Method Editor (IME) support
- (included in the base as per [35f7db](https://git.suckless.org/st/commit/e85b6b64660214121164ea97fb098eaa4935f7db.html))
- [fix-keyboard-input](https://st.suckless.org/patches/fix_keyboard_input/) - [fix-keyboard-input](https://st.suckless.org/patches/fix_keyboard_input/)
- allows cli applications to use all the fancy key combinations that are available to GUI applications - allows cli applications to use all the fancy key combinations that are available to GUI applications

View File

@ -1,49 +0,0 @@
void
ximopen(Display *dpy)
{
XIMCallback destroy = { .client_data = NULL, .callback = ximdestroy };
if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
XSetLocaleModifiers("@im=local");
if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
XSetLocaleModifiers("@im=");
if ((xw.xim = XOpenIM(xw.dpy,
NULL, NULL, NULL)) == NULL) {
die("XOpenIM failed. Could not open input"
" device.\n");
}
}
}
if (XSetIMValues(xw.xim, XNDestroyCallback, &destroy, NULL) != NULL)
die("XSetIMValues failed. Could not set input method value.\n");
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.\n");
}
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
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);
}

View File

@ -1 +0,0 @@
void xximspot(int, int);

View File

@ -1,4 +0,0 @@
static void ximopen(Display *);
static void ximinstantiate(Display *, XPointer, XPointer);
static void ximdestroy(XIM, XPointer, XPointer);
void xximspot(int, int);

View File

@ -5,9 +5,6 @@
#if EXTERNALPIPE_PATCH #if EXTERNALPIPE_PATCH
#include "externalpipe.h" #include "externalpipe.h"
#endif #endif
#if FIXIME_PATCH
#include "fixime_st.h"
#endif
#if ISO14755_PATCH #if ISO14755_PATCH
#include "iso14755.h" #include "iso14755.h"
#endif #endif

View File

@ -5,9 +5,6 @@
#if OPENCOPIED_PATCH #if OPENCOPIED_PATCH
#include "opencopied.c" #include "opencopied.c"
#endif #endif
#if FIXIME_PATCH
#include "fixime.c"
#endif
#if FIXKEYBOARDINPUT_PATCH #if FIXKEYBOARDINPUT_PATCH
#include "fixkeyboardinput.c" #include "fixkeyboardinput.c"
#endif #endif

View File

@ -5,9 +5,6 @@
#if OPENCOPIED_PATCH #if OPENCOPIED_PATCH
#include "opencopied.h" #include "opencopied.h"
#endif #endif
#if FIXIME_PATCH
#include "fixime_x.h"
#endif
#if FONT2_PATCH #if FONT2_PATCH
#include "font2.h" #include "font2.h"
#endif #endif

View File

@ -68,11 +68,6 @@
*/ */
#define EXTERNALPIPE_PATCH 0 #define EXTERNALPIPE_PATCH 0
/* This patch adds better Input Method Editor (IME) support.
* https://st.suckless.org/patches/fix_ime/
*/
#define FIXIME_PATCH 0
/* This patch allows command line applications to use all the fancy key combinations /* This patch allows command line applications to use all the fancy key combinations
* that are available to GUI applications. * that are available to GUI applications.
* https://st.suckless.org/patches/fix_keyboard_input/ * https://st.suckless.org/patches/fix_keyboard_input/

2
st.c
View File

@ -2752,9 +2752,7 @@ draw(void)
term.ocx, term.ocy, term.line[term.ocy][term.ocx]); term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
term.ocx = cx, term.ocy = term.c.y; term.ocx = cx, term.ocy = term.c.y;
xfinishdraw(); xfinishdraw();
#if FIXIME_PATCH
xximspot(term.ocx, term.ocy); xximspot(term.ocx, term.ocy);
#endif // FIXIME_PATCH
} }
void void

1
win.h
View File

@ -39,3 +39,4 @@ void xsetmode(int, unsigned int);
void xsetpointermotion(int); void xsetpointermotion(int);
void xsetsel(char *); void xsetsel(char *);
int xstartdraw(void); int xstartdraw(void);
void xximspot(int, int);

77
x.c
View File

@ -166,6 +166,9 @@ 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 void ximinstantiate(Display *, XPointer, XPointer);
static void ximdestroy(XIM, 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);
@ -946,6 +949,46 @@ xgeommasktogravity(int mask)
return SouthEastGravity; return SouthEastGravity;
} }
void
ximopen(Display *dpy)
{
XIMCallback destroy = { .client_data = NULL, .callback = ximdestroy };
if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
XSetLocaleModifiers("@im=local");
if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
XSetLocaleModifiers("@im=");
if ((xw.xim = XOpenIM(xw.dpy,
NULL, NULL, NULL)) == NULL) {
die("XOpenIM failed. Could not open input"
" device.\n");
}
}
}
if (XSetIMValues(xw.xim, XNDestroyCallback, &destroy, NULL) != NULL)
die("XSetIMValues failed. Could not set input method value.\n");
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.\n");
}
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);
}
int int
xloadfont(Font *f, FcPattern *pattern) xloadfont(Font *f, FcPattern *pattern)
{ {
@ -1196,10 +1239,7 @@ xinit(int cols, int rows)
xw.attrs.background_pixel = dc.col[defaultbg].pixel; xw.attrs.background_pixel = dc.col[defaultbg].pixel;
xw.attrs.border_pixel = dc.col[defaultbg].pixel; xw.attrs.border_pixel = dc.col[defaultbg].pixel;
xw.attrs.bit_gravity = NorthWestGravity; xw.attrs.bit_gravity = NorthWestGravity;
xw.attrs.event_mask = FocusChangeMask | KeyPressMask xw.attrs.event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask
#if FIXIME_PATCH
| KeyReleaseMask
#endif // FIXIME_PATCH
| ExposureMask | VisibilityChangeMask | StructureNotifyMask | ExposureMask | VisibilityChangeMask | StructureNotifyMask
| ButtonMotionMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask
#if ST_EMBEDDER_PATCH #if ST_EMBEDDER_PATCH
@ -1243,26 +1283,7 @@ 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 */
#if FIXIME_PATCH
ximopen(xw.dpy); ximopen(xw.dpy);
#else
if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
XSetLocaleModifiers("@im=local");
if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
XSetLocaleModifiers("@im=");
if ((xw.xim = XOpenIM(xw.dpy,
NULL, NULL, NULL)) == NULL) {
die("XOpenIM failed. Could not open input"
" device.\n");
}
}
}
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.\n");
#endif // FIXIME_PATCH
/* white cursor, black outline */ /* white cursor, black outline */
#if HIDECURSOR_PATCH #if HIDECURSOR_PATCH
@ -1885,6 +1906,16 @@ xfinishdraw(void)
defaultfg : defaultbg].pixel); 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 void
expose(XEvent *ev) expose(XEvent *ev)
{ {