X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;ds=sidebyside;f=dmenu.c;h=6d1cdf01e4b5a69353745ca0217f38340e774bbf;hb=c8f0a3763843966ad480e22b18fe61ff54dc9a39;hp=9d479f9be982563d948ac3b6473f85df7a54a800;hpb=50207344084b385839cef251f77f5129dc85874e;p=dmenu.git diff --git a/dmenu.c b/dmenu.c index 9d479f9..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') @@ -454,13 +457,16 @@ readstdin(void) { if(items) items[i].text = NULL; inputw = maxstr ? textw(dc, maxstr) : 0; + lines = MIN(lines, i); } 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) @@ -478,6 +484,7 @@ run(void) { XRaiseWindow(dc->dpy, win); break; } + } } void @@ -485,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; @@ -509,8 +517,8 @@ setup(void) { XWindowAttributes wa; XGetInputFocus(dc->dpy, &w, &di); - if(w != root && XGetWindowAttributes(dc->dpy, w, &wa)) - XTranslateCoordinates(dc->dpy, root, root, wa.x, wa.y, &x, &y, &dw); + if(w != root && w != PointerRoot && w != None && XGetWindowAttributes(dc->dpy, w, &wa)) + XTranslateCoordinates(dc->dpy, w, root, wa.x, wa.y, &x, &y, &dw); else XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du); for(i = 0; i < n-1; i++) @@ -541,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();