From c8f0a3763843966ad480e22b18fe61ff54dc9a39 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Sun, 16 Oct 2011 17:21:33 +0100 Subject: add xim support --- dmenu.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'dmenu.c') diff --git a/dmenu.c b/dmenu.c index f105b56..6d1cdf0 100644 --- a/dmenu.c +++ b/dmenu.c @@ -58,6 +58,7 @@ static Item *items = NULL; static Item *matches, *matchend; static Item *prev, *curr, *next, *sel; static Window win; +static XIC xic; static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; static char *(*fstrstr)(const char *, const char *) = strstr; @@ -230,8 +231,10 @@ void keypress(XKeyEvent *ev) { char buf[32]; KeySym ksym; + int len; + Status status; - XLookupString(ev, buf, sizeof buf, &ksym, NULL); + len = XmbLookupString(xic, ev, buf, sizeof(buf), &ksym, &status); if(ev->state & ControlMask) { KeySym lower, upper; @@ -273,7 +276,7 @@ keypress(XKeyEvent *ev) { switch(ksym) { default: if(!iscntrl(*buf)) - insert(buf, strlen(buf)); + insert(buf, len); break; case XK_Delete: if(text[cursor] == '\0') @@ -461,7 +464,9 @@ void run(void) { XEvent ev; - while(!XNextEvent(dc->dpy, &ev)) + while(!XNextEvent(dc->dpy, &ev)) { + if(XFilterEvent(&ev, win)) + continue; switch(ev.type) { case Expose: if(ev.xexpose.count == 0) @@ -479,6 +484,7 @@ run(void) { XRaiseWindow(dc->dpy, win); break; } + } } void @@ -486,6 +492,7 @@ setup(void) { int x, y, screen = DefaultScreen(dc->dpy); Window root = RootWindow(dc->dpy, screen); XSetWindowAttributes swa; + XIM xim; #ifdef XINERAMA int n; XineramaScreenInfo *info; @@ -542,6 +549,11 @@ setup(void) { DefaultVisual(dc->dpy, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &swa); + /* input methods */ + xim = XOpenIM(dc->dpy, NULL, NULL, NULL); + xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, + XNClientWindow, win, XNFocusWindow, win, NULL); + XMapRaised(dc->dpy, win); resizedc(dc, mw, mh); drawmenu(); -- cgit v1.2.3-13-gbd6f From 24565608cbf8572211a4a1b3fe7bbe1cf0c4fbbd Mon Sep 17 00:00:00 2001 From: Connor Lane Smith Date: Mon, 17 Oct 2011 01:18:57 +0100 Subject: xim: check for corner cases --- dmenu.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'dmenu.c') diff --git a/dmenu.c b/dmenu.c index 6d1cdf0..895542d 100644 --- a/dmenu.c +++ b/dmenu.c @@ -230,11 +230,13 @@ insert(const char *str, ssize_t n) { void keypress(XKeyEvent *ev) { char buf[32]; - KeySym ksym; int len; + KeySym ksym = NoSymbol; Status status; - len = XmbLookupString(xic, ev, buf, sizeof(buf), &ksym, &status); + len = XmbLookupString(xic, ev, buf, sizeof buf, &ksym, &status); + if(status == XBufferOverflow) + return; if(ev->state & ControlMask) { KeySym lower, upper; @@ -549,10 +551,10 @@ setup(void) { DefaultVisual(dc->dpy, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &swa); - /* input methods */ + /* input methods */ xim = XOpenIM(dc->dpy, NULL, NULL, NULL); xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, - XNClientWindow, win, XNFocusWindow, win, NULL); + XNClientWindow, win, XNFocusWindow, win, NULL); XMapRaised(dc->dpy, win); resizedc(dc, mw, mh); -- cgit v1.2.3-13-gbd6f