add xim support
c8f0a376
1 file(s) · +15 −3
| 58 | 58 | static Item *matches, *matchend; |
|
| 59 | 59 | static Item *prev, *curr, *next, *sel; |
|
| 60 | 60 | static Window win; |
|
| 61 | + | static XIC xic; |
|
| 61 | 62 | ||
| 62 | 63 | static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; |
|
| 63 | 64 | static char *(*fstrstr)(const char *, const char *) = strstr; |
|
| 230 | 231 | keypress(XKeyEvent *ev) { |
|
| 231 | 232 | char buf[32]; |
|
| 232 | 233 | KeySym ksym; |
|
| 234 | + | int len; |
|
| 235 | + | Status status; |
|
| 233 | 236 | ||
| 234 | - | XLookupString(ev, buf, sizeof buf, &ksym, NULL); |
|
| 237 | + | len = XmbLookupString(xic, ev, buf, sizeof(buf), &ksym, &status); |
|
| 235 | 238 | if(ev->state & ControlMask) { |
|
| 236 | 239 | KeySym lower, upper; |
|
| 237 | 240 | ||
| 273 | 276 | switch(ksym) { |
|
| 274 | 277 | default: |
|
| 275 | 278 | if(!iscntrl(*buf)) |
|
| 276 | - | insert(buf, strlen(buf)); |
|
| 279 | + | insert(buf, len); |
|
| 277 | 280 | break; |
|
| 278 | 281 | case XK_Delete: |
|
| 279 | 282 | if(text[cursor] == '\0') |
|
| 461 | 464 | run(void) { |
|
| 462 | 465 | XEvent ev; |
|
| 463 | 466 | ||
| 464 | - | while(!XNextEvent(dc->dpy, &ev)) |
|
| 467 | + | while(!XNextEvent(dc->dpy, &ev)) { |
|
| 468 | + | if(XFilterEvent(&ev, win)) |
|
| 469 | + | continue; |
|
| 465 | 470 | switch(ev.type) { |
|
| 466 | 471 | case Expose: |
|
| 467 | 472 | if(ev.xexpose.count == 0) |
|
| 479 | 484 | XRaiseWindow(dc->dpy, win); |
|
| 480 | 485 | break; |
|
| 481 | 486 | } |
|
| 487 | + | } |
|
| 482 | 488 | } |
|
| 483 | 489 | ||
| 484 | 490 | void |
|
| 486 | 492 | int x, y, screen = DefaultScreen(dc->dpy); |
|
| 487 | 493 | Window root = RootWindow(dc->dpy, screen); |
|
| 488 | 494 | XSetWindowAttributes swa; |
|
| 495 | + | XIM xim; |
|
| 489 | 496 | #ifdef XINERAMA |
|
| 490 | 497 | int n; |
|
| 491 | 498 | XineramaScreenInfo *info; |
|
| 541 | 548 | DefaultDepth(dc->dpy, screen), CopyFromParent, |
|
| 542 | 549 | DefaultVisual(dc->dpy, screen), |
|
| 543 | 550 | CWOverrideRedirect | CWBackPixmap | CWEventMask, &swa); |
|
| 551 | + | ||
| 552 | + | /* input methods */ |
|
| 553 | + | xim = XOpenIM(dc->dpy, NULL, NULL, NULL); |
|
| 554 | + | xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, |
|
| 555 | + | XNClientWindow, win, XNFocusWindow, win, NULL); |
|
| 544 | 556 | ||
| 545 | 557 | XMapRaised(dc->dpy, win); |
|
| 546 | 558 | resizedc(dc, mw, mh); |
|