summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Carbonneaux2015-07-13 06:20:36 -0400
committerQuentin Carbonneaux2015-07-13 06:20:36 -0400
commit2c096d22b6195cf917aa000dfae5f268fc4d52ee (patch)
tree036584098cd297275043088d0f6d1784a23eb829
parenta1228b495615decaa5a1cc35163687a049f759db (diff)
add rough support for input methods
-rw-r--r--x11.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/x11.c b/x11.c
index 5ac955b..dc8d608 100644
--- a/x11.c
+++ b/x11.c
@@ -33,6 +33,8 @@ static Window win;
static Pixmap pbuf;
XftDraw *xft;
static int w, h;
+static XIC xic;
+static XIM xim;
static int
init()
@@ -60,7 +62,7 @@ init()
swa.bit_gravity = NorthWestGravity;
XChangeWindowAttributes(d, win, CWBackingStore|CWBitGravity, &swa);
XStoreName(d, win, "ED");
- XSelectInput(d, win, StructureNotifyMask|ButtonPressMask|ButtonReleaseMask|Button1MotionMask|KeyPressMask|ExposureMask);
+ XSelectInput(d, win, StructureNotifyMask|ButtonPressMask|ButtonReleaseMask|Button1MotionMask|KeyPressMask|ExposureMask|FocusChangeMask);
/* simulate an initial resize and map the window */
ce.type = ConfigureNotify;
@@ -69,6 +71,11 @@ init()
XSendEvent(d, win, False, StructureNotifyMask, (XEvent *)&ce);
XMapWindow(d, win);
+ /* input methods */
+ xim = XOpenIM(d, 0, 0, 0);
+ if (xim)
+ xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing|XIMStatusNothing, XNClientWindow, win, XNFocusWindow, win, NULL);
+
/* allocate font */
font = XftFontOpenName(d, screen, FONTNAME);
if (!font)
@@ -217,8 +224,20 @@ nextevent(GEvent *gev)
while (XPending(d)) {
XNextEvent(d, &e);
+ if (XFilterEvent(&e, None))
+ continue;
switch (e.type) {
+ case FocusIn:
+ if (xic)
+ XSetICFocus(xic);
+ break;
+
+ case FocusOut:
+ if (xic)
+ XUnsetICFocus(xic);
+ break;
+
case Expose:
sync();
continue;
@@ -282,9 +301,13 @@ nextevent(GEvent *gev)
int len;
char buf[8];
KeySym key;
+ Status status;
gev->type = GKey;
- len = XLookupString(&e.xkey, buf, 8, &key, 0);
+ if (xic)
+ len = Xutf8LookupString(xic, &e.xkey, buf, 8, &key, &status);
+ else
+ len = XLookupString(&e.xkey, buf, 8, &key, 0);
switch (key) {
case XK_F1:
case XK_F2:
@@ -326,7 +349,7 @@ nextevent(GEvent *gev)
continue;
if (buf[0] == '\r')
buf[0] = '\n';
- gev->key = buf[0];
+ utf8_decode_rune(&gev->key, (unsigned char *)buf, 8);
break;
}
break;