diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-04-05 10:17:19 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-04-05 10:17:19 -0400 |
commit | d63232774dae78b0ee270a47671be9fd70d99969 (patch) | |
tree | 7f282f0cd8845f49934246ab7629583f636b7eac /xlib.c | |
parent | b97c939bdc404cb38a82f2d425a3ab1812c68f05 (diff) | |
download | runes-d63232774dae78b0ee270a47671be9fd70d99969.tar.gz runes-d63232774dae78b0ee270a47671be9fd70d99969.zip |
move the input processing into the backend
Diffstat (limited to 'xlib.c')
-rw-r--r-- | xlib.c | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -59,6 +59,49 @@ cairo_surface_t *runes_surface_create(RunesWindow *w) return cairo_xlib_surface_create(w->dpy, w->w, vis, 240, 80); } +void runes_window_prepare_input(RunesWindow *w) +{ + unsigned long mask; + + XGetICValues(w->ic, XNFilterEvents, &mask, NULL); + XSelectInput(w->dpy, w->w, mask|KeyPressMask); + XSetICFocus(w->ic); +} + +void runes_window_read_key(RunesWindow *w, char **outbuf, size_t *outlen) +{ + static char *buf = NULL; + static size_t len = 8; + XEvent e; + Status s; + KeySym sym; + size_t chars; + + if (!buf) { + buf = malloc(len); + } + + XNextEvent(w->dpy, &e); + if (XFilterEvent(&e, None) || e.type != KeyPress) { + *outlen = 0; + *outbuf = buf; + return; + } + + for (;;) { + chars = Xutf8LookupString(w->ic, &e.xkey, buf, len - 1, &sym, &s); + if (s == XBufferOverflow) { + len = chars + 1; + buf = realloc(buf, len); + continue; + } + break; + } + + *outlen = chars; + *outbuf = buf; +} + void runes_window_destroy(RunesWindow *w) { XDestroyWindow(w->dpy, w->w); |